numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
ark43_erk_formula.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
28
30
36template <concepts::problem Problem>
38 : public formula_base<ark43_erk_formula<Problem>, Problem> {
39public:
42
43 using typename base_type::problem_type;
44 using typename base_type::scalar_type;
45 using typename base_type::variable_type;
46
47 static_assert(!problem_type::allowed_evaluations.mass,
48 "Mass matrix is not supported.");
49
50 using base_type::base_type;
52
53protected:
54 using base_type::coeff;
55
56public:
58 static constexpr index_type stages = 6;
59
61 static constexpr index_type order = 4;
62
64 static constexpr auto log_tag = logging::log_tag_view(
65 "num_collect::ode::runge_kutta::ark43_erk_formula");
66
68 static constexpr index_type lesser_order = 3;
69
81 static constexpr scalar_type a21 = coeff(1, 2);
82 static constexpr scalar_type a31 = coeff(13861, 62500);
83 static constexpr scalar_type a32 = coeff(6889, 62500);
84 static constexpr scalar_type a41 = coeff(-116923316275, 2393684061468);
85 static constexpr scalar_type a42 = coeff(-2731218467317, 15368042101831);
86 static constexpr scalar_type a43 = coeff(9408046702089, 11113171139209);
87 static constexpr scalar_type a51 = coeff(-451086348788, 2902428689909);
88 static constexpr scalar_type a52 = coeff(-2682348792572, 7519795681897);
89 static constexpr scalar_type a53 = coeff(12662868775082, 11960479115383);
90 static constexpr scalar_type a54 = coeff(3355817975965, 11060851509271);
91 static constexpr scalar_type a61 = coeff(647845179188, 3216320057751);
92 static constexpr scalar_type a62 = coeff(73281519250, 8382639484533);
93 static constexpr scalar_type a63 = coeff(552539513391, 3454668386233);
94 static constexpr scalar_type a64 = coeff(3354512671639, 8306763924573);
95 static constexpr scalar_type a65 = coeff(4040, 17871);
96
97 // b1 = 0
98 static constexpr scalar_type b2 = coeff(1, 2);
99 static constexpr scalar_type b3 = coeff(83, 250);
100 static constexpr scalar_type b4 = coeff(31, 50);
101 static constexpr scalar_type b5 = coeff(17, 20);
102 static constexpr scalar_type b6 = coeff(1);
103
104 static constexpr scalar_type c1 = coeff(82889, 524892);
105 // c2 = 0
106 static constexpr scalar_type c3 = coeff(15625, 83664);
107 static constexpr scalar_type c4 = coeff(69875, 102672);
108 static constexpr scalar_type c5 = coeff(-2260, 8211);
109 static constexpr scalar_type c6 = coeff(1, 4);
110
111 static constexpr scalar_type cw1 = coeff(4586570599, 29645900160);
112 // cw2 = 0
113 static constexpr scalar_type cw3 = coeff(178811875, 945068544);
114 static constexpr scalar_type cw4 = coeff(814220225, 1159782912);
115 static constexpr scalar_type cw5 = coeff(-3700637, 11593932);
116 static constexpr scalar_type cw6 = coeff(61727, 225920);
117
118 static constexpr scalar_type ce1 = c1 - cw1;
119 // ce2 = 0
120 static constexpr scalar_type ce3 = c3 - cw3;
121 static constexpr scalar_type ce4 = c4 - cw4;
122 static constexpr scalar_type ce5 = c5 - cw5;
123 static constexpr scalar_type ce6 = c6 - cw6;
125
127 void step(scalar_type time, scalar_type step_size,
128 const variable_type& current, variable_type& estimate) {
129 variable_type unused;
130 step_embedded(time, step_size, current, estimate, unused);
131 }
132
144 const variable_type& current, variable_type& estimate,
145 variable_type& error) {
146 constexpr auto evaluations = evaluation_type{.diff_coeff = true};
147
148 problem().evaluate_on(time, current, evaluations);
149 k1_ = problem().diff_coeff();
150
151 problem().evaluate_on(time + b2 * step_size,
152 current + step_size * a21 * k1_, evaluations);
153 k2_ = problem().diff_coeff();
154
155 problem().evaluate_on(time + b3 * step_size,
156 current + step_size * (a31 * k1_ + a32 * k2_), evaluations);
157 k3_ = problem().diff_coeff();
158
159 problem().evaluate_on(time + b4 * step_size,
160 current + step_size * (a41 * k1_ + a42 * k2_ + a43 * k3_),
161 evaluations);
162 k4_ = problem().diff_coeff();
163
164 problem().evaluate_on(time + b5 * step_size,
165 current +
166 step_size * (a51 * k1_ + a52 * k2_ + a53 * k3_ + a54 * k4_),
167 evaluations);
168 k5_ = problem().diff_coeff();
169
170 problem().evaluate_on(time + b6 * step_size,
171 current +
172 step_size *
173 (a61 * k1_ + a62 * k2_ + a63 * k3_ + a64 * k4_ + a65 * k5_),
174 evaluations);
175 k6_ = problem().diff_coeff();
176
177 estimate = current +
178 step_size * (c1 * k1_ + c3 * k3_ + c4 * k4_ + c5 * k5_ + c6 * k6_);
179 error = step_size *
180 (ce1 * k1_ + ce3 * k3_ + ce4 * k4_ + ce5 * k5_ + ce6 * k6_);
181 }
182
183private:
196};
197
203template <concepts::problem Problem>
205
206} // namespace num_collect::ode::runge_kutta
Class of tags of logs without memory management.
Class of solvers of ODEs using embedded formulas.
Base class of formulas in ODE solvers.
Class of ARK4(3)6L[2]SA-ERK formula in kennedy2003 .
void step(scalar_type time, scalar_type step_size, const variable_type &current, variable_type &estimate)
Compute the next variable.
static constexpr index_type order
Order of this formula.
static constexpr index_type lesser_order
Order of lesser coefficients of this 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.
Definition of embedded_solver class.
Definition of evaluation_type enumeration.
Definition of formula_base class.
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
Namespace of Runge-Kutta method.
Definition of problem concept.
Struct to specify types of evaluations.
bool diff_coeff
Differential coefficient.