31template<
typename VectorType,
typename IndexType>
44 optExp.read(fvSchemes);
45 optExp.assemble(t, dt, ls, ps);
50 auto expTmp = optExp.explicitOperation(solution.mesh().nCells());
51 auto [vol, expSource, rhs] =
views(solution.mesh().cellVolumes(), expTmp, ls.
rhs());
58 auto solver =
la::Solver(solution.exec(), fvSolution);
59 fence(solution.exec());
62 NF_ASSERT(ls.
exec() == solution.exec(),
"Executors are not the same");
63 return solver.solve(ls, solution.internalVector());
66template<
typename VectorType,
typename IndexType>
76 auto ls = exp.
assemble(solution.mesh(), t, dt, ps);
78 auto solver =
la::Solver(solution.exec(), fvSolution);
79 fence(solution.exec());
80 return solver.solve(ls, solution.internalVector());
94template<
typename VectorType,
typename IndexType>
95std::optional<la::SolverStats>
solve(
110 auto integrator = timeIntegration::TimeIntegration<VectorType>(
111 fvSchemes.
subDict(
"timeIntegration"), fvSolution
117 integrator.solve(exp, solution, t, dt);
133 return (s >= 0) ?
mag : -
mag;
155 return Vec3(Kokkos::abs(value[0]), Kokkos::abs(value[1]), Kokkos::abs(value[2]));
161 return Kokkos::max(lhs, rhs);
168 Kokkos::max(lhs[0], rhs[0]), Kokkos::max(lhs[1], rhs[1]), Kokkos::max(lhs[2], rhs[2])
206 typename MatrixValueType,
207 typename RHSValueType,
208 typename SystemMatrixType,
209 typename BoundaryMatrixType>
212 const VectorType& solution,
218 if (alpha <= 0.0 || alpha == 1.0)
223 const scalar invAlpha = 1.0 / alpha;
225 auto lsView = ls.
view();
226 auto& matrix = lsView.matrix;
227 auto& rhs = lsView.rhs;
229 const auto [rowOffs, colIdxs] =
views(ls.
matrix().rowOffs(), ls.
matrix().colIdxs());
230 const auto field = solution.internalVector().view();
232 const localIdx nCells = field.size();
252 auto sumOff = zero<MatrixValueType>();
253 for (
localIdx idx = rowOffs[celli]; idx < rowOffs[celli + 1]; ++idx)
255 if (colIdxs[idx] != celli)
260 const auto diagIdx = ma.diagIdx(celli);
261 const auto dAug = matrix.values[diagIdx];
263 const auto dRelaxed =
265 matrix.values[diagIdx] = dRelaxed;
266 rhs[celli] = rhs[celli] + (dRelaxed - dAug) * field[celli];
268 "applyMatrixRelaxation"
298template<
typename VectorType>
305 if (alpha <= 0.0 || alpha == 1.0)
310 NF_ASSERT(solution.size() == previous.
size(),
"applyFieldRelaxation: field/prev size mismatch");
312 auto [current, prev] =
views(solution.internalVector(), previous);
315 {0, solution.size()},
317 current[celli] = prev[celli] + alpha * (current[celli] - prev[celli]);
319 "applyFieldRelaxation"
331template<
typename VectorType>
A class representing a dictionary that stores key-value pairs.
Dictionary & subDict(const std::string &key)
Retrieves a sub-dictionary associated with the given key.
A class for the representation of a 3D Vec3.
A class to contain the data and executors for a field and define some basic operations.
localIdx size() const
Gets the size of the field.
la::LinearSystem< AssemblyType, ValueType > assemble(const UnstructuredMesh &mesh, scalar t, scalar dt, std::vector< const PostAssemblyBase< ValueType, IndexType > * > ps={}) const
construct a linear system and force assembly including explicit source terms
const std::vector< TemporalOperator< ValueType > > & temporalOperators() const
void read(const Dictionary &input)
const std::vector< SpatialOperator< ValueType > > & spatialOperators() const
A class representing a linear system of equations.
Vector< RHSValueType > & rhs()
std::shared_ptr< const FaceToMatrixAddress > faceToMatrixAddress() const
LinearSystemView< RHSValueType, MatrixView< MatrixValueType, SparsityView< typename SystemMatrixType::MatrixSparsityType::SparsityIndexType > > > view() &&=delete
const Executor & exec() const
SystemMatrixType & matrix()
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
la::SolverStats iterativeSolveImpl(Expression< typename VectorType::ElementType > &exp, la::LinearSystem< typename VectorType::ElementType > &ls, VectorType &solution, scalar t, scalar dt, const Dictionary &fvSchemes, const Dictionary &fvSolution, std::vector< const PostAssemblyBase< typename VectorType::ElementType, IndexType > * > ps={})
void applyFieldRelaxation(VectorType &solution, const Vector< typename VectorType::ElementType > &previous, scalar alpha)
KOKKOS_INLINE_FUNCTION scalar componentMag(const scalar value)
Componentwise magnitude (scalar overload).
KOKKOS_INLINE_FUNCTION scalar componentMax(const scalar lhs, const scalar rhs)
Componentwise max (scalar overload).
KOKKOS_INLINE_FUNCTION scalar copySign(const scalar mag, const scalar s)
Returns |mag| carrying the sign of s (scalar overload).
auto fieldRelaxationSnapshot(const VectorType &field)
void applyMatrixRelaxation(la::LinearSystem< MatrixValueType, RHSValueType, SystemMatrixType, BoundaryMatrixType > &ls, const VectorType &solution, scalar alpha)
ExpressionType optimize(const ExpressionType &in)
Apply the default optimizer pipeline to an expression.
std::optional< la::SolverStats > solve(Expression< typename VectorType::ElementType, IndexType > &exp, VectorType &solution, scalar t, scalar dt, const Dictionary &fvSchemes, const Dictionary &fvSolution, std::vector< const PostAssemblyBase< typename VectorType::ElementType, IndexType > * > p={})
KOKKOS_INLINE_FUNCTION scalar componentCopySign(const scalar mag, const scalar s)
Componentwise sign-copy (scalar overload).
void fence(const Executor &exec)
KOKKOS_INLINE_FUNCTION scalar mag(const scalar &s)
void parallelFor(const ExecutorType &, std::pair< localIdx, localIdx > range, const Kernel &kernel, std::string name)
auto views(Types &... args)
Unpacks all views of the passed classes.