22 template <
typename System, ScaleAddInPlaceState State>
23 static void step(System& system, State& state,
double time,
double time_step) {
24 if (!std::isfinite(time)) {
25 throw std::invalid_argument(
"Time must be finite");
27 if (!std::isfinite(time_step) || time_step <= 0.0) {
28 throw std::invalid_argument(
"Time step must be finite and positive");
31 auto residual = detail::evaluate_rhs(system, time, state);
32 scale_add_in_place(residual, 0.0, residual, time_step);
33 scale_add_in_place(state, 1.0, residual, b[0]);
35 for (std::size_t stage = 1; stage < a.size(); ++stage) {
36 const auto derivative = detail::evaluate_rhs(system, time + c[stage] * time_step, state);
37 scale_add_in_place(residual, a[stage], derivative, time_step);
38 scale_add_in_place(state, 1.0, residual, b[stage]);
44 static constexpr std::array<double, 5> a = {
46 -567301805773.0 / 1357537059087.0,
47 -2404267990393.0 / 2016746695238.0,
48 -3550918686646.0 / 2091501179385.0,
49 -1275806237668.0 / 842570457699.0,
51 static constexpr std::array<double, 5> b = {
52 1432997174477.0 / 9575080441755.0, 5161836677717.0 / 13612068292357.0,
53 1720146321549.0 / 2090206949498.0, 3134564353537.0 / 4481467310338.0,
54 2277821191437.0 / 14882151754819.0,
56 static constexpr std::array<double, 5> c = {
58 1432997174477.0 / 9575080441755.0,
59 2526269341429.0 / 6820363962896.0,
60 2006345519317.0 / 3224310063776.0,
61 2802321613138.0 / 2924317926251.0,