OISEAU
A modern DGTD framework
Loading...
Searching...
No Matches
run.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 <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
17namespace oiseau::time {
18
20template <typename Integrator, typename System, typename State>
22double run(Integrator& integrator, System& system, State& state, double initial_time,
23 double time_step, std::size_t step_count, std::ostream* progress = nullptr) {
24 if (!std::isfinite(initial_time)) {
25 throw std::invalid_argument("Initial 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 ProgressBar bar(progress, step_count);
32 bar.update(0);
33 auto time = initial_time;
34 for (std::size_t step = 0; step < step_count; ++step) {
35 integrator.step(system, state, time, time_step);
36 time += time_step;
37 bar.update(step + 1);
38 }
39 return time;
40}
41
42} // namespace oiseau::time
Prints a bounded number of updates on one terminal line.
Definition progress_bar.hpp:15
Definition integrator.hpp:25