Tatooine
solver.h
Go to the documentation of this file.
1#ifndef TATOOINE_ODE_SOLVER_H
2#define TATOOINE_ODE_SOLVER_H
3//==============================================================================
4#include <cassert>
5#include <tatooine/concepts.h>
6#include <map>
7#include <tatooine/field.h>
8#include <tatooine/line.h>
9//==============================================================================
10namespace tatooine::ode {
11//==============================================================================
12template <typename F, typename Real, size_t N>
14 : std::integral_constant<
15 bool, std::is_invocable_v<F, vec<Real, N> const&, Real,
16 vec<Real, N> const&> ||
17 std::is_invocable_v<F, vec<Real, N> const&, Real>> {};
18template <typename F, typename Real, size_t N>
20 : std::integral_constant<
21 bool,
22 !std::is_base_of_v<polymorphic::vectorfield<Real, N>, std::decay_t<F>> &&
23 std::is_invocable_v<F, vec<Real, N> const&, Real> &&
24 (std::is_same_v<vec<Real, N>,
25 std::invoke_result_t<F, vec<Real, N>, Real>> ||
26 std::is_same_v<std::optional<vec<Real, N>>,
27 std::invoke_result_t<F, vec<Real, N>, Real>>)> {};
28
29template <typename F, typename Real, size_t N>
30static constexpr auto is_stepper_callback_invocable =
32
33template <typename F, typename Real, size_t N>
34static constexpr auto is_stepper_evaluator =
36template <typename F, typename Real, size_t N>
38 std::regular_invocable<F, vec<Real, N> const&, Real, vec<Real, N> const&> ||
39 std::regular_invocable<F, vec<Real, N> const&, Real>;
40template <typename F, typename Real, size_t N>
42 !std::is_base_of_v<polymorphic::vectorfield<Real, N>, std::decay_t<F>> &&
43 std::regular_invocable<F, vec<Real, N> const&, Real> &&
44 (std::is_same_v<vec<Real, N>,
45 std::invoke_result_t<F, vec<Real, N>, Real>> ||
46 std::is_same_v<std::optional<vec<Real, N>>,
47 std::invoke_result_t<F, vec<Real, N>, Real>>);
48//==============================================================================
49template <typename Derived, typename Real, size_t N>
50struct solver : crtp<Derived> {
51 //----------------------------------------------------------------------------
52 // typedefs
53 //----------------------------------------------------------------------------
57 using pos_type = vec_t;
58
59 //----------------------------------------------------------------------------
60 // methods
61 //----------------------------------------------------------------------------
62 template <typename V, std::floating_point VReal, arithmetic Y0Real,
63 arithmetic T0Real, arithmetic TauReal,
65 constexpr auto solve(vectorfield<V, VReal, N> const& v, vec<Y0Real, N>& y0,
66 T0Real t0, TauReal tau,
67 StepperCallback&& callback) const {
68 as_derived().solve(v, y0, t0, tau, std::forward<StepperCallback>(callback));
69 }
70 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
71 template <arithmetic Y0Real, arithmetic T0Real, arithmetic TauReal,
74 constexpr auto solve(Evaluator&& evaluator, vec<Y0Real, N>& y0, T0Real t0,
75 TauReal tau, StepperCallback&& callback) const {
76 as_derived().solve(std::forward<Evaluator>(evaluator), y0, t0, tau,
77 std::forward<StepperCallback>(callback));
78 }
79 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80 template <std::size_t K, arithmetic Y0Real, arithmetic T0Real, arithmetic TauReal,
83 constexpr auto solve(Evaluator&& evaluator, mat<Y0Real, N, K>& y0s, T0Real t0,
84 TauReal tau, StepperCallback&& callback) const {
85 as_derived().solve(std::forward<Evaluator>(evaluator), y0s, t0, tau,
86 std::forward<StepperCallback>(callback));
87 }
88};
89//==============================================================================
90} // namespace tatooine::ode
91//==============================================================================
92#endif
Definition: concepts.h:33
Definition: solver.h:41
Definition: controller_runge_kutta_with_domain_check.h:19
static constexpr auto is_stepper_evaluator
Definition: solver.h:34
static constexpr auto is_stepper_callback_invocable
Definition: solver.h:30
Definition: crtp.h:7
constexpr auto as_derived() -> derived_type &
returns casted as_derived data
Definition: crtp.h:11
Definition: field.h:134
Definition: mat.h:14
Definition: solver.h:50
vec< Real, N > vec_t
Definition: solver.h:56
constexpr auto as_derived() -> derived_type &
returns casted as_derived data
Definition: crtp.h:11
constexpr auto solve(vectorfield< V, VReal, N > const &v, vec< Y0Real, N > &y0, T0Real t0, TauReal tau, StepperCallback &&callback) const
Definition: solver.h:65
constexpr auto solve(Evaluator &&evaluator, mat< Y0Real, N, K > &y0s, T0Real t0, TauReal tau, StepperCallback &&callback) const
Definition: solver.h:83
constexpr auto solve(Evaluator &&evaluator, vec< Y0Real, N > &y0, T0Real t0, TauReal tau, StepperCallback &&callback) const
Definition: solver.h:74