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/TimeStepControlInterface.hpp>
#include <fmt/format.h>
#include <algorithm>
#include <cassert>
#include <cmath>
@ -436,17 +438,20 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& 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_) {
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<std::string> consistentlyFailingWells(const std::vector<StepReport>& 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<std::string> consistentlyFailingWells(const std::vector<StepReport>& 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<std::string> consistentlyFailingWells(const std::vector<StepReport>& 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;