From: kronbichler Date: Thu, 4 Sep 2008 07:52:08 +0000 (+0000) Subject: Add a function to the vector. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b0619b63307aed31b8976456455ce91444009c4;p=dealii-svn.git Add a function to the vector. git-svn-id: https://svn.dealii.org/trunk@16741 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/trilinos_vector.h b/deal.II/lac/include/lac/trilinos_vector.h index f5902e11ec..f50e788425 100755 --- a/deal.II/lac/include/lac/trilinos_vector.h +++ b/deal.II/lac/include/lac/trilinos_vector.h @@ -329,7 +329,7 @@ namespace TrilinosWrappers Vector (); /** * One of the constructors that - * actually build a vector. This + * actually builds a vector. This * one requires prior knowledge * of the size of the vector and * a communicator from @@ -341,16 +341,17 @@ namespace TrilinosWrappers * from the beginning to the end, * so you might want to use some * more advanced mapping and the - * third constructor with argument + * constructor with argument * Epetra_Map. */ Vector (unsigned int GlobalSize, Epetra_Comm &Comm); /** - * Third constructor. It takes an + * This constructor takes an * Epetra_Map that already knows how * to distribute the individual - * components among the MPI processors. + * components among the MPI processors, + * including the size of the vector. */ Vector (const Epetra_Map &InputMap); @@ -358,7 +359,7 @@ namespace TrilinosWrappers * Copy constructor. Sets the dimension * to that of the given vector and uses * the map of that vector, but - * does not copies any element. Instead, + * does not copy any element. Instead, * the memory will remain untouched * in case fast is false and * initialized with zero otherwise. @@ -490,8 +491,7 @@ namespace TrilinosWrappers * a pair (i,i+n), where * n=local_size(). */ - std::pair - local_range () const; + std::pair local_range () const; /** * Return whether @p index is @@ -545,8 +545,8 @@ namespace TrilinosWrappers * function takes a deal.II vector * of values. */ - void set (const std::vector &indices, - const dealii::Vector &values); + void set (const std::vector &indices, + const ::dealii::Vector &values); /** * This collective set operation is @@ -567,16 +567,30 @@ namespace TrilinosWrappers * stored in @p values to the vector * components specified by @p indices. */ - void add (const std::vector &indices, - const std::vector &values); + void add (const std::vector &indices, + const std::vector &values); + /** + * This is a second collective add + * operation. As a difference, this + * function takes a deal.II vector + * of values. + */ + void add (const std::vector &indices, + const ::dealii::Vector &values); + + /** + * Take an address where n_elements + * are stored contiguously and add + * them into the vector. + */ void add (const unsigned int n_elements, const unsigned int *indices, const TrilinosScalar *values); /** - * Return the scalar/inner product of two - * vectors. The vectors must have the + * Return the scalar (inner) product of + * two vectors. The vectors must have the * same size. */ TrilinosScalar operator * (const Vector &vec) const; @@ -673,7 +687,7 @@ namespace TrilinosWrappers /** * Simple vector addition, equal to the - * operator =. + * operator +=. */ void add (const Vector &V); @@ -865,6 +879,7 @@ namespace TrilinosWrappers std::auto_ptr vector; + private: /** * Trilinos doesn't allow to mix additions * to matrix entries and overwriting diff --git a/deal.II/lac/source/trilinos_vector.cc b/deal.II/lac/source/trilinos_vector.cc index 09d6bfd169..bd99c0eeaa 100755 --- a/deal.II/lac/source/trilinos_vector.cc +++ b/deal.II/lac/source/trilinos_vector.cc @@ -95,7 +95,7 @@ namespace TrilinosWrappers { vector.reset(); map = input_map; - + vector = std::auto_ptr (new Epetra_FEVector(input_map)); last_action = Insert; } @@ -107,10 +107,10 @@ namespace TrilinosWrappers const bool fast) { vector.reset(); - + if (!map.SameAs(v.map)) map = v.map; - + vector = std::auto_ptr (new Epetra_FEVector(v.map,!fast)); last_action = Insert; } @@ -151,7 +151,8 @@ namespace TrilinosWrappers { Assert (numbers::is_finite(s), - ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)")); + ExcMessage("The given value is not finite but either " + "infinite or Not A Number (NaN)")); const int ierr = vector->PutScalar(s); @@ -169,7 +170,8 @@ namespace TrilinosWrappers ExcDimensionMismatch(size(), v.size())); unsigned int i; for (i=0; i &indices, const std::vector &values) { Assert (indices.size() == values.size(), - ExcMessage ("Function called with arguments of different sizes")); - + ExcDimensionMismatch(indices.size(),values.size())); + set (indices.size(), &indices[0], &values[0]); } - + + + void + Vector::set (const std::vector &indices, + const ::dealii::Vector &values) + { + Assert (indices.size() == values.size(), + ExcDimensionMismatch(indices.size(),values.size())); + + set (indices.size(), &indices[0], values.begin()); + } + + + void Vector::set (const unsigned int n_elements, const unsigned int *indices, @@ -261,19 +277,31 @@ namespace TrilinosWrappers } - + void Vector::add (const std::vector &indices, const std::vector &values) { Assert (indices.size() == values.size(), - ExcMessage ("Function called with arguments of different sizes")); - + ExcDimensionMismatch(indices.size(),values.size())); + add (indices.size(), &indices[0], &values[0]); } - - + + + void + Vector::add (const std::vector &indices, + const ::dealii::Vector &values) + { + Assert (indices.size() == values.size(), + ExcDimensionMismatch(indices.size(),values.size())); + + add (indices.size(), &indices[0], values.begin()); + } + + + void Vector::add (const unsigned int n_elements, const unsigned int *indices, @@ -321,11 +349,9 @@ namespace TrilinosWrappers TrilinosScalar Vector::mean_value () const { - TrilinosScalar mean; - int ierr; - ierr = vector->MeanValue (&mean); + const int ierr = vector->MeanValue (&mean); AssertThrow (ierr == 0, ExcTrilinosError(ierr)); return mean;