NeoN
A framework for CFD software
Loading...
Searching...
No Matches
rungeKutta.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#if NN_WITH_SUNDIALS
8
9#include <functional>
10#include <memory>
11
15#include "NeoN/fields/field.hpp"
18
19
21{
22
54template<typename SolutionVectorType>
55class RungeKutta :
56 public TimeIntegratorBase<SolutionVectorType>::template Register<RungeKutta<SolutionVectorType>>
57{
58public:
59
60 using ValueType = typename SolutionVectorType::VectorValueType;
61 using Base =
62 TimeIntegratorBase<SolutionVectorType>::template Register<RungeKutta<SolutionVectorType>>;
63
67 RungeKutta() = default;
68
72 ~RungeKutta() = default;
73
78 RungeKutta(const Dictionary& schemeDict, const Dictionary& solutionDict)
79 : Base(schemeDict, solutionDict)
80 {}
81
88 RungeKutta(const RungeKutta& other);
89
94 RungeKutta(RungeKutta&& other);
95
96 // deleted because base class method deleted.
97 RungeKutta& operator=(const RungeKutta& other) = delete;
98
99 // deleted because base class method deleted.
100 RungeKutta& operator=(RungeKutta&& other) = delete;
101
106 static std::string name() { return "Runge-Kutta"; }
107
112 static std::string doc() { return "Explicit time integration using the Runge-Kutta method."; }
113
118 static std::string schema() { return "none"; }
119
127 void solve(
128 dsl::Expression<ValueType>& exp,
129 SolutionVectorType& solutionVector,
130 scalar t,
131 const scalar dt
132 ) override;
133
138 std::unique_ptr<TimeIntegratorBase<SolutionVectorType>> clone() const override;
139
140
141private:
142
143 NeoN::sundials::SKVector<ValueType>
144 solution_;
145 NeoN::sundials::SKVector<ValueType>
146 initialConditions_;
147 std::shared_ptr<SUNContext> context_ {
148 nullptr, sundials::SUN_CONTEXT_DELETER
149 };
150 std::unique_ptr<char, decltype(sundials::SUN_ARK_DELETER)> ODEMemory_ {
151 nullptr, sundials::SUN_ARK_DELETER
152 };
153 std::unique_ptr<NeoN::dsl::Expression<ValueType>> pdeExpr_ {nullptr
154 };
163 void
164 initSUNERKSolver(dsl::Expression<ValueType>& exp, SolutionVectorType& field, const scalar t);
165
170 void initExpression(const dsl::Expression<ValueType>& exp);
171
175 void initSUNContext();
176
182 void initSUNVector(const Executor& exec, size_t size);
183
188 void initSUNInitialConditions(const SolutionVectorType& solutionVector);
189
194 void initODEMemory(const scalar t);
195};
196
197} // namespace NeoN
198
199#endif
A template class for registering derived classes with a base class.
void solve(Expression< typename VectorType::ElementType > &exp, VectorType &solution, scalar t, scalar dt, const Dictionary &fvSchemes, const Dictionary &fvSolution)
Definition solver.hpp:38
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.