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
48 // virtual void
49 // solve(const LinearSystem<ValueType, int>&, Vector<Vec3>& ) const = 0;
50
51 // Pure virtual function for cloning
52 virtual std::unique_ptr<SolverFactory> clone() const = 0;
53
54protected:
55
57};
58
59class Solver
60{
61
62public:
63
64 Solver(const Solver& solver)
65 : exec_(solver.exec_), solverInstance_(solver.solverInstance_->clone()) {};
66
67 Solver(Solver&& solver)
68 : exec_(solver.exec_), solverInstance_(std::move(solver.solverInstance_)) {};
69
70 Solver(const Executor& exec, std::unique_ptr<SolverFactory> solverInstance)
71 : exec_(exec), solverInstance_(std::move(solverInstance)) {};
72
73 Solver(const Executor& exec, const Dictionary& dict)
74 : exec_(exec), solverInstance_(SolverFactory::create(exec, dict)) {};
75
77 {
78 return solverInstance_->solve(ls, field);
79 }
80
81private:
82
83 const Executor exec_;
84 std::unique_ptr<SolverFactory> solverInstance_;
85};
86
87}
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
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:56
Solver(const Solver &solver)
Definition solver.hpp:64
Solver(const Executor &exec, std::unique_ptr< SolverFactory > solverInstance)
Definition solver.hpp:70
Solver(const Executor &exec, const Dictionary &dict)
Definition solver.hpp:73
Solver(Solver &&solver)
Definition solver.hpp:67
SolverStats solve(const LinearSystem< scalar, localIdx > &ls, Vector< scalar > &field) const
Definition solver.hpp:76
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:18
float scalar
Definition scalar.hpp:16