OOFEM 3.0
Loading...
Searching...
No Matches
oofem::PetscSparseMtrx Class Reference

#include <petscsparsemtrx.h>

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

Public Member Functions

 PetscSparseMtrx (int n=0, int m=0)
virtual ~PetscSparseMtrx ()
std::unique_ptr< SparseMtrxclone () const override
void times (const FloatArray &x, FloatArray &answer) const override
void timesT (const FloatArray &x, FloatArray &answer) const override
void times (const FloatMatrix &B, FloatMatrix &answer) const override
void timesT (const FloatMatrix &B, FloatMatrix &answer) const override
void times (double x) override
void add (double x, SparseMtrx &m) override
void addDiagonal (double x, FloatArray &m) override
int buildInternalStructure (EngngModel *eModel, int n, int m, const IntArray &I, const IntArray &J) override
int buildInternalStructure (EngngModel *eModel, int di, const UnknownNumberingScheme &s) override
int buildInternalStructure (EngngModel *eModel, int di, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s) override
int assemble (const IntArray &loc, const FloatMatrix &mat) override
int assemble (const IntArray &rloc, const IntArray &cloc, const FloatMatrix &mat) override
int assembleBegin () override
 Starts assembling the elements.
int assembleEnd () override
 Returns when assemble is completed.
std::unique_ptr< SparseMtrxgiveSubMatrix (const IntArray &rows, const IntArray &cols) override
bool canBeFactorized () const override
 Determines, whether receiver can be factorized.
SparseMtrxfactorized () override
FloatArraybackSubstitutionWith (FloatArray &y) const override
void zero () override
 Zeroes the receiver.
double computeNorm () const override
 Returns the norm of receiver.
double & at (int i, int j) override
 Returns coefficient at position (i,j).
double at (int i, int j) const override
 Returns coefficient at position (i,j).
void toFloatMatrix (FloatMatrix &answer) const override
 Converts receiving sparse matrix to a dense float matrix.
void printStatistics () const override
 Prints the receiver statistics (one-line) to stdout.
void printYourself () const override
 Prints receiver to stdout. Works only for relatively small matrices.
void printMatlab () const
SparseMtrxType giveType () const override
 Sparse matrix type identification.
bool isAsymmetric () const override
 Returns true if asymmetric.
void writeToFile (const char *fname) const override
 Helpful for debugging, writes the matrix to given file.
const char * giveClassName () const override
void createVecGlobal (Vec *answer) const
 Creates a global vector that fits the instance of this matrix.
int scatterG2L (Vec src, FloatArray &dest) const
 Scatters global vector to natural one.
int scatterL2G (const FloatArray &src, Vec dest) const
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=0, int m=0)
virtual ~SparseMtrx ()
 Destructor.
SparseMtrxVersionType giveVersion ()
 Return receiver version.
void checkBounds (int i, int j) const
int giveNumberOfRows () const
 Returns number of rows of receiver.
int giveNumberOfColumns () const
 Returns number of columns of receiver.
bool isSquare () const
 Returns nonzero if receiver is square matrix.
bool isNotEmpty () const
 Tests for empty matrix.
virtual bool isAllocatedAt (int i, int j) const
 Checks whether memory is allocated at position (i,j).
std::string errorInfo (const char *func) const
 Error printing helper.
FloatArray operator* (const FloatArray &x) const
 IML compatibility, \( A \cdot x\).
FloatArray trans_mult (const FloatArray &x) const
 IML compatibility, \( A^{\mathrm{T}} \cdot x\).

Protected Attributes

Mat mtrx
bool symmFlag
MatType mType
int leqs
int geqs
int blocksize
int di
EngngModelemodel
KSP ksp
 Linear solver context.
bool kspInit
 Flag if context initialized.
bool newValues
 Flag if matrix has changed since last solve.
IS localIS
 Context or scattering/collecting parallel PETSc vectors.
IS globalIS
Protected Attributes inherited from oofem::SparseMtrx
int nRows
 Number of rows.
int nColumns
 Number of columns.
SparseMtrxVersionType version

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

◆ PetscSparseMtrx()

oofem::PetscSparseMtrx::PetscSparseMtrx ( int n = 0,
int m = 0 )

Definition at line 52 of file petscsparsemtrx.C.

References blocksize, di, geqs, globalIS, kspInit, leqs, localIS, mtrx, newValues, oofem::SparseMtrx::SparseMtrx(), and symmFlag.

Referenced by add().

◆ ~PetscSparseMtrx()

oofem::PetscSparseMtrx::~PetscSparseMtrx ( )
virtual

Definition at line 66 of file petscsparsemtrx.C.

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

Member Function Documentation

◆ add()

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

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 278 of file petscsparsemtrx.C.

References giveMtrx(), PetscSparseMtrx(), and oofem::SparseMtrx::SparseMtrx().

◆ addDiagonal()

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

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 286 of file petscsparsemtrx.C.

References createVecGlobal(), emodel, oofem::FloatArray::givePointer(), oofem::FloatArray::giveSize(), mtrx, OOFEM_WARNING, and scatterL2G().

◆ assemble() [1/2]

int oofem::PetscSparseMtrx::assemble ( const IntArray & loc,
const FloatMatrix & mat )
overridevirtual

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 739 of file petscsparsemtrx.C.

References oofem::IntArray::at(), blocksize, di, emodel, oofem::FloatMatrix::giveNumberOfRows(), oofem::FloatMatrix::givePointer(), oofem::IntArray::givePointer(), mtrx, newValues, and oofem::SparseMtrx::version.

◆ assemble() [2/2]

int oofem::PetscSparseMtrx::assemble ( const IntArray & rloc,
const IntArray & cloc,
const FloatMatrix & mat )
overridevirtual

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 795 of file petscsparsemtrx.C.

References oofem::IntArray::at(), di, emodel, oofem::FloatMatrix::givePointer(), oofem::IntArray::givePointer(), oofem::IntArray::giveSize(), mtrx, newValues, and oofem::SparseMtrx::version.

◆ assembleBegin()

int oofem::PetscSparseMtrx::assembleBegin ( )
overridevirtual

Starts assembling the elements.

Reimplemented from oofem::SparseMtrx.

Definition at line 831 of file petscsparsemtrx.C.

References mtrx.

◆ assembleEnd()

int oofem::PetscSparseMtrx::assembleEnd ( )
overridevirtual

Returns when assemble is completed.

Reimplemented from oofem::SparseMtrx.

Definition at line 837 of file petscsparsemtrx.C.

References mtrx, and newValues.

◆ at() [1/2]

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

Returns coefficient at position (i,j).

Implements oofem::SparseMtrx.

Definition at line 875 of file petscsparsemtrx.C.

References OOFEM_ERROR.

◆ at() [2/2]

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

Returns coefficient at position (i,j).

Implements oofem::SparseMtrx.

Definition at line 867 of file petscsparsemtrx.C.

References OOFEM_ERROR.

◆ backSubstitutionWith()

FloatArray * oofem::PetscSparseMtrx::backSubstitutionWith ( FloatArray & y) const
inlineoverridevirtual

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 92 of file petscsparsemtrx.h.

◆ buildInternalStructure() [1/3]

int oofem::PetscSparseMtrx::buildInternalStructure ( EngngModel * eModel,
int di,
const UnknownNumberingScheme & r_s,
const UnknownNumberingScheme & c_s )
overridevirtual

◆ buildInternalStructure() [2/3]

int oofem::PetscSparseMtrx::buildInternalStructure ( EngngModel * eModel,
int di,
const UnknownNumberingScheme & s )
overridevirtual

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 481 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::Natural2GlobalOrdering::giveN2Gmap(), oofem::ParallelContext::giveN2Gmap(), oofem::Natural2LocalOrdering::giveN2Lmap(), oofem::ParallelContext::giveN2Lmap(), oofem::Domain::giveNumberOfDofManagers(), oofem::DofManager::giveNumberOfDofs(), oofem::EngngModel::giveNumberOfDomainEquations(), oofem::Natural2GlobalOrdering::giveNumberOfGlobalEqs(), oofem::Natural2GlobalOrdering::giveNumberOfLocalEqs(), oofem::ParallelContext::giveNumberOfNaturalEqs(), oofem::EngngModel::giveParallelContext(), oofem::IntArray::givePointer(), oofem::EngngModel::giveRank(), oofem::IntArray::giveSize(), globalIS, oofem::Natural2GlobalOrdering::init(), oofem::Natural2LocalOrdering::init(), 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.

◆ buildInternalStructure() [3/3]

int oofem::PetscSparseMtrx::buildInternalStructure ( EngngModel * eModel,
int n,
int m,
const IntArray & I,
const IntArray & J )
overridevirtual

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 301 of file petscsparsemtrx.C.

References blocksize, di, emodel, geqs, ksp, kspInit, leqs, mtrx, oofem::SparseMtrx::nColumns, newValues, oofem::SparseMtrx::nRows, and OOFEM_ERROR.

◆ canBeFactorized()

bool oofem::PetscSparseMtrx::canBeFactorized ( ) const
inlineoverridevirtual

Determines, whether receiver can be factorized.

Implements oofem::SparseMtrx.

Definition at line 90 of file petscsparsemtrx.h.

◆ clone()

std::unique_ptr< SparseMtrx > oofem::PetscSparseMtrx::clone ( ) const
overridevirtual

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 80 of file petscsparsemtrx.C.

References di, emodel, geqs, leqs, mtrx, mType, oofem::SparseMtrx::nColumns, newValues, oofem::SparseMtrx::nRows, and symmFlag.

◆ computeNorm()

double oofem::PetscSparseMtrx::computeNorm ( ) const
overridevirtual

Returns the norm of receiver.

Reimplemented from oofem::SparseMtrx.

Definition at line 859 of file petscsparsemtrx.C.

References mtrx, and oofem::norm().

◆ createVecGlobal()

void oofem::PetscSparseMtrx::createVecGlobal ( Vec * answer) const

Creates a global vector that fits the instance of this matrix.

Definition at line 964 of file petscsparsemtrx.C.

References emodel, geqs, oofem::SparseMtrx::giveNumberOfRows(), and leqs.

Referenced by addDiagonal(), oofem::NRSolver::applyConstraintsToLoadIncrement(), oofem::NRSolver::applyConstraintsToStiffness(), oofem::PetscSolver::solve(), and times().

◆ factorized()

SparseMtrx * oofem::PetscSparseMtrx::factorized ( )
inlineoverridevirtual

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 91 of file petscsparsemtrx.h.

References oofem::SparseMtrx::SparseMtrx().

◆ giveClassName()

const char * oofem::PetscSparseMtrx::giveClassName ( ) const
inlineoverridevirtual

Implements oofem::SparseMtrx.

Definition at line 104 of file petscsparsemtrx.h.

◆ giveDomainIndex()

int oofem::PetscSparseMtrx::giveDomainIndex ( ) const

Definition at line 1091 of file petscsparsemtrx.C.

References di.

Referenced by oofem::SLEPcSolver::solve().

◆ giveLeqs()

int oofem::PetscSparseMtrx::giveLeqs ( )

Definition at line 1086 of file petscsparsemtrx.C.

References leqs.

◆ giveMtrx()

Mat * oofem::PetscSparseMtrx::giveMtrx ( )

◆ giveSubMatrix()

std::unique_ptr< SparseMtrx > oofem::PetscSparseMtrx::giveSubMatrix ( const IntArray & rows,
const IntArray & cols )
overridevirtual

◆ giveSymmetryFlag()

bool oofem::PetscSparseMtrx::giveSymmetryFlag ( ) const

Definition at line 1076 of file petscsparsemtrx.C.

References symmFlag.

◆ giveType()

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

Sparse matrix type identification.

Implements oofem::SparseMtrx.

Definition at line 1061 of file petscsparsemtrx.C.

References oofem::SMT_PetscMtrx.

◆ isAsymmetric()

bool oofem::PetscSparseMtrx::isAsymmetric ( ) const
overridevirtual

Returns true if asymmetric.

Implements oofem::SparseMtrx.

Definition at line 1066 of file petscsparsemtrx.C.

References symmFlag.

◆ printMatlab()

void oofem::PetscSparseMtrx::printMatlab ( ) const

Definition at line 942 of file petscsparsemtrx.C.

References mtrx.

◆ printStatistics()

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

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

Reimplemented from oofem::SparseMtrx.

Definition at line 926 of file petscsparsemtrx.C.

References mtrx.

◆ printYourself()

void oofem::PetscSparseMtrx::printYourself ( ) const
overridevirtual

Prints receiver to stdout. Works only for relatively small matrices.

Reimplemented from oofem::SparseMtrx.

Definition at line 934 of file petscsparsemtrx.C.

References mtrx.

◆ scatterG2L()

int oofem::PetscSparseMtrx::scatterG2L ( Vec src,
FloatArray & dest ) const

◆ scatterL2G()

int oofem::PetscSparseMtrx::scatterL2G ( const FloatArray & src,
Vec dest ) const

◆ setOption()

int oofem::PetscSparseMtrx::setOption ( MatOption op,
PetscBool flag )

Definition at line 1081 of file petscsparsemtrx.C.

References mtrx.

◆ times() [1/3]

void oofem::PetscSparseMtrx::times ( const FloatArray & x,
FloatArray & answer ) const
overridevirtual

Evaluates \( y = A \cdot x \)

Parameters
xArray to be multiplied with receiver.
answery.

Reimplemented from oofem::SparseMtrx.

Definition at line 97 of file petscsparsemtrx.C.

References createVecGlobal(), emodel, oofem::SparseMtrx::giveNumberOfColumns(), oofem::FloatArray::givePointer(), oofem::FloatArray::giveSize(), mtrx, oofem::SparseMtrx::nRows, OOFEM_ERROR, oofem::FloatArray::resize(), scatterG2L(), and scatterL2G().

◆ times() [2/3]

void oofem::PetscSparseMtrx::times ( const FloatMatrix & B,
FloatMatrix & answer ) const
overridevirtual

◆ times() [3/3]

void oofem::PetscSparseMtrx::times ( double x)
overridevirtual

Multiplies receiver by scalar value.

Parameters
xValue to multiply receiver.

Reimplemented from oofem::SparseMtrx.

Definition at line 271 of file petscsparsemtrx.C.

References mtrx.

◆ timesT() [1/2]

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

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 145 of file petscsparsemtrx.C.

References emodel, oofem::SparseMtrx::giveNumberOfRows(), oofem::FloatArray::givePointer(), oofem::FloatArray::giveSize(), mtrx, oofem::SparseMtrx::nColumns, OOFEM_ERROR, and oofem::FloatArray::resize().

◆ timesT() [2/2]

void oofem::PetscSparseMtrx::timesT ( const FloatMatrix & B,
FloatMatrix & answer ) const
overridevirtual

◆ toFloatMatrix()

void oofem::PetscSparseMtrx::toFloatMatrix ( FloatMatrix & answer) const
overridevirtual

◆ writeToFile()

void oofem::PetscSparseMtrx::writeToFile ( const char * fname) const
overridevirtual

Helpful for debugging, writes the matrix to given file.

Reimplemented from oofem::SparseMtrx.

Definition at line 950 of file petscsparsemtrx.C.

References emodel, and mtrx.

◆ zero()

void oofem::PetscSparseMtrx::zero ( )
overridevirtual

Zeroes the receiver.

Implements oofem::SparseMtrx.

Definition at line 847 of file petscsparsemtrx.C.

References mtrx, and newValues.

◆ PetscSolver

friend class PetscSolver
friend

Definition at line 123 of file petscsparsemtrx.h.

References PetscSolver.

Referenced by PetscSolver.

Member Data Documentation

◆ blocksize

int oofem::PetscSparseMtrx::blocksize
protected

◆ di

◆ emodel

◆ geqs

int oofem::PetscSparseMtrx::geqs
protected

◆ globalIS

IS oofem::PetscSparseMtrx::globalIS
protected

◆ ksp

KSP oofem::PetscSparseMtrx::ksp
protected

◆ kspInit

bool oofem::PetscSparseMtrx::kspInit
protected

◆ leqs

int oofem::PetscSparseMtrx::leqs
protected

◆ localIS

IS oofem::PetscSparseMtrx::localIS
protected

Context or scattering/collecting parallel PETSc vectors.

Definition at line 67 of file petscsparsemtrx.h.

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

◆ mtrx

◆ mType

MatType oofem::PetscSparseMtrx::mType
protected

Definition at line 52 of file petscsparsemtrx.h.

Referenced by clone().

◆ newValues

bool oofem::PetscSparseMtrx::newValues
protected

◆ symmFlag

bool oofem::PetscSparseMtrx::symmFlag
protected

Definition at line 51 of file petscsparsemtrx.h.

Referenced by clone(), giveSymmetryFlag(), isAsymmetric(), and PetscSparseMtrx().


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

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011