OOFEM
2.4
OOFEM.org - Object Oriented Finite Element Solver
|
This class provides an sparse matrix interface to PETSc Matrices. More...
#include <petscsparsemtrx.h>
Public Member Functions | |
PetscSparseMtrx (int n, int m) | |
PetscSparseMtrx () | |
virtual | ~PetscSparseMtrx () |
virtual SparseMtrx * | GiveCopy () const |
Returns a newly allocated copy of receiver. More... | |
virtual void | times (const FloatArray &x, FloatArray &answer) const |
Evaluates . More... | |
virtual void | timesT (const FloatArray &x, FloatArray &answer) const |
Evaluates . More... | |
virtual void | times (const FloatMatrix &B, FloatMatrix &answer) const |
Evaluates . More... | |
virtual void | timesT (const FloatMatrix &B, FloatMatrix &answer) const |
Evaluates . More... | |
virtual void | times (double x) |
Multiplies receiver by scalar value. More... | |
virtual void | add (double x, SparseMtrx &m) |
Adds x * m. More... | |
virtual void | addDiagonal (double x, FloatArray &m) |
Adds x * m (treats m as a diagonal matrix, stored as an array) More... | |
virtual int | buildInternalStructure (EngngModel *eModel, int n, int m, const IntArray &I, const IntArray &J) |
Builds internal structure of receiver based on I and J. More... | |
virtual int | buildInternalStructure (EngngModel *eModel, int di, const UnknownNumberingScheme &s) |
Builds internal structure of receiver. More... | |
virtual int | buildInternalStructure (EngngModel *eModel, int di, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s) |
virtual int | assemble (const IntArray &loc, const FloatMatrix &mat) |
Assembles sparse matrix from contribution of local elements. More... | |
virtual int | assemble (const IntArray &rloc, const IntArray &cloc, const FloatMatrix &mat) |
Assembles sparse matrix from contribution of local elements. More... | |
virtual int | assembleBegin () |
Starts assembling the elements. More... | |
virtual int | assembleEnd () |
Returns when assemble is completed. More... | |
virtual SparseMtrx * | giveSubMatrix (const IntArray &rows, const IntArray &cols) |
virtual bool | canBeFactorized () const |
Determines, whether receiver can be factorized. More... | |
virtual SparseMtrx * | factorized () |
Returns the receiver factorized. More... | |
virtual FloatArray * | backSubstitutionWith (FloatArray &y) const |
Computes the solution of linear system where A is receiver. More... | |
virtual void | zero () |
Zeroes the receiver. More... | |
virtual double | computeNorm () const |
Returns the norm of receiver. More... | |
virtual double & | at (int i, int j) |
Returns coefficient at position (i,j). More... | |
virtual double | at (int i, int j) const |
Returns coefficient at position (i,j). More... | |
virtual void | toFloatMatrix (FloatMatrix &answer) const |
Converts receiving sparse matrix to a dense float matrix. More... | |
virtual void | printStatistics () const |
Prints the receiver statistics (one-line) to stdout. More... | |
virtual void | printYourself () const |
Prints receiver to stdout. Works only for relatively small matrices. More... | |
void | printMatlab () const |
virtual SparseMtrxType | giveType () const |
Sparse matrix type identification. More... | |
virtual bool | isAsymmetric () const |
Returns true if asymmetric. More... | |
virtual void | writeToFile (const char *fname) const |
Helpful for debugging, writes the matrix to given file. More... | |
virtual const char * | giveClassName () const |
void | createVecGlobal (Vec *answer) const |
Creates a global vector that fits the instance of this matrix. More... | |
int | scatterG2L (Vec src, FloatArray &dest) const |
Scatters global vector to natural one. More... | |
int | scatterL2G (const FloatArray &src, Vec dest) const |
Scatters and gathers vector in local form to global (parallel) one. More... | |
Mat * | giveMtrx () |
bool | giveSymmetryFlag () const |
int | setOption (MatOption op, PetscBool flag) |
int | giveLeqs () |
int | giveDomainIndex () const |
Public Member Functions inherited from oofem::SparseMtrx | |
SparseMtrx (int n, int m) | |
Constructor, creates (n,m) sparse matrix. More... | |
SparseMtrx () | |
Constructor. More... | |
virtual | ~SparseMtrx () |
Destructor. More... | |
SparseMtrxVersionType | giveVersion () |
Return receiver version. More... | |
void | checkBounds (int i, int j) const |
Checks size of receiver towards requested bounds. More... | |
int | giveNumberOfRows () const |
Returns number of rows of receiver. More... | |
int | giveNumberOfColumns () const |
Returns number of columns of receiver. More... | |
bool | isSquare () const |
Returns nonzero if receiver is square matrix. More... | |
bool | isNotEmpty () const |
Tests for empty matrix. More... | |
virtual bool | isAllocatedAt (int i, int j) const |
Checks whether memory is allocated at position (i,j). More... | |
std::string | errorInfo (const char *func) const |
Error printing helper. More... | |
FloatArray | operator* (const FloatArray &x) const |
IML compatibility, . More... | |
FloatArray | trans_mult (const FloatArray &x) const |
IML compatibility, . More... | |
Protected Attributes | |
Mat | mtrx |
bool | symmFlag |
MatType | mType |
int | leqs |
int | geqs |
int | blocksize |
int | di |
EngngModel * | emodel |
KSP | ksp |
Linear solver context. More... | |
bool | kspInit |
Flag if context initialized. More... | |
bool | newValues |
Flag if matrix has changed since last solve. More... | |
IS | localIS |
Context or scattering/collecting parallel PETSc vectors. More... | |
IS | globalIS |
Protected Attributes inherited from oofem::SparseMtrx | |
int | nRows |
Number of rows. More... | |
int | nColumns |
Number of columns. More... | |
SparseMtrxVersionType | version |
Allows to track if receiver changes. More... | |
Friends | |
class | PetscSolver |
Additional Inherited Members | |
Public Types inherited from oofem::SparseMtrx | |
typedef long | SparseMtrxVersionType |
This class provides an sparse matrix interface to PETSc Matrices.
Definition at line 47 of file petscsparsemtrx.h.
oofem::PetscSparseMtrx::PetscSparseMtrx | ( | int | n, |
int | m | ||
) |
Definition at line 52 of file petscsparsemtrx.C.
oofem::PetscSparseMtrx::PetscSparseMtrx | ( | ) |
Definition at line 55 of file petscsparsemtrx.C.
Referenced by GiveCopy(), and giveSubMatrix().
|
virtual |
|
virtual |
Adds x * m.
x | Value to multiply m by. |
m | Matrix to add (should of the same matrix type). |
Reimplemented from oofem::SparseMtrx.
Definition at line 271 of file petscsparsemtrx.C.
References giveMtrx().
|
virtual |
Adds x * m (treats m as a diagonal matrix, stored as an array)
x | Value to multiply m by. |
m | Matrix to add. |
Reimplemented from oofem::SparseMtrx.
Definition at line 279 of file petscsparsemtrx.C.
References createVecGlobal(), emodel, oofem::FloatArray::givePointer(), oofem::FloatArray::giveSize(), oofem::EngngModel::isParallel(), mtrx, OOFEM_WARNING, and scatterL2G().
|
virtual |
Assembles sparse matrix from contribution of local elements.
This method for each element adds its contribution to itself. Mapping between local element contribution and its global position is given by local code numbers of element.
loc | Location array. The values corresponding to zero loc array value are not assembled. |
mat | Contribution to be assembled using loc array. |
Implements oofem::SparseMtrx.
Definition at line 732 of file petscsparsemtrx.C.
References oofem::IntArray::at(), blocksize, di, emodel, oofem::ParallelContext::giveN2Gmap(), oofem::FloatMatrix::giveNumberOfRows(), oofem::EngngModel::giveParallelContext(), oofem::IntArray::givePointer(), oofem::FloatMatrix::givePointer(), oofem::EngngModel::isParallel(), oofem::Natural2GlobalOrdering::map2New(), mtrx, newValues, and oofem::SparseMtrx::version.
|
virtual |
Assembles sparse matrix from contribution of local elements.
This method for each element adds its contribution to itself. Mapping between local element contribution and its global position is given by row and column local code numbers.
rloc | Row location array. The values corresponding to zero loc array value are not assembled. |
cloc | Column location array. The values corresponding to zero loc array value are not assembled. |
mat | Contribution to be assembled using rloc and cloc arrays. The rloc position determines the row, the cloc position determines the corresponding column. |
Implements oofem::SparseMtrx.
Definition at line 788 of file petscsparsemtrx.C.
References oofem::IntArray::at(), di, emodel, oofem::ParallelContext::giveN2Gmap(), oofem::EngngModel::giveParallelContext(), oofem::IntArray::givePointer(), oofem::FloatMatrix::givePointer(), oofem::IntArray::giveSize(), oofem::EngngModel::isParallel(), oofem::Natural2GlobalOrdering::map2New(), mtrx, newValues, and oofem::SparseMtrx::version.
|
virtual |
Starts assembling the elements.
Reimplemented from oofem::SparseMtrx.
Definition at line 824 of file petscsparsemtrx.C.
References mtrx.
|
virtual |
Returns when assemble is completed.
Reimplemented from oofem::SparseMtrx.
Definition at line 830 of file petscsparsemtrx.C.
|
virtual |
Returns coefficient at position (i,j).
Implements oofem::SparseMtrx.
Definition at line 860 of file petscsparsemtrx.C.
References OOFEM_ERROR.
|
virtual |
Returns coefficient at position (i,j).
Implements oofem::SparseMtrx.
Definition at line 868 of file petscsparsemtrx.C.
References OOFEM_ERROR.
|
inlinevirtual |
Computes the solution of linear system where A is receiver.
Solution vector x overwrites the right hand side vector y. Receiver must be in factorized form.
y | Right hand side on input, solution on output. |
Reimplemented from oofem::SparseMtrx.
Definition at line 94 of file petscsparsemtrx.h.
|
virtual |
Builds internal structure of receiver based on I and J.
This call is for special purpose uses. Normal problems should use the other prealloation methods.
eModel | Pointer to corresponding engineering model. |
I | Row indices |
J | Column indices |
Reimplemented from oofem::SparseMtrx.
Definition at line 294 of file petscsparsemtrx.C.
References blocksize, di, emodel, geqs, oofem::EngngModel::isParallel(), ksp, kspInit, leqs, mtrx, oofem::SparseMtrx::nColumns, newValues, oofem::SparseMtrx::nRows, and OOFEM_ERROR.
|
virtual |
Builds internal structure of receiver.
This method determines the internal profile of sparse matrix, allocates necessary space for storing nonzero coefficients and initializes receiver. In general, the profile of sparse matrix is determined using one (or more) loop over local code numbers of elements. This method must be called before any operation, like assembly, zeroing, or multiplication.
eModel | Pointer to corresponding engineering model. |
di | Domain index specify which domain to use. |
s | Determines unknown numbering scheme. |
Implements oofem::SparseMtrx.
Definition at line 474 of file petscsparsemtrx.C.
References oofem::IntArray::at(), blocksize, di, emodel, geqs, oofem::Domain::giveBcs(), oofem::Domain::giveDofManager(), oofem::EngngModel::giveDomain(), oofem::Domain::giveElements(), oofem::ActiveBoundaryCondition::giveLocationArrays(), oofem::ParallelContext::giveN2Gmap(), oofem::Natural2GlobalOrdering::giveN2Gmap(), oofem::ParallelContext::giveN2Lmap(), oofem::Natural2LocalOrdering::giveN2Lmap(), oofem::Domain::giveNumberOfDofManagers(), oofem::DofManager::giveNumberOfDofs(), oofem::EngngModel::giveNumberOfDomainEquations(), oofem::Natural2GlobalOrdering::giveNumberOfGlobalEqs(), oofem::Natural2GlobalOrdering::giveNumberOfLocalEqs(), oofem::ParallelContext::giveNumberOfNaturalEqs(), oofem::EngngModel::giveParallelComm(), oofem::EngngModel::giveParallelContext(), oofem::IntArray::givePointer(), oofem::EngngModel::giveRank(), oofem::IntArray::giveSize(), globalIS, oofem::Natural2GlobalOrdering::init(), oofem::Natural2LocalOrdering::init(), oofem::IntArray::insertSortedOnce(), oofem::EngngModel::isParallel(), ksp, kspInit, leqs, localIS, oofem::Natural2GlobalOrdering::map2New(), oofem::Natural2LocalOrdering::map2New(), mtrx, oofem::SparseMtrx::nColumns, newValues, oofem::SparseMtrx::nRows, OOFEM_LOG_DEBUG, OOFEM_LOG_INFO, oofem::IntArray::resize(), and VERBOSEPARALLEL_PRINT.
|
virtual |
Reimplemented from oofem::SparseMtrx.
Definition at line 366 of file petscsparsemtrx.C.
References blocksize, di, emodel, geqs, oofem::Domain::giveBcs(), oofem::EngngModel::giveDomain(), oofem::Domain::giveElements(), oofem::ActiveBoundaryCondition::giveLocationArrays(), oofem::EngngModel::giveNumberOfDomainEquations(), oofem::IntArray::insertSortedOnce(), oofem::EngngModel::isParallel(), ksp, kspInit, leqs, mtrx, oofem::SparseMtrx::nColumns, newValues, oofem::SparseMtrx::nRows, and OOFEM_ERROR.
|
inlinevirtual |
Determines, whether receiver can be factorized.
Implements oofem::SparseMtrx.
Definition at line 92 of file petscsparsemtrx.h.
|
virtual |
Returns the norm of receiver.
Reimplemented from oofem::SparseMtrx.
Definition at line 852 of file petscsparsemtrx.C.
References mtrx, and oofem::norm().
void oofem::PetscSparseMtrx::createVecGlobal | ( | Vec * | answer | ) | const |
Creates a global vector that fits the instance of this matrix.
Definition at line 954 of file petscsparsemtrx.C.
References emodel, geqs, oofem::SparseMtrx::giveNumberOfRows(), oofem::EngngModel::giveParallelComm(), oofem::EngngModel::isParallel(), and leqs.
Referenced by addDiagonal(), oofem::NRSolver::applyConstraintsToLoadIncrement(), oofem::NRSolver::applyConstraintsToStiffness(), oofem::PetscSolver::solve(), and times().
|
inlinevirtual |
Returns the receiver factorized.
form is used.
Reimplemented from oofem::SparseMtrx.
Definition at line 93 of file petscsparsemtrx.h.
|
inlinevirtual |
Implements oofem::SparseMtrx.
Definition at line 106 of file petscsparsemtrx.h.
|
virtual |
Returns a newly allocated copy of receiver.
Programmer must take care about proper deallocation of allocated space.
Reimplemented from oofem::SparseMtrx.
Definition at line 73 of file petscsparsemtrx.C.
References di, emodel, geqs, kspInit, leqs, mtrx, mType, oofem::SparseMtrx::nColumns, newValues, oofem::SparseMtrx::nRows, PetscSparseMtrx(), and symmFlag.
int oofem::PetscSparseMtrx::giveDomainIndex | ( | ) | const |
Definition at line 1081 of file petscsparsemtrx.C.
References di.
Referenced by oofem::SLEPcSolver::solve().
int oofem::PetscSparseMtrx::giveLeqs | ( | ) |
Definition at line 1076 of file petscsparsemtrx.C.
References leqs.
Mat * oofem::PetscSparseMtrx::giveMtrx | ( | ) |
Definition at line 1061 of file petscsparsemtrx.C.
References mtrx.
Referenced by add(), oofem::NRSolver::applyConstraintsToStiffness(), oofem::PetscSolver::petsc_solve(), and oofem::SLEPcSolver::solve().
|
virtual |
Reimplemented from oofem::SparseMtrx.
Definition at line 879 of file petscsparsemtrx.C.
References oofem::IntArray::add(), emodel, oofem::EngngModel::giveParallelComm(), oofem::IntArray::givePointer(), oofem::IntArray::giveSize(), mtrx, and PetscSparseMtrx().
bool oofem::PetscSparseMtrx::giveSymmetryFlag | ( | ) | const |
Definition at line 1066 of file petscsparsemtrx.C.
References symmFlag.
|
virtual |
Sparse matrix type identification.
Implements oofem::SparseMtrx.
Definition at line 1051 of file petscsparsemtrx.C.
References oofem::SMT_PetscMtrx.
|
virtual |
Returns true if asymmetric.
Implements oofem::SparseMtrx.
Definition at line 1056 of file petscsparsemtrx.C.
References symmFlag.
void oofem::PetscSparseMtrx::printMatlab | ( | ) | const |
Definition at line 933 of file petscsparsemtrx.C.
References mtrx.
|
virtual |
Prints the receiver statistics (one-line) to stdout.
Reimplemented from oofem::SparseMtrx.
Definition at line 919 of file petscsparsemtrx.C.
References mtrx.
|
virtual |
Prints receiver to stdout. Works only for relatively small matrices.
Reimplemented from oofem::SparseMtrx.
Definition at line 926 of file petscsparsemtrx.C.
References mtrx.
int oofem::PetscSparseMtrx::scatterG2L | ( | Vec | src, |
FloatArray & | dest | ||
) | const |
Scatters global vector to natural one.
Definition at line 971 of file petscsparsemtrx.C.
References oofem::FloatArray::at(), di, emodel, oofem::ParallelContext::giveNumberOfNaturalEqs(), oofem::SparseMtrx::giveNumberOfRows(), oofem::EngngModel::giveParallelContext(), globalIS, oofem::EngngModel::isParallel(), localIS, and oofem::FloatArray::resize().
Referenced by oofem::PetscSolver::solve(), oofem::SLEPcSolver::solve(), and times().
int oofem::PetscSparseMtrx::scatterL2G | ( | const FloatArray & | src, |
Vec | dest | ||
) | const |
Scatters and gathers vector in local form to global (parallel) one.
Only local entries are processed.
Definition at line 1013 of file petscsparsemtrx.C.
References di, emodel, oofem::ParallelContext::giveN2Gmap(), oofem::ParallelContext::giveN2Lmap(), oofem::Natural2GlobalOrdering::giveNewEq(), oofem::Natural2LocalOrdering::giveNewEq(), oofem::EngngModel::giveParallelContext(), oofem::FloatArray::givePointer(), oofem::FloatArray::giveSize(), and oofem::EngngModel::isParallel().
Referenced by addDiagonal(), oofem::PetscSolver::solve(), and times().
int oofem::PetscSparseMtrx::setOption | ( | MatOption | op, |
PetscBool | flag | ||
) |
Definition at line 1071 of file petscsparsemtrx.C.
References mtrx.
|
virtual |
Evaluates .
x | Array to be multiplied with receiver. |
answer | y. |
Reimplemented from oofem::SparseMtrx.
Definition at line 90 of file petscsparsemtrx.C.
References createVecGlobal(), emodel, oofem::SparseMtrx::giveNumberOfColumns(), oofem::FloatArray::givePointer(), oofem::FloatArray::giveSize(), oofem::EngngModel::isParallel(), mtrx, oofem::SparseMtrx::nRows, OOFEM_ERROR, oofem::FloatArray::resize(), scatterG2L(), and scatterL2G().
|
virtual |
Evaluates .
B | Array to be multiplied with receiver. |
answer | C. |
Reimplemented from oofem::SparseMtrx.
Definition at line 169 of file petscsparsemtrx.C.
References oofem::FloatMatrix::copyColumn(), emodel, oofem::SparseMtrx::giveNumberOfColumns(), oofem::FloatMatrix::giveNumberOfColumns(), oofem::SparseMtrx::giveNumberOfRows(), oofem::FloatMatrix::giveNumberOfRows(), oofem::FloatArray::givePointer(), oofem::FloatMatrix::givePointer(), oofem::EngngModel::isParallel(), mtrx, OOFEM_ERROR, and oofem::FloatMatrix::resize().
|
virtual |
Multiplies receiver by scalar value.
x | Value to multiply receiver. |
Reimplemented from oofem::SparseMtrx.
Definition at line 264 of file petscsparsemtrx.C.
References mtrx.
|
virtual |
Evaluates .
x | Array to be multiplied with transpose of the receiver. |
answer | y. |
Reimplemented from oofem::SparseMtrx.
Definition at line 138 of file petscsparsemtrx.C.
References emodel, oofem::SparseMtrx::giveNumberOfRows(), oofem::FloatArray::givePointer(), oofem::FloatArray::giveSize(), oofem::EngngModel::isParallel(), mtrx, oofem::SparseMtrx::nColumns, OOFEM_ERROR, and oofem::FloatArray::resize().
|
virtual |
Evaluates .
B | Matrix to be multiplied with receiver. |
answer | C. |
Reimplemented from oofem::SparseMtrx.
Definition at line 227 of file petscsparsemtrx.C.
References oofem::FloatMatrix::beTranspositionOf(), emodel, oofem::SparseMtrx::giveNumberOfColumns(), oofem::FloatMatrix::giveNumberOfColumns(), oofem::SparseMtrx::giveNumberOfRows(), oofem::FloatMatrix::giveNumberOfRows(), oofem::FloatMatrix::givePointer(), oofem::EngngModel::isParallel(), mtrx, OOFEM_ERROR, and oofem::FloatMatrix::resize().
|
virtual |
Converts receiving sparse matrix to a dense float matrix.
Reimplemented from oofem::SparseMtrx.
Definition at line 905 of file petscsparsemtrx.C.
References oofem::IntArray::add(), oofem::FloatMatrix::beTranspositionOf(), oofem::IntArray::enumerate(), oofem::SparseMtrx::giveNumberOfColumns(), oofem::SparseMtrx::giveNumberOfRows(), oofem::IntArray::givePointer(), oofem::FloatMatrix::givePointer(), oofem::IntArray::giveSize(), and mtrx.
|
virtual |
Helpful for debugging, writes the matrix to given file.
Reimplemented from oofem::SparseMtrx.
Definition at line 940 of file petscsparsemtrx.C.
References emodel, oofem::EngngModel::giveParallelComm(), and mtrx.
|
virtual |
Zeroes the receiver.
Implements oofem::SparseMtrx.
Definition at line 840 of file petscsparsemtrx.C.
|
friend |
Definition at line 125 of file petscsparsemtrx.h.
|
protected |
Definition at line 55 of file petscsparsemtrx.h.
Referenced by assemble(), and buildInternalStructure().
|
protected |
Definition at line 56 of file petscsparsemtrx.h.
Referenced by assemble(), buildInternalStructure(), GiveCopy(), giveDomainIndex(), scatterG2L(), and scatterL2G().
|
protected |
Definition at line 57 of file petscsparsemtrx.h.
Referenced by addDiagonal(), assemble(), buildInternalStructure(), createVecGlobal(), GiveCopy(), giveSubMatrix(), scatterG2L(), scatterL2G(), times(), timesT(), and writeToFile().
|
protected |
Definition at line 54 of file petscsparsemtrx.h.
Referenced by buildInternalStructure(), createVecGlobal(), and GiveCopy().
|
protected |
Definition at line 67 of file petscsparsemtrx.h.
Referenced by buildInternalStructure(), scatterG2L(), and ~PetscSparseMtrx().
|
protected |
Linear solver context.
Definition at line 60 of file petscsparsemtrx.h.
Referenced by buildInternalStructure(), oofem::PetscSolver::petsc_solve(), and ~PetscSparseMtrx().
|
protected |
Flag if context initialized.
Definition at line 62 of file petscsparsemtrx.h.
Referenced by buildInternalStructure(), GiveCopy(), oofem::PetscSolver::petsc_solve(), and ~PetscSparseMtrx().
|
protected |
Definition at line 53 of file petscsparsemtrx.h.
Referenced by buildInternalStructure(), createVecGlobal(), GiveCopy(), and giveLeqs().
|
protected |
Context or scattering/collecting parallel PETSc vectors.
Definition at line 67 of file petscsparsemtrx.h.
Referenced by buildInternalStructure(), scatterG2L(), and ~PetscSparseMtrx().
|
protected |
Definition at line 50 of file petscsparsemtrx.h.
Referenced by addDiagonal(), assemble(), assembleBegin(), assembleEnd(), buildInternalStructure(), computeNorm(), GiveCopy(), giveMtrx(), giveSubMatrix(), printMatlab(), printStatistics(), printYourself(), setOption(), times(), timesT(), toFloatMatrix(), writeToFile(), zero(), and ~PetscSparseMtrx().
|
protected |
Definition at line 52 of file petscsparsemtrx.h.
Referenced by GiveCopy().
|
protected |
Flag if matrix has changed since last solve.
Definition at line 64 of file petscsparsemtrx.h.
Referenced by assemble(), assembleEnd(), buildInternalStructure(), GiveCopy(), oofem::PetscSolver::petsc_solve(), and zero().
|
protected |
Definition at line 51 of file petscsparsemtrx.h.
Referenced by GiveCopy(), giveSymmetryFlag(), and isAsymmetric().