mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #2619 from hakonhagland/refactor_execute
Refactor `execute()` in `FlowMainEbos.hpp`
This commit is contained in:
commit
94ea40b253
@ -256,43 +256,8 @@ 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, /*cleanup=*/true);
|
||||||
|
|
||||||
int status = setupParameters_(argc, argv);
|
|
||||||
if (status)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
setupParallelism();
|
|
||||||
setupEbosSimulator();
|
|
||||||
runDiagnostics(output_cout);
|
|
||||||
createSimulator();
|
|
||||||
|
|
||||||
// do the actual work
|
|
||||||
int retval = runSimulator(output_cout);
|
|
||||||
|
|
||||||
// clean up
|
|
||||||
mergeParallelLogFiles(output_to_files);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
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.
|
||||||
@ -339,6 +304,53 @@ namespace Opm
|
|||||||
OpmLog::note(ss.str());
|
OpmLog::note(ss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
// called by execute() or executeInitStep()
|
||||||
|
int execute_(int argc, char** argv, bool output_cout, bool output_to_files,
|
||||||
|
int (FlowMainEbos::* runOrInitFunc)(bool), bool cleanup)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// deal with some administrative boilerplate
|
||||||
|
|
||||||
|
int status = setupParameters_(argc, argv);
|
||||||
|
if (status)
|
||||||
|
return status;
|
||||||
|
|
||||||
|
setupParallelism();
|
||||||
|
setupEbosSimulator();
|
||||||
|
runDiagnostics(output_cout);
|
||||||
|
createSimulator();
|
||||||
|
|
||||||
|
// if run, do the actual work, else just initialize
|
||||||
|
int exitCode = (this->*runOrInitFunc)(output_cout);
|
||||||
|
if (cleanup) {
|
||||||
|
executeCleanup_(output_to_files);
|
||||||
|
}
|
||||||
|
return exitCode;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void executeCleanup_(bool output_to_files) {
|
||||||
|
// clean up
|
||||||
|
mergeParallelLogFiles(output_to_files);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupParallelism()
|
void setupParallelism()
|
||||||
|
Loading…
Reference in New Issue
Block a user