| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (C) 2026 Tiago V. L. Amorim (@tiagovla) | ||
| 2 | // | ||
| 3 | // This file is part of oiseau (https://github.com/tiagovla/oiseau) | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 6 | |||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <array> | ||
| 10 | #include <cmath> | ||
| 11 | #include <cstddef> | ||
| 12 | #include <stdexcept> | ||
| 13 | |||
| 14 | #include "oiseau/time/detail/rhs.hpp" | ||
| 15 | #include "oiseau/time/integrator.hpp" | ||
| 16 | |||
| 17 | namespace oiseau::time { | ||
| 18 | |||
| 19 | /// Five-stage, fourth-order low-storage Runge-Kutta scheme | ||
| 20 | class LSRK54 { | ||
| 21 | public: | ||
| 22 | template <typename System, ScaleAddInPlaceState State> | ||
| 23 | 66 | static void step(System& system, State& state, double time, double time_step) { | |
| 24 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 31 times.
|
66 | if (!std::isfinite(time)) { |
| 25 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | throw std::invalid_argument("Time must be finite"); |
| 26 | } | ||
| 27 |
6/6✓ Branch 1 taken 29 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 27 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 27 times.
|
62 | if (!std::isfinite(time_step) || time_step <= 0.0) { |
| 28 |
1/2✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
8 | throw std::invalid_argument("Time step must be finite and positive"); |
| 29 | } | ||
| 30 | |||
| 31 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
54 | auto residual = detail::evaluate_rhs(system, time, state); |
| 32 | 54 | scale_add_in_place(residual, 0.0, residual, time_step); | |
| 33 | 54 | scale_add_in_place(state, 1.0, residual, b[0]); | |
| 34 | |||
| 35 |
3/3✓ Branch 0 taken 68 times.
✓ Branch 1 taken 57 times.
✓ Branch 2 taken 10 times.
|
540 | for (std::size_t stage = 1; stage < a.size(); ++stage) { |
| 36 |
1/2✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
|
216 | const auto derivative = detail::evaluate_rhs(system, time + c[stage] * time_step, state); |
| 37 | 216 | scale_add_in_place(residual, a[stage], derivative, time_step); | |
| 38 | 216 | scale_add_in_place(state, 1.0, residual, b[stage]); | |
| 39 | } | ||
| 40 | 54 | } | |
| 41 | |||
| 42 | private: | ||
| 43 | // The a, b, and c coefficients match nodaldg.utils.integration.rk45. | ||
| 44 | static constexpr std::array<double, 5> a = { | ||
| 45 | 0.0, | ||
| 46 | -567301805773.0 / 1357537059087.0, | ||
| 47 | -2404267990393.0 / 2016746695238.0, | ||
| 48 | -3550918686646.0 / 2091501179385.0, | ||
| 49 | -1275806237668.0 / 842570457699.0, | ||
| 50 | }; | ||
| 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, | ||
| 55 | }; | ||
| 56 | static constexpr std::array<double, 5> c = { | ||
| 57 | 0.0, | ||
| 58 | 1432997174477.0 / 9575080441755.0, | ||
| 59 | 2526269341429.0 / 6820363962896.0, | ||
| 60 | 2006345519317.0 / 3224310063776.0, | ||
| 61 | 2802321613138.0 / 2924317926251.0, | ||
| 62 | }; | ||
| 63 | }; | ||
| 64 | |||
| 65 | } // namespace oiseau::time | ||
| 66 |