numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
formula_base.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
24namespace num_collect::ode {
25
32template <typename Derived, concepts::problem Problem>
34public:
36 using problem_type = Problem;
37
39 using variable_type = typename problem_type::variable_type;
40
42 using scalar_type = typename problem_type::scalar_type;
43
51
60 void step(scalar_type time, scalar_type step_size,
61 const variable_type& current, variable_type& estimate) {
62 derived().step(time, step_size, current, estimate);
63 }
64
70 [[nodiscard]] auto problem() -> problem_type& { return problem_; }
71
77 [[nodiscard]] auto problem() const -> const problem_type& {
78 return problem_;
79 }
80
81protected:
87 [[nodiscard]] auto derived() noexcept -> Derived& {
88 return *static_cast<Derived*>(this);
89 }
90
96 [[nodiscard]] auto derived() const noexcept -> const Derived& {
97 return *static_cast<const Derived*>(this);
98 }
99
107 template <typename T>
108 static constexpr auto coeff(T val) -> scalar_type {
109 return static_cast<scalar_type>(val);
110 }
111
121 template <typename T1, typename T2>
122 static constexpr auto coeff(T1 num, T2 den) -> scalar_type {
123 return static_cast<scalar_type>(num) / static_cast<scalar_type>(den);
124 }
125
126private:
129};
130
131} // namespace num_collect::ode
Base class of formulas in ODE solvers.
static constexpr auto coeff(T1 num, T2 den) -> scalar_type
Create coefficients.
typename problem_type::variable_type variable_type
Type of variables.
auto derived() const noexcept -> const Derived &
Access derived object.
auto problem() -> problem_type &
Get the problem.
formula_base(const problem_type &problem=problem_type())
Constructor.
Problem problem_type
Type of problem.
typename problem_type::scalar_type scalar_type
Type of scalars.
auto derived() noexcept -> Derived &
Access derived object.
problem_type problem_
Problem.
auto problem() const -> const problem_type &
Get the problem.
void step(scalar_type time, scalar_type step_size, const variable_type &current, variable_type &estimate)
Compute the next variable.
static constexpr auto coeff(T val) -> scalar_type
Convert coefficients.
Namespace of solvers of ordinary differential equations (ODE).
Definition of problem concept.