From def5c9cb2486ffcac322cfc71ca7c75dd3201a62 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 29 Feb 2024 11:43:36 +0100 Subject: [PATCH] AdaptiveTimeStepping: use {fmt} to format messages std::to_string doesn't use generic format and thus small numbers are truncated to 0.0000000 --- .../timestepping/AdaptiveTimeStepping.hpp | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/opm/simulators/timestepping/AdaptiveTimeStepping.hpp b/opm/simulators/timestepping/AdaptiveTimeStepping.hpp index 26e3b3b4f..a3fa7df13 100644 --- a/opm/simulators/timestepping/AdaptiveTimeStepping.hpp +++ b/opm/simulators/timestepping/AdaptiveTimeStepping.hpp @@ -34,6 +34,8 @@ #include #include +#include + #include #include #include @@ -436,16 +438,19 @@ std::set consistentlyFailingWells(const std::vector& sr report += substepReport; - bool continue_on_uncoverged_solution = ignoreConvergenceFailure_ && !substepReport.converged && dt <= minTimeStep_; + bool continue_on_uncoverged_solution = ignoreConvergenceFailure_ && + !substepReport.converged && + dt <= minTimeStep_; - if (continue_on_uncoverged_solution) { - const auto msg = std::string("Solver failed to converge but timestep ") - + std::to_string(dt) + " is smaller or equal to " - + std::to_string(minTimeStep_) + "\n which is the minimum threshold given" - + "by option --solver-min-time-step= \n"; - if (solverVerbose_) { - OpmLog::problem(msg); - } + if (continue_on_uncoverged_solution && solverVerbose_) { + const auto msg = fmt::format( + "Solver failed to converge but timestep " + "{} is smaller or equal to {}\n" + "which is the minimum threshold given " + "by option --solver-min-time-step\n", + dt, minTimeStep_ + ); + OpmLog::problem(msg); } if (substepReport.converged || continue_on_uncoverged_solution) { @@ -515,8 +520,10 @@ std::set consistentlyFailingWells(const std::vector& sr // If we have restarted (i.e. cut the timestep) too // many times, we have failed and throw an exception. if (restarts >= solverRestartMax_) { - const auto msg = std::string("Solver failed to converge after cutting timestep ") - + std::to_string(restarts) + " times."; + const auto msg = fmt::format( + "Solver failed to converge after cutting timestep {} times.", + restarts + ); if (solverVerbose_) { OpmLog::error(msg); } @@ -531,9 +538,11 @@ std::set consistentlyFailingWells(const std::vector& sr // If we have restarted (i.e. cut the timestep) too // much, we have failed and throw an exception. if (newTimeStep < minTimeStep_) { - const auto msg = std::string("Solver failed to converge after cutting timestep to ") - + std::to_string(minTimeStep_) + "\n which is the minimum threshold given" - + "by option --solver-min-time-step= \n"; + const auto msg = fmt::format( + "Solver failed to converge after cutting timestep to {}\n" + "which is the minimum threshold given by option --solver-min-time-step\n", + minTimeStep_ + ); if (solverVerbose_) { OpmLog::error(msg); } @@ -545,9 +554,11 @@ std::set consistentlyFailingWells(const std::vector& sr auto chopTimestep = [&]() { substepTimer.provideTimeStepEstimate(newTimeStep); if (solverVerbose_) { - std::string msg; - msg = causeOfFailure + "\nTimestep chopped to " - + std::to_string(unit::convert::to(substepTimer.currentStepLength(), unit::day)) + " days\n"; + const auto msg = fmt::format( + "{}\nTimestep chopped to {} days\n", + causeOfFailure, + std::to_string(unit::convert::to(substepTimer.currentStepLength(), unit::day)) + ); OpmLog::problem(msg); } ++restarts; @@ -837,16 +848,16 @@ std::set consistentlyFailingWells(const std::vector& sr double restartFactor_; //!< factor to multiply time step with when solver fails to converge double growthFactor_; //!< factor to multiply time step when solver recovered from failed convergence double maxGrowth_; //!< factor that limits the maximum growth of a time step - double maxTimeStep_; //!< maximal allowed time step size in days - double minTimeStep_; //!< minimal allowed time step size before throwing - bool ignoreConvergenceFailure_; //!< continue instead of stop when minimum time step is reached - int solverRestartMax_; //!< how many restart of solver are allowed - bool solverVerbose_; //!< solver verbosity - bool timestepVerbose_; //!< timestep verbosity - double suggestedNextTimestep_; //!< suggested size of next timestep - bool fullTimestepInitially_; //!< beginning with the size of the time step from data file - double timestepAfterEvent_; //!< suggested size of timestep after an event - bool useNewtonIteration_; //!< use newton iteration count for adaptive time step control + double maxTimeStep_; //!< maximal allowed time step size in days + double minTimeStep_; //!< minimal allowed time step size before throwing + bool ignoreConvergenceFailure_; //!< continue instead of stop when minimum time step is reached + int solverRestartMax_; //!< how many restart of solver are allowed + bool solverVerbose_; //!< solver verbosity + bool timestepVerbose_; //!< timestep verbosity + double suggestedNextTimestep_; //!< suggested size of next timestep + bool fullTimestepInitially_; //!< beginning with the size of the time step from data file + double timestepAfterEvent_; //!< suggested size of timestep after an event + bool useNewtonIteration_; //!< use newton iteration count for adaptive time step control double minTimeStepBeforeShuttingProblematicWells_; //! < shut problematic wells when time step size in days are less than this }; }