12#ifndef MFEM_BLOCKMATRIX
13#define MFEM_BLOCKMATRIX
55 int IsZeroBlock(
int i,
int j)
const {
return (Aij(i,j)==NULL) ? 1 : 0; }
93 void Finalize(
int skip_zeros,
bool fix_empty_rows);
106 virtual const real_t&
Elem (
int i,
int j)
const;
110 mfem_error(
"BlockMatrix::Inverse not implemented \n");
139 const real_t val = 1.)
const;
160 inline void findGlobalRow(
int iglobal,
int & iblock,
int & iloc)
const;
162 inline void findGlobalCol(
int jglobal,
int & jblock,
int & jloc)
const;
178BlockMatrix *
Transpose(
const BlockMatrix & A);
180BlockMatrix *
Mult(
const BlockMatrix & A,
const BlockMatrix & B);
182inline void BlockMatrix::findGlobalRow(
int iglobal,
int & iblock,
185 if (iglobal > row_offsets[nRowBlocks])
190 for (iblock = 0; iblock < nRowBlocks; ++iblock)
192 if (row_offsets[iblock+1] > iglobal) {
break; }
195 iloc = iglobal - row_offsets[iblock];
198inline void BlockMatrix::findGlobalCol(
int jglobal,
int & jblock,
201 if (jglobal > col_offsets[nColBlocks])
206 for (jblock = 0; jblock < nColBlocks; ++jblock)
208 if (col_offsets[jblock+1] > jglobal) {
break; }
211 jloc = jglobal - col_offsets[jblock];
Abstract data type for sparse matrices.
Dynamic 2D array using row-major layout.
virtual ~BlockMatrix()
Destructor.
virtual void AddMult(const Vector &x, Vector &y, const real_t val=1.) const
Matrix-Vector Multiplication y = y + val*A*x.
int RowSize(const int i) const
Return the number of non zeros in row i.
Array< int > & ColOffsets()
Return the columns offsets for block starts.
void EliminateRowCol(int rc, DiagonalPolicy dpolicy=DIAG_ONE)
Eliminate the row and column rc from the matrix.
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....
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...
virtual void AddMultTranspose(const Vector &x, Vector &y, const real_t val=1.) const
MatrixTranspose-Vector Multiplication y = y + val*A'*x.
BlockMatrix(const Array< int > &offsets)
Constructor for square block matrices.
const Array< int > & RowOffsets() const
Return the row offsets for block starts (const version)
void SetBlock(int i, int j, SparseMatrix *mat)
Set A(i,j) = mat.
virtual void PrintMatlab(std::ostream &os=mfem::out) const
Export the monolithic matrix to file.
virtual real_t & Elem(int i, int j)
Returns reference to a_{ij}.
int NumColBlocks() const
Return the number of column blocks.
int IsZeroBlock(int i, int j) const
Check if block (i,j) is a zero block.
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 in...
SparseMatrix & GetBlock(int i, int j)
Return a reference to block (i,j). Reference may be invalid if Aij(i,j) == NULL.
virtual int GetRow(const int row, Array< int > &cols, Vector &srow) const
Gets the columns indexes and values for row row.
Array< int > & RowOffsets()
Return the row offsets for block starts.
virtual int NumNonZeroElems() const
Returns the total number of non zeros in the matrix.
const Array< int > & ColOffsets() const
Return the row offsets for block starts (const version)
int owns_blocks
If owns_blocks the SparseMatrix objects Aij will be deallocated.
virtual void Finalize(int skip_zeros=1)
Finalize all the submatrices.
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....
virtual MatrixInverse * Inverse() const
Returns a pointer to (approximation) of the matrix inverse.
virtual void Mult(const Vector &x, Vector &y) const
Matrix-Vector Multiplication y = A*x.
virtual void MultTranspose(const Vector &x, Vector &y) const
MatrixTranspose-Vector Multiplication y = A'*x.
int NumRowBlocks() const
Return the number of row blocks.
SparseMatrix * CreateMonolithic() const
Returns a monolithic CSR matrix that represents this operator.
virtual Type GetType() const
Abstract data type for matrix inverse.
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
@ DIAG_ONE
Set the diagonal value to one.
Type
Enumeration defining IDs for some classes derived from Operator.
@ MFEM_Block_Matrix
ID for class BlockMatrix.
void mfem_error(const char *msg)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void Transpose(const Table &A, Table &At, int ncols_A_)
Transpose a Table.