Classes | |
class | ExcAccessToNonlocalElement |
class | ExcTrilinosError |
Public Types | |
typedef TrilinosScalar | value_type |
typedef TrilinosScalar | real_type |
typedef size_t | size_type |
typedef internal::VectorReference | reference |
typedef const internal::VectorReference | const_reference |
Public Member Functions | |
1: Basic Object-handling | |
VectorBase () | |
VectorBase (const VectorBase &v) | |
virtual | ~VectorBase () |
void | clear () |
void | reinit (const VectorBase &v, const bool fast=false) |
void | compress () |
bool | is_compressed () const |
VectorBase & | operator= (const TrilinosScalar s) |
VectorBase & | operator= (const VectorBase &v) |
template<typename Number > | |
VectorBase & | operator= (const ::::Vector< Number > &v) |
bool | operator== (const VectorBase &v) const |
bool | operator!= (const VectorBase &v) const |
unsigned int | size () const |
unsigned int | local_size () const |
std::pair< unsigned int, unsigned int > | local_range () const |
bool | in_local_range (const unsigned int index) const |
TrilinosScalar | operator* (const VectorBase &vec) const |
real_type | norm_sqr () const |
TrilinosScalar | mean_value () const |
real_type | l1_norm () const |
real_type | l2_norm () const |
real_type | lp_norm (const TrilinosScalar p) const |
real_type | linfty_norm () const |
bool | all_zero () const |
bool | is_non_negative () const |
2: Data-Access | |
reference | operator() (const unsigned int index) |
TrilinosScalar | operator() (const unsigned int index) const |
TrilinosScalar | el (const unsigned int index) const |
void | set (const std::vector< unsigned int > &indices, const std::vector< TrilinosScalar > &values) |
void | set (const std::vector< unsigned int > &indices, const ::::Vector< TrilinosScalar > &values) |
3: Modification of vectors | |
void | set (const unsigned int n_elements, const unsigned int *indices, const TrilinosScalar *values) |
void | add (const std::vector< unsigned int > &indices, const std::vector< TrilinosScalar > &values) |
void | add (const std::vector< unsigned int > &indices, const ::::Vector< TrilinosScalar > &values) |
void | add (const unsigned int n_elements, const unsigned int *indices, const TrilinosScalar *values) |
VectorBase & | operator*= (const TrilinosScalar factor) |
VectorBase & | operator/= (const TrilinosScalar factor) |
VectorBase & | operator+= (const VectorBase &V) |
VectorBase & | operator-= (const VectorBase &V) |
void | add (const TrilinosScalar s) |
void | add (const VectorBase &V, const bool allow_different_maps=false) |
void | add (const TrilinosScalar a, const VectorBase &V) |
void | add (const TrilinosScalar a, const VectorBase &V, const TrilinosScalar b, const VectorBase &W) |
void | sadd (const TrilinosScalar s, const VectorBase &V) |
void | sadd (const TrilinosScalar s, const TrilinosScalar a, const VectorBase &V) |
void | sadd (const TrilinosScalar s, const TrilinosScalar a, const VectorBase &V, const TrilinosScalar b, const VectorBase &W) |
void | sadd (const TrilinosScalar s, const TrilinosScalar a, const VectorBase &V, const TrilinosScalar b, const VectorBase &W, const TrilinosScalar c, const VectorBase &X) |
void | scale (const VectorBase &scaling_factors) |
void | equ (const TrilinosScalar a, const VectorBase &V) |
void | equ (const TrilinosScalar a, const VectorBase &V, const TrilinosScalar b, const VectorBase &W) |
void | ratio (const VectorBase &a, const VectorBase &b) |
4: Mixed stuff | |
const Epetra_MultiVector & | trilinos_vector () const |
Epetra_FEVector & | trilinos_vector () |
const Epetra_Map & | vector_partitioner () const |
void | print (const char *format=0) const |
void | print (std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const |
void | swap (VectorBase &v) |
unsigned int | memory_consumption () const |
Private Attributes | |
Epetra_CombineMode | last_action |
bool | compressed |
std::auto_ptr< Epetra_FEVector > | vector |
Friends | |
class | internal::VectorReference |
class | Vector |
class | MPI::Vector |
Base class for the two types of Trilinos vectors, the distributed memory vector MPI::Vector and a localized vector Vector. The latter is designed for use in either serial implementations or as a localized copy on each processor. The implementation of this class is based on the Trilinos vector class Epetra_FEVector, the (parallel) partitioning of which is governed by an Epetra_Map. This means that the vector type is generic and can be done in this base class, while the definition of the partition map (and hence, the constructor and reinit function) will have to be done in the derived classes. The Epetra_FEVector is precisely the kind of vector we deal with all the time - we probably get it from some assembly process, where also entries not locally owned might need to written and hence need to be forwarded to the owner. The only requirement for this class to work is that Trilinos is installed with the same compiler as is used for compilation of deal.II.
The interface of this class is modeled after the existing Vector class in deal.II. It has almost the same member functions, and is often exchangable. However, since Trilinos only supports a single scalar type (double), it is not templated, and only works with that type.
Note that Trilinos only guarantees that operations do what you expect if the function GlobalAssemble
has been called after vector assembly in order to distribute the data. Therefore, you need to call Vector::compress() before you actually use the vectors.
typedef TrilinosScalar TrilinosWrappers::VectorBase::value_type |
Declare some of the standard types used in all containers. These types parallel those in the C
standard libraries vector<...>
class.
typedef TrilinosScalar TrilinosWrappers::VectorBase::real_type |
typedef size_t TrilinosWrappers::VectorBase::size_type |
typedef internal::VectorReference TrilinosWrappers::VectorBase::reference |
typedef const internal::VectorReference TrilinosWrappers::VectorBase::const_reference |
TrilinosWrappers::VectorBase::VectorBase | ( | ) |
TrilinosWrappers::VectorBase::VectorBase | ( | const VectorBase & | v | ) |
Copy constructor. Sets the dimension to that of the given vector, and copies all the elements.
virtual TrilinosWrappers::VectorBase::~VectorBase | ( | ) | [virtual] |
Destructor
void TrilinosWrappers::VectorBase::clear | ( | ) |
Release all memory and return to a state just like after having called the default constructor.
void TrilinosWrappers::VectorBase::reinit | ( | const VectorBase & | v, | |
const bool | fast = false | |||
) |
Reinit functionality, sets the dimension and possibly the parallel partitioning (Epetra_Map) of the calling vector to the settings of the input vector.
void TrilinosWrappers::VectorBase::compress | ( | ) |
Compress the underlying representation of the Trilinos object, i.e. flush the buffers of the vector object if it has any. This function is necessary after writing into a vector element-by-element and before anything else can be done on it.
bool TrilinosWrappers::VectorBase::is_compressed | ( | ) | const |
Returns the state of the vector, i.e., whether compress() has already been called after an operation requiring data exchange.
VectorBase& TrilinosWrappers::VectorBase::operator= | ( | const TrilinosScalar | s | ) |
Set all components of the vector to the given number s
. Simply pass this down to the Trilinos Epetra object, but we still need to declare this function to make the example given in the discussion about making the constructor explicit work.
Since the semantics of assigning a scalar to a vector are not immediately clear, this operator should really only be used if you want to set the entire vector to zero. This allows the intuitive notation v=0
. Assigning other values is deprecated and may be disallowed in the future.
Reimplemented in TrilinosWrappers::MPI::Vector, and TrilinosWrappers::Vector.
VectorBase& TrilinosWrappers::VectorBase::operator= | ( | const VectorBase & | v | ) |
Copy function. This function takes a VectorBase vector and copies all the elements. The target vector will have the same parallel distribution as the calling vector.
Reimplemented from Subscriptor.
Reimplemented in TrilinosWrappers::MPI::Vector, and TrilinosWrappers::Vector.
VectorBase& TrilinosWrappers::VectorBase::operator= | ( | const ::::Vector< Number > & | v | ) | [inline] |
Another copy function. This one takes a deal.II vector and copies it into a TrilinosWrapper vector. Note that since we do not provide any Epetra_map that tells about the partitioning of the vector among the MPI processes, the size of the TrilinosWrapper vector has to be the same as the size of the input vector. In order to change the map, use the reinit(const Epetra_Map &input_map) function.
bool TrilinosWrappers::VectorBase::operator== | ( | const VectorBase & | v | ) | const |
Test for equality. This function assumes that the present vector and the one to compare with have the same size already, since comparing vectors of different sizes makes not much sense anyway.
bool TrilinosWrappers::VectorBase::operator!= | ( | const VectorBase & | v | ) | const |
Test for inequality. This function assumes that the present vector and the one to compare with have the same size already, since comparing vectors of different sizes makes not much sense anyway.
Return the global dimension of the vector.
Return the local dimension of the vector, i.e. the number of elements stored on the present MPI process. For sequential vectors, this number is the same as size(), but for parallel vectors it may be smaller.
To figure out which elements exactly are stored locally, use local_range().
Return a pair of indices indicating which elements of this vector are stored locally. The first number is the index of the first element stored, the second the index of the one past the last one that is stored locally. If this is a sequential vector, then the result will be the pair (0,N), otherwise it will be a pair (i,i+n), where n=local_size()
.
Return whether index
is in the local range or not, see also local_range().
TrilinosScalar TrilinosWrappers::VectorBase::operator* | ( | const VectorBase & | vec | ) | const |
Return the scalar (inner) product of two vectors. The vectors must have the same size.
real_type TrilinosWrappers::VectorBase::norm_sqr | ( | ) | const |
Return square of the -norm.
TrilinosScalar TrilinosWrappers::VectorBase::mean_value | ( | ) | const |
Mean value of the elements of this vector.
real_type TrilinosWrappers::VectorBase::l1_norm | ( | ) | const |
-norm of the vector. The sum of the absolute values.
real_type TrilinosWrappers::VectorBase::l2_norm | ( | ) | const |
-norm of the vector. The square root of the sum of the squares of the elements.
real_type TrilinosWrappers::VectorBase::lp_norm | ( | const TrilinosScalar | p | ) | const |
-norm of the vector. The pth root of the sum of the pth powers of the absolute values of the elements.
real_type TrilinosWrappers::VectorBase::linfty_norm | ( | ) | const |
Maximum absolute value of the elements.
bool TrilinosWrappers::VectorBase::all_zero | ( | ) | const |
Return whether the vector contains only elements with value zero. This function is mainly for internal consistency checks and should seldomly be used when not in debug mode since it uses quite some time.
bool TrilinosWrappers::VectorBase::is_non_negative | ( | ) | const |
Return true
if the vector has no negative entries, i.e. all entries are zero or positive. This function is used, for example, to check whether refinement indicators are really all positive (or zero).
Provide access to a given element, both read and write.
Provide read-only access to an element. This is equivalent to the el()
command.
Return the value of the vector entry i. Note that this function does only work properly when we request a data stored on the local processor. The function will throw an exception in case the elements sits on another process.
void TrilinosWrappers::VectorBase::set | ( | const std::vector< unsigned int > & | indices, | |
const std::vector< TrilinosScalar > & | values | |||
) |
A collective set operation: instead of setting individual elements of a vector, this function allows to set a whole set of elements at once. The indices of the elements to be set are stated in the first argument, the corresponding values in the second.
void TrilinosWrappers::VectorBase::set | ( | const std::vector< unsigned int > & | indices, | |
const ::::Vector< TrilinosScalar > & | values | |||
) |
This is a second collective set operation. As a difference, this function takes a deal.II vector of values.
void TrilinosWrappers::VectorBase::set | ( | const unsigned int | n_elements, | |
const unsigned int * | indices, | |||
const TrilinosScalar * | values | |||
) |
This collective set operation is of lower level and can handle anything else — the only thing you have to provide is an address where all the indices are stored and the number of elements to be set.
void TrilinosWrappers::VectorBase::add | ( | const std::vector< unsigned int > & | indices, | |
const std::vector< TrilinosScalar > & | values | |||
) |
A collective add operation: This funnction adds a whole set of values stored in values
to the vector components specified by indices
.
void TrilinosWrappers::VectorBase::add | ( | const std::vector< unsigned int > & | indices, | |
const ::::Vector< TrilinosScalar > & | values | |||
) |
This is a second collective add operation. As a difference, this function takes a deal.II vector of values.
void TrilinosWrappers::VectorBase::add | ( | const unsigned int | n_elements, | |
const unsigned int * | indices, | |||
const TrilinosScalar * | values | |||
) |
Take an address where n_elements
are stored contiguously and add them into the vector. Handles all cases which are not covered by the other two add()
functions above.
VectorBase& TrilinosWrappers::VectorBase::operator*= | ( | const TrilinosScalar | factor | ) |
Multiply the entire vector by a fixed factor.
VectorBase& TrilinosWrappers::VectorBase::operator/= | ( | const TrilinosScalar | factor | ) |
Divide the entire vector by a fixed factor.
VectorBase& TrilinosWrappers::VectorBase::operator+= | ( | const VectorBase & | V | ) |
Add the given vector to the present one.
VectorBase& TrilinosWrappers::VectorBase::operator-= | ( | const VectorBase & | V | ) |
Subtract the given vector from the present one.
void TrilinosWrappers::VectorBase::add | ( | const TrilinosScalar | s | ) |
Addition of s
to all components. Note that s
is a scalar and not a vector.
void TrilinosWrappers::VectorBase::add | ( | const VectorBase & | V, | |
const bool | allow_different_maps = false | |||
) |
Simple vector addition, equal to the operator +=
.
Though, if the second argument allow_different_maps
is set, then it is possible to add data from a different map.
void TrilinosWrappers::VectorBase::add | ( | const TrilinosScalar | a, | |
const VectorBase & | V | |||
) |
Simple addition of a multiple of a vector, i.e. *this = a*V
.
void TrilinosWrappers::VectorBase::add | ( | const TrilinosScalar | a, | |
const VectorBase & | V, | |||
const TrilinosScalar | b, | |||
const VectorBase & | W | |||
) |
Multiple addition of scaled vectors, i.e. *this = a*V + b*W
.
void TrilinosWrappers::VectorBase::sadd | ( | const TrilinosScalar | s, | |
const VectorBase & | V | |||
) |
Scaling and simple vector addition, i.e. *this = s*(*this) + V
.
void TrilinosWrappers::VectorBase::sadd | ( | const TrilinosScalar | s, | |
const TrilinosScalar | a, | |||
const VectorBase & | V | |||
) |
Scaling and simple addition, i.e. *this = s*(*this) + a*V
.
void TrilinosWrappers::VectorBase::sadd | ( | const TrilinosScalar | s, | |
const TrilinosScalar | a, | |||
const VectorBase & | V, | |||
const TrilinosScalar | b, | |||
const VectorBase & | W | |||
) |
Scaling and multiple addition.
void TrilinosWrappers::VectorBase::sadd | ( | const TrilinosScalar | s, | |
const TrilinosScalar | a, | |||
const VectorBase & | V, | |||
const TrilinosScalar | b, | |||
const VectorBase & | W, | |||
const TrilinosScalar | c, | |||
const VectorBase & | X | |||
) |
Scaling and multiple addition. *this = s*(*this) + a*V + b*W + c*X
.
void TrilinosWrappers::VectorBase::scale | ( | const VectorBase & | scaling_factors | ) |
Scale each element of this vector by the corresponding element in the argument. This function is mostly meant to simulate multiplication (and immediate re-assignment) by a diagonal scaling matrix.
void TrilinosWrappers::VectorBase::equ | ( | const TrilinosScalar | a, | |
const VectorBase & | V | |||
) |
Assignment *this = a*V
.
void TrilinosWrappers::VectorBase::equ | ( | const TrilinosScalar | a, | |
const VectorBase & | V, | |||
const TrilinosScalar | b, | |||
const VectorBase & | W | |||
) |
Assignment *this = a*V + b*W
.
void TrilinosWrappers::VectorBase::ratio | ( | const VectorBase & | a, | |
const VectorBase & | b | |||
) |
Compute the elementwise ratio of the two given vectors, that is let this[i] = a[i]/b[i]
. This is useful for example if you want to compute the cellwise ratio of true to estimated error.
This vector is appropriately scaled to hold the result.
If any of the b[i]
is zero, the result is undefined. No attempt is made to catch such situations.
const Epetra_MultiVector& TrilinosWrappers::VectorBase::trilinos_vector | ( | ) | const |
Return a const reference to the underlying Trilinos Epetra_MultiVector class.
Epetra_FEVector& TrilinosWrappers::VectorBase::trilinos_vector | ( | ) |
Return a (modifyable) reference to the underlying Trilinos Epetra_FEVector class.
const Epetra_Map& TrilinosWrappers::VectorBase::vector_partitioner | ( | ) | const |
Return a const reference to the underlying Trilinos Epetra_Map that sets the parallel partitioning of the vector.
void TrilinosWrappers::VectorBase::print | ( | const char * | format = 0 |
) | const |
Output of vector in user-defined format in analogy to the Vector<number> class.
void TrilinosWrappers::VectorBase::print | ( | std::ostream & | out, | |
const unsigned int | precision = 3 , |
|||
const bool | scientific = true , |
|||
const bool | across = true | |||
) | const |
Print to a stream. precision
denotes the desired precision with which values shall be printed, scientific
whether scientific notation shall be used. If across
is true
then the vector is printed in a line, while if false
then the elements are printed on a separate line each.
void TrilinosWrappers::VectorBase::swap | ( | VectorBase & | v | ) |
Swap the contents of this vector and the other vector v
. One could do this operation with a temporary variable and copying over the data elements, but this function is significantly more efficient since it only swaps the pointers to the data of the two vectors and therefore does not need to allocate temporary storage and move data around. Note that the vectors need to be of the same size and base on the same map.
This function is analog to the the swap
function of all C standard containers. Also, there is a global function swap(u,v)
that simply calls u.swap(v)
, again in analogy to standard functions.
Estimate for the memory consumption (not implemented for this class).
friend class internal::VectorReference [friend] |
Make the reference class a friend.
friend class Vector [friend] |
friend class MPI::Vector [friend] |
Epetra_CombineMode TrilinosWrappers::VectorBase::last_action [private] |
Trilinos doesn't allow to mix additions to matrix entries and overwriting them (to make synchronisation of parallel computations simpler). The way we do it is to, for each access operation, store whether it is an insertion or an addition. If the previous one was of different type, then we first have to flush the Trilinos buffers; otherwise, we can simply go on. Luckily, Trilinos has an object for this which does already all the parallel communications in such a case, so we simply use their model, which stores whether the last operation was an addition or an insertion.
bool TrilinosWrappers::VectorBase::compressed [private] |
A boolean variable to hold information on whether the vector is compressed or not.
std::auto_ptr<Epetra_FEVector> TrilinosWrappers::VectorBase::vector [private] |
An Epetra distibuted vector type. Requires an existing Epetra_Map for storing data.