22template<
typename ValueType,
typename SparsityViewType>
45 KOKKOS_INLINE_FUNCTION
56 KOKKOS_INLINE_FUNCTION
69template<
typename ValueType,
typename SparsityType>
75 NF_ASSERT(values_.exec() == sparsityPattern_->exec(),
"Executors are not the same");
77 NF_ASSERT(values_.size() == sparsityPattern_->nnz(),
"Matrix values and columns mismatch");
91 : values_(
values), sparsityPattern_(sp)
128 std::shared_ptr<const SparsityType>
sparsity,
131 requires std::is_same_v<typename SparsityType::SparsityIndexType, localIdx>
160 void reset() { values_ = ValueType {}; }
175 return sparsityPattern_->colIdxs();
184 return sparsityPattern_->rowOffs();
204 [[nodiscard]] std::shared_ptr<const SparsityType>
sparsity()
const {
return sparsityPattern_; }
211 return faceToMatrixAddress_;
222 values_.view(), sparsityPattern_->view()
250 std::shared_ptr<const SparsityType> sparsityPattern_;
252 std::shared_ptr<const FaceToMatrixAddress> faceToMatrixAddress_;
256template<
typename ValueType,
typename IndexType>
259template<
typename ValueType,
typename IndexType>
265template<
typename ValueType,
typename IndexType>
308template<
unsigned int I>
MixinClass signaling copyTo is supported.
A class to contain the data and executors for a field and define some basic operations.
Sparse matrix class with compact storage by row (CSR) format.
std::shared_ptr< const FaceToMatrixAddress > faceToMatrixAddress() const
Get the FaceToMatrixAddress associated with this matrix (may be null).
const Vector< typename SparsityType::SparsityIndexType > & rowOffs() const
Get a reference to row offset vector.
const Vector< ValueType > & values() const
Get a const reference to values vector.
localIdx nRows() const
Get the number of rows in the matrix.
Matrix(const Vector< ValueType > &values, const Vector< typename SparsityType::SparsityIndexType > &colIdxs, const Vector< typename SparsityType::SparsityIndexType > &rowOffs, Dimensions dimensions)
Constructor for Matrix.
MatrixView< const ValueType, SparsityView< typename SparsityType::SparsityIndexType > > view() const
Get a const view representation of the matrix's data.
SparsityType MatrixSparsityType
const Executor & exec() const
Get the executor associated with this matrix.
Matrix(const Vector< ValueType > &values, std::shared_ptr< const SparsityType > sparsity, std::shared_ptr< const FaceToMatrixAddress > faceToMatrixAddress)
Constructor for Matrix with a FaceToMatrixAddress.
ValueType MatrixValueType
MatrixView< ValueType, SparsityView< typename SparsityType::SparsityIndexType > > view()
Get a view representation of the matrix's data.
Vector< ValueType > diag() const
extract the diagonal of the matrix
const Vector< typename SparsityType::SparsityIndexType > & colIdxs() const
Get a reference to column indices vector.
Vector< ValueType > & values()
Get a reference to values vector.
std::shared_ptr< const SparsityType > sparsity() const
Get a reference to column indices vector.
Matrix< ValueType, SparsityType > copyToExecutor(Executor dstExec) const override
Copy the matrix to another executor.
localIdx nNonZeros() const
Get the number of non-zero values in the matrix.
~Matrix()=default
Default destructor.
Matrix(const Vector< ValueType > &values, std::shared_ptr< const SparsityType > sp)
Constructor for Matrix.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
auto getComponent(const CSRMatrix< Vec3, localIdx > &in)
Vector< scalar > scaledInverseDiag(const CSRMatrix< Vec3, localIdx > &, const Vector< scalar > &)
computes the inverted diagonal of a matrix and scales it by a, ie. a*D^-1
void scaledInvDiagNegLUx(const CSRMatrix< Vec3, localIdx > &mtx, const Vector< Vec3 > &a, const Vector< Vec3 > &b, const Vector< scalar > &vol, Vector< scalar > &rAU, Vector< Vec3 > &out)
computes out = -(L+U) x
void negLUx(const CSRMatrix< Vec3, localIdx > &mtx, const Vector< Vec3 > &a, const Vector< Vec3 > &b, const Vector< scalar > &rAU, const Vector< scalar > &vol, Vector< Vec3 > &out)
computes out = -(L+U) x
Vector< ValueType > upper(const CSRMatrix< ValueType, IndexType > &)
extract the upper triangular of the matrix
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
hold the number of rows and columns of a matrix
A view struct to allow easy read/write on all executors.
View< ValueType > values
View to the values of the CSR matrix.
KOKKOS_INLINE_FUNCTION ValueType & entry(const localIdx i, const localIdx j) const
Retrieve a reference to the matrix element at position (i,j).
KOKKOS_INLINE_FUNCTION ValueType & entry(const localIdx offset) const
Direct access to a value given the offset.
MatrixView(const View< ValueType > valueView, SparsityViewType sparsityView)
Constructor for MatrixView.
~MatrixView()=default
Default destructor.
SparsityViewType sparsity
A view struct to allow easy read/write on all executors.