numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
step_size_limits.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 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
22#include <limits>
23
29
30namespace num_collect::ode {
31
32namespace impl {
33
39template <base::concepts::real_scalar Scalar>
40constexpr auto default_step_size_upper_limit = static_cast<Scalar>(1);
41
47template <base::concepts::real_scalar Scalar>
49 constants::sqrt(std::numeric_limits<Scalar>::epsilon());
50
51} // namespace impl
52
58template <base::concepts::real_scalar Scalar>
60public:
62 using scalar_type = Scalar;
63
67 constexpr step_size_limits() = default;
68
75 [[nodiscard]] auto apply(scalar_type val) const -> scalar_type {
76 if (val < lower_limit_) {
77 return lower_limit_;
78 }
79 if (val > upper_limit_) {
80 return upper_limit_;
81 }
82 return val;
83 }
84
90 [[nodiscard]] auto upper_limit() const -> const scalar_type& {
91 return upper_limit_;
92 }
93
99 [[nodiscard]] auto lower_limit() const -> const scalar_type& {
100 return lower_limit_;
101 }
102
111 "0 < lower_limit < upper_limit must be satisfied.");
112 upper_limit_ = val;
113 return *this;
114 }
115
124 static_cast<scalar_type>(0) < val && val < upper_limit_,
125 "0 < lower_limit < upper_limit must be satisfied.");
126 lower_limit_ = val;
127 return *this;
128 }
129
130private:
133
136};
137
138} // namespace num_collect::ode
Class of limits of step sizes.
constexpr step_size_limits()=default
Constructor.
auto lower_limit(const scalar_type &val) -> step_size_limits &
Set the lower limit.
auto apply(scalar_type val) const -> scalar_type
Apply the limit of this object.
scalar_type upper_limit_
Upper limit.
scalar_type lower_limit_
Lower limit.
auto upper_limit(const scalar_type &val) -> step_size_limits &
Set the upper limit.
auto lower_limit() const -> const scalar_type &
Get the lower limit.
auto upper_limit() const -> const scalar_type &
Get the upper limit.
Definition of exceptions.
Definition of macros for logging.
constexpr auto sqrt(F x) -> F
Calculate square root .
Definition sqrt.h:44
constexpr Scalar default_step_size_lower_limit
Default lower limit of the step size.
constexpr auto default_step_size_upper_limit
Default upper limit of the step size.
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 real_scalar concept.
Definition of sqrt function.