23 using state_type =
typename base_type::state_type;
24 using time_type =
typename base_type::time_type;
25 using value_type =
typename base_type::value_type;
26 using system_function =
typename base_type::system_function;
29 time_type rtol =
static_cast<time_type
>(1e-6),
30 time_type atol =
static_cast<time_type
>(1e-9))
31 :
base_type(std::move(sys), rtol, atol) {}
33 void step(state_type& state, time_type dt)
override {
34 adaptive_step(state, dt);
37 time_type adaptive_step(state_type& state, time_type dt)
override {
50 constexpr time_type a2 =
static_cast<time_type
>(1.0/5.0);
51 constexpr time_type a3 =
static_cast<time_type
>(3.0/10.0);
52 constexpr time_type a4 =
static_cast<time_type
>(4.0/5.0);
53 constexpr time_type a5 =
static_cast<time_type
>(8.0/9.0);
55 constexpr time_type b21 =
static_cast<time_type
>(1.0/5.0);
56 constexpr time_type b31 =
static_cast<time_type
>(3.0/40.0);
57 constexpr time_type b32 =
static_cast<time_type
>(9.0/40.0);
58 constexpr time_type b41 =
static_cast<time_type
>(44.0/45.0);
59 constexpr time_type b42 =
static_cast<time_type
>(-56.0/15.0);
60 constexpr time_type b43 =
static_cast<time_type
>(32.0/9.0);
61 constexpr time_type b51 =
static_cast<time_type
>(19372.0/6561.0);
62 constexpr time_type b52 =
static_cast<time_type
>(-25360.0/2187.0);
63 constexpr time_type b53 =
static_cast<time_type
>(64448.0/6561.0);
64 constexpr time_type b54 =
static_cast<time_type
>(-212.0/729.0);
65 constexpr time_type b61 =
static_cast<time_type
>(9017.0/3168.0);
66 constexpr time_type b62 =
static_cast<time_type
>(-355.0/33.0);
67 constexpr time_type b63 =
static_cast<time_type
>(46732.0/5247.0);
68 constexpr time_type b64 =
static_cast<time_type
>(49.0/176.0);
69 constexpr time_type b65 =
static_cast<time_type
>(-5103.0/18656.0);
72 constexpr time_type c1 =
static_cast<time_type
>(35.0/384.0);
73 constexpr time_type c3 =
static_cast<time_type
>(500.0/1113.0);
74 constexpr time_type c4 =
static_cast<time_type
>(125.0/192.0);
75 constexpr time_type c5 =
static_cast<time_type
>(-2187.0/6784.0);
76 constexpr time_type c6 =
static_cast<time_type
>(11.0/84.0);
79 constexpr time_type c1_4 =
static_cast<time_type
>(5179.0/57600.0);
80 constexpr time_type c3_4 =
static_cast<time_type
>(7571.0/16695.0);
81 constexpr time_type c4_4 =
static_cast<time_type
>(393.0/640.0);
82 constexpr time_type c5_4 =
static_cast<time_type
>(-92097.0/339200.0);
83 constexpr time_type c6_4 =
static_cast<time_type
>(187.0/2100.0);
87 this->sys_(this->current_time_, state, k1);
90 for (std::size_t i = 0; i < state.size(); ++i) {
91 temp_state[i] = state[i] + dt * b21 * k1[i];
93 this->sys_(this->current_time_ + a2 * dt, temp_state, k2);
96 for (std::size_t i = 0; i < state.size(); ++i) {
97 temp_state[i] = state[i] + dt * (b31 * k1[i] + b32 * k2[i]);
99 this->sys_(this->current_time_ + a3 * dt, temp_state, k3);
102 for (std::size_t i = 0; i < state.size(); ++i) {
103 temp_state[i] = state[i] + dt * (b41 * k1[i] + b42 * k2[i] + b43 * k3[i]);
105 this->sys_(this->current_time_ + a4 * dt, temp_state, k4);
108 for (std::size_t i = 0; i < state.size(); ++i) {
109 temp_state[i] = state[i] + dt * (b51 * k1[i] + b52 * k2[i] + b53 * k3[i] + b54 * k4[i]);
111 this->sys_(this->current_time_ + a5 * dt, temp_state, k5);
114 for (std::size_t i = 0; i < state.size(); ++i) {
115 temp_state[i] = state[i] + dt * (b61 * k1[i] + b62 * k2[i] + b63 * k3[i] + b64 * k4[i] + b65 * k5[i]);
117 this->sys_(this->current_time_ + dt, temp_state, k6);
120 for (std::size_t i = 0; i < state.size(); ++i) {
121 y_new[i] = state[i] + dt * (c1 * k1[i] + c3 * k3[i] + c4 * k4[i] + c5 * k5[i] + c6 * k6[i]);
125 for (std::size_t i = 0; i < state.size(); ++i) {
126 error[i] = dt * ((c1 - c1_4) * k1[i] + (c3 - c3_4) * k3[i] + (c4 - c4_4) * k4[i] +
127 (c5 - c5_4) * k5[i] + (c6 - c6_4) * k6[i]);
131 time_type error_norm = this->error_norm_scipy_style(error, state, y_new);
134 if (error_norm <=
static_cast<time_type
>(1.0)) {
137 this->advance_time(dt);
140 time_type new_dt = this->suggest_step_size(dt, error_norm, 5);
144 time_type new_dt = this->suggest_step_size(dt, error_norm, 5);