MFEM
v4.2.0
Finite element discretization library
|
Data type sparse matrix. More...
#include <sparsemat.hpp>
Public Member Functions | |
SparseMatrix () | |
Create an empty SparseMatrix. More... | |
SparseMatrix (int nrows, int ncols=-1) | |
Create a sparse matrix with flexible sparsity structure using a row-wise linked list (LIL) format. More... | |
SparseMatrix (int *i, int *j, double *data, int m, int n) | |
Create a sparse matrix in CSR format. Ownership of i, j, and data is transferred to the SparseMatrix. More... | |
SparseMatrix (int *i, int *j, double *data, int m, int n, bool ownij, bool owna, bool issorted) | |
Create a sparse matrix in CSR format. Ownership of i, j, and data is optionally transferred to the SparseMatrix. More... | |
SparseMatrix (int nrows, int ncols, int rowsize) | |
Create a sparse matrix in CSR format where each row has space allocated for exactly rowsize entries. More... | |
SparseMatrix (const SparseMatrix &mat, bool copy_graph=true) | |
Copy constructor (deep copy). More... | |
SparseMatrix (const Vector &v) | |
Create a SparseMatrix with diagonal v, i.e. A = Diag(v) More... | |
void | UseCuSparse (bool _useCuSparse=true) |
SparseMatrix & | operator= (const SparseMatrix &rhs) |
Assignment operator: deep copy. More... | |
void | MakeRef (const SparseMatrix &master) |
Clear the contents of the SparseMatrix and make it a reference to master. More... | |
int | Size () const |
For backward compatibility, define Size() to be synonym of Height(). More... | |
void | Clear () |
Clear the contents of the SparseMatrix. More... | |
bool | Empty () const |
Check if the SparseMatrix is empty. More... | |
int * | GetI () |
Return the array I. More... | |
const int * | GetI () const |
Return the array I, const version. More... | |
int * | GetJ () |
Return the array J. More... | |
const int * | GetJ () const |
Return the array J, const version. More... | |
double * | GetData () |
Return the element data, i.e. the array A. More... | |
const double * | GetData () const |
Return the element data, i.e. the array A, const version. More... | |
Memory< int > & | GetMemoryI () |
const Memory< int > & | GetMemoryI () const |
const int * | ReadI (bool on_dev=true) const |
int * | WriteI (bool on_dev=true) |
int * | ReadWriteI (bool on_dev=true) |
const int * | HostReadI () const |
int * | HostWriteI () |
int * | HostReadWriteI () |
Memory< int > & | GetMemoryJ () |
const Memory< int > & | GetMemoryJ () const |
const int * | ReadJ (bool on_dev=true) const |
int * | WriteJ (bool on_dev=true) |
int * | ReadWriteJ (bool on_dev=true) |
const int * | HostReadJ () const |
int * | HostWriteJ () |
int * | HostReadWriteJ () |
Memory< double > & | GetMemoryData () |
const Memory< double > & | GetMemoryData () const |
const double * | ReadData (bool on_dev=true) const |
double * | WriteData (bool on_dev=true) |
double * | ReadWriteData (bool on_dev=true) |
const double * | HostReadData () const |
double * | HostWriteData () |
double * | HostReadWriteData () |
int | RowSize (const int i) const |
Returns the number of elements in row i. More... | |
int | MaxRowSize () const |
Returns the maximum number of elements among all rows. More... | |
int * | GetRowColumns (const int row) |
Return a pointer to the column indices in a row. More... | |
const int * | GetRowColumns (const int row) const |
Return a pointer to the column indices in a row, const version. More... | |
double * | GetRowEntries (const int row) |
Return a pointer to the entries in a row. More... | |
const double * | GetRowEntries (const int row) const |
Return a pointer to the entries in a row, const version. More... | |
void | SetWidth (int width_=-1) |
Change the width of a SparseMatrix. More... | |
int | ActualWidth () const |
Returns the actual Width of the matrix. More... | |
void | SortColumnIndices () |
Sort the column indices corresponding to each row. More... | |
void | MoveDiagonalFirst () |
Move the diagonal entry to the first position in each row, preserving the order of the rest of the columns. More... | |
virtual double & | Elem (int i, int j) |
Returns reference to a_{ij}. More... | |
virtual const double & | Elem (int i, int j) const |
Returns constant reference to a_{ij}. More... | |
double & | operator() (int i, int j) |
Returns reference to A[i][j]. More... | |
const double & | operator() (int i, int j) const |
Returns reference to A[i][j]. More... | |
void | GetDiag (Vector &d) const |
Returns the Diagonal of A. More... | |
DenseMatrix * | ToDenseMatrix () const |
Produces a DenseMatrix from a SparseMatrix. More... | |
void | ToDenseMatrix (DenseMatrix &B) const |
Produces a DenseMatrix from a SparseMatrix. More... | |
virtual MemoryClass | GetMemoryClass () const |
Return the MemoryClass preferred by the Operator. More... | |
virtual void | Mult (const Vector &x, Vector &y) const |
Matrix vector multiplication. More... | |
void | AddMult (const Vector &x, Vector &y, const double a=1.0) const |
y += A * x (default) or y += a * A * x More... | |
void | MultTranspose (const Vector &x, Vector &y) const |
Multiply a vector with the transposed matrix. y = At * x. More... | |
void | AddMultTranspose (const Vector &x, Vector &y, const double a=1.0) const |
y += At * x (default) or y += a * At * x More... | |
void | BuildTranspose () const |
Build and store internally the transpose of this matrix which will be used in the methods AddMultTranspose() and MultTranspose(). More... | |
void | ResetTranspose () const |
void | PartMult (const Array< int > &rows, const Vector &x, Vector &y) const |
void | PartAddMult (const Array< int > &rows, const Vector &x, Vector &y, const double a=1.0) const |
void | BooleanMult (const Array< int > &x, Array< int > &y) const |
y = A * x, treating all entries as booleans (zero=false, nonzero=true). More... | |
void | BooleanMultTranspose (const Array< int > &x, Array< int > &y) const |
y = At * x, treating all entries as booleans (zero=false, nonzero=true). More... | |
void | AbsMult (const Vector &x, Vector &y) const |
y = |A| * x, using entry-wise absolute values of matrix A More... | |
void | AbsMultTranspose (const Vector &x, Vector &y) const |
y = |At| * x, using entry-wise absolute values of the transpose of matrix A More... | |
double | InnerProduct (const Vector &x, const Vector &y) const |
Compute y^t A x. More... | |
void | GetRowSums (Vector &x) const |
For all i compute \( x_i = \sum_j A_{ij} \). More... | |
double | GetRowNorml1 (int irow) const |
For i = irow compute \( x_i = \sum_j | A_{i, j} | \). More... | |
virtual MatrixInverse * | Inverse () const |
This virtual method is not supported: it always returns NULL. More... | |
void | EliminateRow (int row, const double sol, Vector &rhs) |
Eliminates a column from the transpose matrix. More... | |
void | EliminateRow (int row, DiagonalPolicy dpolicy=DIAG_ZERO) |
Eliminates a row from the matrix. More... | |
void | EliminateCol (int col, DiagonalPolicy dpolicy=DIAG_ZERO) |
Eliminates the column col from the matrix. More... | |
void | EliminateCols (const Array< int > &cols, const Vector *x=NULL, Vector *b=NULL) |
Eliminate all columns i for which cols[i] != 0. More... | |
void | EliminateCols (const Array< int > &col_marker, SparseMatrix &Ae) |
Similar to EliminateCols + save the eliminated entries into Ae so that (*this) + Ae is equal to the original matrix. More... | |
void | EliminateRowCol (int rc, const double sol, Vector &rhs, DiagonalPolicy dpolicy=DIAG_ONE) |
Eliminate row rc and column rc and modify the rhs using sol. More... | |
void | EliminateRowColMultipleRHS (int rc, const Vector &sol, DenseMatrix &rhs, DiagonalPolicy dpolicy=DIAG_ONE) |
Similar to EliminateRowCol(int, const double, Vector &, DiagonalPolicy), but multiple values for eliminated unknowns are accepted, and accordingly multiple right-hand-sides are used. More... | |
void | EliminateRowColDiag (int rc, double value) |
Perform elimination and set the diagonal entry to the given value. More... | |
void | EliminateRowCol (int rc, DiagonalPolicy dpolicy=DIAG_ONE) |
Eliminate row rc and column rc. More... | |
void | EliminateRowCol (int rc, SparseMatrix &Ae, DiagonalPolicy dpolicy=DIAG_ONE) |
Similar to EliminateRowCol(int, DiagonalPolicy) + save the eliminated entries into Ae so that (*this) + Ae is equal to the original matrix. More... | |
void | SetDiagIdentity () |
If a row contains only one diag entry of zero, set it to 1. More... | |
virtual void | EliminateZeroRows (const double threshold=1e-12) |
If a row contains only zeros, set its diagonal to 1. More... | |
void | Gauss_Seidel_forw (const Vector &x, Vector &y) const |
Gauss-Seidel forward and backward iterations over a vector x. More... | |
void | Gauss_Seidel_back (const Vector &x, Vector &y) const |
double | GetJacobiScaling () const |
Determine appropriate scaling for Jacobi iteration. More... | |
void | Jacobi (const Vector &b, const Vector &x0, Vector &x1, double sc) const |
void | DiagScale (const Vector &b, Vector &x, double sc=1.0) const |
void | Jacobi2 (const Vector &b, const Vector &x0, Vector &x1, double sc=1.0) const |
void | Jacobi3 (const Vector &b, const Vector &x0, Vector &x1, double sc=1.0) const |
virtual void | Finalize (int skip_zeros=1) |
Finalize the matrix initialization, switching the storage format from LIL to CSR. More... | |
void | Finalize (int skip_zeros, bool fix_empty_rows) |
A slightly more general version of the Finalize(int) method. More... | |
bool | Finalized () const |
Returns whether or not CSR format has been finalized. More... | |
bool | ColumnsAreSorted () const |
Returns whether or not the columns are sorted. More... | |
void | Threshold (double tol, bool fix_empty_rows=false) |
Remove entries smaller in absolute value than a given tolerance tol. If fix_empty_rows is true, a zero value is inserted in the diagonal entry (for square matrices only) More... | |
void | GetBlocks (Array2D< SparseMatrix * > &blocks) const |
void | GetSubMatrix (const Array< int > &rows, const Array< int > &cols, DenseMatrix &subm) const |
void | SetColPtr (const int row) const |
Initialize the SparseMatrix for fast access to the entries of the given row which becomes the "current row". More... | |
void | ClearColPtr () const |
Reset the "current row" set by calling SetColPtr(). This method must be called between any two calls to SetColPtr(). More... | |
double & | SearchRow (const int col) |
Perform a fast search for an entry in the "current row". See SetColPtr(). More... | |
void | _Add_ (const int col, const double a) |
Add a value to an entry in the "current row". See SetColPtr(). More... | |
void | _Set_ (const int col, const double a) |
Set an entry in the "current row". See SetColPtr(). More... | |
double | _Get_ (const int col) const |
Read the value of an entry in the "current row". See SetColPtr(). More... | |
double & | SearchRow (const int row, const int col) |
void | _Add_ (const int row, const int col, const double a) |
void | _Set_ (const int row, const int col, const double a) |
void | Set (const int i, const int j, const double a) |
void | Add (const int i, const int j, const double a) |
void | SetSubMatrix (const Array< int > &rows, const Array< int > &cols, const DenseMatrix &subm, int skip_zeros=1) |
void | SetSubMatrixTranspose (const Array< int > &rows, const Array< int > &cols, const DenseMatrix &subm, int skip_zeros=1) |
void | AddSubMatrix (const Array< int > &rows, const Array< int > &cols, const DenseMatrix &subm, int skip_zeros=1) |
bool | RowIsEmpty (const int row) const |
virtual int | GetRow (const int row, Array< int > &cols, Vector &srow) const |
Extract all column indices and values from a given row. More... | |
void | SetRow (const int row, const Array< int > &cols, const Vector &srow) |
void | AddRow (const int row, const Array< int > &cols, const Vector &srow) |
void | ScaleRow (const int row, const double scale) |
void | ScaleRows (const Vector &sl) |
this = diag(sl) * this; More... | |
void | ScaleColumns (const Vector &sr) |
this = this * diag(sr); More... | |
SparseMatrix & | operator+= (const SparseMatrix &B) |
Add the sparse matrix 'B' to '*this'. This operation will cause an error if '*this' is finalized and 'B' has larger sparsity pattern. More... | |
void | Add (const double a, const SparseMatrix &B) |
Add the sparse matrix 'B' scaled by the scalar 'a' into '*this'. Only entries in the sparsity pattern of '*this' are added. More... | |
SparseMatrix & | operator= (double a) |
SparseMatrix & | operator*= (double a) |
void | Print (std::ostream &out=mfem::out, int width_=4) const |
Prints matrix to stream out. More... | |
void | PrintMatlab (std::ostream &out=mfem::out) const |
Prints matrix in matlab format. More... | |
void | PrintMM (std::ostream &out=mfem::out) const |
Prints matrix in Matrix Market sparse format. More... | |
void | PrintCSR (std::ostream &out) const |
Prints matrix to stream out in hypre_CSRMatrix format. More... | |
void | PrintCSR2 (std::ostream &out) const |
Prints a sparse matrix to stream out in CSR format. More... | |
void | PrintInfo (std::ostream &out) const |
Print various sparse matrix statistics. More... | |
double | IsSymmetric () const |
Returns max_{i,j} |(i,j)-(j,i)| for a finalized matrix. More... | |
void | Symmetrize () |
(*this) = 1/2 ((*this) + (*this)^t) More... | |
virtual int | NumNonZeroElems () const |
Returns the number of the nonzero elements in the matrix. More... | |
double | MaxNorm () const |
int | CountSmallElems (double tol) const |
Count the number of entries with |a_ij| <= tol. More... | |
int | CheckFinite () const |
Count the number of entries that are NOT finite, i.e. Inf or Nan. More... | |
void | SetGraphOwner (bool ownij) |
Set the graph ownership flag (I and J arrays). More... | |
void | SetDataOwner (bool owna) |
Set the data ownership flag (A array). More... | |
bool | OwnsGraph () const |
Get the graph ownership flag (I and J arrays). More... | |
bool | OwnsData () const |
Get the data ownership flag (A array). More... | |
void | LoseData () |
Lose the ownership of the graph (I, J) and data (A) arrays. More... | |
void | Swap (SparseMatrix &other) |
virtual | ~SparseMatrix () |
Destroys sparse matrix. More... | |
Type | GetType () const |
Public Member Functions inherited from mfem::AbstractSparseMatrix | |
AbstractSparseMatrix (int s=0) | |
Creates a square matrix of the given size. More... | |
AbstractSparseMatrix (int h, int w) | |
Creates a matrix of the given height and width. More... | |
virtual | ~AbstractSparseMatrix () |
Destroys AbstractSparseMatrix. More... | |
Public Member Functions inherited from mfem::Matrix | |
Matrix (int s) | |
Creates a square matrix of size s. More... | |
Matrix (int h, int w) | |
Creates a matrix of the given height and width. More... | |
bool | IsSquare () const |
Returns whether the matrix is a square matrix. More... | |
virtual | ~Matrix () |
Destroys matrix. More... | |
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. More... | |
Operator (int s=0) | |
Construct a square Operator with given size s (default 0). More... | |
Operator (int h, int w) | |
Construct an Operator with the given height (output size) and width (input size). More... | |
int | Height () const |
Get the height (size of output) of the Operator. Synonym with NumRows(). More... | |
int | NumRows () const |
Get the number of rows (size of output) of the Operator. Synonym with Height(). More... | |
int | Width () const |
Get the width (size of input) of the Operator. Synonym with NumCols(). More... | |
int | NumCols () const |
Get the number of columns (size of input) of the Operator. Synonym with Width(). More... | |
virtual Operator & | GetGradient (const Vector &x) const |
Evaluate the gradient operator at the point x. The default behavior in class Operator is to generate an error. More... | |
virtual const Operator * | GetProlongation () const |
Prolongation operator from linear algebra (linear system) vectors, to input vectors for the operator. NULL means identity. More... | |
virtual const Operator * | GetRestriction () const |
Restriction operator from input vectors for the operator to linear algebra (linear system) vectors. NULL means identity. More... | |
virtual const Operator * | GetOutputProlongation () const |
Prolongation operator from linear algebra (linear system) vectors, to output vectors for the operator. NULL means identity. More... | |
virtual const Operator * | GetOutputRestriction () const |
Restriction operator from output vectors for the operator to linear algebra (linear system) vectors. NULL means identity. More... | |
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. More... | |
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. More... | |
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(). More... | |
void | FormSystemOperator (const Array< int > &ess_tdof_list, Operator *&A) |
Return in A a parallel (on truedofs) version of this square operator. More... | |
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). More... | |
void | FormDiscreteOperator (Operator *&A) |
Return in A a parallel (on truedofs) version of this rectangular operator. More... | |
void | PrintMatlab (std::ostream &out, int n=0, int m=0) const |
Prints operator with input size n and output size m in Matlab format. More... | |
virtual | ~Operator () |
Virtual destructor. More... | |
Type | GetType () const |
Return the type ID of the Operator class. More... | |
Protected Types | |
typedef MemAlloc< RowNode, 1024 > | RowNodeAlloc |
Protected Member Functions | |
void | Destroy () |
void | SetEmpty () |
void | InitCuSparse () |
Protected Member Functions inherited from mfem::Operator | |
void | FormConstrainedSystemOperator (const Array< int > &ess_tdof_list, ConstrainedOperator *&Aout) |
see FormSystemOperator() More... | |
void | FormRectangularConstrainedSystemOperator (const Array< int > &trial_tdof_list, const Array< int > &test_tdof_list, RectangularConstrainedOperator *&Aout) |
see FormRectangularSystemOperator() More... | |
Operator * | SetupRAP (const Operator *Pi, const Operator *Po) |
Returns RAP Operator of this, taking in input/output Prolongation matrices. More... | |
Protected Attributes | |
RowNode ** | Rows |
Array of linked lists, one for every row. This array represents the linked list (LIL) storage format. More... | |
int | current_row |
int * | ColPtrJ |
RowNode ** | ColPtrNode |
SparseMatrix * | At |
Transpose of A. Owned. Used to perform MultTranspose() on devices. More... | |
RowNodeAlloc * | NodesMem |
bool | isSorted |
Are the columns sorted already. More... | |
bool | useCuSparse {true} |
cusparseStatus_t | status |
cusparseMatDescr_t | descr =0 |
bool | initBuffers {false} |
cusparseSpMatDescr_t | matA_descr |
cusparseDnVecDescr_t | vecX_descr |
cusparseDnVecDescr_t | vecY_descr |
Arrays used by the CSR storage format. | |
Memory< int > | I |
Array with size (height+1) containing the row offsets. More... | |
Memory< int > | J |
Array with size I[height], containing the column indices for all matrix entries, as indexed by the I array. More... | |
Memory< double > | A |
Array with size I[height], containing the actual entries of the sparse matrix, as indexed by the I array. More... | |
Protected Attributes inherited from mfem::Operator | |
int | height |
Dimension of the output / number of rows in the matrix. More... | |
int | width |
Dimension of the input / number of columns in the matrix. More... | |
Static Protected Attributes | |
static cusparseHandle_t | handle |
static size_t | bufferSize = 0 |
static void * | dBuffer = nullptr |
static int | SparseMatrixCount = 0 |
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 } |
Enumeration defining IDs for some classes derived from Operator. More... | |
Data type sparse matrix.
Definition at line 46 of file sparsemat.hpp.
|
protected |
Definition at line 79 of file sparsemat.hpp.
|
inline |
Create an empty SparseMatrix.
Definition at line 110 of file sparsemat.hpp.
|
explicit |
Create a sparse matrix with flexible sparsity structure using a row-wise linked list (LIL) format.
New entries are added as needed by methods like AddSubMatrix(), SetSubMatrix(), etc. Calling Finalize() will convert the SparseMatrix to the more compact compressed sparse row (CSR) format.
Definition at line 50 of file sparsemat.cpp.
mfem::SparseMatrix::SparseMatrix | ( | int * | i, |
int * | j, | ||
double * | data, | ||
int | m, | ||
int | n | ||
) |
Create a sparse matrix in CSR format. Ownership of i, j, and data is transferred to the SparseMatrix.
Definition at line 76 of file sparsemat.cpp.
mfem::SparseMatrix::SparseMatrix | ( | int * | i, |
int * | j, | ||
double * | data, | ||
int | m, | ||
int | n, | ||
bool | ownij, | ||
bool | owna, | ||
bool | issorted | ||
) |
Create a sparse matrix in CSR format. Ownership of i, j, and data is optionally transferred to the SparseMatrix.
If the parameter data is NULL, then the internal A array is allocated by this constructor (initializing it with zeros and taking ownership, regardless of the parameter owna).
Definition at line 95 of file sparsemat.cpp.
mfem::SparseMatrix::SparseMatrix | ( | int | nrows, |
int | ncols, | ||
int | rowsize | ||
) |
mfem::SparseMatrix::SparseMatrix | ( | const SparseMatrix & | mat, |
bool | copy_graph = true |
||
) |
Copy constructor (deep copy).
If mat is finalized and copy_graph is false, the I and J arrays will use a shallow copy (copy the pointers only) without transferring ownership.
Definition at line 151 of file sparsemat.cpp.
mfem::SparseMatrix::SparseMatrix | ( | const Vector & | v | ) |
Create a SparseMatrix with diagonal v, i.e. A = Diag(v)
Definition at line 218 of file sparsemat.cpp.
|
inlinevirtual |
Destroys sparse matrix.
Definition at line 614 of file sparsemat.hpp.
|
inline |
Add a value to an entry in the "current row". See SetColPtr().
Definition at line 499 of file sparsemat.hpp.
|
inline |
Definition at line 508 of file sparsemat.hpp.
|
inline |
Read the value of an entry in the "current row". See SetColPtr().
Definition at line 792 of file sparsemat.hpp.
|
inline |
Set an entry in the "current row". See SetColPtr().
Definition at line 502 of file sparsemat.hpp.
|
inline |
Definition at line 510 of file sparsemat.hpp.
y = |A| * x, using entry-wise absolute values of matrix A
Definition at line 884 of file sparsemat.cpp.
y = |At| * x, using entry-wise absolute values of the transpose of matrix A
Definition at line 933 of file sparsemat.cpp.
int mfem::SparseMatrix::ActualWidth | ( | ) | const |
Returns the actual Width of the matrix.
This method can be called for matrices finalized or not.
Definition at line 3169 of file sparsemat.cpp.
void mfem::SparseMatrix::Add | ( | const int | i, |
const int | j, | ||
const double | a | ||
) |
Definition at line 2493 of file sparsemat.cpp.
void mfem::SparseMatrix::Add | ( | const double | a, |
const SparseMatrix & | B | ||
) |
Add the sparse matrix 'B' scaled by the scalar 'a' into '*this'. Only entries in the sparsity pattern of '*this' are added.
Definition at line 2865 of file sparsemat.cpp.
|
virtual |
y += A * x (default) or y += a * A * x
Implements mfem::AbstractSparseMatrix.
Definition at line 601 of file sparsemat.cpp.
|
virtual |
y += At * x (default) or y += a * At * x
Implements mfem::AbstractSparseMatrix.
Definition at line 728 of file sparsemat.cpp.
Definition at line 2716 of file sparsemat.cpp.
void mfem::SparseMatrix::AddSubMatrix | ( | const Array< int > & | rows, |
const Array< int > & | cols, | ||
const DenseMatrix & | subm, | ||
int | skip_zeros = 1 |
||
) |
Definition at line 2436 of file sparsemat.cpp.
y = A * x, treating all entries as booleans (zero=false, nonzero=true).
The actual values stored in the data array, A, are not used - this means that all entries in the sparsity pattern are considered to be true by this method.
Definition at line 831 of file sparsemat.cpp.
y = At * x, treating all entries as booleans (zero=false, nonzero=true).
The actual values stored in the data array, A, are not used - this means that all entries in the sparsity pattern are considered to be true by this method.
Definition at line 861 of file sparsemat.cpp.
void mfem::SparseMatrix::BuildTranspose | ( | ) | const |
Build and store internally the transpose of this matrix which will be used in the methods AddMultTranspose() and MultTranspose().
If this method has been called, the internal transpose matrix will be used to perform the action of the transpose matrix in AddMultTranspose(), and MultTranspose().
Warning: any changes in this matrix will invalidate the internal transpose. To rebuild the transpose, call ResetTranspose() followed by a call to this method. If the internal transpose is already built, this method has no effect.
When any non-default backend is enabled, i.e. Device::IsEnabled() is true, the methods AddMultTranspose(), and MultTranspose(), require the internal transpose to be built. If that is not the case (i.e. the internal transpose is not built), these methods will raise an error with an appropriate message pointing to this method. When using the default backend, calling this method is optional.
This method can only be used when the sparse matrix is finalized.
Definition at line 773 of file sparsemat.cpp.
int mfem::SparseMatrix::CheckFinite | ( | ) | const |
Count the number of entries that are NOT finite, i.e. Inf or Nan.
Definition at line 1434 of file sparsemat.cpp.
|
inline |
Clear the contents of the SparseMatrix.
Definition at line 167 of file sparsemat.hpp.
|
inline |
Reset the "current row" set by calling SetColPtr(). This method must be called between any two calls to SetColPtr().
Definition at line 746 of file sparsemat.hpp.
|
inline |
Returns whether or not the columns are sorted.
Definition at line 468 of file sparsemat.hpp.
int mfem::SparseMatrix::CountSmallElems | ( | double | tol | ) | const |
Count the number of entries with |a_ij| <= tol.
Definition at line 1406 of file sparsemat.cpp.
|
protected |
Definition at line 3128 of file sparsemat.cpp.
Definition at line 2341 of file sparsemat.cpp.
|
virtual |
|
virtual |
Returns constant reference to a_{ij}.
Implements mfem::Matrix.
Definition at line 467 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateCol | ( | int | col, |
DiagonalPolicy | dpolicy = DIAG_ZERO |
||
) |
Eliminates the column col from the matrix.
Definition at line 1511 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateCols | ( | const Array< int > & | cols, |
const Vector * | x = NULL , |
||
Vector * | b = NULL |
||
) |
Eliminate all columns i for which cols[i] != 0.
Elimination of a column means that all entries in the column are set to zero. In addition, if the pointers x and b are not NULL, the eliminated matrix entries are multiplied by the corresponding solution value in *x and subtracted from the r.h.s. vector, *b.
Definition at line 1551 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateCols | ( | const Array< int > & | col_marker, |
SparseMatrix & | Ae | ||
) |
Similar to EliminateCols + save the eliminated entries into Ae so that (*this) + Ae is equal to the original matrix.
Definition at line 1590 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateRow | ( | int | row, |
const double | sol, | ||
Vector & | rhs | ||
) |
Eliminates a column from the transpose matrix.
Definition at line 1463 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateRow | ( | int | row, |
DiagonalPolicy | dpolicy = DIAG_ZERO |
||
) |
Eliminates a row from the matrix.
Definition at line 1479 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateRowCol | ( | int | rc, |
const double | sol, | ||
Vector & | rhs, | ||
DiagonalPolicy | dpolicy = DIAG_ONE |
||
) |
Eliminate row rc and column rc and modify the rhs using sol.
Eliminates the column rc to the rhs, deletes the row rc and replaces the element (rc,rc) with 1.0; assumes that element (i,rc) is assembled if and only if the element (rc,i) is assembled. By default, elements (rc,rc) are set to 1.0, although this behavior can be adjusted by changing the dpolicy parameter.
Definition at line 1624 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateRowCol | ( | int | rc, |
DiagonalPolicy | dpolicy = DIAG_ONE |
||
) |
Eliminate row rc and column rc.
Definition at line 1844 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateRowCol | ( | int | rc, |
SparseMatrix & | Ae, | ||
DiagonalPolicy | dpolicy = DIAG_ONE |
||
) |
Similar to EliminateRowCol(int, DiagonalPolicy) + save the eliminated entries into Ae so that (*this) + Ae is equal to the original matrix.
Definition at line 1986 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateRowColDiag | ( | int | rc, |
double | value | ||
) |
Perform elimination and set the diagonal entry to the given value.
Definition at line 1923 of file sparsemat.cpp.
void mfem::SparseMatrix::EliminateRowColMultipleRHS | ( | int | rc, |
const Vector & | sol, | ||
DenseMatrix & | rhs, | ||
DiagonalPolicy | dpolicy = DIAG_ONE |
||
) |
Similar to EliminateRowCol(int, const double, Vector &, DiagonalPolicy), but multiple values for eliminated unknowns are accepted, and accordingly multiple right-hand-sides are used.
Definition at line 1720 of file sparsemat.cpp.
|
virtual |
If a row contains only zeros, set its diagonal to 1.
Implements mfem::AbstractSparseMatrix.
Definition at line 2091 of file sparsemat.cpp.
|
inline |
Check if the SparseMatrix is empty.
Definition at line 170 of file sparsemat.hpp.
|
inlinevirtual |
Finalize the matrix initialization, switching the storage format from LIL to CSR.
This method should be called once, after the matrix has been initialized. Internally, this method converts the matrix from row-wise linked list (LIL) format into CSR (compressed sparse row) format.
Reimplemented from mfem::Matrix.
Definition at line 460 of file sparsemat.hpp.
void mfem::SparseMatrix::Finalize | ( | int | skip_zeros, |
bool | fix_empty_rows | ||
) |
A slightly more general version of the Finalize(int) method.
Definition at line 1128 of file sparsemat.cpp.
|
inline |
Returns whether or not CSR format has been finalized.
Definition at line 466 of file sparsemat.hpp.
Definition at line 2194 of file sparsemat.cpp.
Gauss-Seidel forward and backward iterations over a vector x.
Definition at line 2110 of file sparsemat.cpp.
void mfem::SparseMatrix::GetBlocks | ( | Array2D< SparseMatrix * > & | blocks | ) | const |
Split the matrix into M x N blocks of sparse matrices in CSR format. The 'blocks' array is M x N (i.e. M and N are determined by its dimensions) and its entries are overwritten by the new blocks.
Definition at line 1208 of file sparsemat.cpp.
|
inline |
Return the element data, i.e. the array A.
Definition at line 183 of file sparsemat.hpp.
|
inline |
Return the element data, i.e. the array A, const version.
Definition at line 185 of file sparsemat.hpp.
void mfem::SparseMatrix::GetDiag | ( | Vector & | d | ) | const |
Returns the Diagonal of A.
Definition at line 530 of file sparsemat.cpp.
|
inline |
Return the array I.
Definition at line 173 of file sparsemat.hpp.
|
inline |
Return the array I, const version.
Definition at line 175 of file sparsemat.hpp.
|
inline |
Return the array J.
Definition at line 178 of file sparsemat.hpp.
|
inline |
Return the array J, const version.
Definition at line 180 of file sparsemat.hpp.
double mfem::SparseMatrix::GetJacobiScaling | ( | ) | const |
Determine appropriate scaling for Jacobi iteration.
Definition at line 2277 of file sparsemat.cpp.
|
inlinevirtual |
Return the MemoryClass preferred by the Operator.
This is the MemoryClass that will be used to access the input and output vectors in the Mult() and MultTranspose() methods.
For example, classes using the MFEM_FORALL macro for implementation can return the value returned by Device::GetMemoryClass().
The default implementation of this method in class Operator returns MemoryClass::HOST.
Reimplemented from mfem::Operator.
Definition at line 293 of file sparsemat.hpp.
|
inline |
Definition at line 220 of file sparsemat.hpp.
|
inline |
Definition at line 221 of file sparsemat.hpp.
|
inline |
Definition at line 188 of file sparsemat.hpp.
|
inline |
Definition at line 189 of file sparsemat.hpp.
|
inline |
Definition at line 204 of file sparsemat.hpp.
|
inline |
Definition at line 205 of file sparsemat.hpp.
Extract all column indices and values from a given row.
If the matrix is finalized (i.e. in CSR format), cols and srow will simply be references to the specific portion of the J and A arrays. As required by the AbstractSparseMatrix interface this method returns:
Implements mfem::AbstractSparseMatrix.
Definition at line 2629 of file sparsemat.cpp.
int * mfem::SparseMatrix::GetRowColumns | ( | const int | row | ) |
Return a pointer to the column indices in a row.
Definition at line 343 of file sparsemat.cpp.
const int * mfem::SparseMatrix::GetRowColumns | ( | const int | row | ) | const |
Return a pointer to the column indices in a row, const version.
Definition at line 350 of file sparsemat.cpp.
double * mfem::SparseMatrix::GetRowEntries | ( | const int | row | ) |
Return a pointer to the entries in a row.
Definition at line 357 of file sparsemat.cpp.
const double * mfem::SparseMatrix::GetRowEntries | ( | const int | row | ) | const |
Return a pointer to the entries in a row, const version.
Definition at line 364 of file sparsemat.cpp.
double mfem::SparseMatrix::GetRowNorml1 | ( | int | irow | ) | const |
For i = irow compute \( x_i = \sum_j | A_{i, j} | \).
Definition at line 1043 of file sparsemat.cpp.
void mfem::SparseMatrix::GetRowSums | ( | Vector & | x | ) | const |
For all i compute \( x_i = \sum_j A_{ij} \).
Definition at line 1020 of file sparsemat.cpp.
void mfem::SparseMatrix::GetSubMatrix | ( | const Array< int > & | rows, |
const Array< int > & | cols, | ||
DenseMatrix & | subm | ||
) | const |
Definition at line 2580 of file sparsemat.cpp.
|
inline |
Definition at line 627 of file sparsemat.hpp.
|
inline |
Definition at line 228 of file sparsemat.hpp.
|
inline |
Definition at line 196 of file sparsemat.hpp.
|
inline |
Definition at line 212 of file sparsemat.hpp.
|
inline |
Definition at line 232 of file sparsemat.hpp.
|
inline |
Definition at line 200 of file sparsemat.hpp.
|
inline |
Definition at line 216 of file sparsemat.hpp.
|
inline |
Definition at line 230 of file sparsemat.hpp.
|
inline |
Definition at line 198 of file sparsemat.hpp.
|
inline |
Definition at line 214 of file sparsemat.hpp.
|
protected |
Definition at line 38 of file sparsemat.cpp.
Compute y^t A x.
Definition at line 979 of file sparsemat.cpp.
|
virtual |
This virtual method is not supported: it always returns NULL.
Implements mfem::Matrix.
Definition at line 1458 of file sparsemat.cpp.
double mfem::SparseMatrix::IsSymmetric | ( | ) | const |
Returns max_{i,j} |(i,j)-(j,i)| for a finalized matrix.
Definition at line 1298 of file sparsemat.cpp.
void mfem::SparseMatrix::Jacobi | ( | const Vector & | b, |
const Vector & | x0, | ||
Vector & | x1, | ||
double | sc | ||
) | const |
One scaled Jacobi iteration for the system A x = b. x1 = x0 + sc D^{-1} (b - A x0) where D is the diag of A.
Definition at line 2310 of file sparsemat.cpp.
void mfem::SparseMatrix::Jacobi2 | ( | const Vector & | b, |
const Vector & | x0, | ||
Vector & | x1, | ||
double | sc = 1.0 |
||
) | const |
x1 = x0 + sc D^{-1} (b - A x0) where \( D_{ii} = \sum_j |A_{ij}| \).
Definition at line 2388 of file sparsemat.cpp.
void mfem::SparseMatrix::Jacobi3 | ( | const Vector & | b, |
const Vector & | x0, | ||
Vector & | x1, | ||
double | sc = 1.0 |
||
) | const |
x1 = x0 + sc D^{-1} (b - A x0) where \( D_{ii} = \sum_j A_{ij} \).
Definition at line 2412 of file sparsemat.cpp.
|
inline |
Lose the ownership of the graph (I, J) and data (A) arrays.
Definition at line 609 of file sparsemat.hpp.
void mfem::SparseMatrix::MakeRef | ( | const SparseMatrix & | master | ) |
Clear the contents of the SparseMatrix and make it a reference to master.
After this call, the matrix will point to the same data as master but it will not own its data. The master must be finalized.
Definition at line 257 of file sparsemat.cpp.
double mfem::SparseMatrix::MaxNorm | ( | ) | const |
Definition at line 1381 of file sparsemat.cpp.
int mfem::SparseMatrix::MaxRowSize | ( | ) | const |
Returns the maximum number of elements among all rows.
Definition at line 319 of file sparsemat.cpp.
void mfem::SparseMatrix::MoveDiagonalFirst | ( | ) |
Move the diagonal entry to the first position in each row, preserving the order of the rest of the columns.
Definition at line 438 of file sparsemat.cpp.
Matrix vector multiplication.
Implements mfem::AbstractSparseMatrix.
Definition at line 594 of file sparsemat.cpp.
Multiply a vector with the transposed matrix. y = At * x.
Implements mfem::AbstractSparseMatrix.
Definition at line 721 of file sparsemat.cpp.
|
virtual |
Returns the number of the nonzero elements in the matrix.
Implements mfem::AbstractSparseMatrix.
Definition at line 1359 of file sparsemat.cpp.
double & mfem::SparseMatrix::operator() | ( | int | i, |
int | j | ||
) |
Returns reference to A[i][j].
Definition at line 472 of file sparsemat.cpp.
const double & mfem::SparseMatrix::operator() | ( | int | i, |
int | j | ||
) | const |
Returns reference to A[i][j].
Definition at line 495 of file sparsemat.cpp.
SparseMatrix & mfem::SparseMatrix::operator*= | ( | double | a | ) |
Definition at line 2914 of file sparsemat.cpp.
SparseMatrix & mfem::SparseMatrix::operator+= | ( | const SparseMatrix & | B | ) |
Add the sparse matrix 'B' to '*this'. This operation will cause an error if '*this' is finalized and 'B' has larger sparsity pattern.
Definition at line 2835 of file sparsemat.cpp.
SparseMatrix & mfem::SparseMatrix::operator= | ( | const SparseMatrix & | rhs | ) |
Assignment operator: deep copy.
Definition at line 247 of file sparsemat.cpp.
SparseMatrix & mfem::SparseMatrix::operator= | ( | double | a | ) |
Definition at line 2888 of file sparsemat.cpp.
|
inline |
Get the data ownership flag (A array).
Definition at line 606 of file sparsemat.hpp.
|
inline |
Get the graph ownership flag (I and J arrays).
Definition at line 603 of file sparsemat.hpp.
void mfem::SparseMatrix::PartAddMult | ( | const Array< int > & | rows, |
const Vector & | x, | ||
Vector & | y, | ||
const double | a = 1.0 |
||
) | const |
Definition at line 813 of file sparsemat.cpp.
Definition at line 787 of file sparsemat.cpp.
|
virtual |
Prints matrix to stream out.
Reimplemented from mfem::Matrix.
Definition at line 2938 of file sparsemat.cpp.
void mfem::SparseMatrix::PrintCSR | ( | std::ostream & | out | ) | const |
Prints matrix to stream out in hypre_CSRMatrix format.
Definition at line 3028 of file sparsemat.cpp.
void mfem::SparseMatrix::PrintCSR2 | ( | std::ostream & | out | ) | const |
Prints a sparse matrix to stream out in CSR format.
Definition at line 3052 of file sparsemat.cpp.
void mfem::SparseMatrix::PrintInfo | ( | std::ostream & | out | ) | const |
Print various sparse matrix statistics.
Definition at line 3077 of file sparsemat.cpp.
void mfem::SparseMatrix::PrintMatlab | ( | std::ostream & | out = mfem::out | ) | const |
Prints matrix in matlab format.
Definition at line 2986 of file sparsemat.cpp.
void mfem::SparseMatrix::PrintMM | ( | std::ostream & | out = mfem::out | ) | const |
Prints matrix in Matrix Market sparse format.
Definition at line 3006 of file sparsemat.cpp.
|
inline |
Definition at line 222 of file sparsemat.hpp.
|
inline |
Definition at line 190 of file sparsemat.hpp.
|
inline |
Definition at line 206 of file sparsemat.hpp.
|
inline |
Definition at line 226 of file sparsemat.hpp.
|
inline |
Definition at line 194 of file sparsemat.hpp.
|
inline |
Definition at line 210 of file sparsemat.hpp.
void mfem::SparseMatrix::ResetTranspose | ( | ) | const |
Reset (destroy) the internal transpose matrix. See BuildTranspose() for more details.
Definition at line 781 of file sparsemat.cpp.
bool mfem::SparseMatrix::RowIsEmpty | ( | const int | row | ) | const |
Definition at line 2608 of file sparsemat.cpp.
int mfem::SparseMatrix::RowSize | ( | const int | i | ) | const |
Returns the number of elements in row i.
Definition at line 296 of file sparsemat.cpp.
void mfem::SparseMatrix::ScaleColumns | ( | const Vector & | sr | ) |
this = this * diag(sr);
Definition at line 2807 of file sparsemat.cpp.
void mfem::SparseMatrix::ScaleRow | ( | const int | row, |
const double | scale | ||
) |
Definition at line 2748 of file sparsemat.cpp.
void mfem::SparseMatrix::ScaleRows | ( | const Vector & | sl | ) |
this = diag(sl) * this;
Definition at line 2776 of file sparsemat.cpp.
|
inline |
Perform a fast search for an entry in the "current row". See SetColPtr().
If the matrix is not finalized and the entry is not found in the SparseMatrix, it will be added to the sparsity pattern initialized with zero. If the matrix is finalized and the entry is not found, an error will be generated.
Definition at line 765 of file sparsemat.hpp.
|
inline |
Definition at line 806 of file sparsemat.hpp.
void mfem::SparseMatrix::Set | ( | const int | i, |
const int | j, | ||
const double | a | ||
) |
Definition at line 2474 of file sparsemat.cpp.
|
inline |
Initialize the SparseMatrix for fast access to the entries of the given row which becomes the "current row".
Fast access to the entries of the "current row" can be performed using the methods: SearchRow(const int), Add(const int, const double), Set(const int, const double), and Get(const int).
Definition at line 711 of file sparsemat.hpp.
|
inline |
Set the data ownership flag (A array).
Definition at line 600 of file sparsemat.hpp.
void mfem::SparseMatrix::SetDiagIdentity | ( | ) |
If a row contains only one diag entry of zero, set it to 1.
Definition at line 2080 of file sparsemat.cpp.
|
protected |
Definition at line 269 of file sparsemat.cpp.
|
inline |
Set the graph ownership flag (I and J arrays).
Definition at line 596 of file sparsemat.hpp.
Definition at line 2669 of file sparsemat.cpp.
void mfem::SparseMatrix::SetSubMatrix | ( | const Array< int > & | rows, |
const Array< int > & | cols, | ||
const DenseMatrix & | subm, | ||
int | skip_zeros = 1 |
||
) |
Definition at line 2512 of file sparsemat.cpp.
void mfem::SparseMatrix::SetSubMatrixTranspose | ( | const Array< int > & | rows, |
const Array< int > & | cols, | ||
const DenseMatrix & | subm, | ||
int | skip_zeros = 1 |
||
) |
Definition at line 2545 of file sparsemat.cpp.
void mfem::SparseMatrix::SetWidth | ( | int | width_ = -1 | ) |
Change the width of a SparseMatrix.
If width_ = -1 (DEFAULT), this routine will set the new width to the actual Width of the matrix awidth = max(J) + 1. Values 0 <= width_ < awidth are not allowed (error check in Debug Mode only)
This method can be called for matrices finalized or not.
Definition at line 371 of file sparsemat.cpp.
|
inline |
For backward compatibility, define Size() to be synonym of Height().
Definition at line 164 of file sparsemat.hpp.
void mfem::SparseMatrix::SortColumnIndices | ( | ) |
Sort the column indices corresponding to each row.
Definition at line 409 of file sparsemat.cpp.
void mfem::SparseMatrix::Swap | ( | SparseMatrix & | other | ) |
Definition at line 3882 of file sparsemat.cpp.
void mfem::SparseMatrix::Symmetrize | ( | ) |
(*this) = 1/2 ((*this) + (*this)^t)
Definition at line 1340 of file sparsemat.cpp.
void mfem::SparseMatrix::Threshold | ( | double | tol, |
bool | fix_empty_rows = false |
||
) |
Remove entries smaller in absolute value than a given tolerance tol. If fix_empty_rows is true, a zero value is inserted in the diagonal entry (for square matrices only)
Definition at line 1067 of file sparsemat.cpp.
DenseMatrix * mfem::SparseMatrix::ToDenseMatrix | ( | ) | const |
Produces a DenseMatrix from a SparseMatrix.
Definition at line 564 of file sparsemat.cpp.
void mfem::SparseMatrix::ToDenseMatrix | ( | DenseMatrix & | B | ) | const |
Produces a DenseMatrix from a SparseMatrix.
Definition at line 577 of file sparsemat.cpp.
|
inline |
Definition at line 152 of file sparsemat.hpp.
|
inline |
Definition at line 224 of file sparsemat.hpp.
|
inline |
Definition at line 192 of file sparsemat.hpp.
|
inline |
Definition at line 208 of file sparsemat.hpp.
|
protected |
Array with size I[height], containing the actual entries of the sparse matrix, as indexed by the I array.
Definition at line 64 of file sparsemat.hpp.
|
mutableprotected |
Transpose of A. Owned. Used to perform MultTranspose() on devices.
Definition at line 76 of file sparsemat.hpp.
|
staticprotected |
Definition at line 98 of file sparsemat.hpp.
|
mutableprotected |
Definition at line 72 of file sparsemat.hpp.
|
mutableprotected |
Definition at line 73 of file sparsemat.hpp.
|
mutableprotected |
Definition at line 71 of file sparsemat.hpp.
|
staticprotected |
Definition at line 99 of file sparsemat.hpp.
|
protected |
Definition at line 97 of file sparsemat.hpp.
|
staticprotected |
Definition at line 96 of file sparsemat.hpp.
|
protected |
Array with size (height+1) containing the row offsets.
The data for row r, 0 <= r < height, is at offsets j, I[r] <= j < I[r+1]. The offsets, j, are indices in the J and A arrays. The first entry in this array is always zero, I[0] = 0, and the last entry, I[height], gives the total number of entries stored (at a minimum, all nonzeros must be represented) in the sparse matrix.
Definition at line 58 of file sparsemat.hpp.
|
mutableprotected |
Definition at line 100 of file sparsemat.hpp.
|
protected |
Are the columns sorted already.
Definition at line 84 of file sparsemat.hpp.
|
protected |
Array with size I[height], containing the column indices for all matrix entries, as indexed by the I array.
Definition at line 61 of file sparsemat.hpp.
|
mutableprotected |
Definition at line 103 of file sparsemat.hpp.
|
protected |
Definition at line 80 of file sparsemat.hpp.
|
protected |
Array of linked lists, one for every row. This array represents the linked list (LIL) storage format.
Definition at line 69 of file sparsemat.hpp.
|
staticprotected |
Definition at line 102 of file sparsemat.hpp.
|
protected |
Definition at line 95 of file sparsemat.hpp.
|
protected |
Definition at line 89 of file sparsemat.hpp.
|
mutableprotected |
Definition at line 104 of file sparsemat.hpp.
|
mutableprotected |
Definition at line 105 of file sparsemat.hpp.