OGS
|
Wrapper class for PETSc vector.
Definition at line 32 of file PETScVector.h.
#include <PETScVector.h>
Public Types | |
using | IndexType = PetscInt |
using | PETSc_Vec = Vec |
Private Member Functions | |
void | destroy () |
void | gatherLocalVectors (PetscScalar local_array[], PetscScalar global_array[]) const |
Collect local vectors. | |
PetscScalar * | getLocalVector () const |
PetscInt | getLocalIndex (const PetscInt global_index) const |
Get local index by a global index. | |
void | restoreArray (PetscScalar *array) const |
void | config () |
A function called by constructors to configure members. | |
Private Attributes | |
PETSc_Vec | v_ = nullptr |
PETSc_Vec | v_loc_ = nullptr |
PetscInt | start_rank_ |
Starting index in a rank. | |
PetscInt | end_rank_ |
Ending index in a rank. | |
PetscInt | size_ |
Size of the vector. | |
PetscInt | size_loc_ |
Size of local entries. | |
PetscInt | size_ghosts_ = 0 |
Size of local ghost entries. | |
bool | has_ghost_id_ = false |
Flag to indicate whether the vector is created with ghost entry indices. | |
std::vector< PetscScalar > | entry_array_ |
Array containing the entries of the vector. If the vector is created without given ghost IDs, the array contains all entries of the global vector, v_. Otherwise it only contains the entries of the global vector owned by the current rank. | |
std::map< PetscInt, PetscInt > | global_ids2local_ids_ghost_ |
Map global indices of ghost entries to local indices. | |
Friends | |
void | finalizeVectorAssembly (PETScVector &vec) |
Function to finalize the vector assembly. | |
Definition at line 35 of file PETScVector.h.
Definition at line 38 of file PETScVector.h.
|
inline |
Definition at line 41 of file PETScVector.h.
Constructor.
vec_size | The size of the vector, either global or local |
is_global_size | The flag of the type of vec_size, i.e. whether it is a global size or local size. The default is true. If is_global_size is true, the vector is created by the global size, the local size of the vector is determined by PETSc, and vice versa is the same. |
Definition at line 30 of file PETScVector.cpp.
MathLib::PETScVector::PETScVector | ( | const PetscInt | vec_size, |
const std::vector< PetscInt > & | ghost_ids, | ||
const bool | is_global_size = true ) |
Constructor.
vec_size | The size of the vector, either global or local |
ghost_ids | The global indices of ghost entries |
is_global_size | The flag of the type of vec_size, i.e. whether it is a global size or local size. The default is true. |
Definition at line 47 of file PETScVector.cpp.
References config(), global_ids2local_ids_ghost_, set(), size_loc_, and v_.
|
explicit |
Copy constructor.
existing_vec | The vector to be copied |
deep_copy | The flag for a deep copy, which means to copy the values as well, the default is true |
Definition at line 74 of file PETScVector.cpp.
References set(), shallowCopy(), and v_.
MathLib::PETScVector::PETScVector | ( | PETScVector && | other | ) |
Definition at line 85 of file PETScVector.cpp.
|
inline |
|
inline |
Add a value to an entry.
i | Number of the entry |
value | Value. |
Definition at line 107 of file PETScVector.h.
|
inline |
Add values to several entries.
e_idxs | Indices of entries to be added Note: std::size_t cannot be the type of e_idxs template argument. |
sub_vec | Entries to be added. |
Definition at line 120 of file PETScVector.h.
|
private |
A function called by constructors to configure members.
Definition at line 98 of file PETScVector.cpp.
References end_rank_, set(), size_, size_loc_, start_rank_, and v_.
Referenced by PETScVector(), PETScVector(), and shallowCopy().
void MathLib::PETScVector::copyValues | ( | std::vector< PetscScalar > & | u | ) | const |
Copy local entries including ghost ones to a vector.
u | a vector for the values of local entries. It will be resized to hold the current vector data. |
Definition at line 184 of file PETScVector.cpp.
References getGhostSize(), getLocalSize(), getLocalVector(), restoreArray(), set(), and MathLib::u.
Referenced by setLocalAccessibleVector().
|
inlineprivate |
Definition at line 222 of file PETScVector.h.
Referenced by ~PETScVector(), and shallowCopy().
void MathLib::PETScVector::finalizeAssembly | ( | ) |
Perform MPI collection of assembled entries in buffer.
Definition at line 109 of file PETScVector.cpp.
Referenced by MathLib::applyKnownSolution(), and MathLib::LinAlg::finalizeAssembly().
|
private |
Collect local vectors.
local_array | Local array |
global_array | Global array |
Definition at line 115 of file PETScVector.cpp.
References set(), and size_loc_.
Referenced by getGlobalVector().
PetscScalar MathLib::PETScVector::get | ( | const PetscInt | idx | ) | const |
Definition at line 193 of file PETScVector.cpp.
References entry_array_, getLocalIndex(), global_ids2local_ids_ghost_, set(), and size_.
std::vector< PetscScalar > MathLib::PETScVector::get | ( | std::vector< IndexType > const & | indices | ) | const |
Get several entries. setLocalAccessibleVector() must be called beforehand.
Definition at line 205 of file PETScVector.cpp.
References entry_array_, getLocalIndex(), global_ids2local_ids_ghost_, set(), and size_.
Referenced by operator[]().
|
inline |
Get the number of ghost entries in the same rank.
Definition at line 86 of file PETScVector.h.
References size_ghosts_.
Referenced by copyValues().
void MathLib::PETScVector::getGlobalVector | ( | std::vector< PetscScalar > & | u | ) | const |
Get global vector
u | Array to store the global vector. Memory allocation is needed in advance |
Definition at line 142 of file PETScVector.cpp.
References gatherLocalVectors(), OGS_FATAL, set(), size_, MathLib::u, and v_.
Get local index by a global index.
Definition at line 252 of file PETScVector.cpp.
References global_ids2local_ids_ghost_, set(), size_, and start_rank_.
|
inline |
Get the number of entries in the same rank.
Definition at line 84 of file PETScVector.h.
References size_loc_.
Referenced by copyValues().
|
private |
Get local vector, i.e. entries in the same rank
Definition at line 234 of file PETScVector.cpp.
References has_ghost_id_, set(), v_, and v_loc_.
Referenced by copyValues().
|
inline |
Get the start index of the local vector.
Definition at line 88 of file PETScVector.h.
References start_rank_.
|
inline |
Get the end index of the local vector.
Definition at line 90 of file PETScVector.h.
References end_rank_.
|
inline |
Exposes the underlying PETSc vector.
Definition at line 171 of file PETScVector.h.
References v_.
Referenced by MathLib::LinAlg::axpby(), MathLib::LinAlg::axpy(), MathLib::LinAlg::aypx(), MathLib::LinAlg::componentwiseDivide(), MathLib::LinAlg::copy(), MathLib::LinAlg::matMult(), MathLib::LinAlg::norm1(), MathLib::LinAlg::norm2(), MathLib::LinAlg::normMax(), MathLib::LinAlg::scale(), MathLib::LinAlg::set(), and MathLib::PETScLinearSolver::solve().
Exposes the underlying PETSc vector.
Definition at line 178 of file PETScVector.h.
References v_.
|
delete |
Disallow moving.
|
inline |
Get the value of an entry by [] operator. setLocalAccessibleVector() must be called beforehand.
Definition at line 155 of file PETScVector.h.
|
inlineprivate |
Restore array after finish access local array
array | Pointer to the local array fetched by VecGetArray |
Definition at line 266 of file PETScVector.cpp.
References has_ghost_id_, set(), v_, and v_loc_.
Referenced by copyValues().
|
inline |
Insert a single entry with value.
i | Entry index |
value | Entry value |
Definition at line 97 of file PETScVector.h.
Referenced by PETScVector(), PETScVector(), PETScVector(), add(), add(), MathLib::applyKnownSolution(), config(), copyValues(), destroy(), finalizeAssembly(), gatherLocalVectors(), get(), get(), getGlobalVector(), getLocalIndex(), getLocalVector(), operator[](), restoreArray(), set(), set(), setZero(), shallowCopy(), and viewer().
|
inline |
Add values to several entries
e_idxs | Indices of entries to be added. Note: std::size_t cannot be the type of e_idxs template argument |
sub_vec | Entries to be added |
Definition at line 133 of file PETScVector.h.
void MathLib::PETScVector::setLocalAccessibleVector | ( | ) | const |
Set local accessible vector in order to get entries. Call this before call operator[] or get(...).
Definition at line 179 of file PETScVector.cpp.
References copyValues(), and entry_array_.
Referenced by MathLib::LinAlg::setLocalAccessibleVector().
|
inline |
void MathLib::PETScVector::shallowCopy | ( | const PETScVector & | v | ) |
Definition at line 297 of file PETScVector.cpp.
References config(), destroy(), end_rank_, global_ids2local_ids_ghost_, has_ghost_id_, set(), size_, size_ghosts_, size_loc_, start_rank_, MathLib::v, and v_.
Referenced by PETScVector(), MathLib::LinAlg::copy(), and MathLib::LinAlg::matMult().
|
inline |
void MathLib::PETScVector::viewer | ( | const std::string & | file_name, |
const PetscViewerFormat | vw_format = PETSC_VIEWER_ASCII_MATLAB ) const |
View the global vector for test purpose. Do not use it for output a big vector.
file_name | File name for output |
vw_format | File format listed as: PETSC_VIEWER_DEFAULT Default format PETSC_VIEWER_ASCII_MATLAB MATLAB format PETSC_VIEWER_ASCII_DENSE Print matrix as dense PETSC_VIEWER_ASCII_IMPL Implementation-specific format (which is in many cases the same as the default) PETSC_VIEWER_ASCII_INFO Basic information about object PETSC_VIEWER_ASCII_INFO_DETAIL More detailed info about object PETSC_VIEWER_ASCII_COMMON Identical output format for all objects of a particular type PETSC_VIEWER_ASCII_INDEX (for vectors) Prints the vector element number next to each vector entry PETSC_VIEWER_ASCII_SYMMODU Print parallel vectors without indicating the processor ranges PETSC_VIEWER_ASCII_VTK Outputs the object to a VTK file PETSC_VIEWER_NATIVE Store the object to the binary file in its native format (for example, dense matrices are stored as dense), DMDA vectors are dumped directly to the file instead of being first put in the natural ordering PETSC_VIEWER_DRAW_BASIC Views the vector with a simple 1d plot PETSC_VIEWER_DRAW_LG Views the vector with a line graph PETSC_VIEWER_DRAW_CONTOUR Views the vector with a contour plot |
Definition at line 279 of file PETScVector.cpp.
References set(), v_, and viewer().
Referenced by viewer().
|
friend |
Function to finalize the vector assembly.
Definition at line 314 of file PETScVector.cpp.
|
private |
Ending index in a rank.
Definition at line 239 of file PETScVector.h.
Referenced by config(), getRangeEnd(), and shallowCopy().
|
mutableprivate |
Array containing the entries of the vector. If the vector is created without given ghost IDs, the array contains all entries of the global vector, v_. Otherwise it only contains the entries of the global vector owned by the current rank.
Definition at line 258 of file PETScVector.h.
Referenced by get(), get(), and setLocalAccessibleVector().
Map global indices of ghost entries to local indices.
Definition at line 261 of file PETScVector.h.
Referenced by PETScVector(), get(), get(), getLocalIndex(), and shallowCopy().
Flag to indicate whether the vector is created with ghost entry indices.
Definition at line 249 of file PETScVector.h.
Referenced by getLocalVector(), restoreArray(), and shallowCopy().
|
private |
Size of the vector.
Definition at line 242 of file PETScVector.h.
Referenced by config(), get(), get(), getGlobalVector(), getLocalIndex(), shallowCopy(), and size().
|
private |
Size of local ghost entries.
Definition at line 246 of file PETScVector.h.
Referenced by getGhostSize(), and shallowCopy().
|
private |
Size of local entries.
Definition at line 244 of file PETScVector.h.
Referenced by PETScVector(), config(), gatherLocalVectors(), getLocalSize(), and shallowCopy().
|
private |
Starting index in a rank.
Definition at line 237 of file PETScVector.h.
Referenced by config(), getLocalIndex(), getRangeBegin(), and shallowCopy().
Definition at line 231 of file PETScVector.h.
Referenced by PETScVector(), PETScVector(), PETScVector(), add(), add(), config(), destroy(), finalizeAssembly(), getGlobalVector(), getLocalVector(), getRawVector(), getRawVector(), restoreArray(), set(), set(), setZero(), shallowCopy(), and viewer().
Local vector, which is only for the case that v_ is created with ghost entries.
Definition at line 234 of file PETScVector.h.
Referenced by getLocalVector(), and restoreArray().