numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
non_embedded_formula_wrapper.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
23#include "num_collect/constants/half.h" // IWYU pragma: keep
27
28namespace num_collect::ode {
29
35template <concepts::formula BaseFormula>
37public:
39 using base_formula_type = BaseFormula;
40
42 using problem_type = typename base_formula_type::problem_type;
43
45 using variable_type = typename problem_type::variable_type;
46
48 using scalar_type = typename problem_type::scalar_type;
49
51 static constexpr index_type stages = base_formula_type::stages;
52
54 static constexpr index_type order = base_formula_type::order;
55
57 static constexpr index_type lesser_order = base_formula_type::order;
58
60 static constexpr logging::log_tag_view log_tag = base_formula_type::log_tag;
61
70
79 void step(scalar_type time, scalar_type step_size,
80 const variable_type& current, variable_type& estimate) {
81 formula_.step(time, step_size, current, estimate);
82 }
83
95 const variable_type& current, variable_type& estimate,
96 variable_type& error) {
97 variable_type rough_estimate;
98 step(time, step_size, current, rough_estimate);
99 variable_type half_estimate;
100 const scalar_type half_step_size =
102 step(time, half_step_size, current, half_estimate);
103 step(time, half_step_size, half_estimate, estimate);
104 error = rough_estimate - estimate;
105 }
106
112 [[nodiscard]] auto problem() -> problem_type& { return formula_.problem(); }
113
119 [[nodiscard]] auto problem() const -> const problem_type& {
120 return formula_.problem();
121 }
122
123private:
126};
127
133template <typename Formula>
136
137} // namespace num_collect::ode
Class of tags of logs without memory management.
Class of solvers of ODEs using embedded formulas.
Wrapper class to use a non-embedded formula as an embedded formula.
static constexpr index_type stages
Number of stages of this formula.
void step_embedded(scalar_type time, scalar_type step_size, const variable_type &current, variable_type &estimate, variable_type &error)
Compute the next variable and weak estimate of it with embedded formula.
auto problem() const -> const problem_type &
Get the problem.
typename problem_type::scalar_type scalar_type
Type of scalars.
typename problem_type::variable_type variable_type
Type of variables.
typename base_formula_type::problem_type problem_type
Type of problem.
static constexpr index_type lesser_order
Order of lesser coefficients of this formula.
static constexpr logging::log_tag_view log_tag
Log tag.
void step(scalar_type time, scalar_type step_size, const variable_type &current, variable_type &estimate)
Compute the next variable.
non_embedded_formula_wrapper(const problem_type &problem=problem_type())
Constructor.
static constexpr index_type order
Order of this formula.
BaseFormula base_formula_type
Type of formula to use in this class.
Definition of embedded_solver class.
Definition of formula concept.
Definition of half.
Definition of index_type type.
Definition of log_tag_view class.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
constexpr T half
Value 0.5.
Definition half.h:30
Namespace of solvers of ordinary differential equations (ODE).