MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::BlockMatrix Class Reference

#include <blockmatrix.hpp>

Inheritance diagram for mfem::BlockMatrix:
[legend]
Collaboration diagram for mfem::BlockMatrix:
[legend]

Public Member Functions

 BlockMatrix (const Array< int > &offsets)
 Constructor for square block matrices.
 
 BlockMatrix (const Array< int > &row_offsets, const Array< int > &col_offsets)
 Constructor for rectangular block matrices.
 
void SetBlock (int i, int j, SparseMatrix *mat)
 Set A(i,j) = mat.
 
int NumRowBlocks () const
 Return the number of row blocks.
 
int NumColBlocks () const
 Return the number of column blocks.
 
SparseMatrixGetBlock (int i, int j)
 Return a reference to block (i,j). Reference may be invalid if Aij(i,j) == NULL.
 
const SparseMatrixGetBlock (int i, int j) const
 
int IsZeroBlock (int i, int j) const
 Check if block (i,j) is a zero block.
 
Array< int > & RowOffsets ()
 Return the row offsets for block starts.
 
Array< int > & ColOffsets ()
 Return the columns offsets for block starts.
 
const Array< int > & RowOffsets () const
 Return the row offsets for block starts (const version)
 
const Array< int > & ColOffsets () const
 Return the row offsets for block starts (const version)
 
int RowSize (const int i) const
 Return the number of non zeros in row i.
 
void EliminateRowCol (int rc, DiagonalPolicy dpolicy=DIAG_ONE)
 Eliminate the row and column rc from the matrix.
 
void EliminateRowCols (const Array< int > &vdofs, BlockMatrix *Ae, DiagonalPolicy dpolicy=DIAG_ONE)
 Eliminate the rows and columns corresponding to the entries in vdofs + save the eliminated entries into Ae so that (*this) + Ae is equal to the original matrix.
 
void EliminateRowCol (Array< int > &ess_bc_dofs, Vector &sol, Vector &rhs)
 Symmetric elimination of the marked degree of freedom.
 
virtual void Finalize (int skip_zeros=1)
 Finalize all the submatrices.
 
void Finalize (int skip_zeros, bool fix_empty_rows)
 A slightly more general version of the Finalize(int) method.
 
SparseMatrixCreateMonolithic () const
 Returns a monolithic CSR matrix that represents this operator.
 
virtual void PrintMatlab (std::ostream &os=mfem::out) const
 Export the monolithic matrix to file.
 
void PartMult (const Array< int > &rows, const Vector &x, Vector &y) const
 Partial matrix vector multiplication of (*this) with x involving only the rows given by rows. The result is given in y.
 
void PartAddMult (const Array< int > &rows, const Vector &x, Vector &y, const real_t a=1.0) const
 Partial matrix vector multiplication of (*this) with x involving only the rows given by rows. The result is multiplied by a and added to y.
 
virtual ~BlockMatrix ()
 Destructor.
 
virtual Type GetType () const
 
Matrix interface
virtual real_tElem (int i, int j)
 Returns reference to a_{ij}.
 
virtual const real_tElem (int i, int j) const
 Returns constant reference to a_{ij}.
 
virtual MatrixInverseInverse () const
 Returns a pointer to (approximation) of the matrix inverse.
 
AbstractSparseMatrix interface
virtual int NumNonZeroElems () const
 Returns the total number of non zeros in the matrix.
 
virtual int GetRow (const int row, Array< int > &cols, Vector &srow) const
 Gets the columns indexes and values for row row.
 
virtual void EliminateZeroRows (const real_t threshold=1e-12)
 If the matrix is square, this method will place 1 on the diagonal (i,i) if row i has "almost" zero l1-norm.
 
virtual void Mult (const Vector &x, Vector &y) const
 Matrix-Vector Multiplication y = A*x.
 
virtual void AddMult (const Vector &x, Vector &y, const real_t val=1.) const
 Matrix-Vector Multiplication y = y + val*A*x.
 
virtual void MultTranspose (const Vector &x, Vector &y) const
 MatrixTranspose-Vector Multiplication y = A'*x.
 
virtual void AddMultTranspose (const Vector &x, Vector &y, const real_t val=1.) const
 MatrixTranspose-Vector Multiplication y = y + val*A'*x.
 
- Public Member Functions inherited from mfem::AbstractSparseMatrix
 AbstractSparseMatrix (int s=0)
 Creates a square matrix of the given size.
 
 AbstractSparseMatrix (int h, int w)
 Creates a matrix of the given height and width.
 
virtual ~AbstractSparseMatrix ()
 Destroys AbstractSparseMatrix.
 
- Public Member Functions inherited from mfem::Matrix
 Matrix (int s)
 Creates a square matrix of size s.
 
 Matrix (int h, int w)
 Creates a matrix of the given height and width.
 
bool IsSquare () const
 Returns whether the matrix is a square matrix.
 
virtual void Print (std::ostream &out=mfem::out, int width_=4) const
 Prints matrix to stream out.
 
virtual ~Matrix ()
 Destroys matrix.
 
- Public Member Functions inherited from mfem::Operator
void InitTVectors (const Operator *Po, const Operator *Ri, const Operator *Pi, Vector &x, Vector &b, Vector &X, Vector &B) const
 Initializes memory for true vectors of linear system.
 
 Operator (int s=0)
 Construct a square Operator with given size s (default 0).
 
 Operator (int h, int w)
 Construct an Operator with the given height (output size) and width (input size).
 
int Height () const
 Get the height (size of output) of the Operator. Synonym with NumRows().
 
int NumRows () const
 Get the number of rows (size of output) of the Operator. Synonym with Height().
 
int Width () const
 Get the width (size of input) of the Operator. Synonym with NumCols().
 
int NumCols () const
 Get the number of columns (size of input) of the Operator. Synonym with Width().
 
virtual MemoryClass GetMemoryClass () const
 Return the MemoryClass preferred by the Operator.
 
virtual void ArrayMult (const Array< const Vector * > &X, Array< Vector * > &Y) const
 Operator application on a matrix: Y=A(X).
 
virtual void ArrayMultTranspose (const Array< const Vector * > &X, Array< Vector * > &Y) const
 Action of the transpose operator on a matrix: Y=A^t(X).
 
virtual void ArrayAddMult (const Array< const Vector * > &X, Array< Vector * > &Y, const real_t a=1.0) const
 Operator application on a matrix: Y+=A(X) (default) or Y+=a*A(X).
 
virtual void ArrayAddMultTranspose (const Array< const Vector * > &X, Array< Vector * > &Y, const real_t a=1.0) const
 Operator transpose application on a matrix: Y+=A^t(X) (default) or Y+=a*A^t(X).
 
virtual OperatorGetGradient (const Vector &x) const
 Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate an error.
 
virtual void AssembleDiagonal (Vector &diag) const
 Computes the diagonal entries into diag. Typically, this operation only makes sense for linear Operators. In some cases, only an approximation of the diagonal is computed.
 
virtual const OperatorGetProlongation () const
 Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator. NULL means identity.
 
virtual const OperatorGetRestriction () const
 Restriction operator from input vectors for the operator to linear algebra (linear system) vectors. NULL means identity.
 
virtual const OperatorGetOutputProlongation () const
 Prolongation operator from linear algebra (linear system) vectors, to output vectors for the operator. NULL means identity.
 
virtual const OperatorGetOutputRestrictionTranspose () const
 Transpose of GetOutputRestriction, directly available in this form to facilitate matrix-free RAP-type operators.
 
virtual const OperatorGetOutputRestriction () const
 Restriction operator from output vectors for the operator to linear algebra (linear system) vectors. NULL means identity.
 
void FormLinearSystem (const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
 Form a constrained linear system using a matrix-free approach.
 
void FormRectangularLinearSystem (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B)
 Form a column-constrained linear system using a matrix-free approach.
 
virtual void RecoverFEMSolution (const Vector &X, const Vector &b, Vector &x)
 Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear system obtained from Operator::FormLinearSystem() or Operator::FormRectangularLinearSystem().
 
void FormSystemOperator (const Array< int > &ess_tdof_list, Operator *&A)
 Return in A a parallel (on truedofs) version of this square operator.
 
void FormRectangularSystemOperator (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, Operator *&A)
 Return in A a parallel (on truedofs) version of this rectangular operator (including constraints).
 
void FormDiscreteOperator (Operator *&A)
 Return in A a parallel (on truedofs) version of this rectangular operator.
 
void PrintMatlab (std::ostream &out, int n, int m=0) const
 Prints operator with input size n and output size m in Matlab format.
 
virtual ~Operator ()
 Virtual destructor.
 
Type GetType () const
 Return the type ID of the Operator class.
 

Public Attributes

int owns_blocks
 If owns_blocks the SparseMatrix objects Aij will be deallocated.
 

Additional Inherited Members

- Public Types inherited from mfem::Operator
enum  DiagonalPolicy { DIAG_ZERO , DIAG_ONE , DIAG_KEEP }
 Defines operator diagonal policy upon elimination of rows and/or columns. More...
 
enum  Type {
  ANY_TYPE , MFEM_SPARSEMAT , Hypre_ParCSR , PETSC_MATAIJ ,
  PETSC_MATIS , PETSC_MATSHELL , PETSC_MATNEST , PETSC_MATHYPRE ,
  PETSC_MATGENERIC , Complex_Operator , MFEM_ComplexSparseMat , Complex_Hypre_ParCSR ,
  Complex_DenseMat , MFEM_Block_Matrix , MFEM_Block_Operator
}
 Enumeration defining IDs for some classes derived from Operator. More...
 
- Protected Member Functions inherited from mfem::Operator
void FormConstrainedSystemOperator (const Array< int > &ess_tdof_list, ConstrainedOperator *&Aout)
 see FormSystemOperator()
 
void FormRectangularConstrainedSystemOperator (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, RectangularConstrainedOperator *&Aout)
 see FormRectangularSystemOperator()
 
OperatorSetupRAP (const Operator *Pi, const Operator *Po)
 Returns RAP Operator of this, using input/output Prolongation matrices Pi corresponds to "P", Po corresponds to "Rt".
 
- Protected Attributes inherited from mfem::Operator
int height
 Dimension of the output / number of rows in the matrix.
 
int width
 Dimension of the input / number of columns in the matrix.
 

Detailed Description

Definition at line 24 of file blockmatrix.hpp.

Constructor & Destructor Documentation

◆ BlockMatrix() [1/2]

mfem::BlockMatrix::BlockMatrix ( const Array< int > & offsets)

Constructor for square block matrices.

Parameters
offsetsoffsets that mark the start of each row/column block (size nRowBlocks+1).
Note
BlockMatrix will not own/copy the data contained in offsets.

Definition at line 23 of file blockmatrix.cpp.

◆ BlockMatrix() [2/2]

mfem::BlockMatrix::BlockMatrix ( const Array< int > & row_offsets,
const Array< int > & col_offsets )

Constructor for rectangular block matrices.

Parameters
row_offsetsoffsets that mark the start of each row block (size nRowBlocks+1).
col_offsetsoffsets that mark the start of each column block (size nColBlocks+1).
Note
BlockMatrix will not own/copy the data contained in offsets.

Definition at line 35 of file blockmatrix.cpp.

◆ ~BlockMatrix()

mfem::BlockMatrix::~BlockMatrix ( )
virtual

Destructor.

Definition at line 49 of file blockmatrix.cpp.

Member Function Documentation

◆ AddMult()

void mfem::BlockMatrix::AddMult ( const Vector & x,
Vector & y,
const real_t val = 1. ) const
virtual

Matrix-Vector Multiplication y = y + val*A*x.

Implements mfem::AbstractSparseMatrix.

Definition at line 453 of file blockmatrix.cpp.

◆ AddMultTranspose()

void mfem::BlockMatrix::AddMultTranspose ( const Vector & x,
Vector & y,
const real_t val = 1. ) const
virtual

MatrixTranspose-Vector Multiplication y = y + val*A'*x.

Implements mfem::AbstractSparseMatrix.

Definition at line 492 of file blockmatrix.cpp.

◆ ColOffsets() [1/2]

Array< int > & mfem::BlockMatrix::ColOffsets ( )
inline

Return the columns offsets for block starts.

Definition at line 59 of file blockmatrix.hpp.

◆ ColOffsets() [2/2]

const Array< int > & mfem::BlockMatrix::ColOffsets ( ) const
inline

Return the row offsets for block starts (const version)

Definition at line 63 of file blockmatrix.hpp.

◆ CreateMonolithic()

SparseMatrix * mfem::BlockMatrix::CreateMonolithic ( ) const

Returns a monolithic CSR matrix that represents this operator.

Definition at line 560 of file blockmatrix.cpp.

◆ Elem() [1/2]

real_t & mfem::BlockMatrix::Elem ( int i,
int j )
virtual

Returns reference to a_{ij}.

Implements mfem::Matrix.

Definition at line 133 of file blockmatrix.cpp.

◆ Elem() [2/2]

const real_t & mfem::BlockMatrix::Elem ( int i,
int j ) const
virtual

Returns constant reference to a_{ij}.

Implements mfem::Matrix.

Definition at line 149 of file blockmatrix.cpp.

◆ EliminateRowCol() [1/2]

void mfem::BlockMatrix::EliminateRowCol ( Array< int > & ess_bc_dofs,
Vector & sol,
Vector & rhs )

Symmetric elimination of the marked degree of freedom.

Parameters
ess_bc_dofsmarker of the degree of freedom to be eliminated dof i is eliminated if ess_bc_dofs[i] = 1.
solvector that stores the values of the degree of freedom that need to be eliminated
rhsvector that stores the rhs of the system.

Definition at line 250 of file blockmatrix.cpp.

◆ EliminateRowCol() [2/2]

void mfem::BlockMatrix::EliminateRowCol ( int rc,
DiagonalPolicy dpolicy = DIAG_ONE )

Eliminate the row and column rc from the matrix.

Eliminates the column and row rc, replacing the element (rc,rc) with 1.0. Assumes that element (i,rc) is assembled if and only if the element (rc,i) is assembled. If dpolicy is specified, the element (rc,rc) is treated according to that policy.

Definition at line 213 of file blockmatrix.cpp.

◆ EliminateRowCols()

void mfem::BlockMatrix::EliminateRowCols ( const Array< int > & vdofs,
BlockMatrix * Ae,
DiagonalPolicy dpolicy = DIAG_ONE )

Eliminate the rows and columns corresponding to the entries in vdofs + save the eliminated entries into Ae so that (*this) + Ae is equal to the original matrix.

Definition at line 322 of file blockmatrix.cpp.

◆ EliminateZeroRows()

void mfem::BlockMatrix::EliminateZeroRows ( const real_t threshold = 1e-12)
virtual

If the matrix is square, this method will place 1 on the diagonal (i,i) if row i has "almost" zero l1-norm.

If entry (i,i) does not belong to the sparsity pattern of A, then a error will occur.

Implements mfem::AbstractSparseMatrix.

Definition at line 370 of file blockmatrix.cpp.

◆ Finalize() [1/2]

void mfem::BlockMatrix::Finalize ( int skip_zeros,
bool fix_empty_rows )

A slightly more general version of the Finalize(int) method.

Definition at line 423 of file blockmatrix.cpp.

◆ Finalize() [2/2]

virtual void mfem::BlockMatrix::Finalize ( int skip_zeros = 1)
inlinevirtual

Finalize all the submatrices.

Reimplemented from mfem::Matrix.

Definition at line 91 of file blockmatrix.hpp.

◆ GetBlock() [1/2]

SparseMatrix & mfem::BlockMatrix::GetBlock ( int i,
int j )

Return a reference to block (i,j). Reference may be invalid if Aij(i,j) == NULL.

Definition at line 82 of file blockmatrix.cpp.

◆ GetBlock() [2/2]

const SparseMatrix & mfem::BlockMatrix::GetBlock ( int i,
int j ) const

Return a reference to block (i,j). Reference may be invalid if Aij(i,j) == NULL. (const version)

Definition at line 98 of file blockmatrix.cpp.

◆ GetRow()

int mfem::BlockMatrix::GetRow ( const int row,
Array< int > & cols,
Vector & srow ) const
virtual

Gets the columns indexes and values for row row.

The return value is always 0 since cols and srow are copies of the values in the matrix.

Implements mfem::AbstractSparseMatrix.

Definition at line 183 of file blockmatrix.cpp.

◆ GetType()

virtual Type mfem::BlockMatrix::GetType ( ) const
inlinevirtual

Definition at line 156 of file blockmatrix.hpp.

◆ Inverse()

virtual MatrixInverse * mfem::BlockMatrix::Inverse ( ) const
inlinevirtual

Returns a pointer to (approximation) of the matrix inverse.

Implements mfem::Matrix.

Definition at line 108 of file blockmatrix.hpp.

◆ IsZeroBlock()

int mfem::BlockMatrix::IsZeroBlock ( int i,
int j ) const
inline

Check if block (i,j) is a zero block.

Definition at line 55 of file blockmatrix.hpp.

◆ Mult()

void mfem::BlockMatrix::Mult ( const Vector & x,
Vector & y ) const
virtual

Matrix-Vector Multiplication y = A*x.

Implements mfem::AbstractSparseMatrix.

Definition at line 438 of file blockmatrix.cpp.

◆ MultTranspose()

void mfem::BlockMatrix::MultTranspose ( const Vector & x,
Vector & y ) const
virtual

MatrixTranspose-Vector Multiplication y = A'*x.

Implements mfem::AbstractSparseMatrix.

Definition at line 481 of file blockmatrix.cpp.

◆ NumColBlocks()

int mfem::BlockMatrix::NumColBlocks ( ) const
inline

Return the number of column blocks.

Definition at line 48 of file blockmatrix.hpp.

◆ NumNonZeroElems()

int mfem::BlockMatrix::NumNonZeroElems ( ) const
virtual

Returns the total number of non zeros in the matrix.

Implements mfem::AbstractSparseMatrix.

Definition at line 116 of file blockmatrix.cpp.

◆ NumRowBlocks()

int mfem::BlockMatrix::NumRowBlocks ( ) const
inline

Return the number of row blocks.

Definition at line 46 of file blockmatrix.hpp.

◆ PartAddMult()

void mfem::BlockMatrix::PartAddMult ( const Array< int > & rows,
const Vector & x,
Vector & y,
const real_t a = 1.0 ) const

Partial matrix vector multiplication of (*this) with x involving only the rows given by rows. The result is multiplied by a and added to y.

Definition at line 539 of file blockmatrix.cpp.

◆ PartMult()

void mfem::BlockMatrix::PartMult ( const Array< int > & rows,
const Vector & x,
Vector & y ) const

Partial matrix vector multiplication of (*this) with x involving only the rows given by rows. The result is given in y.

Definition at line 521 of file blockmatrix.cpp.

◆ PrintMatlab()

void mfem::BlockMatrix::PrintMatlab ( std::ostream & os = mfem::out) const
virtual

Export the monolithic matrix to file.

Reimplemented from mfem::Operator.

Definition at line 640 of file blockmatrix.cpp.

◆ RowOffsets() [1/2]

Array< int > & mfem::BlockMatrix::RowOffsets ( )
inline

Return the row offsets for block starts.

Definition at line 57 of file blockmatrix.hpp.

◆ RowOffsets() [2/2]

const Array< int > & mfem::BlockMatrix::RowOffsets ( ) const
inline

Return the row offsets for block starts (const version)

Definition at line 61 of file blockmatrix.hpp.

◆ RowSize()

int mfem::BlockMatrix::RowSize ( const int i) const

Return the number of non zeros in row i.

Definition at line 165 of file blockmatrix.cpp.

◆ SetBlock()

void mfem::BlockMatrix::SetBlock ( int i,
int j,
SparseMatrix * mat )

Set A(i,j) = mat.

Definition at line 61 of file blockmatrix.cpp.

Member Data Documentation

◆ owns_blocks

int mfem::BlockMatrix::owns_blocks

If owns_blocks the SparseMatrix objects Aij will be deallocated.

Definition at line 154 of file blockmatrix.hpp.


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