<h3>General</h3>
<ol>
+ <li><p>New: Added a new constructor for PETScWrappers::Vector that takes
+ an existing PETSc Vec that was created by the user and is only wrapped for
+ usage.
+ <br>
+ (TH, 2010/12/03)
+ </p></li>
+
<li><p>Updated: The version of the <a href="http://www.threadingbuildingblocks.org">Threading
Building Blocks (TBB)</a> shipped with deal.II has been updated
to release 3.0 Update 3 (Commercially aligned version).
template <typename Number>
explicit Vector (const dealii::Vector<Number> &v);
+ /**
+ * Construct it from an existing PETSc
+ * Vector of type Vec. Note: this does
+ * not copy the contents and just keeps
+ * a pointer. You need to make sure the
+ * vector is not used twice at the same
+ * time or destroyed while in use. This
+ * class does not destroy the PETSc
+ * object. Handle with care!
+ */
+ explicit Vector (const Vec & v);
+
/**
* Copy-constructor the values from a
* PETSc wrapper vector class.
*this = v;
}
+
+
+ inline
+ Vector::Vector (const Vec & v)
+ :
+ VectorBase(v)
+ {}
inline
Vector &
Vector::operator = (const MPI::Vector &v)
{
+ int ierr;
+ if (attained_ownership)
+ {
// the petsc function we call wants to
// generate the vector itself, so destroy
// the old one first
- int ierr = VecDestroy (vector);
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ ierr = VecDestroy (vector);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+ }
+ attained_ownership = true;
+
// then do the gather
// operation. <rant>petsc has changed its
// interface again, and replaced a single
*/
VectorBase (const VectorBase &v);
+ /**
+ * Initialize a Vector from a PETSc Vec
+ * object. Note that we do not copy the
+ * vector and we do not attain
+ * ownership, so we do not destroy the
+ * PETSc object in the destructor.
+ */
+ explicit VectorBase (const Vec & v);
+
/**
* Destructor
*/
*/
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 destructed in
+ * the destructor.
+ */
+ bool attained_ownership;
+
/**
* Collective set or add
* operation: This function is
// AssertThrow (ierr == 0, ExcPETScError(ierr));
// so let's go the slow way:
- int ierr;
- ierr = VecDestroy (vector);
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ if (attained_ownership)
+ {
+ int ierr = VecDestroy (vector);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+ }
create_vector (n);
}
const int ierr
= VecCreateSeq (PETSC_COMM_SELF, n, &vector);
AssertThrow (ierr == 0, ExcPETScError(ierr));
+ attained_ownership = true;
}
}
VectorBase::VectorBase ()
:
ghosted(false),
- last_action (LastAction::none)
+ last_action (LastAction::none),
+ attained_ownership(true)
{}
Subscriptor (),
ghosted(v.ghosted),
ghost_indices(v.ghost_indices),
- last_action (LastAction::none)
+ last_action (LastAction::none),
+ attained_ownership(true)
{
int ierr = VecDuplicate (v.vector, &vector);
AssertThrow (ierr == 0, ExcPETScError(ierr));
}
+
+ VectorBase::VectorBase (const Vec & v)
+ :
+ Subscriptor (),
+ vector(v),
+ ghosted(false),
+ last_action (LastAction::none),
+ attained_ownership(false)
+ {}
+
+
+
VectorBase::~VectorBase ()
{
- const int ierr = VecDestroy (vector);
- AssertThrow (ierr == 0, ExcPETScError(ierr));
+ if (attained_ownership)
+ {
+ const int ierr = VecDestroy (vector);
+ AssertThrow (ierr == 0, ExcPETScError(ierr));
+ }
}