NeoN
A framework for CFD software
Loading...
Searching...
No Matches
solver.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include "NeoN/core/input.hpp"
10
11namespace NeoN::la
12{
13
14
15/* @brief A helper to collect statistics of the solver */
26
27/* @class SolverFactory
28**
29*/
31 public RuntimeSelectionFactory<SolverFactory, Parameters<const Executor&, const Dictionary&>>
32{
33public:
34
35 static std::unique_ptr<SolverFactory> create(const Executor& exec, const Dictionary& dict)
36 {
37 auto key = dict.get<std::string>("solver");
38 SolverFactory::keyExistsOrError(key);
39 return SolverFactory::table().at(key)(exec, dict);
40 }
41
42 static std::string name() { return "SolverFactory"; }
43
44 SolverFactory(const Executor& exec) : exec_(exec) {};
45
47
49
50 // Pure virtual function for cloning
51 virtual std::unique_ptr<SolverFactory> clone() const = 0;
52
53protected:
54
56};
57
58class Solver
59{
60
61public:
62
63 Solver(const Solver& solver)
64 : exec_(solver.exec_), solverInstance_(solver.solverInstance_->clone()) {};
65
66 Solver(Solver&& solver)
67 : exec_(solver.exec_), solverInstance_(std::move(solver.solverInstance_)) {};
68
69 Solver(const Executor& exec, std::unique_ptr<SolverFactory> solverInstance)
70 : exec_(exec), solverInstance_(std::move(solverInstance)) {};
71
72 Solver(const Executor& exec, const Dictionary& dict)
73 : exec_(exec), solverInstance_(SolverFactory::create(exec, dict)) {};
74
76 {
77 return solverInstance_->solve(ls, field);
78 }
79
81 {
82 return solverInstance_->solve(ls, field);
83 }
84
85private:
86
87 const Executor exec_;
88 std::unique_ptr<SolverFactory> solverInstance_;
89};
90
91}
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:30
A class representing a linear system of equations.
static std::string name()
Definition solver.hpp:42
virtual std::unique_ptr< SolverFactory > clone() const =0
SolverFactory(const Executor &exec)
Definition solver.hpp:44
virtual SolverStats solve(const LinearSystem< Vec3, localIdx > &, Vector< Vec3 > &) const =0
static std::unique_ptr< SolverFactory > create(const Executor &exec, const Dictionary &dict)
Definition solver.hpp:35
virtual SolverStats solve(const LinearSystem< scalar, localIdx > &, Vector< scalar > &) const =0
const Executor exec_
Definition solver.hpp:55
SolverStats solve(const LinearSystem< Vec3, localIdx > &ls, Vector< Vec3 > &field) const
Definition solver.hpp:80
Solver(const Solver &solver)
Definition solver.hpp:63
Solver(const Executor &exec, std::unique_ptr< SolverFactory > solverInstance)
Definition solver.hpp:69
Solver(const Executor &exec, const Dictionary &dict)
Definition solver.hpp:72
Solver(Solver &&solver)
Definition solver.hpp:66
SolverStats solve(const LinearSystem< scalar, localIdx > &ls, Vector< scalar > &field) const
Definition solver.hpp:75
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:18
float scalar
Definition scalar.hpp:16