numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
symplectic_forest4_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
33
35
58template <concepts::multi_variate_problem Problem>
60 : public formula_base<symplectic_forest4_formula<Problem>, Problem> {
61public:
63 using base_type =
65
66 using typename base_type::problem_type;
67 using typename base_type::scalar_type;
68 using typename base_type::variable_type;
69
70 using base_type::base_type;
72
73 static_assert(!problem_type::allowed_evaluations.mass,
74 "Mass matrix is not supported.");
75
76protected:
77 using base_type::coeff;
78
79public:
81 static constexpr index_type stages = 7;
82
84 static constexpr index_type order = 4;
85
87 static constexpr auto log_tag = logging::log_tag_view(
88 "num_collect::ode::symplectic::symplectic_forest4_formula");
89
91 static constexpr scalar_type alpha = static_cast<scalar_type>(1) -
92 constants::cbrt(static_cast<scalar_type>(2));
93
102 static constexpr scalar_type bp1 = static_cast<scalar_type>(1) /
103 (static_cast<scalar_type>(2) * (static_cast<scalar_type>(1) + alpha));
104 static constexpr scalar_type bq1 =
105 static_cast<scalar_type>(1) / (static_cast<scalar_type>(1) + alpha);
106 static constexpr scalar_type bp2 = alpha /
107 (static_cast<scalar_type>(2) * (static_cast<scalar_type>(1) + alpha));
108 static constexpr scalar_type bq2 = (alpha - static_cast<scalar_type>(1)) /
109 (static_cast<scalar_type>(1) + alpha);
110 static constexpr scalar_type bp3 = bp2;
111 static constexpr scalar_type bq3 = bq1;
112 static constexpr scalar_type bp4 = bp1;
114
116 void step(scalar_type time, scalar_type step_size,
117 const variable_type& current, variable_type& estimate) {
118 const index_type dim = current.size();
119 const index_type half_dim = dim / 2;
120 NUM_COLLECT_PRECONDITION(dim % 2 == 0,
121 "This formula requires vectors with even dimensions.");
122
123 estimate = current;
124
125 constexpr auto evaluations = evaluation_type{.diff_coeff = true};
126
127 problem().evaluate_on(time, estimate, evaluations);
128 estimate.head(half_dim) +=
129 step_size * bp1 * problem().diff_coeff().head(half_dim);
130
131 problem().evaluate_on(time, estimate, evaluations);
132 estimate.tail(half_dim) +=
133 step_size * bq1 * problem().diff_coeff().tail(half_dim);
134
135 problem().evaluate_on(time, estimate, evaluations);
136 estimate.head(half_dim) +=
137 step_size * bp2 * problem().diff_coeff().head(half_dim);
138
139 problem().evaluate_on(time, estimate, evaluations);
140 estimate.tail(half_dim) +=
141 step_size * bq2 * problem().diff_coeff().tail(half_dim);
142
143 problem().evaluate_on(time, estimate, evaluations);
144 estimate.head(half_dim) +=
145 step_size * bp3 * problem().diff_coeff().head(half_dim);
146
147 problem().evaluate_on(time, estimate, evaluations);
148 estimate.tail(half_dim) +=
149 step_size * bq3 * problem().diff_coeff().tail(half_dim);
150
151 problem().evaluate_on(time, estimate, evaluations);
152 estimate.head(half_dim) +=
153 step_size * bp4 * problem().diff_coeff().head(half_dim);
154 }
155};
156
179template <concepts::problem Problem>
182
183} // namespace num_collect::ode::symplectic
Definition of cbrt function.
Class of tags of logs without memory management.
Base class of formulas in ODE solvers.
Class of simple solver of ODEs.
Class of fourth-order symplectic integration formula in forest1990.
static constexpr index_type order
Order of this formula.
static constexpr scalar_type alpha
A constant of this formula .
void step(scalar_type time, scalar_type step_size, const variable_type &current, variable_type &estimate)
Compute the next variable.
static constexpr index_type stages
Number of stages of this formula.
Definition of evaluation_type enumeration.
Definition of exceptions.
Definition of formula_base class.
Definition of index_type type.
Definition of log_tag_view class.
Definition of macros for logging.
Definition of multi_variate_problem concept.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
constexpr auto cbrt(T x)
Calculate cubic root .
Definition cbrt.h:38
Namespace of symplectic integration.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of problem concept.
Definition of simple_solver class.
Struct to specify types of evaluations.
bool diff_coeff
Differential coefficient.