|
IFEM
90A354
|
Class for representing the system matrix in PETSc format. More...
#include <PETScMatrix.h>


Public Member Functions | |
| PETScMatrix (const ProcessAdm &padm, const LinSolParams &spar) | |
| Constructor. | |
| ~PETScMatrix () override | |
| The destructor frees the dynamically allocated arrays. | |
| LinAlg::MatrixType | getType () const override |
| Returns the matrix type. | |
| SystemMatrix * | copy () const override |
| Creates a copy of the system matrix and returns a pointer to it. | |
| size_t | dim (int idim=1) const override |
| Returns the dimension of the system matrix. More... | |
| bool | init (int maxEq, const IntMat *elms=nullptr, const IntMat *neighs=nullptr, const IntVec *part=nullptr) |
| Initializes a scalar matrix based on element connections. More... | |
| void | preAssemble (const std::vector< IntVec > &MMNPC, size_t nel) override |
| Initializes the equation sparsity pattern based on element connections. More... | |
| void | initAssembly (const SAM &sam, char) override |
| Initializes the element assembly process. More... | |
| void | init () override |
| Initializes the matrix to zero assuming it is properly dimensioned. | |
| bool | assemble (const Matrix &eM, const SAM &sam, int e) override |
| Adds an element matrix into the associated system matrix. More... | |
| bool | assemble (const Matrix &eM, const SAM &sam, SystemVector &B, int e) override |
| Adds an element matrix into the associated system matrix. More... | |
| bool | assemble (const Matrix &eM, const SAM &sam, SystemVector &B, const IntVec &meq) override |
| Adds an element matrix into the associated system matrix. More... | |
| bool | assemble (const Matrix &eM, const IntVec &meq) override |
| Adds an element matrix into the associated system matrix. More... | |
| bool | endAssembly () override |
| Finalizes the system matrix assembly. | |
| bool | multiply (const SystemVector &B, SystemVector &C) const override |
| Performs the matrix-vector multiplication C = *this * B. | |
| bool | solve (SystemVector &B, Real *) override |
| Solves the linear system of equations for a given right-hand-side. More... | |
| bool | solve (const SystemVector &B, SystemVector &x) override |
| Solves the linear system of equations for a given right-hand-side. More... | |
| void | mult (Real alpha) override |
| Multiplication with a scalar. | |
| bool | solveEig (PETScMatrix &B, RealArray &eigVal, Matrix &eigVec, int nev, Real shift=Real(0), int iop=1) |
| Solves a generalized symmetric-definite eigenproblem. More... | |
| Real | Linfnorm () const override |
| Returns the L-infinity norm of the matrix. | |
| Mat & | getMatrix () |
| Returns the PETSc matrix (for assignment). | |
| const Mat & | getMatrix () const |
| Returns the PETSc matrix (for read access). | |
| const std::vector< Mat > & | getBlockMatrices () const |
| Get vector of block matrices. Used for tests only. | |
| const std::vector< IS > & | getIS () const |
| Get vector of index sets. | |
| bool | setParameters (bool setup) |
| Set the linear solver parameters (solver type, preconditioner, tolerances). More... | |
| const ProcessAdm & | getAdm () const |
| Returns a const-ref to process administrator. | |
| bool | solveMultipleRhs (PETScVectors &B, Matrix &sField) |
| Solve for multiple right-hand-side vectors. More... | |
| const DomainDecomposition & | getDD () const |
| Returns a const-ref to domain decompositioning. | |
| bool | add (Real sigma, int ieq) override |
| Adds the constant σ to the diagonal of this matrix. | |
Public Member Functions inherited from SystemMatrix | |
| virtual | ~SystemMatrix () |
| Empty destructor. | |
| virtual bool | lockPattern (bool) |
| Locks or unlocks the sparsity pattern. | |
| virtual bool | empty () const |
| Checks if the matrix is empty. | |
| bool | isZero () const |
| Checks if the matrix have no non-zero contributions. | |
| virtual void | compressPattern () |
| Compresses the sparsity pattern. | |
| void | initNonZeroEqs () |
| Initializes the nonZeroEqs flags. | |
| bool | flagNonZeroEqs (const IntVec &meq={}) |
| Flags the equations meq as pivots with non-zero contributions. | |
| bool | flagNonZeroEqs (const SystemMatrix &B) |
| Flags the non-zero equations from B as non-zero pivots in this. | |
| virtual bool | augment (const SystemMatrix &, size_t, size_t) |
| Augments a similar matrix symmetrically to the current matrix. | |
| virtual bool | truncate (Real=Real(1.0e-16)) |
| Truncates all small matrix elements to zero. | |
| virtual bool | add (const SystemMatrix &, Real=Real(1)) |
| Adds a matrix with similar structure to the current matrix. | |
| virtual void | dump (std::ostream &, LinAlg::StorageFormat, const char *=nullptr) |
| Dumps the system matrix on a specified format. | |
| virtual void | dump (const char *fileName, std::streamsize precision=0, LinAlg::StorageFormat format=LinAlg::FLAT) |
| Dumps the system matrix to specified file. | |
| virtual bool | load (const char *, bool=false) |
| Loads the system matrix from specified file. | |
| StdVector | operator* (const SystemVector &b) const |
| Calculates a matrix-vector product. | |
| StdVector | operator/ (const SystemVector &b) |
| Solves a linear equation system. | |
Protected Member Functions | |
| bool | solve (const Vec &b, Vec &x, bool knoll) |
| Solve a linear system. | |
| PETScMatrix (const PETScMatrix &A)=delete | |
| Disabled copy constructor. | |
| PETScMatrix (const ProcessAdm &padm, const PETScSolParams &spar) | |
| Clone matrix data. | |
| void | setupSparsity (const IntVec &elms, const SAM &sam) |
| Setup sparsity pattern for model. More... | |
| void | setupBlockSparsity (const IntVec &elms, const SAM &sam) |
| Setup sparsity pattern for block-matrices for a model. | |
| void | setupGlb2Blk (const SAM &sam) |
| Calculates blocks for global eqs. | |
| Mat | preAllocator (const int nrows, const int ncols=0) const |
| Sets up preallocator matrix. | |
| std::vector< Mat > | preAllocators () const |
| Sets up preallocator matrices for blocks. | |
Protected Member Functions inherited from SystemMatrix | |
| SystemMatrix () | |
| Default constructor. | |
| SystemMatrix (const SystemMatrix &a) | |
| Copy constructor. | |
| virtual std::ostream & | write (std::ostream &os) const |
| Writes the system matrix to the given output stream. | |
Protected Attributes | |
| Mat | pA |
| The actual PETSc matrix. | |
| PetscInt | nrow |
| Number of matrix rows. | |
| PetscInt | ncol |
| Number of matrix columns. | |
| KSP | ksp |
| Linear equation solver. | |
| MatNullSpace * | nsp |
| Null-space of linear operator. | |
| const ProcessAdm & | adm |
| Process administrator. | |
| PETScSolParams | solParams |
| Linear solver parameters. | |
| bool | setParams |
| If linear solver parameters are set. | |
| std::string | forcedKSPType |
| Force a KSP type ignoring the parameters. | |
| PetscInt | ISsize |
| Number of index sets/elements. | |
| PetscRealVec | coords |
| Coordinates of local nodes (x0,y0,z0,x1,y1,...) | |
| ISMat | dirIndexSet |
| Direction ordering. | |
| int | nLinSolves |
| Number of linear solves. | |
| bool | assembled |
| True if PETSc matrix has been assembled. | |
| bool | factored |
| True if PETsc matrix has been factored. | |
| IS | glob2LocEq = nullptr |
| Index set for global-to-local equations. | |
| std::vector< Mat > | matvec |
| Blocks for block matrices. | |
| std::vector< IS > | isvec |
| Index sets for blocks. | |
| std::vector< std::array< int, 2 > > | glb2Blk |
| Maps equations to block and block eq. | |
| std::unique_ptr< DomainDecomposition > | m_dd {} |
| Internal partitioning information. | |
Additional Inherited Members | |
Static Public Member Functions inherited from SystemMatrix | |
| static SystemMatrix * | create (const ProcessAdm *adm, LinAlg::MatrixType mType, int num_thread_SLU=1) |
| Static method creating a matrix of the given type. | |
| static SystemMatrix * | create (const ProcessAdm *adm, LinAlg::MatrixType mType, const LinSolParams &spar) |
| Static method creating a matrix of the given type. | |
Class for representing the system matrix in PETSc format.
It is an interface to PETSc modules for assembling and solving linear systems of equations.
Adds an element matrix into the associated system matrix.
| [in] | eM | The element matrix |
| [in] | meq | Matrix of element equation numbers |
Implements SystemMatrix.
Adds an element matrix into the associated system matrix.
| [in] | eM | The element matrix |
| [in] | sam | Auxiliary data for FE assembly management |
| [in] | e | Identifier for the element that eM belongs to |
Implements SystemMatrix.
References adm, ProcessAdm::dd, SystemMatrix::flagNonZeroEqs(), SAM::getElmEqns(), glb2Blk, SAM::meqn, SAM::mmceq, SAM::mpmceq, utl::matrix< T >::rows(), and SAM::ttcc.
|
overridevirtual |
Adds an element matrix into the associated system matrix.
| [in] | eM | The element matrix |
| [in] | sam | Auxiliary data for FE assembly management |
| B | The system right-hand-side vector | |
| [in] | meq | Matrix of element equation numbers |
When multi-point constraints are present, contributions from these are also added into the system right-hand-side vector, B.
Implements SystemMatrix.
References adm, utl::matrix< T >::cols(), ProcessAdm::dd, SystemMatrix::flagNonZeroEqs(), glb2Blk, SAM::meqn, SAM::mmceq, SAM::mpmceq, utl::matrix< T >::rows(), and SAM::ttcc.
|
overridevirtual |
Adds an element matrix into the associated system matrix.
| [in] | eM | The element matrix |
| [in] | sam | Auxiliary data for FE assembly management |
| B | The system right-hand-side vector | |
| [in] | e | Identifier for the element that eM belongs to |
When multi-point constraints are present, contributions from these are also added into the system right-hand-side vector, B.
Implements SystemMatrix.
References adm, ProcessAdm::dd, SystemMatrix::flagNonZeroEqs(), SAM::getElmEqns(), glb2Blk, SAM::meqn, SAM::mmceq, SAM::mpmceq, utl::matrix< T >::rows(), and SAM::ttcc.
|
overridevirtual |
Returns the dimension of the system matrix.
| [in] | idim | Which direction to return the dimension in. |
Implements SystemMatrix.
Referenced by _eig_ax(), and eig_sol_().
| bool PETScMatrix::init | ( | int | maxEq, |
| const IntMat * | elms = nullptr, |
||
| const IntMat * | neighs = nullptr, |
||
| const IntVec * | part = nullptr |
||
| ) |
Initializes a scalar matrix based on element connections.
| [in] | maxEq | Maximum equation number |
| [in] | elms | Element nodal connection |
| [in] | neighs | Element graph |
| [in] | part | Partitioning to use |
References adm, ProcessAdm::dd, DomainDecomposition::isPartitioned(), m_dd, ncol, nrow, and pA.
Referenced by ASMbase::globalL2projection().
|
overridevirtual |
Initializes the element assembly process.
| [in] | sam | Auxiliary data describing the FE model topology, etc. |
Must be called once before the element assembly loop. The PETSc data structures are initialized and the all symbolic operations that are needed before the actual assembly can start are performed.
Implements SystemMatrix.
References adm, assembled, ProcessAdm::dd, DomainDecomposition::getBlockEqs(), DomainDecomposition::getElms(), DomainDecomposition::getGlobalEq(), PETScSolParams::getLinSysType(), DomainDecomposition::getMaxEq(), DomainDecomposition::getMinEq(), DomainDecomposition::getNoBlocks(), PETScSolParams::getNoBlocks(), DomainDecomposition::isPartitioned(), isvec, matvec, ncol, SAM::nel, nrow, pA, setupBlockSparsity(), setupSparsity(), solParams, LinAlg::SPD, and LinAlg::SYMMETRIC.
|
overridevirtual |
Initializes the equation sparsity pattern based on element connections.
| [in] | MMNPC | Matrix of matrices of nodal point correspondances |
| [in] | nel | Number of elements |
Reimplemented from SystemMatrix.
References endAssembly(), m_dd, nrow, pA, and preAllocator().
| bool PETScMatrix::setParameters | ( | bool | setup | ) |
Set the linear solver parameters (solver type, preconditioner, tolerances).
| [in] | setup | True to setup KSP/PC |
References adm, ProcessAdm::dd, forcedKSPType, PETScSolParams::getBlock(), DomainDecomposition::getBlockEqs(), PETScSolParams::getDoubleValue(), PETScSolParams::getIntValue(), SettingMap::getStringValue(), PETScSolParams::getStringValue(), isvec, ksp, matvec, PETScSolParams::setupPC(), and solParams.
Referenced by solve(), and solveEig().
Setup sparsity pattern for model.
| [in] | elms | Elements on this process |
| [in] | sam | Auxiliary data describing the FE model topology, etc. |
References adm, ProcessAdm::dd, endAssembly(), DomainDecomposition::getMaxEq(), DomainDecomposition::getMinEq(), pA, and preAllocator().
Referenced by initAssembly().
|
overridevirtual |
Solves the linear system of equations for a given right-hand-side.
| [in] | B | Right-hand-side vector |
| [out] | x | Solution vector |
Reimplemented from SystemMatrix.
References PETScVector::getVector(), and solve().
|
overridevirtual |
Solves the linear system of equations for a given right-hand-side.
| B | Right-hand-side vector on input, solution vector on output |
Implements SystemMatrix.
References PETScSolParams::getStringValue(), PETScVector::getVector(), and solParams.
Referenced by solve(), and solveMultipleRhs().
| bool PETScMatrix::solveEig | ( | PETScMatrix & | B, |
| RealArray & | eigVal, | ||
| Matrix & | eigVec, | ||
| int | nev, | ||
| Real | shift = Real(0), |
||
| int | iop = 1 |
||
| ) |
Solves a generalized symmetric-definite eigenproblem.
The eigenproblem is assumed to be on the form A x = λ B x where A ( = *this ) and B both are assumed to be symmetric and B also to be positive definite. The eigenproblem is solved by the SLEPc library subroutine EPSSolve.
| B | Symmetric and positive definite mass matrix. | |
| [out] | eigVal | Computed eigenvalues |
| [out] | eigVec | Computed eigenvectors stored column by column |
| [in] | nev | The number of eigenvalues and eigenvectors to compute |
| [in] | shift | Eigenvalue shift |
| [in] | iop | Option telling whether to factorize matrix A or B. |
References adm, ProcessAdm::dd, utl::matrix< T >::fillColumn(), DomainDecomposition::getG2LEQ(), PETScSolParams::getIntValue(), DomainDecomposition::isPartitioned(), ksp, pA, utl::matrix< T >::resize(), setParameters(), and solParams.
Referenced by eig::solve().
| bool PETScMatrix::solveMultipleRhs | ( | PETScVectors & | B, |
| Matrix & | sField | ||
| ) |
Solve for multiple right-hand-side vectors.
| B | Vectors with right-hand-sides to solve for |
| sField | Resulting vectors stored as a matrix |
References PETScVectors::dim(), PETScVectors::get(), m_dd, PETScVectors::size(), and solve().