numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
tanaka1_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
29
31
38template <concepts::problem Problem,
39 concepts::slope_equation_solver FormulaSolver =
40 inexact_newton_slope_equation_solver<Problem>>
42 : public implicit_formula_base<tanaka1_formula<Problem, FormulaSolver>,
43 Problem, FormulaSolver> {
44public:
47
49 using base_type =
51 FormulaSolver>;
52
53 using typename base_type::problem_type;
54 using typename base_type::scalar_type;
55 using typename base_type::variable_type;
56
57 static_assert(!problem_type::allowed_evaluations.mass,
58 "Mass matrix is not supported.");
59
62
63protected:
64 using base_type::coeff;
66
67public:
69 static constexpr index_type stages = 2;
70
72 static constexpr index_type order = 3;
73
75 static constexpr index_type lesser_order = 1;
76
78 static constexpr auto log_tag =
79 logging::log_tag_view("num_collect::ode::runge_kutta::tanaka1_formula");
80
92 static constexpr scalar_type a11 = coeff(13, 20);
93 static constexpr scalar_type a21 = coeff(-127, 180);
94 static constexpr scalar_type a22 = coeff(13, 20);
95
96 static constexpr scalar_type b1 = coeff(13, 20);
97 static constexpr scalar_type b2 = coeff(-1, 18);
98
99 static constexpr scalar_type c1 = coeff(100, 127);
100 static constexpr scalar_type c2 = coeff(27, 127);
101
102 static constexpr scalar_type cw1 = coeff(1);
103
104 static constexpr scalar_type ce1 = c1 - cw1;
105 static constexpr scalar_type ce2 = c2;
107
109 void step(scalar_type time, scalar_type step_size,
110 const variable_type& current, variable_type& estimate) {
111 variable_type unused;
112 step_embedded(time, step_size, current, estimate, unused);
113 }
114
126 const variable_type& current, variable_type& estimate,
127 variable_type& error) {
128 formula_solver().update_jacobian(
129 problem(), time + b1 * step_size, step_size, current, a11);
130 k1_ = problem().diff_coeff();
131 formula_solver().init(k1_);
132 formula_solver().solve();
133
134 formula_solver().update_jacobian(problem(), time + b2 * step_size,
135 step_size, current + step_size * a21 * k1_, a22);
136 k2_ = problem().diff_coeff();
137 formula_solver().init(k2_);
138 formula_solver().solve();
139
140 estimate = current + step_size * (c1 * k1_ + c2 * k2_);
141 error = step_size * (ce1 * k1_ + ce2 * k2_);
142 }
143
144private:
153};
154
160template <concepts::problem Problem>
162
163} // 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.
auto problem() -> problem_type &
Get the problem.
static constexpr auto coeff(T val) -> scalar_type
Convert coefficients.
typename problem_type::variable_type variable_type
Type of variables.
typename problem_type::scalar_type scalar_type
Type of scalars.
auto formula_solver() -> formula_solver_type &
Get solver of formula.
typename problem_type::variable_type variable_type
Type of variables.
void step(scalar_type time, scalar_type step_size, const variable_type &current, variable_type &estimate)
Compute the next variable.
typename problem_type::scalar_type scalar_type
Type of scalars.
auto formula_solver() -> formula_solver_type &
Get solver of 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.
static constexpr index_type order
Order of this formula.
static constexpr index_type lesser_order
Order of lesser coefficients of this formula.
Definition of embedded_solver class.
Definition of implicit_formula_base class.
Definition of index_type type.
Definition of inexact_newton_slope_equation_solver class.
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.
Definition of slope_equation_solver concept.