/**
* Initialize a Vector from a PETSc Vec object. Note that we do not copy
- * the vector and we do not obtain ownership, so we do not destroy the
- * PETSc object in the destructor.
+ * the vector.
*/
explicit VectorBase(const Vec &v);
// Make the reference class a friend.
friend class internal::VectorReference;
- /**
- * Specifies if the vector is the owner of the PETSc Vec. This is true if
- * it got created by this class and determines if it gets destroyed in
- * the destructor.
- */
- bool obtained_ownership;
-
/**
* Collective set or add operation: This function is invoked by the
* collective @p set and @p add with the @p add_values flag set to the
: vector(nullptr)
, ghosted(false)
, last_action(::dealii::VectorOperation::unknown)
- , obtained_ownership(true)
{
Assert(MultithreadInfo::is_running_single_threaded(),
ExcMessage("PETSc does not support multi-threaded access, set "
, ghosted(v.ghosted)
, ghost_indices(v.ghost_indices)
, last_action(::dealii::VectorOperation::unknown)
- , obtained_ownership(true)
{
Assert(MultithreadInfo::is_running_single_threaded(),
ExcMessage("PETSc does not support multi-threaded access, set "
, vector(v)
, ghosted(false)
, last_action(::dealii::VectorOperation::unknown)
- , obtained_ownership(false)
{
Assert(MultithreadInfo::is_running_single_threaded(),
ExcMessage("PETSc does not support multi-threaded access, set "
"the thread limit to 1 in MPI_InitFinalize()."));
+
+ const PetscErrorCode ierr =
+ PetscObjectReference(reinterpret_cast<PetscObject>(vector));
+ AssertNothrow(ierr == 0, ExcPETScError(ierr));
+ (void)ierr;
}
VectorBase::~VectorBase()
{
- if (obtained_ownership)
- {
- const PetscErrorCode ierr = VecDestroy(&vector);
- AssertNothrow(ierr == 0, ExcPETScError(ierr));
- (void)ierr;
- }
+ const PetscErrorCode ierr = VecDestroy(&vector);
+ AssertNothrow(ierr == 0, ExcPETScError(ierr));
+ (void)ierr;
}
void
VectorBase::clear()
{
- if (obtained_ownership)
- {
- const PetscErrorCode ierr = VecDestroy(&vector);
- AssertThrow(ierr == 0, ExcPETScError(ierr));
- }
+ const PetscErrorCode ierr = VecDestroy(&vector);
+ AssertThrow(ierr == 0, ExcPETScError(ierr));
ghosted = false;
ghost_indices.clear();
- last_action = ::dealii::VectorOperation::unknown;
- obtained_ownership = true;
+ last_action = ::dealii::VectorOperation::unknown;
}