1#ifndef TATOOINE_ODE_BOOST_SOLVER_H
2#define TATOOINE_ODE_BOOST_SOLVER_H
7#include <boost/numeric/odeint.hpp>
11template <
typename Real,
size_t N>
13 using type = boost::false_type;
14 static const bool value = type::value;
21template <
typename Real,
size_t N,
typename Stepper>
45 template <
arithmetic Y0Real,
typename Evaluator,
49 StepperCallback &&callback)
const {
50 using ::boost::numeric::odeint::step_adjustment_error;
51 constexpr auto callback_takes_derivative =
52 std::is_invocable_v<StepperCallback, pos_type, Real, vec_t>;
59 ::boost::numeric::odeint::integrate_adaptive(
61 [&evaluator, tau, t0, num_same_in_a_row = std::size_t{},
66 if (rel_error < 1e-12) {
69 num_same_in_a_row = 0;
71 if (num_same_in_a_row == 10) {
72 throw step_adjustment_error{
""};
75 sample = evaluator(y, t);
77 x_copy, Real(t0), Real(t0 + tau),
79 [tau, t0, &callback, &evaluator](
const pos_type &y, Real t) {
80 if constexpr (!callback_takes_derivative) {
83 callback(y, t, evaluator(y, t));
86 }
catch (step_adjustment_error
const &) {
87 if constexpr (!callback_takes_derivative) {
90 using derivative_type =
decltype(evaluator(y0, t0));
Definition: concepts.h:33
Definition: controller_runge_kutta_with_domain_check.h:19
Definition: algorithm.h:6
constexpr auto euclidean_length(base_tensor< Tensor, T, N > const &t_in) -> T
Definition: length.h:12
auto nan(const char *arg="")
Definition: nan.h:26
constexpr auto euclidean_distance(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: distance.h:19
boost::false_type type
Definition: solver.h:13
auto stepsize() -> auto &
Definition: solver.h:96
solver(const Stepper &stepper, const Real stepsize)
Definition: solver.h:40
auto stepsize() const
Definition: solver.h:97
Real m_stepsize
Definition: solver.h:32
solver(Stepper &&stepper, const Real stepsize)
Definition: solver.h:42
constexpr void solve(Evaluator &&evaluator, vec< Y0Real, N > const &y0, arithmetic auto const t0, arithmetic auto tau, StepperCallback &&callback) const
Definition: solver.h:47
Stepper m_stepper
Definition: solver.h:31
friend parent_type
Definition: solver.h:36
vec< Real, N > vec_t
Definition: solver.h:56
vec_t pos_type
Definition: solver.h:57