NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
solver.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025 NeoN authors
3#pragma once
4
5#include "NeoN/core/input.hpp"
8
9namespace NeoN::la
10{
11/* @class SolverFactory
12**
13*/
15 public RuntimeSelectionFactory<SolverFactory, Parameters<const Executor&, const Dictionary&>>
16{
17public:
18
19 static std::unique_ptr<SolverFactory> create(const Executor& exec, const Dictionary& dict)
20 {
21 auto key = dict.get<std::string>("solver");
22 SolverFactory::keyExistsOrError(key);
23 return SolverFactory::table().at(key)(exec, dict);
24 }
25
26 static std::string name() { return "SolverFactory"; }
27
28 SolverFactory(const Executor& exec) : exec_(exec) {};
29
30 virtual void solve(const LinearSystem<scalar, localIdx>&, Vector<scalar>&) const = 0;
31
32 // virtual void
33 // solve(const LinearSystem<ValueType, int>&, Vector<Vec3>& ) const = 0;
34
35 // Pure virtual function for cloning
36 virtual std::unique_ptr<SolverFactory> clone() const = 0;
37
38protected:
39
41};
42
43class Solver
44{
45
46public:
47
48 Solver(const Solver& solver)
49 : exec_(solver.exec_), solverInstance_(solver.solverInstance_->clone()) {};
50
51 Solver(Solver&& solver)
52 : exec_(solver.exec_), solverInstance_(std::move(solver.solverInstance_)) {};
53
54 Solver(const Executor& exec, std::unique_ptr<SolverFactory> solverInstance)
55 : exec_(exec), solverInstance_(std::move(solverInstance)) {};
56
57 Solver(const Executor& exec, const Dictionary& dict)
58 : exec_(exec), solverInstance_(SolverFactory::create(exec, dict)) {};
59
61 {
62 solverInstance_->solve(ls, field);
63 }
64
65private:
66
67 const Executor exec_;
68 std::unique_ptr<SolverFactory> solverInstance_;
69};
70
71}
A class representing a dictionary that stores key-value pairs.
T & get(const std::string &key)
Retrieves the value associated with the given key, casting it to the specified type.
A factory class for runtime selection of derived classes.
A class to contain the data and executors for a field and define some basic operations.
Definition vector.hpp:53
A class representing a linear system of equations.
static std::string name()
Definition solver.hpp:26
virtual std::unique_ptr< SolverFactory > clone() const =0
virtual void solve(const LinearSystem< scalar, localIdx > &, Vector< scalar > &) const =0
SolverFactory(const Executor &exec)
Definition solver.hpp:28
static std::unique_ptr< SolverFactory > create(const Executor &exec, const Dictionary &dict)
Definition solver.hpp:19
const Executor exec_
Definition solver.hpp:40
Solver(const Solver &solver)
Definition solver.hpp:48
Solver(const Executor &exec, std::unique_ptr< SolverFactory > solverInstance)
Definition solver.hpp:54
Solver(const Executor &exec, const Dictionary &dict)
Definition solver.hpp:57
void solve(const LinearSystem< scalar, localIdx > &ls, Vector< scalar > &field) const
Definition solver.hpp:60
Solver(Solver &&solver)
Definition solver.hpp:51
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16