From b74b870cae0da8948afa8f63533e44864aa54f1f Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Thu, 29 Aug 2024 11:50:42 +0200 Subject: [PATCH] [NL|PL] High precision output for Time --- NumLib/TimeStepping/Time.h | 17 +++++++++++++++++ ProcessLib/TimeLoop.cpp | 14 +++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/NumLib/TimeStepping/Time.h b/NumLib/TimeStepping/Time.h index eb4e3ead45b..5add39bfeda 100644 --- a/NumLib/TimeStepping/Time.h +++ b/NumLib/TimeStepping/Time.h @@ -19,7 +19,16 @@ namespace NumLib { +struct Time; +} +template <> +struct fmt::formatter<NumLib::Time> : fmt::ostream_formatter +{ +}; + +namespace NumLib +{ struct Time { constexpr explicit Time(double const time) : value_{time} {} @@ -80,6 +89,14 @@ struct Time return (*this <=> x) == std::weak_ordering::equivalent; } + friend inline std::ostream& operator<<(std::ostream& os, Time const& t) + { + auto const precision = os.precision(); + return os << std::setprecision( + std::numeric_limits<double>::max_digits10) + << t() << std::setprecision(precision); + } + private: MathLib::KahanSum value_; }; diff --git a/ProcessLib/TimeLoop.cpp b/ProcessLib/TimeLoop.cpp index d66fe2343b2..1b6d125e2d7 100644 --- a/ProcessLib/TimeLoop.cpp +++ b/ProcessLib/TimeLoop.cpp @@ -519,9 +519,9 @@ bool TimeLoop::executeTimeStep() const std::size_t timesteps = _accepted_steps + 1; // TODO(wenqing): , input option for time unit. INFO( - "=== Time stepping at step #{:d} and time {:.18g} with step size " + "=== Time stepping at step #{:d} and time {} with step size " "{:.18g}", - timesteps, _current_time(), _dt); + timesteps, _current_time, _dt); updateDeactivatedSubdomains(_per_process_data, _current_time()); @@ -555,8 +555,8 @@ bool TimeLoop::calculateNextTimeStep() if (current_time == (_current_time + _dt)) { ERR("Time step size of {:.18g} is too small.\n" - "Time stepping stops at step {:d} and at time of {:.18g}.", - _dt, timesteps, _current_time()); + "Time stepping stops at step {:d} and at time of {}.", + _dt, timesteps, _current_time); return false; } @@ -656,9 +656,9 @@ NumLib::NonlinearSolverStatus TimeLoop::solveUncoupledEquationSystems( process_data->nonlinear_solver_status = nonlinear_solver_status; if (!nonlinear_solver_status.error_norms_met) { - ERR("The nonlinear solver failed in time step #{:d} at t = {:.18g} " - "s for process #{:d}.", - timestep_id, t(), process_id); + ERR("The nonlinear solver failed in time step #{:d} at t = {} s " + "for process #{:d}.", + timestep_id, t, process_id); if (!process_data->timestep_algorithm->canReduceTimestepSize( process_data->timestep_current, -- GitLab