numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
simple_solver.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
25#include "num_collect/constants/zero.h" // IWYU pragma: keep
30
31namespace num_collect::ode {
32
38template <concepts::formula Formula>
39class simple_solver : public solver_base<simple_solver<Formula>, Formula> {
40public:
43
46
47 using typename base_type::formula_type;
48 using typename base_type::problem_type;
49 using typename base_type::scalar_type;
50 using typename base_type::variable_type;
51
52 using base_type::base_type;
55
58 time_ = time;
60 steps_ = 0;
61 }
62
70
74 const {
75 iteration_logger.template append<index_type>(
76 "Steps", &this_type::steps);
77 iteration_logger.template append<scalar_type>("Time", &this_type::time);
78 iteration_logger.template append<scalar_type>("StepSize",
79 static_cast<scalar_type (this_type::*)() const>(
81 }
82
84 [[nodiscard]] auto time() const -> scalar_type { return time_; }
85
87 [[nodiscard]] auto variable() const -> const variable_type& {
88 return variable_;
89 }
90
92 [[nodiscard]] auto step_size() const -> scalar_type { return step_size_; }
93
95 [[nodiscard]] auto steps() const -> index_type { return steps_; }
96
99 NUM_COLLECT_PRECONDITION(val > static_cast<scalar_type>(0),
100 "Step size must be a positive value.");
101 step_size_ = val;
102 return *this;
103 }
104
105private:
108
111
113 static constexpr auto default_step_size = static_cast<scalar_type>(1e-4);
114
117
120
123};
124
125} // namespace num_collect::ode
Class of simple solver of ODEs.
void step()
Compute the variable of the next step.
typename problem_type::variable_type variable_type
auto step_size(scalar_type val) -> this_type &
Set the step size.
void init(scalar_type time, const variable_type &variable)
Initialize.
auto formula() -> formula_type &
Get the formula.
auto steps() const -> index_type
Get the number of steps.
auto step_size() const -> scalar_type
Get the step size.
solver_base< simple_solver< Formula >, Formula > base_type
void configure_iteration_logger(logging::iterations::iteration_logger< this_type > &iteration_logger) const
Configure an iteration logger.
Definition of exceptions.
Definition of formula concept.
Definition of index_type type.
Definition of iteration_logger class.
Definition of macros for logging.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
Namespace of solvers of ordinary differential equations (ODE).
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 solver_base class.
Definition of zero.