12 #ifndef MFEM_BLOCKMATRIX
13 #define MFEM_BLOCKMATRIX
15 #include "../config/config.hpp"
16 #include "../general/array.hpp"
17 #include "../general/globals.hpp"
55 int IsZeroBlock(
int i,
int j)
const {
return (Aij(i,j)==NULL) ? 1 : 0; }
87 void Finalize(
int skip_zeros,
bool fix_empty_rows);
98 virtual double&
Elem (
int i,
int j);
100 virtual const double&
Elem (
int i,
int j)
const;
104 mfem_error(
"BlockMatrix::Inverse not implemented \n");
133 const double val = 1.)
const;
143 inline void findGlobalRow(
int iglobal,
int & iblock,
int & iloc)
const;
145 inline void findGlobalCol(
int jglobal,
int & jblock,
int & jloc)
const;
165 inline void BlockMatrix::findGlobalRow(
int iglobal,
int & iblock,
168 if (iglobal > row_offsets[nRowBlocks])
173 for (iblock = 0; iblock < nRowBlocks; ++iblock)
175 if (row_offsets[iblock+1] > iglobal) {
break; }
178 iloc = iglobal - row_offsets[iblock];
181 inline void BlockMatrix::findGlobalCol(
int jglobal,
int & jblock,
184 if (jglobal > col_offsets[nColBlocks])
189 for (jblock = 0; jblock < nColBlocks; ++jblock)
191 if (col_offsets[jblock+1] > jglobal) {
break; }
194 jloc = jglobal - col_offsets[jblock];
virtual MatrixInverse * Inverse() const
Returns a pointer to (approximation) of the matrix inverse.
SparseMatrix * CreateMonolithic() const
Returns a monolithic CSR matrix that represents this operator.
int owns_blocks
If owns_blocks the SparseMatrix objects Aij will be deallocated.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
Abstract data type for sparse matrices.
Abstract data type for matrix inverse.
BlockMatrix(const Array< int > &offsets)
Constructor for square block matrices.
virtual void AddMultTranspose(const Vector &x, Vector &y, const double val=1.) const
MatrixTranspose-Vector Multiplication y = y + val*A'*x.
virtual int GetRow(const int row, Array< int > &cols, Vector &srow) const
Gets the columns indexes and values for row row.
void SetBlock(int i, int j, SparseMatrix *mat)
Set A(i,j) = mat.
virtual double & Elem(int i, int j)
Returns reference to a_{ij}.
virtual void Finalize(int skip_zeros=1)
Finalize all the submatrices.
int IsZeroBlock(int i, int j) const
Check if block (i,j) is a zero block.
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
int NumRowBlocks() const
Return the number of row blocks.
Array< int > & ColOffsets()
Return the columns offsets for block starts.
void PrintMatlab(std::ostream &os=mfem::out) const
Export the monolithic matrix to file.
Array< int > & RowOffsets()
Return the row offsets for block starts.
Set the diagonal value to one.
virtual int NumNonZeroElems() const
Returns the total number of non zeros in the matrix.
virtual ~BlockMatrix()
Destructor.
Dynamic 2D array using row-major layout.
virtual void MultTranspose(const Vector &x, Vector &y) const
MatrixTranspose-Vector Multiplication y = A'*x.
virtual void Mult(const Vector &x, Vector &y) const
Matrix-Vector Multiplication y = A*x.
int NumColBlocks() const
Return the number of column blocks.
void Transpose(const Table &A, Table &At, int ncols_A_)
Transpose a Table.
void EliminateRowCol(int rc, DiagonalPolicy dpolicy=DIAG_ONE)
Eliminate the row and column rc from the matrix.
virtual void AddMult(const Vector &x, Vector &y, const double val=1.) const
Matrix-Vector Multiplication y = y + val*A*x.
DiagonalPolicy
Defines operator diagonal policy upon elimination of rows and/or columns.
const Array< int > & ColOffsets() const
Return the row offsets for block starts (const version)
SparseMatrix & GetBlock(int i, int j)
Return a reference to block (i,j). Reference may be invalid if Aij(i,j) == NULL.
const Array< int > & RowOffsets() 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.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
virtual void EliminateZeroRows(const double 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...