NeoN
A framework for CFD software
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#if NN_WITH_SUNDIALS
7
8#include <functional>
9#include <memory>
10
14#include "NeoN/fields/field.hpp"
17
18
20{
21
53template<typename SolutionVectorType>
54class RungeKutta :
55 public TimeIntegratorBase<SolutionVectorType>::template Register<RungeKutta<SolutionVectorType>>
56{
57public:
58
59 using ValueType = typename SolutionVectorType::VectorValueType;
60 using Base =
61 TimeIntegratorBase<SolutionVectorType>::template Register<RungeKutta<SolutionVectorType>>;
62
66 RungeKutta() = default;
67
71 ~RungeKutta() = default;
72
77 RungeKutta(const Dictionary& schemeDict, const Dictionary& solutionDict)
78 : Base(schemeDict, solutionDict)
79 {}
80
87 RungeKutta(const RungeKutta& other);
88
93 RungeKutta(RungeKutta&& other);
94
95 // deleted because base class method deleted.
96 RungeKutta& operator=(const RungeKutta& other) = delete;
97
98 // deleted because base class method deleted.
99 RungeKutta& operator=(RungeKutta&& other) = delete;
100
105 static std::string name() { return "Runge-Kutta"; }
106
111 static std::string doc() { return "Explicit time integration using the Runge-Kutta method."; }
112
117 static std::string schema() { return "none"; }
118
126 void solve(
127 dsl::Expression<ValueType>& exp,
128 SolutionVectorType& solutionVector,
129 scalar t,
130 const scalar dt
131 ) override;
132
137 std::unique_ptr<TimeIntegratorBase<SolutionVectorType>> clone() const override;
138
139
140private:
141
142 NeoN::sundials::SKVector<ValueType>
143 solution_;
144 NeoN::sundials::SKVector<ValueType>
145 initialConditions_;
146 std::shared_ptr<SUNContext> context_ {
147 nullptr, sundials::SUN_CONTEXT_DELETER
148 };
149 std::unique_ptr<char, decltype(sundials::SUN_ARK_DELETER)> ODEMemory_ {
150 nullptr, sundials::SUN_ARK_DELETER
151 };
152 std::unique_ptr<NeoN::dsl::Expression<ValueType>> pdeExpr_ {nullptr
153 };
162 void
163 initSUNERKSolver(dsl::Expression<ValueType>& exp, SolutionVectorType& field, const scalar t);
164
169 void initExpression(const dsl::Expression<ValueType>& exp);
170
174 void initSUNContext();
175
181 void initSUNVector(const Executor& exec, size_t size);
182
187 void initSUNInitialConditions(const SolutionVectorType& solutionVector);
188
193 void initODEMemory(const scalar t);
194};
195
196} // namespace NeoN
197
198#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:36
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.