OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
oofem::SparseMtrx Class Referenceabstract

Base class for all matrices stored in sparse format. More...

#include <sparsemtrx.h>

+ Inheritance diagram for oofem::SparseMtrx:

Public Types

typedef long SparseMtrxVersionType
 

Public Member Functions

 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 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)=0
 Builds internal structure of receiver. More...
 
virtual int buildInternalStructure (EngngModel *eModel, int di, const UnknownNumberingScheme &r_s, const UnknownNumberingScheme &c_s)
 Build internal structure of receiver. More...
 
virtual int assemble (const IntArray &loc, const FloatMatrix &mat)=0
 Assembles sparse matrix from contribution of local elements. More...
 
virtual int assemble (const IntArray &rloc, const IntArray &cloc, const FloatMatrix &mat)=0
 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 bool canBeFactorized () const =0
 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 ()=0
 Zeroes the receiver. More...
 
virtual double computeNorm () const
 Returns the norm of receiver. More...
 
virtual SparseMtrxgiveSubMatrix (const IntArray &rows, const IntArray &cols)
 
virtual double & at (int i, int j)=0
 Returns coefficient at position (i,j). More...
 
virtual double at (int i, int j) const =0
 Returns coefficient at position (i,j). More...
 
virtual bool isAllocatedAt (int i, int j) const
 Checks whether memory is allocated 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...
 
virtual void writeToFile (const char *fname) const
 Helpful for debugging, writes the matrix to given file. More...
 
virtual SparseMtrxType giveType () const =0
 Sparse matrix type identification. More...
 
virtual bool isAsymmetric () const =0
 Returns true if asymmetric. More...
 
virtual const char * giveClassName () const =0
 
std::string errorInfo (const char *func) const
 Error printing helper. More...
 
IML compatibility
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

int nRows
 Number of rows. More...
 
int nColumns
 Number of columns. More...
 
SparseMtrxVersionType version
 Allows to track if receiver changes. More...
 

Detailed Description

Base class for all matrices stored in sparse format.

Basically sparse matrix contains contribution of local element matrices. Localization of local element matrix into global (structural) matrix is determined using element code numbers. Basic methods include

  • Building internal structure of sparse matrix (according to code numbers of elements)
  • Assembling of local element matrices
  • Multiplication by array
  • Possible factorization and back substitution.

Definition at line 60 of file sparsemtrx.h.

Member Typedef Documentation

Definition at line 63 of file sparsemtrx.h.

Constructor & Destructor Documentation

oofem::SparseMtrx::SparseMtrx ( int  n,
int  m 
)
inline

Constructor, creates (n,m) sparse matrix.

Due to sparsity character of matrix, not all coefficient are physically stored (in general, zero members are omitted).

Definition at line 87 of file sparsemtrx.h.

oofem::SparseMtrx::SparseMtrx ( )
inline

Constructor.

Definition at line 89 of file sparsemtrx.h.

virtual oofem::SparseMtrx::~SparseMtrx ( )
inlinevirtual

Destructor.

Definition at line 91 of file sparsemtrx.h.

Member Function Documentation

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

Adds x * m.

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

Reimplemented in oofem::Skyline, and oofem::PetscSparseMtrx.

Definition at line 166 of file sparsemtrx.h.

References OOFEM_ERROR.

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

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

Parameters
xValue to multiply m by.
mMatrix to add.

Reimplemented in oofem::PetscSparseMtrx.

Definition at line 172 of file sparsemtrx.h.

References oofem::FloatArray::at(), and oofem::FloatArray::giveSize().

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

Implemented in oofem::CompCol, oofem::Skyline, oofem::SymCompCol, oofem::DynCompCol, oofem::DynCompRow, oofem::PetscSparseMtrx, oofem::SkylineUnsym, and oofem::SpoolesSparseMtrx.

Referenced by oofem::SurfaceTensionBoundaryCondition::assemble(), oofem::PrescribedGradientBCNeumann::assemble(), oofem::PrescribedMean::assemble(), oofem::TransportGradientNeumann::assemble(), oofem::LinearConstraintBC::assemble(), oofem::MixedGradientPressureWeakPeriodic::assemble(), oofem::PrescribedGradientBCWeak::assemble(), oofem::MixedGradientPressureNeumann::assemble(), oofem::WeakPeriodicBoundaryCondition::assemble(), oofem::EngngModel::assemble(), oofem::PrescribedGradientBCWeak::assembleExtraDisplock(), oofem::PrescribedGradientBCWeak::assembleGPContrib(), oofem::ContactDefinition::computeContactTangent(), oofem::TrabBoneNL3D::NonlocalMaterialStiffnessInterface_addIPContribution(), oofem::MisesMatNl::NonlocalMaterialStiffnessInterface_addIPContribution(), oofem::RankineMatNl::NonlocalMaterialStiffnessInterface_addIPContribution(), and oofem::IDNLMaterial::NonlocalMaterialStiffnessInterface_addIPContribution().

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

Implemented in oofem::CompCol, oofem::Skyline, oofem::SymCompCol, oofem::DynCompCol, oofem::DynCompRow, oofem::PetscSparseMtrx, oofem::SkylineUnsym, and oofem::SpoolesSparseMtrx.

virtual int oofem::SparseMtrx::assembleBegin ( )
inlinevirtual

Starts assembling the elements.

Reimplemented in oofem::PetscSparseMtrx.

Definition at line 235 of file sparsemtrx.h.

Referenced by oofem::EngngModel::assemble().

virtual int oofem::SparseMtrx::assembleEnd ( )
inlinevirtual

Returns when assemble is completed.

Reimplemented in oofem::PetscSparseMtrx.

Definition at line 237 of file sparsemtrx.h.

Referenced by oofem::EngngModel::assemble().

virtual double oofem::SparseMtrx::at ( int  i,
int  j 
) const
pure virtual
virtual FloatArray* oofem::SparseMtrx::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 in oofem::Skyline, oofem::PetscSparseMtrx, oofem::SkylineUnsym, and oofem::SpoolesSparseMtrx.

Definition at line 253 of file sparsemtrx.h.

Referenced by oofem::MicroMaterial::giveMacroStiffnessMatrix(), oofem::LDLTFactorization::solve(), and oofem::SubspaceIteration::solve().

virtual int oofem::SparseMtrx::buildInternalStructure ( EngngModel eModel,
int  n,
int  m,
const IntArray I,
const IntArray J 
)
inlinevirtual

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 in oofem::PetscSparseMtrx.

Definition at line 185 of file sparsemtrx.h.

References OOFEM_ERROR.

Referenced by oofem::MicroMaterial::giveMacroStiffnessMatrix().

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

Implemented in oofem::CompCol, oofem::SymCompCol, oofem::Skyline, oofem::DynCompCol, oofem::DynCompRow, oofem::PetscSparseMtrx, oofem::SkylineUnsym, and oofem::SpoolesSparseMtrx.

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

Build internal structure of receiver.

See also
buildInternalStructure
Parameters
eModelPointer to corresponding engineering model.
diDomain index specify which domain to use.
r_sDetermines unknown numbering scheme for the rows.
c_sDetermines unknown numbering scheme for the columns.
Returns
Zero iff successful.

Reimplemented in oofem::PetscSparseMtrx.

Definition at line 208 of file sparsemtrx.h.

References OOFEM_ERROR.

virtual bool oofem::SparseMtrx::canBeFactorized ( ) const
pure virtual
void oofem::SparseMtrx::checkBounds ( int  i,
int  j 
) const
inline

Checks size of receiver towards requested bounds.

Current implementation will call exit(1), if positions are outside bounds.

Parameters
iRequired number of rows.
jRequired number of columns.

Definition at line 102 of file sparsemtrx.h.

References OOFEM_ERROR.

virtual double oofem::SparseMtrx::computeNorm ( ) const
inlinevirtual

Returns the norm of receiver.

Reimplemented in oofem::PetscSparseMtrx.

Definition at line 258 of file sparsemtrx.h.

References OOFEM_ERROR.

std :: string oofem::SparseMtrx::errorInfo ( const char *  func) const
inline

Error printing helper.

Definition at line 287 of file sparsemtrx.h.

References oofem::operator*().

virtual SparseMtrx* oofem::SparseMtrx::factorized ( )
inlinevirtual

Returns the receiver factorized.

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

Returns
pointer to the receiver

Reimplemented in oofem::Skyline, oofem::PetscSparseMtrx, oofem::SkylineUnsym, and oofem::SpoolesSparseMtrx.

Definition at line 245 of file sparsemtrx.h.

Referenced by oofem::MicroMaterial::giveMacroStiffnessMatrix(), oofem::LDLTFactorization::solve(), and oofem::SubspaceIteration::solve().

virtual const char* oofem::SparseMtrx::giveClassName ( ) const
pure virtual
virtual SparseMtrx* oofem::SparseMtrx::GiveCopy ( ) const
inlinevirtual

Returns a newly allocated copy of receiver.

Programmer must take care about proper deallocation of allocated space.

Returns
Newly allocated copy of receiver.

Reimplemented in oofem::CompCol, oofem::SymCompCol, oofem::Skyline, oofem::DynCompCol, oofem::DynCompRow, oofem::SkylineUnsym, oofem::SpoolesSparseMtrx, and oofem::PetscSparseMtrx.

Definition at line 127 of file sparsemtrx.h.

References OOFEM_ERROR.

virtual SparseMtrx* oofem::SparseMtrx::giveSubMatrix ( const IntArray rows,
const IntArray cols 
)
inlinevirtual

Reimplemented in oofem::Skyline, and oofem::PetscSparseMtrx.

Definition at line 263 of file sparsemtrx.h.

References OOFEM_ERROR.

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

virtual SparseMtrxType oofem::SparseMtrx::giveType ( ) const
pure virtual
SparseMtrxVersionType oofem::SparseMtrx::giveVersion ( )
inline

Return receiver version.

Definition at line 94 of file sparsemtrx.h.

Referenced by oofem::NRSolver::applyConstraintsToStiffness(), oofem::SpoolesSolver::solve(), and oofem::IMLSolver::solve().

virtual bool oofem::SparseMtrx::isAllocatedAt ( int  i,
int  j 
) const
inlinevirtual

Checks whether memory is allocated at position (i,j).

Reimplemented in oofem::Skyline.

Definition at line 271 of file sparsemtrx.h.

Referenced by oofem::MicroMaterial::giveMacroStiffnessMatrix().

virtual bool oofem::SparseMtrx::isAsymmetric ( ) const
pure virtual
bool oofem::SparseMtrx::isNotEmpty ( ) const
inline

Tests for empty matrix.

Definition at line 120 of file sparsemtrx.h.

bool oofem::SparseMtrx::isSquare ( ) const
inline

Returns nonzero if receiver is square matrix.

Definition at line 118 of file sparsemtrx.h.

FloatArray oofem::SparseMtrx::operator* ( const FloatArray x) const
inline

IML compatibility, $ A \cdot x$.

Definition at line 291 of file sparsemtrx.h.

virtual void oofem::SparseMtrx::printStatistics ( ) const
inlinevirtual

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

Reimplemented in oofem::DynCompCol, oofem::PetscSparseMtrx, oofem::DynCompRow, oofem::SkylineUnsym, and oofem::SpoolesSparseMtrx.

Definition at line 275 of file sparsemtrx.h.

References OOFEM_LOG_INFO.

Referenced by oofem::NonLinearDynamic::assemble(), and oofem::NonLinearStatic::assemble().

virtual void oofem::SparseMtrx::printYourself ( ) const
inlinevirtual

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

Reimplemented in oofem::Skyline, oofem::CompCol, oofem::PetscSparseMtrx, oofem::SkylineUnsym, and oofem::SpoolesSparseMtrx.

Definition at line 277 of file sparsemtrx.h.

References OOFEM_LOG_INFO.

virtual void oofem::SparseMtrx::times ( const FloatArray x,
FloatArray answer 
) const
inlinevirtual
virtual void oofem::SparseMtrx::times ( const FloatMatrix B,
FloatMatrix answer 
) const
inlinevirtual

Evaluates $ C = A^{\mathrm{T}} \cdot B $.

Parameters
BArray to be multiplied with receiver.
answerC.

Reimplemented in oofem::PetscSparseMtrx.

Definition at line 149 of file sparsemtrx.h.

References OOFEM_ERROR.

virtual void oofem::SparseMtrx::times ( double  x)
inlinevirtual

Multiplies receiver by scalar value.

Parameters
xValue to multiply receiver.

Reimplemented in oofem::CompCol, oofem::SymCompCol, oofem::Skyline, oofem::DynCompCol, oofem::DynCompRow, oofem::SkylineUnsym, oofem::SpoolesSparseMtrx, and oofem::PetscSparseMtrx.

Definition at line 160 of file sparsemtrx.h.

References OOFEM_ERROR.

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

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

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

Reimplemented in oofem::CompCol, oofem::SymCompCol, oofem::Skyline, oofem::DynCompCol, oofem::DynCompRow, oofem::SkylineUnsym, oofem::SpoolesSparseMtrx, and oofem::PetscSparseMtrx.

Definition at line 143 of file sparsemtrx.h.

References OOFEM_ERROR.

virtual void oofem::SparseMtrx::timesT ( const FloatMatrix B,
FloatMatrix answer 
) const
inlinevirtual

Evaluates $ C = A^{\mathrm{T}} \cdot B $.

Parameters
BMatrix to be multiplied with receiver.
answerC.

Reimplemented in oofem::PetscSparseMtrx.

Definition at line 155 of file sparsemtrx.h.

References OOFEM_ERROR.

virtual void oofem::SparseMtrx::toFloatMatrix ( FloatMatrix answer) const
inlinevirtual

Converts receiving sparse matrix to a dense float matrix.

Reimplemented in oofem::Skyline, oofem::CompCol, oofem::PetscSparseMtrx, and oofem::SkylineUnsym.

Definition at line 273 of file sparsemtrx.h.

References OOFEM_ERROR.

FloatArray oofem::SparseMtrx::trans_mult ( const FloatArray x) const
inline

IML compatibility, $ A^{\mathrm{T}} \cdot x$.

Definition at line 298 of file sparsemtrx.h.

virtual void oofem::SparseMtrx::writeToFile ( const char *  fname) const
inlinevirtual

Helpful for debugging, writes the matrix to given file.

Reimplemented in oofem::Skyline, oofem::PetscSparseMtrx, and oofem::SkylineUnsym.

Definition at line 279 of file sparsemtrx.h.

References OOFEM_LOG_INFO.

Member Data Documentation

SparseMtrxVersionType oofem::SparseMtrx::version
protected

Allows to track if receiver changes.

Any change on receiver should increment this variable. The factorization should not change version (nrsolver direct control relies on that). This version info is used for example by preconditioners associated to particular matrix; the preconditioner initialization can be demanding and this versioning allows to reuse initialized preconditioner for same matrix, if there is no change;

Definition at line 80 of file sparsemtrx.h.

Referenced by oofem::Skyline::add(), oofem::SpoolesSparseMtrx::assemble(), oofem::SkylineUnsym::assemble(), oofem::PetscSparseMtrx::assemble(), oofem::DynCompRow::assemble(), oofem::DynCompCol::assemble(), oofem::SymCompCol::assemble(), oofem::Skyline::assemble(), oofem::CompCol::assemble(), oofem::SkylineUnsym::at(), oofem::DynCompRow::at(), oofem::DynCompCol::at(), oofem::SymCompCol::at(), oofem::CompCol::at(), oofem::Skyline::at(), oofem::SkylineUnsym::buildInternalStructure(), oofem::DynCompRow::buildInternalStructure(), oofem::DynCompCol::buildInternalStructure(), oofem::Skyline::buildInternalStructure(), oofem::SymCompCol::buildInternalStructure(), oofem::CompCol::buildInternalStructure(), oofem::DynCompCol::DynCompCol(), oofem::DynCompRow::DynCompRow(), oofem::DynCompRow::ILUPYourself(), oofem::DynCompRow::operator()(), oofem::DynCompCol::operator()(), oofem::SymCompCol::operator()(), oofem::CompCol::operator()(), oofem::DynCompRow::operator=(), oofem::DynCompCol::operator=(), oofem::CompCol::operator=(), oofem::SkylineUnsym::setInternalStructure(), oofem::Skyline::setInternalStructure(), oofem::SkylineUnsym::times(), oofem::DynCompRow::times(), oofem::DynCompCol::times(), oofem::Skyline::times(), oofem::SymCompCol::times(), oofem::CompCol::times(), oofem::SkylineUnsym::zero(), oofem::DynCompRow::zero(), oofem::DynCompCol::zero(), oofem::SymCompCol::zero(), oofem::Skyline::zero(), and oofem::CompCol::zero().


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

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:41 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011