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 >
190 MPI_Comm
const &
comm )
208 MPI_Comm
const &
comm )
225 MPI_Comm
const &
comm ) = 0;
239 MPI_Comm
const &
comm ) = 0;
252 MPI_Comm
const &
comm )
254 localMatrix.move( hostMemorySpace,
false );
257 for(
localIndex i = 0; i < localMatrix.numRows(); ++i )
259 maxEntriesPerRow = std::max( maxEntriesPerRow, localMatrix.numNonZeros( i ) );
270 for(
localIndex localRow = 0; localRow < localMatrix.numRows(); ++localRow )
272 insert( localRow + rankOffset, localMatrix.getColumns( localRow ), localMatrix.getEntries( localRow ) );
559 gemv( -1.0, x, 1.0, r );
619 R.multiply( AP, dst );
640 P1.leftMultiplyTranspose( AP2, dst );
684 bool useTranspose =
false )
const = 0;
692 integer const dofPerPoint )
const = 0;
721 Vector const & vecRight ) = 0;
757 bool const keepDiag =
false,
758 real64 const diagValue = 0.0 ) = 0;
794 bool const excludeDiag ) = 0;
879 rowLengths.move( LvArray::MemorySpace::host );
1005 virtual void print( std::ostream & os = std::cout )
const = 0;
1016 virtual void write(
string const & filename,
1017 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
VECTOR Vector
Alias for template parameter.
virtual globalIndex numGlobalRows() const =0
virtual localIndex numLocalNonzeros() const
virtual globalIndex numGlobalNonzeros() const
virtual localIndex numLocalRows() const =0
virtual localIndex numLocalCols() const =0
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 localIndex numLocalCols() const=0
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.
virtual localIndex numLocalRows() const=0
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 void add(globalIndex const rowIndex, globalIndex const colIndex, real64 const value)=0
Add to one element.
virtual void leftScale(Vector const &vec)=0
Pre-multiplies (left) with diagonal matrix consisting of the values in vec.
virtual void getRowLocalLengths(arrayView1d< localIndex > const &lengths) const =0
Get the local row lengths of every local row (number of nonzeros in local columns)
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
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 computeScalingVector(Vector &scaling) const =0
Compute left and right scaling vectors for diagonal scaling.
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 localIndex maxRowLength() const
Returns the number of nonzero entries in the longest row of the matrix.
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
CRSMatrix< real64, globalIndex > extract() const
Extract local part of the 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 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 localIndex maxRowLengthLocal() const =0
Returns the number of nonzero entries in the longest local row of the matrix.
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 void extractLocal(CRSMatrixView< real64, localIndex > const &localMat) const =0
Extract block of the matrix corresponding to locally owned columns using previously allocated storage...
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
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.
virtual void extract(CRSMatrixView< real64, globalIndex const > const &localMat) const =0
Extract local part of the matrix using previously allocated storage and structure.
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 multiplyP1tAP2(Matrix const &P1, Matrix const &P2, Matrix &dst) const
Compute the triple product dst = P1^T * this * P2
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 extract(CRSMatrixView< real64, globalIndex > const &localMat) const =0
Extract local part of the matrix using previously allocated storage.
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.
CRSMatrix< real64, localIndex > extractLocal() const
Extract block of the matrix corresponding to locally owned columns.
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.
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
LvArray::CRSMatrix< T, COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > CRSMatrix
Alias for CRS Matrix class.
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.
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
int integer
Signed integer type.
Array< T, 1 > array1d
Alias for 1D array.
MatrixPatternOp
Describes relationship between and treatment of nonzero patterns of arguments in matrix functions lik...
static T max(T const &value, MPI_Comm comm=MPI_COMM_GEOS)
Convenience function for a MPI_Allreduce using a MPI_MAX operation.