OISEAU
A modern DGTD framework
Loading...
Searching...
No Matches
lsrk54.hpp
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
17namespace oiseau::time {
18
20class LSRK54 {
21 public:
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");
26 }
27 if (!std::isfinite(time_step) || time_step <= 0.0) {
28 throw std::invalid_argument("Time step must be finite and positive");
29 }
30
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]);
34
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]);
39 }
40 }
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
Five-stage, fourth-order low-storage Runge-Kutta scheme.
Definition lsrk54.hpp:20