24#ifdef NF_WITH_MPI_SUPPORT
34template<
typename VectorType,
typename IndexType>
47 optExp.read(fvSchemes);
48 optExp.assemble(t, dt, ls, ps);
53 auto expTmp = optExp.explicitOperation(solution.mesh().nCells());
54 auto [vol, expSource, rhs] =
views(solution.mesh().cellVolumes(), expTmp, ls.
rhs());
61 auto solver =
la::Solver(solution.exec(), fvSolution);
62 fence(solution.exec());
65 NF_ASSERT(ls.
exec() == solution.exec(),
"Executors are not the same");
66 return solver.solve(ls, solution.internalVector());
69template<
typename VectorType,
typename IndexType>
79 auto ls =
exp.assemble(solution.mesh(), t, dt, ps);
81 auto solver =
la::Solver(solution.exec(), fvSolution);
82 fence(solution.exec());
83 return solver.solve(ls, solution.internalVector());
97template<
typename VectorType,
typename IndexType>
98std::optional<la::SolverStats>
solve(
100 VectorType& solution,
113 auto integrator = timeIntegration::TimeIntegration<VectorType>(
114 fvSchemes.
subDict(
"timeIntegration"), fvSolution
120 integrator.solve(exp, solution, t, dt);
136 return (s >= 0) ?
mag : -
mag;
158 return Vec3(Kokkos::abs(value[0]), Kokkos::abs(value[1]), Kokkos::abs(value[2]));
164 return Kokkos::max(lhs, rhs);
171 Kokkos::max(lhs[0], rhs[0]), Kokkos::max(lhs[1], rhs[1]), Kokkos::max(lhs[2], rhs[2])
210 typename MatrixValueType,
211 typename RHSValueType,
212 typename SystemMatrixType,
213 typename BoundaryMatrixType>
216 const VectorType& solution,
222 if (alpha <= 0.0 || alpha == 1.0)
227 const scalar invAlpha = 1.0 / alpha;
229 auto lsView = ls.
view();
230 auto& matrix = lsView.matrix;
231 auto& rhs = lsView.rhs;
233 const auto [rowOffs, colIdxs] =
views(ls.
matrix().rowOffs(), ls.
matrix().colIdxs());
234 const auto field = solution.internalVector().view();
236 const localIdx nCells = field.size();
246 auto globalSum = [&](
scalar& sum)
248#ifdef NF_WITH_MPI_SUPPORT
249 if (solution.mesh().boundaryMesh().isDistributed())
251 mpi::allReduce(sum, mpi::ReduceOp::Sum, ls.commPattern().env.comm());
258 if constexpr (std::is_same_v<MatrixValueType, scalar>)
265 sum += matrix.values[ma.diagIdx(celli)];
274 for (
int cmpt = 0; cmpt < 3; ++cmpt)
281 sum += matrix.values[ma.diagIdx(celli)][cmpt];
286 convention[cmpt] = sumDiag >= 0 ?
scalar(1) :
scalar(-1);
310 for (
localIdx idx = rowOffs[celli]; idx < rowOffs[celli + 1]; ++idx)
312 if (colIdxs[idx] != celli)
317 const auto diagIdx = ma.diagIdx(celli);
318 const auto dAug = matrix.values[diagIdx];
322 matrix.values[diagIdx] = dRelaxed;
323 rhs[celli] = rhs[celli] + (dRelaxed - dAug) * field[celli];
325 "applyMatrixRelaxation"
355template<
typename VectorType>
362 if (alpha <= 0.0 || alpha == 1.0)
367 NF_ASSERT(solution.size() == previous.
size(),
"applyFieldRelaxation: field/prev size mismatch");
369 auto [current, prev] =
views(solution.internalVector(), previous);
372 {0, solution.size()},
374 current[celli] = prev[celli] + alpha * (current[celli] - prev[celli]);
376 "applyFieldRelaxation"
388template<
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.
An executor-aware contiguous container for numerical data with vector-style arithmetic semantics.
sizeType size() const
Returns the number of elements in the Vector.
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 T zero()
KOKKOS_INLINE_FUNCTION scalar mag(const scalar &s)
KOKKOS_INLINE_FUNCTION T one()
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.
void parallelReduce(const Executor &exec, std::pair< localIdx, localIdx > range, const Kernel &kernel, T &value)