20 #ifndef GEOS_LINEARALGEBRA_INTERFACES_MATRIXBASE_HPP_
21 #define GEOS_LINEARALGEBRA_INTERFACES_MATRIXBASE_HPP_
25 #include "LvArray/src/output.hpp"
74 template<
typename MATRIX,
typename VECTOR >
188 MPI_Comm
const &
comm )
206 MPI_Comm
const &
comm )
223 MPI_Comm
const &
comm ) = 0;
237 MPI_Comm
const &
comm ) = 0;
250 MPI_Comm
const &
comm )
252 localMatrix.move( hostMemorySpace,
false );
255 for(
localIndex i = 0; i < localMatrix.numRows(); ++i )
257 maxEntriesPerRow = std::max( maxEntriesPerRow, localMatrix.numNonZeros( i ) );
268 for(
localIndex localRow = 0; localRow < localMatrix.numRows(); ++localRow )
270 insert( localRow + rankOffset, localMatrix.getColumns( localRow ), localMatrix.getEntries( localRow ) );
557 gemv( -1.0, x, 1.0, r );
617 R.multiply( AP, dst );
635 P.leftMultiplyTranspose( AP, dst );
668 bool useTranspose =
false )
const = 0;
676 integer const dofPerPoint )
const = 0;
705 Vector const & vecRight ) = 0;
735 bool const keepDiag =
false,
736 real64 const diagValue = 0.0 ) = 0;
772 bool const excludeDiag ) = 0;
928 virtual void print( std::ostream & os = std::cout )
const = 0;
939 virtual void write(
string const & filename,
940 LAIOutputFormat const format = LAIOutputFormat::MATRIX_MARKET )
const = 0;
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
Abstract base class for linear operators.
virtual globalIndex numGlobalCols() const =0
Get the number of global columns.
VECTOR Vector
Alias for template parameter.
virtual globalIndex numGlobalRows() const =0
Get the number of global rows.
virtual localIndex numLocalRows() const =0
Get the number of local rows.
virtual localIndex numLocalCols() const =0
Get the number of local columns.
virtual MPI_Comm comm() const =0
Get the MPI communicator the matrix was created with.
Common base template for all matrix wrapper types.
virtual void multiply(Matrix const &src, Matrix &dst) const =0
Matrix/Matrix multiplication.
virtual void rightMultiplyTranspose(Matrix const &src, Matrix &dst) const =0
Matrix/Matrix transpose multiplication.
virtual real64 norm1() const =0
Returns the one norm of the matrix.
virtual bool created() const =0
Query matrix creation status.
virtual void multiplyPtAP(Matrix const &P, Matrix &dst) const
Compute the triple product dst = P^T * this * P
virtual globalIndex ilower() const =0
Returns the index of the first global row owned by that processor.
virtual void add(globalIndex const *rowIndices, globalIndex const *colIndices, real64 const *values, localIndex const numRows, localIndex const numCols)=0
Add a dense block of values.
virtual real64 normMax(arrayView1d< globalIndex const > const &rowIndices) const =0
Returns the max norm of the matrix on a subset of rows.
virtual void insert(arraySlice1d< globalIndex const > const &rowIndices, arraySlice1d< globalIndex const > const &colIndices, arraySlice2d< real64 const > const &values)=0
Insert a dense block of values.
virtual void residual(Vector const &x, Vector const &b, Vector &r) const override
Compute residual r = b - A * x.
virtual void createWithGlobalSize(globalIndex const globalRows, globalIndex const globalCols, localIndex const maxEntriesPerRow, MPI_Comm const &comm)=0
Create a rectangular matrix from number of rows/columns.
virtual void multiplyRAP(Matrix const &R, Matrix const &P, Matrix &dst) const
Compute the triple product dst = R * this * P
virtual void set(globalIndex const rowIndex, globalIndex const *colIndices, real64 const *values, localIndex const size)=0
Set elements to one row using c-style arrays.
friend std::ostream & operator<<(std::ostream &os, Matrix const &matrix)
Stream insertion operator for all matrix types.
void setDofManager(DofManager const *const dofManager)
Associate a DofManager with this matrix.
MATRIX Matrix
Type alias for actual derived matrix class.
bool assembled() const
Query matrix assembled status.
virtual void write(string const &filename, LAIOutputFormat const format=LAIOutputFormat::MATRIX_MARKET) const =0
Write the matrix to filename in a matlab-compatible format.
virtual void getRowCopy(globalIndex const globalRow, arraySlice1d< globalIndex > const &colIndices, arraySlice1d< real64 > const &values) const =0
Returns a copy of the data in row globalRow.
virtual void transpose(Matrix &dst) const =0
Matrix transposition.
virtual void set(real64 const value)=0
Set all non-zero elements to a value.
virtual void leftMultiplyTranspose(Matrix const &src, Matrix &dst) const =0
Matrix/Matrix transpose multiplication.
virtual localIndex maxRowLength() const =0
Returns the number of nonzero entries in the longest row of the matrix.
virtual void add(globalIndex const rowIndex, globalIndex const colIndex, real64 const value)=0
Add to one element.
virtual localIndex numLocalNonzeros() const =0
Returns the number of nonzeros in the local portion of the matrix.
virtual void leftScale(Vector const &vec)=0
Pre-multiplies (left) with diagonal matrix consisting of the values in vec.
bool closed() const
Query matrix closed status.
virtual void createWithGlobalSize(globalIndex const globalSize, localIndex const maxEntriesPerRow, MPI_Comm const &comm)
Create a square matrix from global number of rows.
virtual globalIndex jlower() const =0
Returns the index of the first global col owned by that processor.
virtual void apply(Vector const &src, Vector &dst) const override=0
Apply operator to a vector, dst = this(src).
virtual void clampEntries(real64 const lo, real64 const hi, bool const excludeDiag)=0
Clamp each matrix value between values of lo and hi.
bool m_closed
Flag indicating whether the matrix is currently open for adding new entries.
virtual void rescaleRows(arrayView1d< globalIndex const > const &rowIndices, RowSumType const rowSumType)=0
Rescales selected rows of matrix using row sum reciprocal as a factor.
virtual void separateComponentFilter(Matrix &dst, integer const dofPerPoint) const =0
Apply a separate component approximation (filter) to this matrix.
virtual void leftRightScale(Vector const &vecLeft, Vector const &vecRight)=0
Post-multiplies (right) with diagonal matrix consisting of the values in vecRight and pre-multiplies ...
bool insertable() const
Query matrix status.
bool m_assembled
Flag indicating whether the matrix (sparsity pattern) has been assembled.
virtual real64 normFrobenius() const =0
Returns the Frobenius norm of the matrix.
virtual void applyTranspose(Vector const &src, Vector &dst) const =0
Apply transpose of the matrix to a vector.
virtual void scale(real64 const scalingFactor)=0
Multiply all elements by scalingFactor.
virtual void getRowSums(Vector &dst, RowSumType const rowSumType) const =0
Populate a vector with row sums of this.
virtual globalIndex getGlobalRowID(localIndex const index) const =0
Map a local row index to global row index.
virtual void createWithLocalSize(localIndex const localSize, localIndex const maxEntriesPerRow, MPI_Comm const &comm)
Create a square matrix from local number of rows.
virtual globalIndex numGlobalRows() const=0
Get the number of global rows.
virtual real64 normInf() const =0
Returns the infinity norm of the matrix.
virtual void insert(globalIndex const rowIndex, globalIndex const colIndex, real64 const value)=0
Insert one element.
virtual void zero()=0
Set all elements to zero.
virtual void open()=0
Open matrix for adding new entries.
virtual void addDiagonal(Vector const &src, real64 const scale)=0
Add (scaled) entries of a vector to the diagonal of this matrix.
virtual real64 normMax() const =0
Returns the max norm of the matrix (the largest absolute element value).
virtual void insert(globalIndex const rowIndex, arraySlice1d< globalIndex const > const &colIndices, arraySlice1d< real64 const > const &values)=0
Insert elements of one row using array1d.
virtual void add(globalIndex const rowIndex, globalIndex const *colIndices, real64 const *values, localIndex const size)=0
Add elements to one row using c-style arrays.
virtual void insert(globalIndex const *rowIndices, globalIndex const *colIndices, real64 const *values, localIndex const numRows, localIndex const numCols)=0
Insert dense matrix.
virtual void extractDiagonal(Vector &dst) const =0
Extract diagonal values into a vector.
virtual void insert(globalIndex const rowIndex, globalIndex const *colIndices, real64 const *values, localIndex const size)=0
Insert elements to one row using c-style arrays.
virtual void add(globalIndex const rowIndex, arraySlice1d< globalIndex const > const &colIndices, arraySlice1d< real64 const > const &values)=0
Add elements to one row using array1d.
DofManager const * m_dofManager
(optional) DofManager associated with this matrix
virtual void set(globalIndex const *rowIndices, globalIndex const *colIndices, real64 const *values, localIndex const numRows, localIndex const numCols)=0
Set a dense block of values.
virtual globalIndex numGlobalNonzeros() const =0
Returns the total number of nonzeros in the matrix.
virtual void set(arraySlice1d< globalIndex const > const &rowIndices, arraySlice1d< globalIndex const > const &colIndices, arraySlice2d< real64 const > const &values)=0
Set a dense block of values.
virtual void print(std::ostream &os=std::cout) const =0
Print the matrix in Trilinos format to a stream.
virtual void multiplyRARt(Matrix const &R, Matrix &dst) const
Compute the triple product dst = R * this * R^T
virtual void getRowLengths(arrayView1d< localIndex > const &lengths) const =0
Get the row lengths of every local row.
virtual void add(arraySlice1d< globalIndex const > const &rowIndices, arraySlice1d< globalIndex const > const &colIndices, arraySlice2d< real64 const > const &values)=0
Add a dense block of values.
virtual globalIndex iupper() const =0
Returns index one past the last global row owned by that processor.
DofManager const * dofManager() const
virtual void rightScale(Vector const &vec)=0
Post-multiplies (right) with diagonal matrix consisting of the values in vec.
virtual globalIndex numGlobalCols() const=0
Get the number of global columns.
bool ready() const
Query matrix ready status.
virtual void set(globalIndex const rowIndex, arraySlice1d< globalIndex const > const &colIndices, arraySlice1d< real64 const > const &values)=0
Set elements of one row using array1d.
virtual real64 clearRow(globalIndex const row, bool const keepDiag=false, real64 const diagValue=0.0)=0
Clear a row, and optionally set diagonal element to diagValue.
bool modifiable() const
Query matrix status.
virtual localIndex getLocalRowID(globalIndex const index) const =0
Map a global row index to local row index.
virtual void reset()
Reset the matrix to default state.
virtual void gemv(real64 const alpha, Vector const &x, real64 const beta, Vector &y, bool useTranspose=false) const =0
Compute gemv y = alpha*A*x + beta*y.
virtual localIndex rowLength(globalIndex const globalRowIndex) const =0
Get row length via global row index.
virtual void close()=0
Assemble and compress the matrix.
virtual void createWithLocalSize(localIndex const localRows, localIndex const localCols, localIndex const maxEntriesPerRow, MPI_Comm const &comm)=0
Create a rectangular matrix from number of rows/columns.
virtual void addEntries(Matrix const &src, MatrixPatternOp const op, real64 const scale)=0
Add entries of another matrix to this.
virtual globalIndex jupper() const =0
Returns index one past the last global col owned by that processor.
virtual void create(CRSMatrixView< real64 const, globalIndex const > const &localMatrix, localIndex const numLocalColumns, MPI_Comm const &comm)
Create parallel matrix from a local CRS matrix.
virtual void set(globalIndex const rowIndex, globalIndex const colIndex, real64 const value)=0
Set one element.
virtual void insert(arrayView1d< globalIndex const > const &rowIndices, arrayView1d< globalIndex const > const &colIndices, arrayView1d< real64 const > const &values)=0
Insert values stored in 3 linear vectors.
#define GEOS_LAI_ASSERT_EQ(lhs, rhs)
#define GEOS_LAI_ASSERT(expr)
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
RowSumType
Type of row sum to compute.
LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
ArraySlice< T, 2, USD > arraySlice2d
Alias for 2D array slice.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
ArraySlice< T, 1, USD > arraySlice1d
Alias for 1D array slice.
std::int32_t integer
Signed integer type.
MatrixPatternOp
Describes relationship between and treatment of nonzero patterns of arguments in matrix functions lik...