* elements.
*/
template <typename Number>
- explicit Vector (const Epetra_Map &InputMap,
+ explicit Vector (const Epetra_Map &InputMap,
const dealii::Vector<Number> &v);
/**
/**
* Reinit functionality. This
- * function sets the calling
- * vector to the dimension and
- * the parallel distribution of
- * the input vector, but does not
- * copy the elements in
- * <tt>v</tt>. If <tt>fast</tt>
- * is not <tt>true</tt>, the
- * elements in the vector are
- * initialized with zero,
- * otherwise the content will be
- * left unchanged and the user
- * has to set all elements.
+ * function sets the calling vector
+ * to the dimension and the parallel
+ * distribution of the input vector,
+ * but does not copy the elements in
+ * <tt>v</tt>. If <tt>fast</tt> is
+ * not <tt>true</tt>, the elements in
+ * the vector are initialized with
+ * zero, otherwise the content will
+ * be left unchanged and the user has
+ * to set all elements.
*
- * This class has a third
- * possible argument,
+ * Reinit functionality. This class
+ * also has a third possible
+ * argument,
* <tt>allow_different_maps</tt>,
* that allows for an exchange of
* data between two equal-sized
* vectors (but being distributed
* differently among the
- * processors). A trivial
- * application of this function
- * is to generate a replication
- * of a whole vector on each
- * machine, when the calling
- * vector is build according to
- * the localized vector class
+ * processors). A trivial application
+ * of this function is to generate a
+ * replication of a whole vector on
+ * each machine, when the calling
+ * vector is build according to the
+ * localized vector class
* TrilinosWrappers::Vector, and
* <tt>v</tt> is a distributed
- * vector. In this case, the
- * variable <tt>fast</tt> needs
- * to be set to <tt>false</tt>,
- * since it does not make sense
- * to exchange data between
- * differently parallelized
+ * vector. In this case, the variable
+ * <tt>fast</tt> needs to be set to
+ * <tt>false</tt>, since it does not
+ * make sense to exchange data
+ * between differently parallelized
* vectors without touching the
* elements.
*/
// that a direct access is not possible.
std::vector<int> indices (size);
std::vector<double> values (size);
- for (unsigned int i=0; i<size; ++i)
+ for (int i=0; i<size; ++i)
{
indices[i] = map.GID(i);
values[i] = v(i);
const int ierr = vector->ReplaceGlobalValues (size, &indices[0],
&values[0]);
- AssertThrow (ierr == 0, ExcTrilinosError());
+ AssertThrow (ierr == 0, VectorBase::ExcTrilinosError());
}
Vector &
Vector::operator = (const ::dealii::Vector<Number> &v)
{
+ if (size() != v.size())
+ {
#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
- map = Epetra_Map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD));
+ map = Epetra_Map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD));
#else
- map = Epetra_Map (v.size(), 0, Epetra_SerialComm());
+ map = Epetra_Map (v.size(), 0, Epetra_SerialComm());
#endif
-
- vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
-
- const int min_my_id = map.MinMyGID();
- const int size = map.NumMyElements();
-
- Assert (map.MaxLID() == size-1,
- ExcDimensionMismatch(map.MaxLID(), size-1));
-
- // Need to copy out values, since the
- // deal.II might not use doubles, so
- // that a direct access is not possible.
- std::vector<int> indices (size);
- std::vector<double> values (size);
- for (unsigned int i=0; i<size; ++i)
- {
- indices[i] = map.GID(i);
- values[i] = v(i);
}
-
- const int ierr = vector->ReplaceGlobalValues (size, &indices[0],
- &values[0]);
- AssertThrow (ierr == 0, ExcTrilinosError());
+
+ *this = Vector(map, v);
return *this;
}
* the vector to the size
* specified by <tt>n</tt>.
*/
- void reinit (const unsigned int n);
+ void reinit (const unsigned int n,
+ const bool fast = false);
/**
* Initialization with an
/**
* Reinit function. Takes the
- * information of a
- * Vector and copies
- * everything to the calling
- * vector.
+ * information of a Vector and copies
+ * everything to the calling vector,
+ * now also allowing different maps.
*/
void reinit (const VectorBase &V,
const bool fast = false,
template <typename number>
Vector::Vector (const dealii::Vector<number> &v)
- :
-#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
- map (v.size(), 0, Epetra_MpiComm(MPI_COMM_WORLD))
-#else
- map (v.size(), 0, Epetra_SerialComm())
-#endif
{
- vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
-
- std::vector<int> indices (v.size());
- std::vector<double> values (v.size());
- for (unsigned int i=0; i<v.size(); ++i)
- {
- indices[i] = map.GID(i);
- values[i] = v(i);
- }
-
- const int ierr = vector->ReplaceGlobalValues((int)v.size(),
- &indices[0], &values[0]);
-
- AssertThrow (ierr == 0, ExcTrilinosError(ierr));
+ *this = v;
}
// that a direct access is not possible.
std::vector<int> indices (size);
std::vector<double> values (size);
- for (unsigned int i=0; i<size; ++i)
+ for (int i=0; i<size; ++i)
{
indices[i] = map.GID(i);
values[i] = v(i);
const int ierr = vector->ReplaceGlobalValues (size, &indices[0],
&values[0]);
- AssertThrow (ierr == 0, ExcTrilinosError());
+ AssertThrow (ierr == 0, VectorBase::ExcTrilinosError(ierr));
return *this;
}
else
{
vector.reset();
- map = v.map;
+ map = Epetra_Map(v.vector->Map().NumGlobalElements(),
+ v.vector->Map().NumMyElements(),
+ v.vector->Map().IndexBase(),
+ v.vector->Map().Comm());
vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(*v.vector));
}
void
- Vector::reinit (const unsigned int n)
+ Vector::reinit (const unsigned int n,
+ const bool fast)
{
- vector.reset();
-
- if (map.NumGlobalElements() != (int)n)
+ if (size() != n)
{
+ vector.reset();
+
#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
map = Epetra_LocalMap ((int)n, 0, Epetra_MpiComm(MPI_COMM_WORLD));
#else
map = Epetra_LocalMap ((int)n, 0, Epetra_SerialComm());
#endif
- }
- last_action = Zero;
+ last_action = Zero;
- vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector (map));
+ vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector (map));
+ }
}
if (map.NumGlobalElements() != input_map.NumGlobalElements())
{
- map = Epetra_LocalMap (input_map.NumGlobalElements(),0,
+ map = Epetra_LocalMap (input_map.NumGlobalElements(),
+ input_map.IndexBase(),
input_map.Comm());
}
{
vector.reset();
if (map.SameAs(v.vector->Map()) == false)
- map = Epetra_LocalMap (v.vector->GlobalLength(),0,v.vector->Comm());
+ map = Epetra_LocalMap (v.vector->GlobalLength(),
+ v.vector->Map().IndexBase(),
+ v.vector->Comm());
vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
last_action = Zero;
Vector &
Vector::operator = (const MPI::Vector &v)
{
- if (vector->Map().SameAs(v.vector->Map()) == false)
+ if (size() != v.size())
{
- map = Epetra_LocalMap (v.vector->Map().NumGlobalElements(), 0,
+ map = Epetra_LocalMap (v.vector->Map().NumGlobalElements(),
+ v.vector->Map().IndexBase(),
v.vector->Comm());
vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
}
{
if (vector->Map().SameAs(v.vector->Map()) == false)
{
- map = Epetra_LocalMap (v.vector->Map().NumGlobalElements(), 0,
+ map = Epetra_LocalMap (v.vector->Map().NumGlobalElements(),
+ v.vector->Map().IndexBase(),
v.vector->Comm());
vector = std::auto_ptr<Epetra_FEVector> (new Epetra_FEVector(map));
}