3 #include <spdlog/fmt/chrono.h>
16 if (p[0] ==
'\e' && p[1] ==
'[')
21 throw std::runtime_error(
"string terminates inside ANSI colour sequence");
28 void printProgress(
const std::filesystem::path& input_file_path,
size_t percentage,
size_t iteration,
size_t expected_iterations,
29 int estimated_remaining_seconds = -1,
double particle_updates_per_second = -1,
bool finished =
false) {
30 struct winsize size {};
31 ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
33 auto should_progress_bar_length = std::min(std::max(size.ws_col - 90, 0), 100);
34 auto length_full_progress_bar =
static_cast<size_t>(percentage *
static_cast<double>(should_progress_bar_length) / 100.0);
36 auto progress_bar = fmt::format(
"[{}{}]",
ansi_blue_bold + std::string(length_full_progress_bar,
'#'),
37 std::string(should_progress_bar_length - length_full_progress_bar,
' ') +
ansi_end);
39 std::string line = fmt::format(
"{} {}/{} {:>4} ETA: {} MUP/s: {} [{}]", progress_bar, iteration, expected_iterations,
46 line = line.substr(0, size.ws_col - 3) +
"...";
49 std::cout <<
"\33[2K\r" << line << std::flush;
52 std::cout << std::endl;
57 t_start = std::chrono::high_resolution_clock::now();
64 const size_t percentage = std::min(100ul,
static_cast<size_t>(100.0 *
static_cast<double>(simulation.
params.
start_iteration) /
79 auto t_now = std::chrono::high_resolution_clock::now();
80 const double seconds_since_last_write = std::chrono::duration<double>(t_now -
t_prev).count();
84 const int estimated_remaining_seconds = std::floor(seconds_since_last_write *
static_cast<double>(
expected_iterations - iteration) /
88 const size_t percentage =
89 std::min(100ul,
static_cast<size_t>(100.0 *
static_cast<double>(iteration) /
static_cast<double>(
expected_iterations)));
95 double particle_updates_per_second =
static_cast<double>(particle_updates) / seconds_since_last_write;
107 smoothed_particle_updates_per_second);
118 std::string indent = std::string(depth * 2,
' ');
124 ProgressBarInterceptor::operator std::string()
const {
return ""; }
const std::string ansi_bright_white_bold
const std::string ansi_end
const std::string ansi_orange_bold
const std::string ansi_blue_bold
int displayed_width(const char *p)
void printProgress(const std::filesystem::path &input_file_path, size_t percentage, size_t iteration, size_t expected_iterations, int estimated_remaining_seconds=-1, double particle_updates_per_second=-1, bool finished=false)
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
void logSummary(int depth) const override
Logs the summary of the progress bar.
double last_particle_updates_per_second
void onSimulationEnd(size_t iteration, Simulation &simulation) override
This function is empty as the progress bar doesnt need to do anything at the end of the simulation.
void operator()(size_t iteration, Simulation &simulation) override
This function is called on every nth iteration. It prints a progress bar to the console and updates t...
std::chrono::high_resolution_clock::time_point t_start
size_t expected_iterations
double last_remaining_seconds
std::chrono::high_resolution_clock::time_point t_prev
void onSimulationStart(Simulation &simulation) override
This function initalized the start time of the simulation and the previous time point.
size_t last_particle_count
size_t every_nth_iteration
double delta_t
Time step of a single simulation iteration.
std::filesystem::path input_file_path
Path to the input file of the simulation.
size_t start_iteration
Start iteration of the simulation.
double end_time
End time of the simulation.
Class to run a simulation.
std::unique_ptr< ParticleContainer > particle_container
Reference to the ParticleContainer on whose content the simulation is performed.
const SimulationParams & params
Reference to the simulation parameters object.
std::string to_string(const Container &container, const std::string &delimiter=", ", const std::array< std::string, 2 > &surround={"[", "]"})