NeoN
A framework for CFD software
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
12
13/* @brief A helper to collect statistics of the solver */
22
23/* @class SolverFactory
24**
25*/
27 public RuntimeSelectionFactory<SolverFactory, Parameters<const Executor&, const Dictionary&>>
28{
29public:
30
31 static std::unique_ptr<SolverFactory> create(const Executor& exec, const Dictionary& dict)
32 {
33 auto key = dict.get<std::string>("solver");
34 SolverFactory::keyExistsOrError(key);
35 return SolverFactory::table().at(key)(exec, dict);
36 }
37
38 static std::string name() { return "SolverFactory"; }
39
40 SolverFactory(const Executor& exec) : exec_(exec) {};
41
43
44 // virtual void
45 // solve(const LinearSystem<ValueType, int>&, Vector<Vec3>& ) const = 0;
46
47 // Pure virtual function for cloning
48 virtual std::unique_ptr<SolverFactory> clone() const = 0;
49
50protected:
51
53};
54
55class Solver
56{
57
58public:
59
60 Solver(const Solver& solver)
61 : exec_(solver.exec_), solverInstance_(solver.solverInstance_->clone()) {};
62
63 Solver(Solver&& solver)
64 : exec_(solver.exec_), solverInstance_(std::move(solver.solverInstance_)) {};
65
66 Solver(const Executor& exec, std::unique_ptr<SolverFactory> solverInstance)
67 : exec_(exec), solverInstance_(std::move(solverInstance)) {};
68
69 Solver(const Executor& exec, const Dictionary& dict)
70 : exec_(exec), solverInstance_(SolverFactory::create(exec, dict)) {};
71
73 {
74 return solverInstance_->solve(ls, field);
75 }
76
77private:
78
79 const Executor exec_;
80 std::unique_ptr<SolverFactory> solverInstance_;
81};
82
83}
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:28
A class representing a linear system of equations.
static std::string name()
Definition solver.hpp:38
virtual std::unique_ptr< SolverFactory > clone() const =0
SolverFactory(const Executor &exec)
Definition solver.hpp:40
static std::unique_ptr< SolverFactory > create(const Executor &exec, const Dictionary &dict)
Definition solver.hpp:31
virtual SolverStats solve(const LinearSystem< scalar, localIdx > &, Vector< scalar > &) const =0
const Executor exec_
Definition solver.hpp:52
Solver(const Solver &solver)
Definition solver.hpp:60
Solver(const Executor &exec, std::unique_ptr< SolverFactory > solverInstance)
Definition solver.hpp:66
Solver(const Executor &exec, const Dictionary &dict)
Definition solver.hpp:69
Solver(Solver &&solver)
Definition solver.hpp:63
SolverStats solve(const LinearSystem< scalar, localIdx > &ls, Vector< scalar > &field) const
Definition solver.hpp:72
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16
float scalar
Definition scalar.hpp:14