diff --git a/opm/simulators/flow/FlowMainEbos.hpp b/opm/simulators/flow/FlowMainEbos.hpp index 5b68e6083..7e636b694 100644 --- a/opm/simulators/flow/FlowMainEbos.hpp +++ b/opm/simulators/flow/FlowMainEbos.hpp @@ -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; } } diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp index 882249608..26b10dbb3 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp @@ -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; diff --git a/opm/simulators/timestepping/SimulatorReport.cpp b/opm/simulators/timestepping/SimulatorReport.cpp index bc5348f6e..045760639 100644 --- a/opm/simulators/timestepping/SimulatorReport.cpp +++ b/opm/simulators/timestepping/SimulatorReport.cpp @@ -42,6 +42,7 @@ namespace Opm total_newton_iterations( 0 ), total_linear_iterations( 0 ), converged(false), + exit_status(EXIT_SUCCESS), verbose_(verbose) { } diff --git a/opm/simulators/timestepping/SimulatorReport.hpp b/opm/simulators/timestepping/SimulatorReport.hpp index e1ffae61a..8ab9be88b 100644 --- a/opm/simulators/timestepping/SimulatorReport.hpp +++ b/opm/simulators/timestepping/SimulatorReport.hpp @@ -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);