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

Skip to content

A couple small changes for subvectors #3896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/numerics/numeric_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ class NumericVector : public ReferenceCountedObject<NumericVector<T>>,
* rows. This is currently only implemented for
* PetscVectors.
*/
virtual void restore_subvector(NumericVector<T> &&, const std::vector<numeric_index_type> &)
virtual void restore_subvector(std::unique_ptr<NumericVector<T>>,
const std::vector<numeric_index_type> &)
{
libmesh_not_implemented();
}
Expand Down
2 changes: 1 addition & 1 deletion include/numerics/petsc_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class PetscVector final : public NumericVector<T>
virtual std::unique_ptr<NumericVector<T>>
get_subvector(const std::vector<numeric_index_type> & rows) override;

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

private:
Expand Down
11 changes: 9 additions & 2 deletions src/numerics/petsc_vector.C
Original file line number Diff line number Diff line change
Expand Up @@ -1426,15 +1426,17 @@ PetscVector<T>::get_subvector(const std::vector<numeric_index_type> & rows)
ierr = VecGetSubVector(_vec, parent_is, &subvec);
LIBMESH_CHKERR(ierr);

this->_is_closed = false;

return std::make_unique<PetscVector<T>>(subvec, this->comm());
}

template <typename T>
void
PetscVector<T>::restore_subvector(NumericVector<T> && subvector,
PetscVector<T>::restore_subvector(std::unique_ptr<NumericVector<T>> subvector,
const std::vector<numeric_index_type> & rows)
{
auto * const petsc_subvector = cast_ptr<PetscVector<T> *>(&subvector);
auto * const petsc_subvector = cast_ptr<PetscVector<T> *>(subvector.get());

// Construct index set
WrappedPetsc<IS> parent_is;
Expand All @@ -1448,6 +1450,11 @@ PetscVector<T>::restore_subvector(NumericVector<T> && subvector,
Vec subvec = petsc_subvector->vec();
ierr = VecRestoreSubVector(_vec, parent_is, &subvec);
LIBMESH_CHKERR(ierr);

if (this->type() == GHOSTED)
VecGhostUpdateBeginEnd(this->comm(), _vec, INSERT_VALUES, SCATTER_FORWARD);

this->_is_closed = true;
}

//------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/systems/condensed_eigen_system.C
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ CondensedEigenSystem::copy_sub_to_super(const NumericVector<Number> & sub,
super.local_size());
auto super_sub_view = super.get_subvector(local_non_condensed_dofs_vector);
*super_sub_view = sub;
super.restore_subvector(std::move(*super_sub_view), local_non_condensed_dofs_vector);
super.restore_subvector(std::move(super_sub_view), local_non_condensed_dofs_vector);
}

void
Expand All @@ -279,7 +279,7 @@ CondensedEigenSystem::copy_super_to_sub(NumericVector<Number> & super,
super.local_size());
auto super_sub_view = super.get_subvector(local_non_condensed_dofs_vector);
sub = *super_sub_view;
super.restore_subvector(std::move(*super_sub_view), local_non_condensed_dofs_vector);
super.restore_subvector(std::move(super_sub_view), local_non_condensed_dofs_vector);
}

void
Expand Down