20template<
typename ValueType,
typename IndexType>
41template<
typename ValueType,
typename IndexType>
69 return LinearSystem(matrix_.copyToHost(), rhs_.copyToHost());
74 fill(matrix_.values(), zero<ValueType>());
75 fill(rhs_, zero<ValueType>());
101template<
typename ValueType,
typename IndexType>
105 auto [result, b, x] =
spans(resultVector, ls.
rhs(), xfield);
107 auto values = ls.
matrix().values().view();
108 auto colIdxs = ls.
matrix().colIdxs().view();
109 auto rowPtrs = ls.
matrix().rowPtrs().view();
113 {0, ls.matrix().nRows()},
114 KOKKOS_LAMBDA(
const localIdx rowi) {
115 IndexType rowStart = rowPtrs[rowi];
116 IndexType rowEnd = rowPtrs[rowi + 1];
118 for (IndexType coli = rowStart; coli < rowEnd; coli++)
120 sum += values[coli] * x[colIdxs[coli]];
122 result[rowi] = sum - b[rowi];
130template<
typename ValueTypeIn,
typename IndexTypeIn,
typename ValueTypeOut,
typename IndexTypeOut>
131LinearSystem<ValueTypeOut, IndexTypeOut>
134 auto exec = ls.
exec();
137 convert<ValueTypeIn, IndexTypeIn, ValueTypeOut, IndexTypeOut>(exec, ls.
view.matrix),
146template<
typename ValueType,
typename IndexType,
typename SparsityType>
149 const auto& exec = sparsity.mesh().
exec();
156 Vector<ValueType>(exec, nnzs, zero<ValueType>()), sparsity.colIdxs(), sparsity.rowPtrs()
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.
A class representing a linear system of equations.
const CSRMatrix< ValueType, IndexType > & matrix() const
LinearSystemView< ValueType, IndexType > view() const &&=delete
CSRMatrix< ValueType, IndexType > & matrix()
LinearSystem copyToHost() const
const Vector< ValueType > & rhs() const
LinearSystem(const LinearSystem &ls)
LinearSystem(const CSRMatrix< ValueType, IndexType > &matrix, const Vector< ValueType > &rhs)
LinearSystem(const Executor exec)
LinearSystemView< const ValueType, const IndexType > view() const &
const Executor & exec() const
Vector< ValueType > & rhs()
LinearSystemView< ValueType, IndexType > view() &&=delete
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
LinearSystem< ValueTypeOut, IndexTypeOut > convertLinearSystem(const LinearSystem< ValueTypeIn, IndexTypeIn > &ls)
LinearSystem< ValueType, IndexType > createEmptyLinearSystem(const SparsityType &sparsity)
Vector< ValueType > spmv(LinearSystem< ValueType, IndexType > &ls, Vector< ValueType > &xfield)
void parallelFor(const Executor &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name="parallelFor")
void fill(Vector< ValueType > &a, const std::type_identity_t< ValueType > value, std::pair< localIdx, localIdx > range={0, 0})
Fill the field with a scalar value using a specific executor.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
auto spans(Args &... fields)
A view struct to allow easy read/write on all executors.
A view linear into a linear system's data.
LinearSystemView()=default
LinearSystemView(CSRMatrixView< ValueType, IndexType > matrixView, View< ValueType > rhsView)
CSRMatrixView< ValueType, IndexType > matrix
~LinearSystemView()=default