NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
ginkgo.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2024 NeoN authors
3
4#pragma once
5
6#if NF_WITH_GINKGO
7
8#include <ginkgo/ginkgo.hpp>
9#include <ginkgo/extensions/kokkos.hpp>
10
11#include "NeoN/fields/field.hpp"
16
17
18namespace NeoN::la::ginkgo
19{
20
21gko::config::pnode parse(const Dictionary& dict);
22
23class GinkgoSolver : public SolverFactory::template Register<GinkgoSolver>
24{
25
26 using Base = SolverFactory::template Register<GinkgoSolver>;
27
28public:
29
30 GinkgoSolver(Executor exec, const Dictionary& solverConfig)
31 : Base(exec), gkoExec_(getGkoExecutor(exec)), config_(parse(solverConfig)),
32 factory_(gko::config::parse(
33 config_, gko::config::registry(), gko::config::make_type_descriptor<scalar>()
34 )
35 .on(gkoExec_))
36 {}
37
38 static std::string name() { return "Ginkgo"; }
39
40 static std::string doc() { return "TBD"; }
41
42 static std::string schema() { return "none"; }
43
44 virtual void solve(const LinearSystem<scalar, localIdx>& sys, Vector<scalar>& x) const final
45 {
46 auto nrows = sys.rhs().size();
47
48 auto gkoMtx = detail::createGkoMtx(gkoExec_, sys);
49 auto solver = factory_->generate(gkoMtx);
50 // std::shared_ptr<const gko::log::Convergence<ValueType>> logger =
51 // gko::log::Convergence<ValueType>::create();
52 // solver->add_logger(logger);
53
54 auto rhs = detail::createGkoDense(gkoExec_, sys.rhs().data(), nrows);
55 auto gkoX = detail::createGkoDense(gkoExec_, x.data(), nrows);
56
57 solver->apply(rhs, gkoX);
58 // auto res_norm = gko::as<gko::matrix::Dense<ValueType>>(logger->get_residual_norm());
59 // auto res_norm_host = gko::matrix::Dense<ValueType>::create(
60 // res_norm->get_executor()->get_master(), gko::dim<2> {1}
61 // );
62 // res_norm_host->copy_from(res_norm);
63 }
64
65 virtual std::unique_ptr<SolverFactory> clone() const final
66 {
67 // FIXME
68 return {};
69 }
70
71private:
72
73 std::shared_ptr<const gko::Executor> gkoExec_;
74 gko::config::pnode config_;
75 std::shared_ptr<const gko::LinOpFactory> factory_;
76};
77
78
79}
80
81#endif
A template class for registering derived classes with a base class.
void solve(Expression< typename VectorType::ElementType > &exp, VectorType &solution, scalar t, scalar dt, const Dictionary &fvSchemes, const Dictionary &fvSolution)
Definition solver.hpp:38
float scalar
Definition scalar.hpp:14
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.