19 #ifndef GEOSX_LINEARALGEBRA_INTERFACES_MATRIXBASE_HPP_ 20 #define GEOSX_LINEARALGEBRA_INTERFACES_MATRIXBASE_HPP_ 48 template<
typename MATRIX,
typename VECTOR >
146 virtual bool created()
const = 0;
166 MPI_Comm
const & comm )
184 MPI_Comm
const & comm )
201 MPI_Comm
const & comm ) = 0;
215 MPI_Comm
const & comm ) = 0;
226 MPI_Comm
const & comm )
228 localMatrix.
move( LvArray::MemorySpace::CPU,
false );
264 virtual void open() = 0;
272 virtual void close() = 0;
294 virtual void set(
real64 const value ) = 0;
299 virtual void zero() = 0;
552 gemv( -1.0, x, 1.0, r );
659 bool useTranspose =
false )
const = 0;
665 virtual void scale(
real64 const scalingFactor ) = 0;
686 Vector const & vecRight ) = 0;
708 bool const keepDiag =
false,
709 real64 const diagValue = 0.0 ) = 0;
722 bool const samePattern =
true ) = 0;
902 virtual MPI_Comm
getComm()
const = 0;
915 virtual void print( std::ostream & os = std::cout )
const = 0;
926 virtual void write(
string const & filename,
953 #endif //GEOSX_LINEARALGEBRA_INTERFACES_MATRIXBASE_HPP_ virtual void multiplyPtAP(Matrix const &P, Matrix &dst) const
Compute the triple product dst = P^T * this * P
Wrapper class for Epetra's CrsMatrix.
MatrixBase & operator=(MatrixBase const &)=default
Copy assignment.
virtual void createWithLocalSize(localIndex const localSize, localIndex const maxEntriesPerRow, MPI_Comm const &comm)
Create a square matrix from local number of rows.
bool assembled() const
Query matrix assembled status.
virtual real64 normInf() const =0
Returns the infinity norm of the matrix.
virtual void transpose(Matrix &dst) const =0
Matrix transposition.
friend std::ostream & operator<<(std::ostream &os, Matrix const &matrix)
Stream insertion operator for all matrix types.
INDEX_TYPE_NC numNonZeros() const
virtual void leftMultiplyTranspose(Matrix const &src, Matrix &dst) const =0
Matrix/Matrix transpose multiplication.
bool m_assembled
Flag indicating whether the matrix (sparsity pattern) has been assembled.
virtual globalIndex jupper() const =0
Returns index one past the last global col owned by that processor.
long long int globalIndex
Global index type (for indexing objects across MPI partitions).
virtual real64 getDiagValue(globalIndex globalRow) const =0
get diagonal element value on a given row
This class serves to provide a sliced multidimensional interface to the family of LvArray classes...
std::string format(int NDIM, INDEX_TYPE const *const dims)
This function returns a string that may be used as the "type" in a call to TV_ttf_add_row(). This will either be a single value or an array.
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.
void move(MemorySpace const space, bool const touch=true) const
Move this SparsityPattern to the given memory space and touch the values, sizes and offsets...
virtual localIndex globalRowLength(globalIndex const globalRowIndex) const =0
Get row length via global row index.
bool ready() const
Query matrix ready status.
virtual bool created() const =0
Query matrix creation status.
virtual void close()=0
Assemble and compress the matrix.
virtual void addDiagonal(Vector const &src)=0
Add entries of a vector to the diagonal of this matrix.
virtual void multiply(Matrix const &src, Matrix &dst) const =0
Matrix/Matrix multiplication.
virtual globalIndex numGlobalNonzeros() const =0
Returns the total number of nonzeros in the matrix.
virtual void leftMultiplyTranspose(EpetraMatrix const &src, EpetraMatrix &dst) const override
Matrix/Matrix transpose multiplication.
constexpr INDEX_TYPE_NC numRows() const
virtual localIndex localRowLength(localIndex localRowIndex) const =0
Get row length via local row index.
virtual void applyTranspose(Vector const &src, Vector &dst) const =0
Apply transpose of the matrix to a vector.
double real64
64-bit floating point type.
virtual globalIndex iupper() const =0
Returns index one past the last global row owned by that processor.
virtual void leftScale(Vector const &vec)=0
Pre-multiplies (left) with diagonal matrix consisting of the values in vec.
virtual void print(std::ostream &os=std::cout) const =0
Print the matrix in Trilinos format to a stream.
MatrixBase()
Constructs a matrix in default state.
constexpr ArraySlice< COL_TYPE const, 1, 0, INDEX_TYPE_NC > getColumns(INDEX_TYPE const row) const
virtual void add(globalIndex const rowIndex, globalIndex const colIndex, real64 const value)=0
Add to one element.
ArraySlice< T, 1, 0, INDEX_TYPE_NC > getEntries(INDEX_TYPE const row) const
virtual localIndex numLocalCols() const =0
Return the local number of columns on each processor.
virtual void open()=0
Open matrix for adding new entries.
virtual void apply(Vector const &src, Vector &dst) const override=0
Apply operator to a vector.
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 ...
virtual globalIndex numGlobalCols() const override=0
Returns the number of global columns.
virtual void insert(globalIndex const rowIndex, globalIndex const colIndex, real64 const value)=0
Insert one element.
virtual real64 norm1() const =0
Returns the one norm of the matrix.
virtual void create(CRSMatrixView< real64 const, globalIndex const > const &localMatrix, MPI_Comm const &comm)
Create parallel matrix from a local CRS matrix.
virtual real64 normFrobenius() const =0
Returns the Frobenius norm of the matrix.
virtual globalIndex ilower() const =0
Returns the index of the first global row owned by that processor.
virtual void extractDiagonal(Vector &dst) const =0
Extract diagonal values into a vector.
bool m_closed
Flag indicating whether the matrix is currently open for adding new entries.
virtual void multiply(EpetraMatrix const &src, EpetraMatrix &dst) const override
Matrix/Matrix multiplication.
virtual globalIndex numGlobalRows() const override
Returns the number of global rows.
virtual localIndex numLocalRows() const =0
Return the local number of columns on each processor.
virtual localIndex numLocalNonzeros() const =0
Returns the number of nonzeros in the local portion of the matrix.
virtual void createWithGlobalSize(globalIndex const globalSize, localIndex const maxEntriesPerRow, MPI_Comm const &comm)
Create a square matrix from global number of rows.
virtual void addEntries(Matrix const &src, real64 const scale=1.0, bool const samePattern=true)=0
Add entries of another matrix to this.
~MatrixBase()=default
Destructor.
#define GEOSX_LAI_ASSERT_EQ(lhs, rhs)
virtual void multiplyRAP(Matrix const &R, Matrix const &P, Matrix &dst) const
Compute the triple product dst = R * this * P
virtual globalIndex numGlobalCols() const override
Returns the number of global columns.
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.
bool closed() const
Query matrix closed status.
virtual void print(std::ostream &os=std::cout) const override
Print the matrix in Trilinos format to a stream.
virtual void scale(real64 const scalingFactor)=0
Multiply all elements by scalingFactor.
bool modifiable() const
Query matrix status.
bool insertable() const
Query matrix status.
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
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 residual(Vector const &x, Vector const &b, Vector &r) const override
Compute residual r = Ax - b.
virtual void zero()=0
Set all elements to zero.
#define GEOSX_LAI_ASSERT(expr)
virtual globalIndex jlower() const =0
Returns the index of the first global col owned by that processor.
virtual localIndex maxRowLength() const =0
Returns the number of nonzero entries in the longest row of the matrix.
virtual localIndex getLocalRowID(globalIndex const index) const =0
Map a global row index to local row index.
virtual void rightMultiplyTranspose(Matrix const &src, Matrix &dst) const =0
Matrix/Matrix transpose multiplication.
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 reset()
Reset the matrix to default state.
This class creates and provides basic support for the Epetra_FEVector vector object type used in Tril...
Abstract base class for linear operators.
constexpr std::enable_if_t< std::is_arithmetic< T >::value, T > max(T const a, T const b)
virtual void copy(EpetraVector const &x) override
Update vector y as y = x.
virtual globalIndex numGlobalRows() const override=0
Returns the number of global rows.
virtual MPI_Comm getComm() const =0
Get the MPI communicator the matrix was created with.
virtual void rightScale(Vector const &vec)=0
Post-multiplies (right) with diagonal matrix consisting of the values in vec.
Common base template for all matrix wrapper types.
This class provides a view into a compressed row storage matrix.
virtual globalIndex getGlobalRowID(localIndex const index) const =0
Map a local row index to global row index.