| 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 <cmath> | ||
| 10 | #include <cstddef> | ||
| 11 | #include <ostream> | ||
| 12 | #include <stdexcept> | ||
| 13 | |||
| 14 | #include "oiseau/time/integrator.hpp" | ||
| 15 | #include "oiseau/time/progress_bar.hpp" | ||
| 16 | |||
| 17 | namespace oiseau::time { | ||
| 18 | |||
| 19 | /// Runs a fixed number of equal time steps and returns the final time. | ||
| 20 | template <typename Integrator, typename System, typename State> | ||
| 21 | requires TimeIntegrator<Integrator, System, State> | ||
| 22 | 27 | double run(Integrator& integrator, System& system, State& state, double initial_time, | |
| 23 | double time_step, std::size_t step_count, std::ostream* progress = nullptr) { | ||
| 24 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 13 times.
|
27 | if (!std::isfinite(initial_time)) { |
| 25 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | throw std::invalid_argument("Initial time must be finite"); |
| 26 | } | ||
| 27 |
6/6✓ Branch 1 taken 11 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 9 times.
|
23 | 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 | 15 | ProgressBar bar(progress, step_count); | |
| 32 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
15 | bar.update(0); |
| 33 | 15 | auto time = initial_time; | |
| 34 |
2/2✓ Branch 0 taken 823 times.
✓ Branch 1 taken 9 times.
|
893 | for (std::size_t step = 0; step < step_count; ++step) { |
| 35 |
1/2✓ Branch 1 taken 813 times.
✗ Branch 2 not taken.
|
878 | integrator.step(system, state, time, time_step); |
| 36 | 878 | time += time_step; | |
| 37 |
1/2✓ Branch 1 taken 823 times.
✗ Branch 2 not taken.
|
878 | bar.update(step + 1); |
| 38 | } | ||
| 39 | 15 | return time; | |
| 40 | } | ||
| 41 | |||
| 42 | } // namespace oiseau::time | ||
| 43 |