NeoN
A framework for CFD software
Loading...
Searching...
No Matches
ginkgo.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#if NF_WITH_GINKGO
8
9#include <chrono>
10
11#include <ginkgo/ginkgo.hpp>
12#include <ginkgo/extensions/kokkos.hpp>
13#include <ginkgo/extensions/config/json_config.hpp>
14
15#include "NeoN/fields/field.hpp"
21
22
23namespace NeoN::la::ginkgo
24{
25
26std::shared_ptr<gko::Executor> getGkoExecutor(Executor exec);
27
28gko::config::pnode parse(const Dictionary& dict);
29
30class GinkgoSolver : public SolverFactory::template Register<GinkgoSolver>
31{
32
33 using Base = SolverFactory::template Register<GinkgoSolver>;
34
35public:
36
37 GinkgoSolver(Executor exec, const Dictionary& solverConfig)
38 : Base(exec), gkoExec_(getGkoExecutor(exec)), config_(parse(solverConfig)),
39 factory_(gko::config::parse(
40 config_, gko::config::registry(), gko::config::make_type_descriptor<scalar>()
41 )
42 .on(gkoExec_))
43 {}
44
45 static std::string name() { return "Ginkgo"; }
46
47 static std::string doc() { return "TBD"; }
48
49 static std::string schema() { return "none"; }
50
51 virtual SolverStats
52 solve(const LinearSystem<scalar, localIdx>& sys, Vector<scalar>& x) const final;
53
54 virtual SolverStats solve(const LinearSystem<Vec3, localIdx>& sys, Vector<Vec3>& x) const final;
55
56 // TODO why use a smart pointer here?
57 virtual std::unique_ptr<SolverFactory> clone() const final
58 {
59 NF_ERROR_EXIT("Not implemented");
60 return {};
61 }
62
63private:
64
65 std::shared_ptr<const gko::Executor> gkoExec_;
66 gko::config::pnode config_;
67 std::shared_ptr<const gko::LinOpFactory> factory_;
68};
69
70
71}
72
73#endif
A template class for registering derived classes with a base class.
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
Definition error.hpp:110
la::SolverStats solve(Expression< typename VectorType::ElementType > &exp, VectorType &solution, scalar t, scalar dt, const Dictionary &fvSchemes, const Dictionary &fvSolution, std::vector< PostAssemblyBase< typename VectorType::ElementType > > p={})
Definition solver.hpp:72
float scalar
Definition scalar.hpp:16
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.