Merge pull request #5237 from akva2/timestepping_use_fmt

AdaptiveTimeStepping: use {fmt} to format messages
This commit is contained in:
Markus Blatt 2024-02-29 14:25:26 +01:00 committed by GitHub
commit bb85fc9939
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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,17 +438,20 @@ 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",
dt, minTimeStep_
);
OpmLog::problem(msg); 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;