numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
avf2_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
26#include "num_collect/constants/one.h" // IWYU pragma: keep
27#include "num_collect/constants/zero.h" // IWYU pragma: keep
36
38
45template <concepts::problem Problem>
47public:
49 using problem_type = Problem;
50
52 using variable_type = typename problem_type::variable_type;
53
55 using scalar_type = typename problem_type::scalar_type;
56
58 static constexpr index_type stages = 1;
59
61 static constexpr index_type order = 2;
62
64 static constexpr auto log_tag =
65 logging::log_tag_view("num_collect::ode::avf::avf2_formula");
66
74
83 void step(scalar_type time, scalar_type step_size,
84 const variable_type& current, variable_type& estimate) {
85 problem().evaluate_on(
86 time, current, evaluation_type{.diff_coeff = true});
87 estimate = current + step_size * problem().diff_coeff();
88
89 integrand_.time(time);
90 integrand_.prev_var(current);
91 variable_type prev_estimate;
92 constexpr index_type max_loops = 10000;
93 for (index_type i = 0; i < max_loops; ++i) {
94 integrand_.next_var(estimate);
95 prev_estimate = estimate;
96 estimate = current +
97 step_size *
100 if (norm(estimate - prev_estimate) < tol_residual_norm_) {
101 return;
102 }
103 }
104 }
105
111 [[nodiscard]] auto problem() -> problem_type& {
112 return integrand_.problem();
113 }
114
120 [[nodiscard]] auto problem() const -> const problem_type& {
121 return integrand_.problem();
122 }
123
130 NUM_COLLECT_PRECONDITION(val > static_cast<scalar_type>(0),
131 "Tolerance of residual norm must be a positive value.");
132 tol_residual_norm_ = val;
133 }
134
135private:
138
140 static constexpr index_type integrator_degree = 5;
141
145
147 static constexpr auto default_tol_residual_norm =
148 static_cast<scalar_type>(1e-8);
149
152};
153
160template <concepts::problem Problem>
162
169template <concepts::problem Problem>
171
172} // namespace num_collect::ode::avf
Definition of avf_integrand class.
Class to perform numerical integration with Gauss-Legendre formula.
Class of tags of logs without memory management.
Class of 2nd order average vector field (AVF) method quispel2008.
Problem problem_type
Type of problem.
static constexpr auto default_tol_residual_norm
Default tolerance of residual norm.
void step(scalar_type time, scalar_type step_size, const variable_type &current, variable_type &estimate)
Compute the next variable.
void tol_residual_norm(scalar_type val)
Set tolerance of residual norm.
typename problem_type::variable_type variable_type
Type of variables.
static constexpr index_type integrator_degree
Degree of integrator.
static constexpr auto log_tag
Log tag.
avf2_formula(const problem_type &problem=problem_type())
Constructor.
impl::avf_integrand< problem_type > integrand_
Integrand.
typename problem_type::scalar_type scalar_type
Type of scalars.
static constexpr index_type stages
Number of stages of this formula.
scalar_type tol_residual_norm_
Tolerance of residual norm.
integration::gauss_legendre_integrator< variable_type(scalar_type)> integrator_
Integrator.
static constexpr index_type order
Order of this formula.
auto problem() const -> const problem_type &
Get the problem.
auto problem() -> problem_type &
Get the problem.
Class of integrand for average vector field (AVF) method quispel2008.
void time(scalar_type val)
Set time.
void prev_var(const variable_type &var)
Set the previous variable.
void next_var(const variable_type &var)
Set the next variable.
auto problem() -> problem_type &
Get the problem.
Class of solvers of ODEs using embedded formulas.
Class of simple solver of ODEs.
Definition of evaluation_type enumeration.
Definition of exceptions.
Definition of legendre_roots function.
Definition of index_type type.
Definition of log_tag_view class.
Definition of macros for logging.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
auto norm(const Matrix &matrix)
Calculate norm of a matrix.
Definition norm.h:39
constexpr T zero
Value 0.
Definition zero.h:30
constexpr T one
Value 1.
Definition one.h:30
Namespace of average vector field (AVF) method.
Definition of non_embedded_formula_wrapper class.
Definition of norm class.
Definition of one.
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.
Definition of zero.