Improve error message when time step is cut too often/much.

Changes
```
Program threw an exception: [/home/mblatt/src/dune/opm/opm-simulators/opm/simulators/timestepping/AdaptiveTimeSteppingEbos.hpp:586] Solver failed to converge after cutting timestep 11 times.
```
to
```
Simulation aborted: Solver failed to converge after cutting timestep 11 times.
```

Which seems more user friendly.
This commit is contained in:
Markus Blatt 2023-07-12 13:56:14 +02:00
parent 9f87301ff4
commit fc9b1cccce
2 changed files with 30 additions and 20 deletions

View File

@ -324,6 +324,27 @@ void handleExtraConvergenceOutput(SimulatorReport& report,
// called by execute() or executeInitStep()
int execute_(int (FlowMainEbos::* runOrInitFunc)(), bool cleanup)
{
auto logger = [this](const std::exception& e, const std::string& message_start) {
std::ostringstream message;
message << message_start << e.what();
if (this->output_cout_) {
// in some cases exceptions are thrown before the logging system is set
// up.
if (OpmLog::hasBackend("STREAMLOG")) {
OpmLog::error(message.str());
}
else {
std::cout << message.str() << "\n";
}
}
#if HAVE_MPI
if (this->mpi_size_ > 1)
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
#endif
return EXIT_FAILURE;
};
try {
// deal with some administrative boilerplate
@ -342,25 +363,11 @@ void handleExtraConvergenceOutput(SimulatorReport& report,
}
return exitCode;
}
catch (const LinearTimeSteppingBreakdown& e) {
return logger(e, "Simulation aborted: ");
}
catch (const std::exception& e) {
std::ostringstream message;
message << "Program threw an exception: " << e.what();
if (this->output_cout_) {
// in some cases exceptions are thrown before the logging system is set
// up.
if (OpmLog::hasBackend("STREAMLOG")) {
OpmLog::error(message.str());
}
else {
std::cout << message.str() << "\n";
}
}
#if HAVE_MPI
if (this->mpi_size_ > 1)
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
#endif
return EXIT_FAILURE;
return logger(e, "Simulation aborted as program threw an unexpected exception: ");
}
}

View File

@ -446,6 +446,7 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& sr
std::string causeOfFailure;
try {
substepReport = solver.step(substepTimer);
if (solverVerbose_) {
// report number of linear iterations
OpmLog::debug("Overall linear iterations used: " + std::to_string(substepReport.total_linear_iterations));
@ -580,7 +581,8 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& sr
if (solverVerbose_) {
OpmLog::error(msg);
}
OPM_THROW_NOLOG(NumericalProblem, msg);
// Use throw directly to prevent file and line
throw LinearTimeSteppingBreakdown{msg};
}
// The new, chopped timestep.
@ -596,7 +598,8 @@ std::set<std::string> consistentlyFailingWells(const std::vector<StepReport>& sr
if (solverVerbose_) {
OpmLog::error(msg);
}
OPM_THROW_NOLOG(NumericalProblem, msg);
// Use throw directly to prevent file and line
throw LinearTimeSteppingBreakdown{msg};
}
// Define utility function for chopping timestep.