Stop simulating if the schedule has set an exit condition.

The program will return the value set in the EXIT keyword.
This commit is contained in:
Atgeirr Flø Rasmussen 2020-04-15 15:21:17 +02:00
parent 88525f7c39
commit a1091bd718
4 changed files with 15 additions and 5 deletions

View File

@ -258,12 +258,12 @@ namespace Opm
createSimulator();
// do the actual work
runSimulator(output_cout);
int retval = runSimulator(output_cout);
// clean up
mergeParallelLogFiles(output_to_files);
return EXIT_SUCCESS;
return retval;
}
catch (const std::exception& e) {
std::ostringstream message;
@ -463,7 +463,7 @@ namespace Opm
}
// Run the simulator.
void runSimulator(bool output_cout)
int runSimulator(bool output_cout)
{
const auto& schedule = this->schedule();
const auto& timeMap = schedule.getTimeMap();
@ -508,12 +508,12 @@ namespace Opm
successReport.reportFullyImplicit(ss, &failureReport);
OpmLog::info(ss.str());
}
return successReport.exit_status;
} else {
if (output_cout) {
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
}
return EXIT_SUCCESS;
}
}

View File

@ -164,6 +164,14 @@ public:
// Main simulation loop.
while (!timer.done()) {
if (schedule().exitStatus().has_value()) {
if (terminalOutput_) {
OpmLog::info("Stopping simulation since EXIT was triggered by an action keyword.");
}
report.exit_status = schedule().exitStatus().value();
break;
}
// Report timestep.
if (terminalOutput_) {
std::ostringstream ss;

View File

@ -42,6 +42,7 @@ namespace Opm
total_newton_iterations( 0 ),
total_linear_iterations( 0 ),
converged(false),
exit_status(EXIT_SUCCESS),
verbose_(verbose)
{
}

View File

@ -44,6 +44,7 @@ namespace Opm
unsigned int total_linear_iterations;
bool converged;
int exit_status;
/// Default constructor initializing all times to 0.0.
explicit SimulatorReport(bool verbose=true);