![]() |
Vulpes
0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
|
#include <sparse_matrix.hpp>
Public Types | |
| enum | Type { Plain , IntelMKL , AcceleratedSIMD , Vectorized , Block } |
Public Member Functions | |
| template<typename DofHandler> | |
| SparseMatrix (const DofHandler &dof_handler, Type type=Plain, PetscInt block_size=1, PetscInt aij_block_size=1) | |
| Construct a SparseMatrix based on a DofHandler's sparsity pattern. | |
| SparseMatrix (const SparseMatrix &other, MatDuplicateOption duplicate_options) | |
| Construct a SparseMatrix by duplicating another SparseMatrix. | |
| SparseMatrix (PetscInt loc_size, PetscInt glob_size, Type type=Plain) | |
| Construct a SparseMatrix with given local and global sizes. | |
| SparseMatrix & | operator= (const SparseMatrix &other)=delete |
| SparseMatrix (const SparseMatrix &)=delete | |
| SparseMatrix (SparseMatrix &&)=delete | |
| SparseMatrix & | operator= (SparseMatrix &&)=delete |
| template<typename DofHandler> | |
| void | init (const DofHandler &dof_handler, Type type=Plain, PetscInt block_size=1, PetscInt aij_block_size=1) |
| Initialize the SparseMatrix based on a DofHandler's sparsity pattern. | |
| void | compress () |
| Finalize the assembly of the matrix by doing intracommunication. | |
| void | zero () |
| Set all entries to zero, keeping the nonzero pattern. | |
| void | print () const |
| Print the matrix to standard output. | |
| void | save (const std::string &filename, const std::string &matname="", PetscViewerFormat format=PETSC_VIEWER_ASCII_MATLAB) const |
| Save the matrix to a file. | |
| void | saveBinary (const std::string &filename, const std::string &matname="") const |
| Save the matrix to a file in binary format. | |
| std::array< PetscInt, 2 > | getSize () const |
| Get the size of the matrix as an array [rows, cols]. | |
| PetscInt | getBlockSize () const |
| Get the block size of the matrix. | |
| void | copy (const la::SparseMatrix &src, MatStructure str=DIFFERENT_NONZERO_PATTERN) |
| Copy the contents of another SparseMatrix into this one. | |
| void | insertValue (PetscScalar value, PetscInt i, PetscInt j, InsertMode mode=ADD_VALUES) |
| Insert a single value into the matrix. | |
| void | insertValues (const PetscScalar *loc_mat, const PetscInt *idxs_row, const PetscInt *idxs_col, PetscInt n_loc, DataLayout orientation=ColumnMajor, InsertMode mode=ADD_VALUES) |
| Insert a sub matrix into the matrix. | |
| void | insertValues (const Eigen::Ref< const Eigen::MatrixXd > &loc_mat, const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > &idxs_row_col, DataLayout orientation=ColumnMajor, InsertMode mode=ADD_VALUES) |
| Insert a sub matrix into the matrix. | |
| void | insertValues (const Eigen::Ref< const Eigen::MatrixXd > &loc_mat, const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > &idxs_row, const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > &idxs_col, DataLayout orientation=ColumnMajor, InsertMode mode=ADD_VALUES) |
| Insert a sub matrix into the matrix. | |
| void | insertValuesBlocked (const PetscScalar *loc_mat, const PetscInt *idxs_row, const PetscInt *idxs_col, PetscInt n_loc, DataLayout orientation=ColumnMajor, InsertMode mode=ADD_VALUES) |
| Insert a blocked sub matrix into the matrix. | |
| void | insertValuesBlocked (const Eigen::Ref< const Eigen::MatrixXd > &loc_mat, const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > &idxs_row_col, DataLayout orientation=ColumnMajor, InsertMode mode=ADD_VALUES) |
| Insert a blocked sub matrix into the matrix. | |
| void | insertValuesBlocked (const Eigen::Ref< const Eigen::MatrixXd > &loc_mat, const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > &idxs_row, const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > &idxs_col, DataLayout orientation=ColumnMajor, InsertMode mode=ADD_VALUES) |
| Insert a blocked sub matrix into the matrix. | |
| Eigen::MatrixXd | toEigenDense () const |
| const auto & | getPetscMatrix () const |
| Get the underlying PETSc matrix. | |
| auto & | getPetscMatrix () |
| Get the underlying PETSc matrix (non-const). | |
| std::pair< PetscInt, PetscInt > | getMatrixSizes () const |
| Get the local and global sizes of the matrix. | |
| PetscReal | norm (NormType normType=NORM_FROBENIUS) const |
| Get the norm of the matrix. | |
| void | vmult (const Vector &in, Vector &out) const |
| void | vmultT (const Vector &in, Vector &out) const |
| void | vmultAdd (const Vector &in_mult, const Vector &in_add, Vector &out) const |
| void | vmultTAdd (const Vector &in_mult, const Vector &in_add, Vector &out) const |
| void | matMult (const SparseMatrix &B, SparseMatrix &C, MatReuse reuse=MAT_INITIAL_MATRIX, PetscReal fill=PETSC_DETERMINE) const |
| void | matMultTranspose (const SparseMatrix &B, SparseMatrix &C, MatReuse reuse=MAT_INITIAL_MATRIX, PetscReal fill=PETSC_DETERMINE) const |
| void | transposeMatMult (const SparseMatrix &B, SparseMatrix &C, MatReuse reuse=MAT_INITIAL_MATRIX, PetscReal fill=PETSC_DETERMINE) const |
| void | addScaledMatrix (const SparseMatrix &other, PetscScalar scale, MatStructure str=UNKNOWN_NONZERO_PATTERN) |
| void | scale (PetscScalar value) |
| Multiply all entries by a scalar, in place. | |
| void | pinDof (PetscInt dof_idx, PetscScalar value=1.0) |
| Pin a degree of freedom to enforce a constraint This performs symmetric elimination: sets row and column of the specified DOF to zero, except the diagonal which is set to 1.0. This removes a DOF from the system and is useful for enforcing Dirichlet BCs or removing null space (e.g., constant modes in periodic problems). The corresponding RHS entry should be set to the desired value. | |
| void | setNearNullSpace (const Vector &v) |
| Attach a near null space to the matrix, used by algebraic multigrid preconditioners (e.g. GAMG) to build the coarse spaces. | |
| ~SparseMatrix () | |
Static Public Member Functions | |
| static bool | compareSparseMatrices (const SparseMatrix &mat1, const SparseMatrix &mat2, double tolerance=1e-12) |
| Static function that compares two sparse matrices for equality within a given tolerance. | |
Protected Member Functions | |
| SparseMatrix (Mat existing_matrix) | |
| void | createMatrix (Type type) |
| void | setMatrixSizes (const PetscInt n_loc, const PetscInt n_glob) |
| template<typename DofHandler> | |
| void | computePreallocationData (const DofHandler &dof_handler, const PetscInt dof_begin, const PetscInt dof_end, std::vector< PetscInt > &dnn, std::vector< PetscInt > &onn) |
| void | allocateMatrix (Type type, const std::vector< PetscInt > &dnn, const std::vector< PetscInt > &onn, PetscInt block_size) |
Protected Attributes | |
| Mat | m_petsc_matrix |
|
inlineexplicit |
Construct a SparseMatrix based on a DofHandler's sparsity pattern.
| dof_handler | The DofHandler providing the sparsity pattern |
| type | The type of the matrix (Plain, Block, etc.) |
| block_size | The block size for Block type matrices |
| aij_block_size | Block size of the rows and columns of a non-Block matrix (e.g. the dofs of a DG cell): the storage stays AIJ, the blocks are used by GAMG (aggregation of whole blocks) and PBJACOBI |
| vulpes::la::SparseMatrix::SparseMatrix | ( | const SparseMatrix & | other, |
| MatDuplicateOption | duplicate_options ) |
Construct a SparseMatrix by duplicating another SparseMatrix.
| other | The SparseMatrix to duplicate |
| duplicate_options | Copy options (sparsity pattern, values, etc.) |
Construct a SparseMatrix with given local and global sizes.
| loc_size | The local number of rows |
| glob_size | The global number of rows |
| type | The type of the matrix (Plain, Block, etc.) |
|
delete |
|
delete |
| vulpes::la::SparseMatrix::~SparseMatrix | ( | ) |
|
inlineexplicitprotected |
| void vulpes::la::SparseMatrix::addScaledMatrix | ( | const SparseMatrix & | other, |
| PetscScalar | scale, | ||
| MatStructure | str = UNKNOWN_NONZERO_PATTERN ) |
|
protected |
|
static |
Static function that compares two sparse matrices for equality within a given tolerance.
| mat1 | First matrix |
| mat2 | Second matrix |
| tolerance | Tolerance for comparison |
| void vulpes::la::SparseMatrix::compress | ( | ) |
Finalize the assembly of the matrix by doing intracommunication.
|
inlineprotected |
| void vulpes::la::SparseMatrix::copy | ( | const la::SparseMatrix & | src, |
| MatStructure | str = DIFFERENT_NONZERO_PATTERN ) |
Copy the contents of another SparseMatrix into this one.
|
protected |
| PetscInt vulpes::la::SparseMatrix::getBlockSize | ( | ) | const |
Get the block size of the matrix.
| std::pair< PetscInt, PetscInt > vulpes::la::SparseMatrix::getMatrixSizes | ( | ) | const |
Get the local and global sizes of the matrix.
|
inline |
Get the underlying PETSc matrix (non-const).
|
inline |
Get the underlying PETSc matrix.
| std::array< PetscInt, 2 > vulpes::la::SparseMatrix::getSize | ( | ) | const |
Get the size of the matrix as an array [rows, cols].
|
inline |
Initialize the SparseMatrix based on a DofHandler's sparsity pattern.
| dof_handler | The DofHandler providing the sparsity pattern |
| type | The type of the matrix (Plain, Block, etc.) |
| block_size | The block size for Block type matrices |
| aij_block_size | Block size of the rows and columns of a non-Block matrix, see the constructor |
| void vulpes::la::SparseMatrix::insertValue | ( | PetscScalar | value, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert a single value into the matrix.
| void vulpes::la::SparseMatrix::insertValues | ( | const Eigen::Ref< const Eigen::MatrixXd > & | loc_mat, |
| const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > & | idxs_row, | ||
| const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > & | idxs_col, | ||
| DataLayout | orientation = ColumnMajor, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert a sub matrix into the matrix.
| loc_mat | Eigen reference to the local matrix values |
| idxs_row | Row indices |
| idxs_col | Column indices |
| orientation | Data layout of the local matrix (ColumnMajor or RowMajor) |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| void vulpes::la::SparseMatrix::insertValues | ( | const Eigen::Ref< const Eigen::MatrixXd > & | loc_mat, |
| const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > & | idxs_row_col, | ||
| DataLayout | orientation = ColumnMajor, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert a sub matrix into the matrix.
| loc_mat | Eigen reference to the local matrix values |
| idxs_row_col | Row and column indices (same for both) |
| orientation | Data layout of the local matrix (ColumnMajor or RowMajor) |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| void vulpes::la::SparseMatrix::insertValues | ( | const PetscScalar * | loc_mat, |
| const PetscInt * | idxs_row, | ||
| const PetscInt * | idxs_col, | ||
| PetscInt | n_loc, | ||
| DataLayout | orientation = ColumnMajor, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert a sub matrix into the matrix.
| loc_mat | Pointer to the local matrix values |
| idxs_row | Pointer to the row indices |
| idxs_col | Pointer to the column indices |
| n_loc | Number of local rows/columns |
| orientation | Data layout of the local matrix (ColumnMajor or RowMajor) |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| void vulpes::la::SparseMatrix::insertValuesBlocked | ( | const Eigen::Ref< const Eigen::MatrixXd > & | loc_mat, |
| const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > & | idxs_row, | ||
| const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > & | idxs_col, | ||
| DataLayout | orientation = ColumnMajor, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert a blocked sub matrix into the matrix.
| loc_mat | Eigen reference to the local matrix values (it must have size [block_size * n_loc, block_size * n_loc]) |
| idxs_row | Row indices |
| idxs_col | Column indices |
| orientation | Data layout of the local matrix (ColumnMajor or RowMajor) |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| void vulpes::la::SparseMatrix::insertValuesBlocked | ( | const Eigen::Ref< const Eigen::MatrixXd > & | loc_mat, |
| const datastructure::CrsMap< PetscInt, PetscInt >::RowView< false > & | idxs_row_col, | ||
| DataLayout | orientation = ColumnMajor, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert a blocked sub matrix into the matrix.
| loc_mat | Eigen reference to the local matrix values (it must have size [block_size * n_loc, block_size * n_loc]) |
| idxs_row_col | Row and column indices (same for both) |
| orientation | Data layout of the local matrix (ColumnMajor or RowMajor) |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| void vulpes::la::SparseMatrix::insertValuesBlocked | ( | const PetscScalar * | loc_mat, |
| const PetscInt * | idxs_row, | ||
| const PetscInt * | idxs_col, | ||
| PetscInt | n_loc, | ||
| DataLayout | orientation = ColumnMajor, | ||
| InsertMode | mode = ADD_VALUES ) |
Insert a blocked sub matrix into the matrix.
| loc_mat | Pointer to the local matrix values (it must have size [block_size * n_loc, block_size * n_loc]) |
| idxs_row | Pointer to the row indices |
| idxs_col | Pointer to the column indices |
| n_loc | Number of local rows/columns (in blocks) |
| orientation | Data layout of the local matrix (ColumnMajor or RowMajor) |
| mode | Insertion mode (ADD_VALUES or INSERT_VALUES) |
| void vulpes::la::SparseMatrix::matMult | ( | const SparseMatrix & | B, |
| SparseMatrix & | C, | ||
| MatReuse | reuse = MAT_INITIAL_MATRIX, | ||
| PetscReal | fill = PETSC_DETERMINE ) const |
| void vulpes::la::SparseMatrix::matMultTranspose | ( | const SparseMatrix & | B, |
| SparseMatrix & | C, | ||
| MatReuse | reuse = MAT_INITIAL_MATRIX, | ||
| PetscReal | fill = PETSC_DETERMINE ) const |
| PetscReal vulpes::la::SparseMatrix::norm | ( | NormType | normType = NORM_FROBENIUS | ) | const |
Get the norm of the matrix.
|
delete |
|
delete |
| void vulpes::la::SparseMatrix::pinDof | ( | PetscInt | dof_idx, |
| PetscScalar | value = 1.0 ) |
Pin a degree of freedom to enforce a constraint This performs symmetric elimination: sets row and column of the specified DOF to zero, except the diagonal which is set to 1.0. This removes a DOF from the system and is useful for enforcing Dirichlet BCs or removing null space (e.g., constant modes in periodic problems). The corresponding RHS entry should be set to the desired value.
| dof_idx | The global index of the DOF to pin |
| value | The diagonal value to set (default 1.0) |
| void vulpes::la::SparseMatrix::print | ( | ) | const |
Print the matrix to standard output.
| void vulpes::la::SparseMatrix::save | ( | const std::string & | filename, |
| const std::string & | matname = "", | ||
| PetscViewerFormat | format = PETSC_VIEWER_ASCII_MATLAB ) const |
Save the matrix to a file.
| filename | The name of the file |
| matname | The name of the matrix inside the file |
| format | The format to use for saving |
| void vulpes::la::SparseMatrix::saveBinary | ( | const std::string & | filename, |
| const std::string & | matname = "" ) const |
Save the matrix to a file in binary format.
| filename | The name of the file |
| matname | The name of the matrix inside the file |
| void vulpes::la::SparseMatrix::scale | ( | PetscScalar | value | ) |
Multiply all entries by a scalar, in place.
|
protected |
| void vulpes::la::SparseMatrix::setNearNullSpace | ( | const Vector & | v | ) |
Attach a near null space to the matrix, used by algebraic multigrid preconditioners (e.g. GAMG) to build the coarse spaces.
| v | Vector spanning the near null space (e.g. the coefficients of the constant function for the Laplacian); it is copied and normalized |
| Eigen::MatrixXd vulpes::la::SparseMatrix::toEigenDense | ( | ) | const |
Convert the sparse matrix to a dense Eigen matrix
| void vulpes::la::SparseMatrix::transposeMatMult | ( | const SparseMatrix & | B, |
| SparseMatrix & | C, | ||
| MatReuse | reuse = MAT_INITIAL_MATRIX, | ||
| PetscReal | fill = PETSC_DETERMINE ) const |
| void vulpes::la::SparseMatrix::vmultAdd | ( | const Vector & | in_mult, |
| const Vector & | in_add, | ||
| Vector & | out ) const |
| void vulpes::la::SparseMatrix::vmultTAdd | ( | const Vector & | in_mult, |
| const Vector & | in_add, | ||
| Vector & | out ) const |
| void vulpes::la::SparseMatrix::zero | ( | ) |
Set all entries to zero, keeping the nonzero pattern.
|
protected |