NeoN
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 NeoN authors
3
4#pragma once
5
6#include <functional>
7#include <memory>
8
12#include "NeoN/fields/field.hpp"
15
16
18{
19
51template<typename SolutionVectorType>
53 public TimeIntegratorBase<SolutionVectorType>::template Register<RungeKutta<SolutionVectorType>>
54{
55public:
56
57 using ValueType = typename SolutionVectorType::VectorValueType;
58 using Base =
60
64 RungeKutta() = default;
65
69 ~RungeKutta() = default;
70
75 RungeKutta(const Dictionary& schemeDict, const Dictionary& solutionDict)
76 : Base(schemeDict, solutionDict)
77 {}
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 solve(
126 SolutionVectorType& solutionVector,
127 scalar t,
128 const scalar dt
129 ) override;
130
135 std::unique_ptr<TimeIntegratorBase<SolutionVectorType>> clone() const override;
136
137
138private:
139
141 solution_;
143 initialConditions_;
144 std::shared_ptr<SUNContext> context_ {
146 };
147 std::unique_ptr<char, decltype(sundials::SUN_ARK_DELETER)> ODEMemory_ {
149 };
150 std::unique_ptr<NeoN::dsl::Expression<ValueType>> pdeExpr_ {nullptr
151 };
160 void
161 initSUNERKSolver(dsl::Expression<ValueType>& exp, SolutionVectorType& field, const scalar t);
162
167 void initExpression(const dsl::Expression<ValueType>& exp);
168
172 void initSUNContext();
173
179 void initSUNVector(const Executor& exec, size_t size);
180
185 void initSUNInitialConditions(const SolutionVectorType& solutionVector);
186
191 void initODEMemory(const scalar t);
192};
193
194} // namespace NeoN
A class representing a dictionary that stores key-value pairs.
Unified interface for SUNDIALS Kokkos vector management.
Definition sundials.hpp:373
Integrates in time, using Sundials, a PDE expression using the Runge-Kutta method.
RungeKutta()=default
Default constructor.
static std::string doc()
Returns the documentation for the class.
~RungeKutta()=default
Default destructor.
static std::string name()
Returns the name of the class.
std::unique_ptr< TimeIntegratorBase< SolutionVectorType > > clone() const override
Return a copy of this instantiated class.
void solve(dsl::Expression< ValueType > &exp, SolutionVectorType &solutionVector, scalar t, const scalar dt) override
Solves one (explicit) time step, from n to n+1.
TimeIntegratorBase< SolutionVectorType >::template Register< RungeKutta< SolutionVectorType > > Base
static std::string schema()
Returns the schema for the class.
RungeKutta & operator=(RungeKutta &&other)=delete
RungeKutta(RungeKutta &&other)
Move Constructor.
RungeKutta & operator=(const RungeKutta &other)=delete
typename SolutionVectorType::VectorValueType ValueType
RungeKutta(const RungeKutta &other)
Copy constructor.
RungeKutta(const Dictionary &schemeDict, const Dictionary &solutionDict)
Constructor that initializes the RungeKutta solver with a dictionary configuration.
A template class for registering derived classes with a base class.
auto SUN_CONTEXT_DELETER
Custom deleter for SUNContext shared pointers.
Definition sundials.hpp:29
auto SUN_ARK_DELETER
Custom deleter for explicit type RK solvers (ERK, ARK, etc) for the unique pointers.
Definition sundials.hpp:42
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16
float scalar
Definition scalar.hpp:14