NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
rungeKutta.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 NeoFOAM authors
3
4#pragma once
5
6#include <functional>
7#include <memory>
8
15
16
18{
19
51template<typename SolutionFieldType>
53 public TimeIntegratorBase<SolutionFieldType>::template Register<RungeKutta<SolutionFieldType>>
54{
55public:
56
57 using ValueType = SolutionFieldType::FieldValueType;
59 using Base =
61 using Base::dict_;
62
66 RungeKutta() = default;
67
71 ~RungeKutta() = default;
72
77 RungeKutta(const Dictionary& dict) : Base(dict) {}
78
85 RungeKutta(const RungeKutta& other);
86
92
93 // deleted because base class method deleted.
94 RungeKutta& operator=(const RungeKutta& other) = delete;
95
96 // deleted because base class method deleted.
97 RungeKutta& operator=(RungeKutta&& other) = delete;
98
103 static std::string name() { return "Runge-Kutta"; }
104
109 static std::string doc() { return "Explicit time integration using the Runge-Kutta method."; }
110
115 static std::string schema() { return "none"; }
116
124 void
125 solve(Expression& exp, SolutionFieldType& solutionField, scalar t, const scalar dt) override;
126
131 std::unique_ptr<TimeIntegratorBase<SolutionFieldType>> clone() const override;
132
133
134private:
135
137 solution_;
139 initialConditions_;
140 std::shared_ptr<SUNContext> context_ {
142 };
143 std::unique_ptr<char, decltype(sundials::SUN_ARK_DELETER)> ODEMemory_ {
145 };
146 std::unique_ptr<NeoFOAM::dsl::Expression> pdeExpr_ {nullptr
147 };
156 void initSUNERKSolver(Expression& exp, SolutionFieldType& field, const scalar t);
157
162 void initExpression(const Expression& exp);
163
167 void initSUNContext();
168
174 void initSUNVector(const Executor& exec, size_t size);
175
180 void initSUNInitialConditions(const SolutionFieldType& solutionField);
181
186 void initODEMemory(const scalar t);
187};
188
189} // namespace NeoFOAM
A class representing a dictionary that stores key-value pairs.
Unified interface for SUNDIALS Kokkos vector management.
Definition sundials.hpp:371
Integrates in time, using Sundials, a PDE expression using the Runge-Kutta method.
std::unique_ptr< TimeIntegratorBase< SolutionFieldType > > clone() const override
Return a copy of this instantiated class.
RungeKutta()=default
Default constructor.
static std::string schema()
Returns the schema for the class.
RungeKutta & operator=(RungeKutta &&other)=delete
void solve(Expression &exp, SolutionFieldType &solutionField, scalar t, const scalar dt) override
Solves one (explicit) time step, from n to n+1.
NeoFOAM::dsl::Expression Expression
RungeKutta & operator=(const RungeKutta &other)=delete
static std::string name()
Returns the name of the class.
SolutionFieldType::FieldValueType ValueType
RungeKutta(const RungeKutta &other)
Copy constructor.
static std::string doc()
Returns the documentation for the class.
RungeKutta(RungeKutta &&other)
Move Constructor.
~RungeKutta()=default
Default destructor.
TimeIntegratorBase< SolutionFieldType >::template Register< RungeKutta< SolutionFieldType > > Base
RungeKutta(const Dictionary &dict)
Constructor that initializes the RungeKutta solver with a dictionary configuration.
A template class for registering derived classes with a base class.
auto SUN_ARK_DELETER
Custom deleter for explicit type RK solvers (ERK, ARK, etc) for the unique pointers.
Definition sundials.hpp:42
auto SUN_CONTEXT_DELETER
Custom deleter for SUNContext shared pointers.
Definition sundials.hpp:29
float scalar
Definition scalar.hpp:11
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16