Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10d830f

Browse files
authored
Merge pull request #3896 from lindsayad/subvector-api-changes
A couple small changes for subvectors
2 parents 1e7a1cc + eaa757f commit 10d830f

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

include/numerics/numeric_vector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T>>,
749749
* rows. This is currently only implemented for
750750
* PetscVectors.
751751
*/
752-
virtual void restore_subvector(NumericVector<T> &&, const std::vector<numeric_index_type> &)
752+
virtual void restore_subvector(std::unique_ptr<NumericVector<T>>,
753+
const std::vector<numeric_index_type> &)
753754
{
754755
libmesh_not_implemented();
755756
}

include/numerics/petsc_vector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class PetscVector final : public NumericVector<T>
349349
virtual std::unique_ptr<NumericVector<T>>
350350
get_subvector(const std::vector<numeric_index_type> & rows) override;
351351

352-
virtual void restore_subvector(NumericVector<T> && subvector,
352+
virtual void restore_subvector(std::unique_ptr<NumericVector<T>> subvector,
353353
const std::vector<numeric_index_type> & rows) override;
354354

355355
private:

src/numerics/petsc_vector.C

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,15 +1426,17 @@ PetscVector<T>::get_subvector(const std::vector<numeric_index_type> & rows)
14261426
ierr = VecGetSubVector(_vec, parent_is, &subvec);
14271427
LIBMESH_CHKERR(ierr);
14281428

1429+
this->_is_closed = false;
1430+
14291431
return std::make_unique<PetscVector<T>>(subvec, this->comm());
14301432
}
14311433

14321434
template <typename T>
14331435
void
1434-
PetscVector<T>::restore_subvector(NumericVector<T> && subvector,
1436+
PetscVector<T>::restore_subvector(std::unique_ptr<NumericVector<T>> subvector,
14351437
const std::vector<numeric_index_type> & rows)
14361438
{
1437-
auto * const petsc_subvector = cast_ptr<PetscVector<T> *>(&subvector);
1439+
auto * const petsc_subvector = cast_ptr<PetscVector<T> *>(subvector.get());
14381440

14391441
// Construct index set
14401442
WrappedPetsc<IS> parent_is;
@@ -1448,6 +1450,11 @@ PetscVector<T>::restore_subvector(NumericVector<T> && subvector,
14481450
Vec subvec = petsc_subvector->vec();
14491451
ierr = VecRestoreSubVector(_vec, parent_is, &subvec);
14501452
LIBMESH_CHKERR(ierr);
1453+
1454+
if (this->type() == GHOSTED)
1455+
VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);
1456+
1457+
this->_is_closed = true;
14511458
}
14521459

14531460
//------------------------------------------------------------------

src/systems/condensed_eigen_system.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ CondensedEigenSystem::copy_sub_to_super(const NumericVector<Number> & sub,
267267
super.local_size());
268268
auto super_sub_view = super.get_subvector(local_non_condensed_dofs_vector);
269269
*super_sub_view = sub;
270-
super.restore_subvector(std::move(*super_sub_view), local_non_condensed_dofs_vector);
270+
super.restore_subvector(std::move(super_sub_view), local_non_condensed_dofs_vector);
271271
}
272272

273273
void
@@ -279,7 +279,7 @@ CondensedEigenSystem::copy_super_to_sub(NumericVector<Number> & super,
279279
super.local_size());
280280
auto super_sub_view = super.get_subvector(local_non_condensed_dofs_vector);
281281
sub = *super_sub_view;
282-
super.restore_subvector(std::move(*super_sub_view), local_non_condensed_dofs_vector);
282+
super.restore_subvector(std::move(super_sub_view), local_non_condensed_dofs_vector);
283283
}
284284

285285
void

0 commit comments

Comments
 (0)