mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-09-05 04:40:19 -05:00
Refactor execute()
Currently, execute() calls runSimulator() to run the simulation. When the Python step_init() is implemented (see a later commit), it will instead call an executeStepInit() that will need to do the same initialization as in execute() except that it should call a runSimulatorInit() instead of runSimulator(). In order to avoid code duplication for execute() and executeStepInit(), execute() is here refactored into an execute_() method.
This commit is contained in:
@@ -245,45 +245,11 @@ namespace Opm
|
|||||||
/// input.
|
/// input.
|
||||||
int execute(int argc, char** argv, bool output_cout, bool output_to_files)
|
int execute(int argc, char** argv, bool output_cout, bool output_to_files)
|
||||||
{
|
{
|
||||||
try {
|
return execute_(argc, argv, output_cout, output_to_files,
|
||||||
// deal with some administrative boilerplate
|
&FlowMainEbos::runSimulator);
|
||||||
|
|
||||||
int status = setupParameters_(argc, argv);
|
|
||||||
if (status)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
setupParallelism();
|
|
||||||
setupEbosSimulator(output_cout);
|
|
||||||
runDiagnostics(output_cout);
|
|
||||||
createSimulator();
|
|
||||||
|
|
||||||
// do the actual work
|
|
||||||
runSimulator(output_cout);
|
|
||||||
|
|
||||||
// clean up
|
|
||||||
mergeParallelLogFiles(output_to_files);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
std::ostringstream message;
|
|
||||||
message << "Program threw an exception: " << e.what();
|
|
||||||
|
|
||||||
if (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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Print an ASCII-art header to the PRT and DEBUG files.
|
// Print an ASCII-art header to the PRT and DEBUG files.
|
||||||
// \return Whether unkown keywords were seen during parsing.
|
// \return Whether unkown keywords were seen during parsing.
|
||||||
static void printPRTHeader(bool output_cout)
|
static void printPRTHeader(bool output_cout)
|
||||||
@@ -328,6 +294,49 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// called by execute() or executeInitStep()
|
||||||
|
int execute_(int argc, char** argv, bool output_cout, bool output_to_files,
|
||||||
|
void (FlowMainEbos::* runOrInitFunc)(bool))
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// deal with some administrative boilerplate
|
||||||
|
|
||||||
|
int status = setupParameters_(argc, argv);
|
||||||
|
if (status)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
setupParallelism();
|
||||||
|
setupEbosSimulator(output_cout);
|
||||||
|
runDiagnostics(output_cout);
|
||||||
|
createSimulator();
|
||||||
|
|
||||||
|
// if run, do the actual work, else just initialize
|
||||||
|
(this->*runOrInitFunc)(output_cout);
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
mergeParallelLogFiles(output_to_files);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::ostringstream message;
|
||||||
|
message << "Program threw an exception: " << e.what();
|
||||||
|
|
||||||
|
if (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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
void setupParallelism()
|
void setupParallelism()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user