Classes | |
struct | LastAction |
Public Types | |
typedef PetscScalar | value_type |
typedef PetscScalar | real_type |
typedef size_t | size_type |
typedef internal::VectorReference | reference |
typedef const internal::VectorReference | const_reference |
Public Member Functions | |
VectorBase () | |
VectorBase (const VectorBase &v) | |
virtual | ~VectorBase () |
void | compress () |
VectorBase & | operator= (const PetscScalar s) |
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 |
reference | operator() (const unsigned int index) |
PetscScalar | operator() (const unsigned int index) const |
void | set (const std::vector< unsigned int > &indices, const std::vector< PetscScalar > &values) |
void | add (const std::vector< unsigned int > &indices, const std::vector< PetscScalar > &values) |
PetscScalar | operator* (const VectorBase &vec) const |
real_type | norm_sqr () const |
PetscScalar | mean_value () const |
real_type | l1_norm () const |
real_type | l2_norm () const |
real_type | lp_norm (const PetscScalar p) const |
real_type | linfty_norm () const |
real_type | normalize () const |
real_type | max () const |
VectorBase & | abs () |
VectorBase & | conjugate () |
VectorBase & | mult () |
bool | all_zero () const |
bool | is_non_negative () const |
VectorBase & | operator*= (const PetscScalar factor) |
VectorBase & | operator/= (const PetscScalar factor) |
VectorBase & | operator+= (const VectorBase &V) |
VectorBase & | operator-= (const VectorBase &V) |
void | add (const PetscScalar s) |
void | add (const VectorBase &V) |
void | add (const PetscScalar a, const VectorBase &V) |
void | add (const PetscScalar a, const VectorBase &V, const PetscScalar b, const VectorBase &W) |
void | sadd (const PetscScalar s, const VectorBase &V) |
void | sadd (const PetscScalar s, const PetscScalar a, const VectorBase &V) |
void | sadd (const PetscScalar s, const PetscScalar a, const VectorBase &V, const PetscScalar b, const VectorBase &W) |
void | sadd (const PetscScalar s, const PetscScalar a, const VectorBase &V, const PetscScalar b, const VectorBase &W, const PetscScalar c, const VectorBase &X) |
void | scale (const VectorBase &scaling_factors) |
void | equ (const PetscScalar a, const VectorBase &V) |
void | equ (const PetscScalar a, const VectorBase &V, const PetscScalar b, const VectorBase &W) |
void | ratio (const VectorBase &a, const VectorBase &b) |
void | print (std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const |
void | swap (VectorBase &v) |
operator const Vec & () const | |
unsigned int | memory_consumption () const |
Protected Member Functions | |
void | do_set_add_operation (const std::vector< unsigned int > &indices, const std::vector< PetscScalar > &values, const bool add_values) |
Protected Attributes | |
Vec | vector |
LastAction::Values | last_action |
Friends | |
class | internal::VectorReference |
Base class for all vector classes that are implemented on top of the PETSc vector types. Since in PETSc all vector types (i.e. sequential and parallel ones) are built by filling the contents of an abstract object that is only referenced through a pointer of a type that is independent of the actual vector type, we can implement almost all functionality of vectors in this base class. Derived classes will then only have to provide the functionality to create one or the other kind of vector.
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 PETSc only supports a single scalar type (either double, float, or a complex data type), it is not templated, and only works with whatever your PETSc installation has defined the data type PetscScalar
to.
Note that PETSc only guarantees that operations do what you expect if the functions VecAssemblyBegin
and VecAssemblyEnd
have been called after vector assembly. Therefore, you need to call Vector::compress() before you actually use the vector.
typedef PetscScalar PETScWrappers::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 PetscScalar PETScWrappers::VectorBase::real_type |
typedef size_t PETScWrappers::VectorBase::size_type |
typedef internal::VectorReference PETScWrappers::VectorBase::reference |
typedef const internal::VectorReference PETScWrappers::VectorBase::const_reference |
PETScWrappers::VectorBase::VectorBase | ( | ) |
Default constructor. It doesn't do anything, derived classes will have to initialize the data.
PETScWrappers::VectorBase::VectorBase | ( | const VectorBase & | v | ) |
Copy constructor. Sets the dimension to that of the given vector, and copies all elements.
virtual PETScWrappers::VectorBase::~VectorBase | ( | ) | [virtual] |
Destructor
void PETScWrappers::VectorBase::compress | ( | ) |
Compress the underlying representation of the PETSc 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.
VectorBase& PETScWrappers::VectorBase::operator= | ( | const PetscScalar | s | ) |
Set all components of the vector to the given number s
. Simply pass this down to the individual block objects, 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 PETScWrappers::MPI::Vector, and PETScWrappers::Vector.
bool PETScWrappers::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 PETScWrappers::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 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().
Provide access to a given element, both read and write.
Provide read-only access to an element.
void PETScWrappers::VectorBase::set | ( | const std::vector< unsigned int > & | indices, | |
const std::vector< PetscScalar > & | 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 PETScWrappers::VectorBase::add | ( | const std::vector< unsigned int > & | indices, | |
const std::vector< PetscScalar > & | values | |||
) |
A collective add operation: This function adds a whole set of values stored in values
to the vector components specified by indices
.
PetscScalar PETScWrappers::VectorBase::operator* | ( | const VectorBase & | vec | ) | const |
Return the scalar product of two vectors. The vectors must have the same size.
real_type PETScWrappers::VectorBase::norm_sqr | ( | ) | const |
Return square of the -norm.
PetscScalar PETScWrappers::VectorBase::mean_value | ( | ) | const |
Mean value of the elements of this vector.
real_type PETScWrappers::VectorBase::l1_norm | ( | ) | const |
-norm of the vector. The sum of the absolute values.
real_type PETScWrappers::VectorBase::l2_norm | ( | ) | const |
-norm of the vector. The square root of the sum of the squares of the elements.
real_type PETScWrappers::VectorBase::lp_norm | ( | const PetscScalar | 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 PETScWrappers::VectorBase::linfty_norm | ( | ) | const |
Maximum absolute value of the elements.
real_type PETScWrappers::VectorBase::normalize | ( | ) | const |
Normalize vector by dividing by the -norm of the vector. Return vector norm before normalization.
real_type PETScWrappers::VectorBase::max | ( | ) | const |
Return vector component with the maximal magnitude.
VectorBase& PETScWrappers::VectorBase::abs | ( | ) |
Replace every element in a vector with its absolute value.
VectorBase& PETScWrappers::VectorBase::conjugate | ( | ) |
Conjugate a vector.
VectorBase& PETScWrappers::VectorBase::mult | ( | ) |
A collective piecewise multiply operation. TODO: The model for this function should be similer to add ().
bool PETScWrappers::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 PETScWrappers::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).
VectorBase& PETScWrappers::VectorBase::operator*= | ( | const PetscScalar | factor | ) |
Multiply the entire vector by a fixed factor.
VectorBase& PETScWrappers::VectorBase::operator/= | ( | const PetscScalar | factor | ) |
Divide the entire vector by a fixed factor.
VectorBase& PETScWrappers::VectorBase::operator+= | ( | const VectorBase & | V | ) |
Add the given vector to the present one.
VectorBase& PETScWrappers::VectorBase::operator-= | ( | const VectorBase & | V | ) |
Subtract the given vector from the present one.
void PETScWrappers::VectorBase::add | ( | const PetscScalar | s | ) |
Addition of s
to all components. Note that s
is a scalar and not a vector.
void PETScWrappers::VectorBase::add | ( | const VectorBase & | V | ) |
Simple vector addition, equal to the operator +=
.
void PETScWrappers::VectorBase::add | ( | const PetscScalar | a, | |
const VectorBase & | V | |||
) |
Simple addition of a multiple of a vector, i.e. *this += a*V
.
void PETScWrappers::VectorBase::add | ( | const PetscScalar | a, | |
const VectorBase & | V, | |||
const PetscScalar | b, | |||
const VectorBase & | W | |||
) |
Multiple addition of scaled vectors, i.e. *this += a*V+b*W
.
void PETScWrappers::VectorBase::sadd | ( | const PetscScalar | s, | |
const VectorBase & | V | |||
) |
Scaling and simple vector addition, i.e. *this = s*(*this)+V
.
void PETScWrappers::VectorBase::sadd | ( | const PetscScalar | s, | |
const PetscScalar | a, | |||
const VectorBase & | V | |||
) |
Scaling and simple addition, i.e. *this = s*(*this)+a*V
.
void PETScWrappers::VectorBase::sadd | ( | const PetscScalar | s, | |
const PetscScalar | a, | |||
const VectorBase & | V, | |||
const PetscScalar | b, | |||
const VectorBase & | W | |||
) |
Scaling and multiple addition.
void PETScWrappers::VectorBase::sadd | ( | const PetscScalar | s, | |
const PetscScalar | a, | |||
const VectorBase & | V, | |||
const PetscScalar | b, | |||
const VectorBase & | W, | |||
const PetscScalar | c, | |||
const VectorBase & | X | |||
) |
Scaling and multiple addition. *this = s*(*this)+a*V + b*W + c*X
.
void PETScWrappers::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 PETScWrappers::VectorBase::equ | ( | const PetscScalar | a, | |
const VectorBase & | V | |||
) |
Assignment *this = a*V
.
void PETScWrappers::VectorBase::equ | ( | const PetscScalar | a, | |
const VectorBase & | V, | |||
const PetscScalar | b, | |||
const VectorBase & | W | |||
) |
Assignment *this = a*V + b*W
.
void PETScWrappers::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.
void PETScWrappers::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 PETScWrappers::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.
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.
PETScWrappers::VectorBase::operator const Vec & | ( | ) | const |
Conversion operator to gain access to the underlying PETSc type. If you do this, you cut this class off some information it may need, so this conversion operator should only be used if you know what you do. In particular, it should only be used for read-only operations into the vector.
Estimate for the memory consumption (not implemented for this class).
void PETScWrappers::VectorBase::do_set_add_operation | ( | const std::vector< unsigned int > & | indices, | |
const std::vector< PetscScalar > & | values, | |||
const bool | add_values | |||
) | [protected] |
Collective set or add operation: This function is invoked by the collective set
and add
with the add_values
flag set to the corresponding value.
friend class internal::VectorReference [friend] |
Make the reference class a friend.
Vec PETScWrappers::VectorBase::vector [protected] |
A generic vector object in PETSc. The actual type, a sequential vector, is set in the constructor.
LastAction::Values PETScWrappers::VectorBase::last_action [mutable, protected] |
Store whether the last action was a write or add operation. This variable is mutable
so that the accessor classes can write to it, even though the vector object they refer to is constant.