AdaptiveTimeStepping: use {fmt} to format messages

std::to_string doesn't use generic format and thus small numbers
are truncated to 0.0000000
This commit is contained in:
Arne Morten Kvarving 2024-02-29 11:43:36 +01:00
parent 5bafd76b94
commit def5c9cb24

View File

@ -34,6 +34,8 @@
#include <opm/simulators/timestepping/TimeStepControl.hpp> #include <opm/simulators/timestepping/TimeStepControl.hpp>
#include <opm/simulators/timestepping/TimeStepControlInterface.hpp> #include <opm/simulators/timestepping/TimeStepControlInterface.hpp>
#include <fmt/format.h>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
@ -436,16 +438,19 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& sr
report += substepReport; 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) { if (continue_on_uncoverged_solution && solverVerbose_) {
const auto msg = std::string("Solver failed to converge but timestep ") const auto msg = fmt::format(
+ std::to_string(dt) + " is smaller or equal to " "Solver failed to converge but timestep "
+ std::to_string(minTimeStep_) + "\n which is the minimum threshold given" "{} is smaller or equal to {}\n"
+ "by option --solver-min-time-step= \n"; "which is the minimum threshold given "
if (solverVerbose_) { "by option --solver-min-time-step\n",
OpmLog::problem(msg); dt, minTimeStep_
} );
OpmLog::problem(msg);
} }
if (substepReport.converged || continue_on_uncoverged_solution) { if (substepReport.converged || continue_on_uncoverged_solution) {
@ -515,8 +520,10 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& sr
// If we have restarted (i.e. cut the timestep) too // If we have restarted (i.e. cut the timestep) too
// many times, we have failed and throw an exception. // many times, we have failed and throw an exception.
if (restarts >= solverRestartMax_) { if (restarts >= solverRestartMax_) {
const auto msg = std::string("Solver failed to converge after cutting timestep ") const auto msg = fmt::format(
+ std::to_string(restarts) + " times."; "Solver failed to converge after cutting timestep {} times.",
restarts
);
if (solverVerbose_) { if (solverVerbose_) {
OpmLog::error(msg); OpmLog::error(msg);
} }
@ -531,9 +538,11 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& sr
// If we have restarted (i.e. cut the timestep) too // If we have restarted (i.e. cut the timestep) too
// much, we have failed and throw an exception. // much, we have failed and throw an exception.
if (newTimeStep < minTimeStep_) { if (newTimeStep < minTimeStep_) {
const auto msg = std::string("Solver failed to converge after cutting timestep to ") const auto msg = fmt::format(
+ std::to_string(minTimeStep_) + "\n which is the minimum threshold given" "Solver failed to converge after cutting timestep to {}\n"
+ "by option --solver-min-time-step= \n"; "which is the minimum threshold given by option --solver-min-time-step\n",
minTimeStep_
);
if (solverVerbose_) { if (solverVerbose_) {
OpmLog::error(msg); OpmLog::error(msg);
} }
@ -545,9 +554,11 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& sr
auto chopTimestep = [&]() { auto chopTimestep = [&]() {
substepTimer.provideTimeStepEstimate(newTimeStep); substepTimer.provideTimeStepEstimate(newTimeStep);
if (solverVerbose_) { if (solverVerbose_) {
std::string msg; const auto msg = fmt::format(
msg = causeOfFailure + "\nTimestep chopped to " "{}\nTimestep chopped to {} days\n",
+ std::to_string(unit::convert::to(substepTimer.currentStepLength(), unit::day)) + " days\n"; causeOfFailure,
std::to_string(unit::convert::to(substepTimer.currentStepLength(), unit::day))
);
OpmLog::problem(msg); OpmLog::problem(msg);
} }
++restarts; ++restarts;
@ -837,16 +848,16 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& sr
double restartFactor_; //!< factor to multiply time step with when solver fails to converge 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 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 maxGrowth_; //!< factor that limits the maximum growth of a time step
double maxTimeStep_; //!< maximal allowed time step size in days double maxTimeStep_; //!< maximal allowed time step size in days
double minTimeStep_; //!< minimal allowed time step size before throwing double minTimeStep_; //!< minimal allowed time step size before throwing
bool ignoreConvergenceFailure_; //!< continue instead of stop when minimum time step is reached bool ignoreConvergenceFailure_; //!< continue instead of stop when minimum time step is reached
int solverRestartMax_; //!< how many restart of solver are allowed int solverRestartMax_; //!< how many restart of solver are allowed
bool solverVerbose_; //!< solver verbosity bool solverVerbose_; //!< solver verbosity
bool timestepVerbose_; //!< timestep verbosity bool timestepVerbose_; //!< timestep verbosity
double suggestedNextTimestep_; //!< suggested size of next timestep double suggestedNextTimestep_; //!< suggested size of next timestep
bool fullTimestepInitially_; //!< beginning with the size of the time step from data file bool fullTimestepInitially_; //!< beginning with the size of the time step from data file
double timestepAfterEvent_; //!< suggested size of timestep after an event double timestepAfterEvent_; //!< suggested size of timestep after an event
bool useNewtonIteration_; //!< use newton iteration count for adaptive time step control 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 double minTimeStepBeforeShuttingProblematicWells_; //! < shut problematic wells when time step size in days are less than this
}; };
} }