20 #ifndef GEOS_LINEARALGEBRA_INTERFACES_PETSCSPARSEMATRIX_HPP_
21 #define GEOS_LINEARALGEBRA_INTERFACES_PETSCSPARSEMATRIX_HPP_
38 extern "C" struct _p_Mat;
61 using Mat =
struct _p_Mat *;
126 MPI_Comm
const &
comm )
override;
131 MPI_Comm
const &
comm )
override;
150 real64 const value )
override;
154 real64 const value )
override;
158 real64 const value )
override;
228 Vector & dst )
const override;
247 bool useTranspose =
false )
const override;
264 integer const dofsPerNode )
const override;
267 bool const keepDiag =
false,
268 real64 const diagValue = 0.0 )
override;
279 bool const excludeDiag )
override;
378 virtual MPI_Comm
comm()
const override;
380 virtual void print( std::ostream & os = std::cout )
const override;
382 virtual void write(
string const & filename,
383 LAIOutputFormat const format = LAIOutputFormat::MATRIX_MARKET )
const override;
Abstract base class for linear operators.
Common base template for all matrix wrapper types.
virtual void residual(Vector const &x, Vector const &b, Vector &r) const override
Compute residual r = b - A * x.
void setDofManager(DofManager const *const dofManager)
Associate a DofManager with this matrix.
bool assembled() const
Query matrix assembled status.
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.
bool insertable() const
Query matrix status.
virtual void createWithLocalSize(localIndex const localSize, localIndex const maxEntriesPerRow, MPI_Comm const &comm)
Create a square matrix from local number of rows.
DofManager const * dofManager() const
bool ready() const
Query matrix ready status.
bool modifiable() const
Query matrix status.
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.
Facilitates exporting Petsc matrix and associated vector objects (either in parallel or serial).
This class creates and provides basic support for the Mat matrix object type used in PETSc.
virtual localIndex numLocalCols() const override
Get the number of local columns.
virtual void set(globalIndex const *rowIndices, globalIndex const *colIndices, real64 const *values, localIndex const numRows, localIndex const numCols) override
Set a dense block of values.
virtual globalIndex numGlobalNonzeros() const override
Returns the total number of nonzeros in the matrix.
virtual localIndex numLocalRows() const override
Get the number of local rows.
PetscMatrix & operator=(PetscMatrix const &src)
Copy assignment.
virtual globalIndex numGlobalRows() const override
Get the number of global rows.
struct _p_Mat * Mat
Alias for PETSc matrix struct pointer.
virtual void clampEntries(real64 const lo, real64 const hi, bool const excludeDiag) override
Clamp each matrix value between values of lo and hi.
PetscMatrix(PetscMatrix const &src)
Copy constructor.
virtual real64 normMax(arrayView1d< globalIndex const > const &m) const override
Returns the max norm of the matrix on a subset of rows.
virtual void transpose(PetscMatrix &dst) const override
Matrix transposition.
virtual void set(globalIndex const rowIndex, globalIndex const *colIndices, real64 const *values, localIndex const size) override
Set elements to one row using c-style arrays.
virtual void insert(globalIndex const rowIndex, arraySlice1d< globalIndex const > const &colIndices, arraySlice1d< real64 const > const &values) override
Insert elements of one row using array1d.
virtual void zero() override
Set all elements to zero.
virtual globalIndex numGlobalCols() const override
Get the number of global columns.
Mat & unwrapped()
Returns a non-const pointer to the underlying matrix.
virtual void scale(real64 const scalingFactor) override
Multiply all elements by scalingFactor.
virtual void close() override
Assemble and compress the matrix.
PetscMatrix()
Empty matrix constructor.
virtual void leftMultiplyTranspose(PetscMatrix const &src, PetscMatrix &dst) const override
Matrix/Matrix transpose multiplication.
virtual globalIndex jupper() const override
Returns index one past the last global col owned by that processor.
virtual void insert(globalIndex const rowIndex, globalIndex const *colIndices, real64 const *values, localIndex const size) override
Insert elements to one row using c-style arrays.
virtual void getRowSums(PetscVector &dst, RowSumType const rowSumType) const override
Populate a vector with row sums of this.
virtual void rescaleRows(arrayView1d< globalIndex const > const &rowIndices, RowSumType const rowSumType) override
Rescales selected rows of matrix using row sum reciprocal as a factor.
virtual void add(globalIndex const *rowIndices, globalIndex const *colIndices, real64 const *values, localIndex const numRows, localIndex const numCols) override
Add a dense block of values.
virtual void apply(PetscVector const &src, PetscVector &dst) const override
Apply operator to a vector, dst = this(src).
virtual void add(globalIndex const rowIndex, arraySlice1d< globalIndex const > const &colIndices, arraySlice1d< real64 const > const &values) override
Add elements to one row using array1d.
virtual localIndex maxRowLength() const override
Returns the number of nonzero entries in the longest row of the matrix.
virtual void set(globalIndex const rowIndex, arraySlice1d< globalIndex const > const &colIndices, arraySlice1d< real64 const > const &values) override
Set elements of one row using array1d.
virtual void open() override
Open matrix for adding new entries.
virtual void getRowLengths(arrayView1d< localIndex > const &lengths) const override
Get the row lengths of every local row.
virtual void set(arraySlice1d< globalIndex const > const &rowIndices, arraySlice1d< globalIndex const > const &colIndices, arraySlice2d< real64 const > const &values) override
Set a dense block of values.
virtual void leftScale(PetscVector const &vec) override
Pre-multiplies (left) with diagonal matrix consisting of the values in vec.
PetscMatrix(PetscMatrix &&src) noexcept
Move constructor.
virtual void createWithLocalSize(localIndex const localRows, localIndex const localCols, localIndex const maxEntriesPerRow, MPI_Comm const &comm) override
Create a rectangular matrix from number of rows/columns.
virtual void print(std::ostream &os=std::cout) const override
Print the matrix in Trilinos format to a stream.
virtual void separateComponentFilter(PetscMatrix &dst, integer const dofsPerNode) const override
Apply a separate component approximation (filter) to this matrix.
virtual void rightScale(PetscVector const &vec) override
Post-multiplies (right) with diagonal matrix consisting of the values in vec.
virtual MPI_Comm comm() const override
Get the MPI communicator the matrix was created with.
virtual real64 clearRow(globalIndex const row, bool const keepDiag=false, real64 const diagValue=0.0) override
Clear a row, and optionally set diagonal element to diagValue.
virtual void multiplyPtAP(PetscMatrix const &P, PetscMatrix &dst) const override
Compute the triple product dst = P^T * this * P
virtual real64 normFrobenius() const override
Returns the Frobenius norm of the matrix.
virtual void leftRightScale(PetscVector const &vecLeft, PetscVector const &vecRight) override
Post-multiplies (right) with diagonal matrix consisting of the values in vecRight and pre-multiplies ...
virtual void insert(globalIndex const *rowIndices, globalIndex const *colIndices, real64 const *values, localIndex const numRows, localIndex const numCols) override
Insert dense matrix.
virtual void insert(arrayView1d< globalIndex const > const &rowIndices, arrayView1d< globalIndex const > const &colIndices, arrayView1d< real64 const > const &values) override
Insert values stored in 3 linear vectors.
virtual localIndex rowLength(globalIndex const globalRowIndex) const override
Get row length via global row index.
virtual void multiplyRAP(PetscMatrix const &R, PetscMatrix const &P, PetscMatrix &dst) const override
Compute the triple product dst = R * this * P
~PetscMatrix() override
Destructor.
virtual void add(globalIndex const rowIndex, globalIndex const colIndex, real64 const value) override
Add to one element.
virtual globalIndex ilower() const override
Returns the index of the first global row owned by that processor.
virtual real64 normMax() const override
Returns the max norm of the matrix (the largest absolute element value).
virtual void getRowCopy(globalIndex globalRow, arraySlice1d< globalIndex > const &colIndices, arraySlice1d< real64 > const &values) const override
Returns a copy of the data in row globalRow.
virtual globalIndex jlower() const override
Returns the index of the first global col owned by that processor.
const Mat & unwrapped() const
Returns a const pointer to the underlying matrix.
virtual void applyTranspose(Vector const &src, Vector &dst) const override
Apply transpose of the matrix to a vector.
virtual void insert(globalIndex const rowIndex, globalIndex const colIndex, real64 const value) override
Insert one element.
virtual void add(arraySlice1d< globalIndex const > const &rowIndices, arraySlice1d< globalIndex const > const &colIndices, arraySlice2d< real64 const > const &values) override
Add a dense block of values.
virtual real64 normInf() const override
Returns the infinity norm of the matrix.
virtual void createWithGlobalSize(globalIndex const globalRows, globalIndex const globalCols, localIndex const maxEntriesPerRow, MPI_Comm const &comm) override
Create a rectangular matrix from number of rows/columns.
virtual globalIndex iupper() const override
Returns index one past the last global row owned by that processor.
virtual bool created() const override
Get the number of global rows.
virtual void insert(arraySlice1d< globalIndex const > const &rowIndices, arraySlice1d< globalIndex const > const &colIndices, arraySlice2d< real64 const > const &values) override
Insert a dense block of values.
virtual real64 norm1() const override
Returns the one norm of the matrix.
virtual void gemv(real64 const alpha, PetscVector const &x, real64 const beta, PetscVector &y, bool useTranspose=false) const override
Compute gemv y = alpha*A*x + beta*y.
virtual void rightMultiplyTranspose(PetscMatrix const &src, PetscMatrix &dst) const override
Matrix/Matrix transpose multiplication.
virtual localIndex getLocalRowID(globalIndex const index) const override
Map a global row index to local row index.
virtual void addEntries(PetscMatrix const &src, MatrixPatternOp const op, real64 const scale=1.0) override
Add entries of another matrix to this.
virtual localIndex numLocalNonzeros() const override
Returns the number of nonzeros in the local portion of the matrix.
virtual void set(globalIndex const rowIndex, globalIndex const colIndex, real64 const value) override
Set one element.
virtual void add(globalIndex const rowIndex, globalIndex const *colIndices, real64 const *values, localIndex const size) override
Add elements to one row using c-style arrays.
virtual globalIndex getGlobalRowID(localIndex const index) const override
Map a local row index to global row index.
virtual void write(string const &filename, LAIOutputFormat const format=LAIOutputFormat::MATRIX_MARKET) const override
Write the matrix to filename in a matlab-compatible format.
PetscMatrix & operator=(PetscMatrix &&src) noexcept
Move assignment.
virtual void multiply(PetscMatrix const &src, PetscMatrix &dst) const override
Matrix/Matrix multiplication.
virtual void addDiagonal(PetscVector const &src, real64 const scale) override
Add (scaled) entries of a vector to the diagonal of this matrix.
virtual void reset() override
Reset the matrix to default state.
virtual void set(real64 const value) override
Set all non-zero elements to a value.
virtual void extractDiagonal(PetscVector &dst) const override
Extract diagonal values into a vector.
This class creates and provides basic support for Vec vector object type used in PETSc.
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).
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.
Array< T, 1 > array1d
Alias for 1D array.
MatrixPatternOp
Describes relationship between and treatment of nonzero patterns of arguments in matrix functions lik...