8#include <ginkgo/ginkgo.hpp>
9#include <ginkgo/extensions/kokkos.hpp>
17namespace NeoFOAM::la::ginkgo
20template<
typename ValueType>
26 std::shared_ptr<const gko::Executor> gkoExec_;
27 Dictionary solverDict_;
29 virtual std::shared_ptr<gko::LinOp> solverGen(
30 std::shared_ptr<const gko::Executor> exec,
31 std::shared_ptr<const gko::LinOp> mtx,
38 GkoSolverBase(Executor exec, Dictionary solverDict)
44 virtual void solve(LinearSystem<ValueType, int>& sys, Field<ValueType>& x)
46 size_t nrows = sys.rhs().size();
48 auto solver = solverGen(
50 detail::createGkoMtx(gkoExec_, sys),
51 size_t(solverDict_.get<
int>(
"maxIters")),
52 float(solverDict_.get<
double>(
"relTol"))
55 auto rhs = detail::createGkoDense(gkoExec_, sys.rhs().data(), nrows);
56 auto gkoX = detail::createGkoDense(gkoExec_, x.data(), nrows);
57 solver->apply(rhs, gkoX);
62template<
typename ValueType>
63class CG :
public GkoSolverBase<ValueType>
66 virtual std::shared_ptr<gko::LinOp> solverGen(
67 std::shared_ptr<const gko::Executor> exec,
68 std::shared_ptr<const gko::LinOp> mtx,
74 gko::solver::Bicgstab<ValueType>::build()
76 gko::stop::Iteration::build().with_max_iters(maxIter),
77 gko::stop::ResidualNorm<ValueType>::build().with_reduction_factor(relTol)
80 return fact->generate(mtx);
85 CG(Executor exec, Dictionary solverDict) : GkoSolverBase<ValueType>(exec, solverDict) {}
88template<
typename ValueType>
89class BiCGStab :
public GkoSolverBase<ValueType>
91 virtual std::shared_ptr<gko::LinOp> solverGen(
92 std::shared_ptr<const gko::Executor> exec,
93 std::shared_ptr<const gko::LinOp> mtx,
99 gko::solver::Bicgstab<ValueType>::build()
101 gko::stop::Iteration::build().with_max_iters(maxIter),
102 gko::stop::ResidualNorm<ValueType>::build().with_reduction_factor(relTol)
105 return fact->generate(mtx);
110 BiCGStab(Executor exec, Dictionary solverDict) : GkoSolverBase<ValueType>(exec, solverDict) {}
void solve(Expression< typename FieldType::ElementType > &exp, FieldType &solution, scalar t, scalar dt, const Dictionary &fvSchemes, const Dictionary &fvSolution)
std::shared_ptr< gko::Executor > getGkoExecutor(Executor exec)