![]() |
Vulpes
0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
|
A wrapper around PETSc Vec for distributed vectors. More...
#include <vector.hpp>
Classes | |
| struct | GhostTag |
| Tag selecting the ghost-aware constructor overload (see createGhosted()). More... | |
Public Member Functions | |
| template<typename DofHandler> | |
| Vector (const DofHandler &dof_handler, PetscInt block_size=1) | |
| Construct a Vector from a DofHandler. | |
| Vector (const std::pair< PetscInt, PetscInt > &sizes) | |
| Construct a Vector given local and global sizes. | |
| template<typename DofHandler> | |
| Vector (GhostTag, const DofHandler &dof_handler) | |
| Construct a ghost-aware Vector from a DofHandler: the local form additionally carries a padding segment for this rank's ghost dofs (DofHandler::getGhostDofs()), refreshed on demand by updateGhosts() and readable via toLocalGhostedEigenVector(). Prefer the createGhosted() factory over calling this directly. | |
| Vector & | operator= (const Vector &other)=delete |
| Vector (const Vector &other) | |
| Copy constructor. | |
| template<typename DofHandler> | |
| void | init (const DofHandler &dof_handler, PetscInt block_size) |
| Initialize the vector based on a DofHandler. | |
| template<typename DofHandler> | |
| void | initGhosted (const DofHandler &dof_handler) |
| Initialize a ghost-aware vector from a DofHandler (see the GhostTag constructor). | |
| void | copy (const Vector &other) |
| Copy the contents of another vector. | |
| void | compress () |
| Compress the vector (do intracommunication). | |
| void | print () const |
| Print the vector to standard output. | |
| void | save (const std::string &filename, const std::string &vecname="", PetscViewerFormat format=PETSC_VIEWER_ASCII_MATLAB) const |
| Save the vector to a file. | |
| void | saveBinary (const std::string &filename, const std::string &vecname="") const |
| Save the vector to a binary file. | |
| void | insertValues (const PetscScalar *values, const PetscInt *indices, PetscInt n_values, InsertMode mode=ADD_VALUES) |
| Insert values into the vector at specified indices. | |
| void | insertValuesBlocked (const PetscScalar *values, const PetscInt *indices, PetscInt n_values, InsertMode mode=ADD_VALUES) |
| Insert blocked values into the vector at specified indices. | |
| void | insertValues (const Eigen::Ref< const Eigen::MatrixXd > &loc_vec, const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > &idxs, InsertMode mode=ADD_VALUES) |
| Insert values from an Eigen matrix into the vector at specified indices. | |
| void | insertValuesBlocked (const Eigen::Ref< const Eigen::MatrixXd > &loc_vec, const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > &idxs, InsertMode mode=ADD_VALUES) |
| Insert blocked values from an Eigen matrix into the vector at specified indices. | |
| void | setValue (PetscInt idx, PetscScalar value, InsertMode mode=INSERT_VALUES) |
| Set a single value in the vector. | |
| PetscScalar | getValue (PetscInt idx) const |
| Get a single value from the vector. | |
| void | getLocalValues (std::vector< PetscScalar > &values) const |
| Get all local values of the vector. | |
| std::array< PetscInt, 2 > | getOwnershipRange () const |
| Get the ownership range of the vector. | |
| PetscInt | getBlockSize () const |
| Get the block size of the vector. | |
| Eigen::Map< const Eigen::VectorXd > | toEigenMap () const |
| Convert the locally-owned vector entries to an Eigen map (same as toLocalEigenMap()). | |
| Eigen::Map< const Eigen::VectorXd > | toLocalEigenMap () const |
| Convert the locally-owned vector entries to an Eigen map. | |
| void | updateGhosts () |
| Refresh the ghost padding of a ghost-aware Vector (see createGhosted()) from each ghost dof's owning rank. Collective; call after writing new values, before reading any ghost value via toLocalGhostedEigenVector(). Only valid on a Vector built via createGhosted(). | |
| void | updateGhostsBegin () |
| updateGhosts() split in two, so that the exchanges of several vectors overlap: begin all of them, then end all of them. | |
| void | updateGhostsEnd () |
| void | accumulateGhostsBegin () |
| Add the ghost entries of the local form (see getLocalGhostedView()) into the entries of their owning ranks, the reverse of updateGhosts(). Collective; split as updateGhostsBegin/End. The ghost entries keep their values: zero them before the next sum. | |
| void | accumulateGhostsEnd () |
| Eigen::Map< Eigen::VectorXd > | getLocalGhostedView () |
| Writable view of the local form of a ghost-aware Vector (owned dofs, then ghost dofs, indexed by DofHandler::localGhostedIndex()). Valid until restoreLocalGhostedView(), which must be called before any other use of the Vector. | |
| void | restoreLocalGhostedView () |
| Eigen::VectorXd | toLocalGhostedEigenVector () const |
| Local-form snapshot of a ghost-aware Vector (see createGhosted()): this rank's owned dofs first ([0, n_owned)), then its ghost dofs in DofHandler::getGhostDofs() order ([n_owned, n_owned + n_ghost)). Use DofHandler::localGhostedIndex(global_dof_id) to index into it rather than hand-rolling ownership-range arithmetic against a global dof id – doing that by hand for a ghost dof is exactly the bug this class exists to remove (a global dof id belonging to another rank is not a valid index into toEigenMap()/toLocalEigenMap()). The ghost segment is only current immediately after updateGhosts(); nothing invalidates it automatically on a subsequent write. Only valid on a Vector built via createGhosted(). | |
| std::pair< PetscInt, PetscInt > | getLocAndGlobSize () const |
| Get local and global sizes of the vector. | |
| const Vec & | getPetscVector () const |
| Get the underlying PETSc vector (const version). | |
| Vec & | getPetscVector () |
| Get the underlying PETSc vector (non-const version). | |
| void | zero () |
| Zero out the vector. | |
| void | set (double value) |
| Set all values in the vector to a constant. | |
| void | scale (double value) |
| Scale the vector by a constant. | |
| PetscScalar | norm (NormType norm_type=NORM_2) const |
| Compute the norm of the vector. | |
| void | add (const Vector &x) |
| Add a vector in place (this += x). | |
| void | add (PetscScalar alpha, const Vector &x) |
| Add a vector in place (this += alpha x). | |
| void | addScaled (PetscScalar alpha, const Vector &x) |
| Add a vector in place (this = x + alpha this). | |
| void | addGeneric (PetscScalar alpha, PetscScalar beta, const Vector &x) |
| Add a vector in place (this = alpha x + beta this). | |
| void | addCouple (PetscScalar alpha, const Vector &x, const Vector &y) |
| Add a vector in place (this = alpha x + y). | |
| void | addTriplet (PetscScalar alpha, PetscScalar beta, PetscScalar gamma, const Vector &x, const Vector &y) |
| Add a vector in place (this = alpha x + beta y + gamma this). | |
| void | pow (PetscScalar power) |
| Replaces each component of a vector by its p-th power. | |
| void | abs () |
| Replaces each component of a vector by its absolute value. | |
| PetscInt | getSize () const |
| Get the size of the vector. | |
| PetscInt | getLocalSize () const |
| Get the local size of the vector. | |
| PetscScalar | sum () const |
| Compute the sum of all elements in the vector. | |
| PetscScalar | norm2 () const |
| Compute the Euclidean norm of the vector. | |
| ~Vector () | |
Static Public Member Functions | |
| template<typename DofHandler> | |
| static Vector | createGhosted (const DofHandler &dof_handler) |
| Construct a ghost-aware Vector from a DofHandler. See the GhostTag constructor above for what this enables. | |
| static bool | compareVectors (const Vector &vec1, const Vector &vec2, double tolerance=1e-12) |
| Static method to compare two vectors with tolerance. | |
Protected Member Functions | |
| void | createVector () |
| void | setVectorSizes (const PetscInt n_loc, const PetscInt n_glob) |
| void | setupVector () |
Protected Attributes | |
| Vec | m_petsc_vector |
| bool | m_is_ghosted = false |
| Vec | m_local_form = nullptr |
| PetscScalar * | m_local_array = nullptr |
A wrapper around PETSc Vec for distributed vectors.
|
inlineexplicit |
Construct a Vector from a DofHandler.
|
inlineexplicit |
Construct a Vector given local and global sizes.
|
inline |
Construct a ghost-aware Vector from a DofHandler: the local form additionally carries a padding segment for this rank's ghost dofs (DofHandler::getGhostDofs()), refreshed on demand by updateGhosts() and readable via toLocalGhostedEigenVector(). Prefer the createGhosted() factory over calling this directly.
| vulpes::la::Vector::Vector | ( | const Vector & | other | ) |
Copy constructor.
| vulpes::la::Vector::~Vector | ( | ) |
| void vulpes::la::Vector::abs | ( | ) |
Replaces each component of a vector by its absolute value.
| void vulpes::la::Vector::accumulateGhostsBegin | ( | ) |
Add the ghost entries of the local form (see getLocalGhostedView()) into the entries of their owning ranks, the reverse of updateGhosts(). Collective; split as updateGhostsBegin/End. The ghost entries keep their values: zero them before the next sum.
| void vulpes::la::Vector::accumulateGhostsEnd | ( | ) |
|
inline |
Add a vector in place (this += x).
| void vulpes::la::Vector::add | ( | PetscScalar | alpha, |
| const Vector & | x ) |
Add a vector in place (this += alpha x).
Add a vector in place (this = alpha x + y).
| void vulpes::la::Vector::addGeneric | ( | PetscScalar | alpha, |
| PetscScalar | beta, | ||
| const Vector & | x ) |
Add a vector in place (this = alpha x + beta this).
| void vulpes::la::Vector::addScaled | ( | PetscScalar | alpha, |
| const Vector & | x ) |
Add a vector in place (this = x + alpha this).
| void vulpes::la::Vector::addTriplet | ( | PetscScalar | alpha, |
| PetscScalar | beta, | ||
| PetscScalar | gamma, | ||
| const Vector & | x, | ||
| const Vector & | y ) |
Add a vector in place (this = alpha x + beta y + gamma this).
|
static |
Static method to compare two vectors with tolerance.
| void vulpes::la::Vector::compress | ( | ) |
Compress the vector (do intracommunication).
| void vulpes::la::Vector::copy | ( | const Vector & | other | ) |
Copy the contents of another vector.
|
inlinestatic |
|
protected |
| PetscInt vulpes::la::Vector::getBlockSize | ( | ) | const |
Get the block size of the vector.
| Eigen::Map< Eigen::VectorXd > vulpes::la::Vector::getLocalGhostedView | ( | ) |
Writable view of the local form of a ghost-aware Vector (owned dofs, then ghost dofs, indexed by DofHandler::localGhostedIndex()). Valid until restoreLocalGhostedView(), which must be called before any other use of the Vector.
| PetscInt vulpes::la::Vector::getLocalSize | ( | ) | const |
Get the local size of the vector.
| void vulpes::la::Vector::getLocalValues | ( | std::vector< PetscScalar > & | values | ) | const |
Get all local values of the vector.
| std::pair< PetscInt, PetscInt > vulpes::la::Vector::getLocAndGlobSize | ( | ) | const |
Get local and global sizes of the vector.
| std::array< PetscInt, 2 > vulpes::la::Vector::getOwnershipRange | ( | ) | const |
Get the ownership range of the vector.
|
inline |
Get the underlying PETSc vector (non-const version).
|
inline |
Get the underlying PETSc vector (const version).
| PetscInt vulpes::la::Vector::getSize | ( | ) | const |
Get the size of the vector.
| PetscScalar vulpes::la::Vector::getValue | ( | PetscInt | idx | ) | const |
Get a single value from the vector.
|
inline |
Initialize the vector based on a DofHandler.
|
inline |
Initialize a ghost-aware vector from a DofHandler (see the GhostTag constructor).
| void vulpes::la::Vector::insertValues | ( | const Eigen::Ref< const Eigen::MatrixXd > & | loc_vec, |
| const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > & | idxs, | ||
| InsertMode | mode = ADD_VALUES ) |
| void vulpes::la::Vector::insertValues | ( | const PetscScalar * | values, |
| const PetscInt * | indices, | ||
| PetscInt | n_values, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert values into the vector at specified indices.
| values | Pointer to the array of values to insert |
| indices | Pointer to the array of indices where values should be inserted |
| n_values | Number of values to insert |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| void vulpes::la::Vector::insertValuesBlocked | ( | const Eigen::Ref< const Eigen::MatrixXd > & | loc_vec, |
| const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > & | idxs, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert blocked values from an Eigen matrix into the vector at specified indices.
| loc_vec | Eigen reference to the local blocked vector values (should be of size block_size times the size of idxs) |
| idxs | Indices where the blocked values should be inserted |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| void vulpes::la::Vector::insertValuesBlocked | ( | const PetscScalar * | values, |
| const PetscInt * | indices, | ||
| PetscInt | n_values, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert blocked values into the vector at specified indices.
| values | Pointer to the array of blocked values to insert (of size block_size * n_values) |
| indices | Pointer to the array of indices where blocked values should be inserted |
| n_values | Number of blocked values to insert |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| PetscScalar vulpes::la::Vector::norm | ( | NormType | norm_type = NORM_2 | ) | const |
Compute the norm of the vector.
| PetscScalar vulpes::la::Vector::norm2 | ( | ) | const |
Compute the Euclidean norm of the vector.
| void vulpes::la::Vector::pow | ( | PetscScalar | power | ) |
Replaces each component of a vector by its p-th power.
| void vulpes::la::Vector::print | ( | ) | const |
Print the vector to standard output.
| void vulpes::la::Vector::restoreLocalGhostedView | ( | ) |
| void vulpes::la::Vector::save | ( | const std::string & | filename, |
| const std::string & | vecname = "", | ||
| PetscViewerFormat | format = PETSC_VIEWER_ASCII_MATLAB ) const |
Save the vector to a file.
| void vulpes::la::Vector::saveBinary | ( | const std::string & | filename, |
| const std::string & | vecname = "" ) const |
Save the vector to a binary file.
| void vulpes::la::Vector::scale | ( | double | value | ) |
Scale the vector by a constant.
| void vulpes::la::Vector::set | ( | double | value | ) |
Set all values in the vector to a constant.
|
protected |
| void vulpes::la::Vector::setValue | ( | PetscInt | idx, |
| PetscScalar | value, | ||
| InsertMode | mode = INSERT_VALUES ) |
Set a single value in the vector.
|
protected |
| PetscScalar vulpes::la::Vector::sum | ( | ) | const |
Compute the sum of all elements in the vector.
| Eigen::Map< const Eigen::VectorXd > vulpes::la::Vector::toEigenMap | ( | ) | const |
Convert the locally-owned vector entries to an Eigen map (same as toLocalEigenMap()).
| Eigen::Map< const Eigen::VectorXd > vulpes::la::Vector::toLocalEigenMap | ( | ) | const |
Convert the locally-owned vector entries to an Eigen map.
| Eigen::VectorXd vulpes::la::Vector::toLocalGhostedEigenVector | ( | ) | const |
Local-form snapshot of a ghost-aware Vector (see createGhosted()): this rank's owned dofs first ([0, n_owned)), then its ghost dofs in DofHandler::getGhostDofs() order ([n_owned, n_owned + n_ghost)). Use DofHandler::localGhostedIndex(global_dof_id) to index into it rather than hand-rolling ownership-range arithmetic against a global dof id – doing that by hand for a ghost dof is exactly the bug this class exists to remove (a global dof id belonging to another rank is not a valid index into toEigenMap()/toLocalEigenMap()). The ghost segment is only current immediately after updateGhosts(); nothing invalidates it automatically on a subsequent write. Only valid on a Vector built via createGhosted().
| void vulpes::la::Vector::updateGhosts | ( | ) |
Refresh the ghost padding of a ghost-aware Vector (see createGhosted()) from each ghost dof's owning rank. Collective; call after writing new values, before reading any ghost value via toLocalGhostedEigenVector(). Only valid on a Vector built via createGhosted().
| void vulpes::la::Vector::updateGhostsBegin | ( | ) |
updateGhosts() split in two, so that the exchanges of several vectors overlap: begin all of them, then end all of them.
| void vulpes::la::Vector::updateGhostsEnd | ( | ) |
| void vulpes::la::Vector::zero | ( | ) |
Zero out the vector.
|
protected |
|
protected |
|
protected |
|
protected |