OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
oofem::PetscSparseMtrx Class Reference

This class provides an sparse matrix interface to PETSc Matrices. More...

#include <petscsparsemtrx.h>

+ Inheritance diagram for oofem::PetscSparseMtrx:
+ Collaboration diagram for oofem::PetscSparseMtrx:

Public Member Functions

 PetscSparseMtrx (int n, int m)
 
 PetscSparseMtrx ()
 
virtual ~PetscSparseMtrx ()
 
virtual SparseMtrxGiveCopy () const
 Returns a newly allocated copy of receiver. More...
 
virtual void times (const FloatArray &x, FloatArray &answer) const
 Evaluates $ y = A \cdot x $. More...
 
virtual void timesT (const FloatArray &x, FloatArray &answer) const
 Evaluates $ y = A^{\mathrm{T}} \cdot x $. More...
 
virtual void times (const FloatMatrix &B, FloatMatrix &answer) const
 Evaluates $ C = A^{\mathrm{T}} \cdot B $. More...
 
virtual void timesT (const FloatMatrix &B, FloatMatrix &answer) const
 Evaluates $ C = A^{\mathrm{T}} \cdot B $. 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 SparseMtrxgiveSubMatrix (const IntArray &rows, const IntArray &cols)
 
virtual bool canBeFactorized () const
 Determines, whether receiver can be factorized. More...
 
virtual SparseMtrxfactorized ()
 Returns the receiver factorized. More...
 
virtual FloatArraybackSubstitutionWith (FloatArray &y) const
 Computes the solution of linear system $ A\cdot x = y $ 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, $ A \cdot x$. More...
 
FloatArray trans_mult (const FloatArray &x) const
 IML compatibility, $ A^{\mathrm{T}} \cdot x$. More...
 

Protected Attributes

Mat mtrx
 
bool symmFlag
 
MatType mType
 
int leqs
 
int geqs
 
int blocksize
 
int di
 
EngngModelemodel
 
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
 

Detailed Description

This class provides an sparse matrix interface to PETSc Matrices.

Definition at line 47 of file petscsparsemtrx.h.

Constructor & Destructor Documentation

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().

oofem::PetscSparseMtrx::~PetscSparseMtrx ( )
virtual

Definition at line 59 of file petscsparsemtrx.C.

References globalIS, ksp, kspInit, localIS, and mtrx.

Member Function Documentation

void oofem::PetscSparseMtrx::add ( double  x,
SparseMtrx m 
)
virtual

Adds x * m.

Parameters
xValue to multiply m by.
mMatrix to add (should of the same matrix type).

Reimplemented from oofem::SparseMtrx.

Definition at line 271 of file petscsparsemtrx.C.

References giveMtrx().

void oofem::PetscSparseMtrx::addDiagonal ( double  x,
FloatArray m 
)
virtual

Adds x * m (treats m as a diagonal matrix, stored as an array)

Parameters
xValue to multiply m by.
mMatrix 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().

int oofem::PetscSparseMtrx::assemble ( const IntArray loc,
const FloatMatrix mat 
)
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.

Parameters
locLocation array. The values corresponding to zero loc array value are not assembled.
matContribution to be assembled using loc array.
Returns
Zero iff successful.

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.

int oofem::PetscSparseMtrx::assemble ( const IntArray rloc,
const IntArray cloc,
const FloatMatrix mat 
)
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.

Parameters
rlocRow location array. The values corresponding to zero loc array value are not assembled.
clocColumn location array. The values corresponding to zero loc array value are not assembled.
matContribution to be assembled using rloc and cloc arrays. The rloc position determines the row, the cloc position determines the corresponding column.
Returns
Zero iff successful.

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.

int oofem::PetscSparseMtrx::assembleBegin ( )
virtual

Starts assembling the elements.

Reimplemented from oofem::SparseMtrx.

Definition at line 824 of file petscsparsemtrx.C.

References mtrx.

int oofem::PetscSparseMtrx::assembleEnd ( )
virtual

Returns when assemble is completed.

Reimplemented from oofem::SparseMtrx.

Definition at line 830 of file petscsparsemtrx.C.

References mtrx, and newValues.

double & oofem::PetscSparseMtrx::at ( int  i,
int  j 
)
virtual

Returns coefficient at position (i,j).

Implements oofem::SparseMtrx.

Definition at line 860 of file petscsparsemtrx.C.

References OOFEM_ERROR.

double oofem::PetscSparseMtrx::at ( int  i,
int  j 
) const
virtual

Returns coefficient at position (i,j).

Implements oofem::SparseMtrx.

Definition at line 868 of file petscsparsemtrx.C.

References OOFEM_ERROR.

virtual FloatArray* oofem::PetscSparseMtrx::backSubstitutionWith ( FloatArray y) const
inlinevirtual

Computes the solution of linear system $ A\cdot x = y $ where A is receiver.

Solution vector x overwrites the right hand side vector y. Receiver must be in factorized form.

Parameters
yRight hand side on input, solution on output.
Returns
Pointer to y array.

Reimplemented from oofem::SparseMtrx.

Definition at line 94 of file petscsparsemtrx.h.

int oofem::PetscSparseMtrx::buildInternalStructure ( EngngModel eModel,
int  n,
int  m,
const IntArray I,
const IntArray J 
)
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.

Parameters
eModelPointer to corresponding engineering model.
IRow indices
JColumn indices
Returns
Zero iff successful.

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.

int oofem::PetscSparseMtrx::buildInternalStructure ( EngngModel eModel,
int  di,
const UnknownNumberingScheme s 
)
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.

Parameters
eModelPointer to corresponding engineering model.
diDomain index specify which domain to use.
sDetermines unknown numbering scheme.
Returns
Zero iff successful.
Todo:
Split this into upper and lower triangular part like for the sequential matrix (we can then use SBAIJ which is a huge performance boost)
Todo:
Take into account active boundary conditions here.

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.

int oofem::PetscSparseMtrx::buildInternalStructure ( EngngModel eModel,
int  di,
const UnknownNumberingScheme r_s,
const UnknownNumberingScheme c_s 
)
virtual
virtual bool oofem::PetscSparseMtrx::canBeFactorized ( ) const
inlinevirtual

Determines, whether receiver can be factorized.

Implements oofem::SparseMtrx.

Definition at line 92 of file petscsparsemtrx.h.

double oofem::PetscSparseMtrx::computeNorm ( ) const
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
virtual SparseMtrx* oofem::PetscSparseMtrx::factorized ( )
inlinevirtual

Returns the receiver factorized.

$ L^{\mathrm{T}} \cdot D \cdot L $ form is used.

Returns
pointer to the receiver

Reimplemented from oofem::SparseMtrx.

Definition at line 93 of file petscsparsemtrx.h.

virtual const char* oofem::PetscSparseMtrx::giveClassName ( ) const
inlinevirtual

Implements oofem::SparseMtrx.

Definition at line 106 of file petscsparsemtrx.h.

SparseMtrx * oofem::PetscSparseMtrx::GiveCopy ( ) const
virtual

Returns a newly allocated copy of receiver.

Programmer must take care about proper deallocation of allocated space.

Returns
Newly allocated copy of receiver.

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 ( )
SparseMtrx * oofem::PetscSparseMtrx::giveSubMatrix ( const IntArray rows,
const IntArray cols 
)
virtual
bool oofem::PetscSparseMtrx::giveSymmetryFlag ( ) const

Definition at line 1066 of file petscsparsemtrx.C.

References symmFlag.

SparseMtrxType oofem::PetscSparseMtrx::giveType ( ) const
virtual

Sparse matrix type identification.

Implements oofem::SparseMtrx.

Definition at line 1051 of file petscsparsemtrx.C.

References oofem::SMT_PetscMtrx.

bool oofem::PetscSparseMtrx::isAsymmetric ( ) const
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.

void oofem::PetscSparseMtrx::printStatistics ( ) const
virtual

Prints the receiver statistics (one-line) to stdout.

Reimplemented from oofem::SparseMtrx.

Definition at line 919 of file petscsparsemtrx.C.

References mtrx.

void oofem::PetscSparseMtrx::printYourself ( ) const
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::scatterL2G ( const FloatArray src,
Vec  dest 
) const
int oofem::PetscSparseMtrx::setOption ( MatOption  op,
PetscBool  flag 
)

Definition at line 1071 of file petscsparsemtrx.C.

References mtrx.

void oofem::PetscSparseMtrx::times ( const FloatArray x,
FloatArray answer 
) const
virtual
void oofem::PetscSparseMtrx::times ( double  x)
virtual

Multiplies receiver by scalar value.

Parameters
xValue to multiply receiver.

Reimplemented from oofem::SparseMtrx.

Definition at line 264 of file petscsparsemtrx.C.

References mtrx.

void oofem::PetscSparseMtrx::timesT ( const FloatArray x,
FloatArray answer 
) const
virtual

Evaluates $ y = A^{\mathrm{T}} \cdot x $.

Parameters
xArray to be multiplied with transpose of the receiver.
answery.

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().

void oofem::PetscSparseMtrx::toFloatMatrix ( FloatMatrix answer) const
virtual
void oofem::PetscSparseMtrx::writeToFile ( const char *  fname) const
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.

void oofem::PetscSparseMtrx::zero ( )
virtual

Zeroes the receiver.

Implements oofem::SparseMtrx.

Definition at line 840 of file petscsparsemtrx.C.

References mtrx, and newValues.

Friends And Related Function Documentation

friend class PetscSolver
friend

Definition at line 125 of file petscsparsemtrx.h.

Member Data Documentation

int oofem::PetscSparseMtrx::blocksize
protected

Definition at line 55 of file petscsparsemtrx.h.

Referenced by assemble(), and buildInternalStructure().

int oofem::PetscSparseMtrx::di
protected
EngngModel* oofem::PetscSparseMtrx::emodel
protected
int oofem::PetscSparseMtrx::geqs
protected

Definition at line 54 of file petscsparsemtrx.h.

Referenced by buildInternalStructure(), createVecGlobal(), and GiveCopy().

IS oofem::PetscSparseMtrx::globalIS
protected

Definition at line 67 of file petscsparsemtrx.h.

Referenced by buildInternalStructure(), scatterG2L(), and ~PetscSparseMtrx().

KSP oofem::PetscSparseMtrx::ksp
protected

Linear solver context.

Definition at line 60 of file petscsparsemtrx.h.

Referenced by buildInternalStructure(), oofem::PetscSolver::petsc_solve(), and ~PetscSparseMtrx().

bool oofem::PetscSparseMtrx::kspInit
protected

Flag if context initialized.

Definition at line 62 of file petscsparsemtrx.h.

Referenced by buildInternalStructure(), GiveCopy(), oofem::PetscSolver::petsc_solve(), and ~PetscSparseMtrx().

int oofem::PetscSparseMtrx::leqs
protected

Definition at line 53 of file petscsparsemtrx.h.

Referenced by buildInternalStructure(), createVecGlobal(), GiveCopy(), and giveLeqs().

IS oofem::PetscSparseMtrx::localIS
protected

Context or scattering/collecting parallel PETSc vectors.

Definition at line 67 of file petscsparsemtrx.h.

Referenced by buildInternalStructure(), scatterG2L(), and ~PetscSparseMtrx().

MatType oofem::PetscSparseMtrx::mType
protected

Definition at line 52 of file petscsparsemtrx.h.

Referenced by GiveCopy().

bool oofem::PetscSparseMtrx::newValues
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().

bool oofem::PetscSparseMtrx::symmFlag
protected

Definition at line 51 of file petscsparsemtrx.h.

Referenced by GiveCopy(), giveSymmetryFlag(), and isAsymmetric().


The documentation for this class was generated from the following files:

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:39 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011