mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #2689 from hakonhagland/main_ebos_constr
Capture the variables argc, argv, outputCout, and outputFiles in Opm::FlowMainEbos
This commit is contained in:
commit
f9ac56b31c
@ -47,7 +47,7 @@ void flowEbosBlackoilSetDeck(double setupTime, Deck *deck, EclipseState& eclStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Opm::FlowMainEbos<TTAG(EclFlowProblem)>>
|
std::unique_ptr<Opm::FlowMainEbos<TTAG(EclFlowProblem)>>
|
||||||
flowEbosBlackoilMainInit(int argc, char** argv)
|
flowEbosBlackoilMainInit(int argc, char** argv, bool outputCout, bool outputFiles)
|
||||||
{
|
{
|
||||||
// we always want to use the default locale, and thus spare us the trouble
|
// we always want to use the default locale, and thus spare us the trouble
|
||||||
// with incorrect locale settings.
|
// with incorrect locale settings.
|
||||||
@ -59,14 +59,15 @@ flowEbosBlackoilMainInit(int argc, char** argv)
|
|||||||
Dune::MPIHelper::instance(argc, argv);
|
Dune::MPIHelper::instance(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return std::make_unique<Opm::FlowMainEbos<TTAG(EclFlowProblem)>>();
|
return std::make_unique<Opm::FlowMainEbos<TTAG(EclFlowProblem)>>(
|
||||||
|
argc, argv, outputCout, outputFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------- Main program -----------------
|
// ----------------- Main program -----------------
|
||||||
int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles)
|
int flowEbosBlackoilMain(int argc, char** argv, bool outputCout, bool outputFiles)
|
||||||
{
|
{
|
||||||
auto mainfunc = flowEbosBlackoilMainInit(argc, argv);
|
auto mainfunc = flowEbosBlackoilMainInit(argc, argv, outputCout, outputFiles);
|
||||||
return mainfunc->execute(argc, argv, outputCout, outputFiles);
|
return mainfunc->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,9 @@ int flowEbosBrineMain(int argc, char** argv, bool outputCout, bool outputFiles)
|
|||||||
Dune::MPIHelper::instance(argc, argv).rank();
|
Dune::MPIHelper::instance(argc, argv).rank();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowBrineProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowBrineProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,9 @@ int flowEbosEnergyMain(int argc, char** argv, bool outputCout, bool outputFiles)
|
|||||||
Dune::MPIHelper::instance(argc, argv).rank();
|
Dune::MPIHelper::instance(argc, argv).rank();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowEnergyProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowEnergyProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,9 @@ int flowEbosFoamMain(int argc, char** argv, bool outputCout, bool outputFiles)
|
|||||||
Dune::MPIHelper::instance(argc, argv).rank();
|
Dune::MPIHelper::instance(argc, argv).rank();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowFoamProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowFoamProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,9 @@ int flowEbosGasOilMain(int argc, char** argv, bool outputCout, bool outputFiles)
|
|||||||
Dune::MPIHelper::instance(argc, argv);
|
Dune::MPIHelper::instance(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowGasOilProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowGasOilProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles} ;
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,9 @@ int flowEbosOilWaterMain(int argc, char** argv, bool outputCout, bool outputFile
|
|||||||
Dune::MPIHelper::instance(argc, argv);
|
Dune::MPIHelper::instance(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowOilWaterProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowOilWaterProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,9 @@ int flowEbosOilWaterBrineMain(int argc, char** argv, bool outputCout, bool outpu
|
|||||||
Dune::MPIHelper::instance(argc, argv);
|
Dune::MPIHelper::instance(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowOilWaterBrineProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowOilWaterBrineProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,9 @@ int flowEbosOilWaterPolymerMain(int argc, char** argv, bool outputCout, bool out
|
|||||||
Dune::MPIHelper::instance(argc, argv);
|
Dune::MPIHelper::instance(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowOilWaterPolymerProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowOilWaterPolymerProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -84,8 +84,9 @@ int flowEbosOilWaterPolymerInjectivityMain(int argc, char** argv, bool outputCou
|
|||||||
Dune::MPIHelper::instance(argc, argv);
|
Dune::MPIHelper::instance(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowOilWaterPolymerInjectivityProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowOilWaterPolymerInjectivityProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,9 @@ int flowEbosPolymerMain(int argc, char** argv, bool outputCout, bool outputFiles
|
|||||||
Dune::MPIHelper::instance(argc, argv).rank();
|
Dune::MPIHelper::instance(argc, argv).rank();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowPolymerProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowPolymerProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,9 @@ int flowEbosSolventMain(int argc, char** argv, bool outputCout, bool outputFiles
|
|||||||
Dune::MPIHelper::instance(argc, argv).rank();
|
Dune::MPIHelper::instance(argc, argv).rank();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Opm::FlowMainEbos<TTAG(EclFlowSolventProblem)> mainfunc;
|
Opm::FlowMainEbos<TTAG(EclFlowSolventProblem)>
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
mainfunc {argc, argv, outputCout, outputFiles};
|
||||||
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,13 @@ namespace Opm
|
|||||||
|
|
||||||
typedef Opm::SimulatorFullyImplicitBlackoilEbos<TypeTag> Simulator;
|
typedef Opm::SimulatorFullyImplicitBlackoilEbos<TypeTag> Simulator;
|
||||||
|
|
||||||
|
FlowMainEbos(int argc, char **argv, bool output_cout, bool output_files )
|
||||||
|
: argc_{argc}, argv_{argv},
|
||||||
|
output_cout_{output_cout}, output_files_{output_files}
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Read the command line parameters. Throws an exception if something goes wrong.
|
// Read the command line parameters. Throws an exception if something goes wrong.
|
||||||
static int setupParameters_(int argc, char** argv)
|
static int setupParameters_(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@ -291,10 +298,9 @@ namespace Opm
|
|||||||
/// This is the main function of Flow. It runs a complete simulation with the
|
/// This is the main function of Flow. It runs a complete simulation with the
|
||||||
/// given grid and simulator classes, based on the user-specified command-line
|
/// given grid and simulator classes, based on the user-specified command-line
|
||||||
/// input.
|
/// input.
|
||||||
int execute(int argc, char** argv, bool output_cout, bool output_to_files)
|
int execute()
|
||||||
{
|
{
|
||||||
return execute_(argc, argv, output_cout, output_to_files,
|
return execute_(&FlowMainEbos::runSimulator, /*cleanup=*/true);
|
||||||
&FlowMainEbos::runSimulator, /*cleanup=*/true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print an ASCII-art header to the PRT and DEBUG files.
|
// Print an ASCII-art header to the PRT and DEBUG files.
|
||||||
@ -343,25 +349,24 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
// called by execute() or executeInitStep()
|
// called by execute() or executeInitStep()
|
||||||
int execute_(int argc, char** argv, bool output_cout, bool output_to_files,
|
int execute_(int (FlowMainEbos::* runOrInitFunc)(), bool cleanup)
|
||||||
int (FlowMainEbos::* runOrInitFunc)(bool), bool cleanup)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// deal with some administrative boilerplate
|
// deal with some administrative boilerplate
|
||||||
|
|
||||||
int status = setupParameters_(argc, argv);
|
int status = setupParameters_(this->argc_, this->argv_);
|
||||||
if (status)
|
if (status)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
setupParallelism();
|
setupParallelism();
|
||||||
setupEbosSimulator();
|
setupEbosSimulator();
|
||||||
runDiagnostics(output_cout);
|
runDiagnostics();
|
||||||
createSimulator();
|
createSimulator();
|
||||||
|
|
||||||
// if run, do the actual work, else just initialize
|
// if run, do the actual work, else just initialize
|
||||||
int exitCode = (this->*runOrInitFunc)(output_cout);
|
int exitCode = (this->*runOrInitFunc)();
|
||||||
if (cleanup) {
|
if (cleanup) {
|
||||||
executeCleanup_(output_to_files);
|
executeCleanup_();
|
||||||
}
|
}
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
@ -369,7 +374,7 @@ namespace Opm
|
|||||||
std::ostringstream message;
|
std::ostringstream message;
|
||||||
message << "Program threw an exception: " << e.what();
|
message << "Program threw an exception: " << e.what();
|
||||||
|
|
||||||
if (output_cout) {
|
if (this->output_cout_) {
|
||||||
// in some cases exceptions are thrown before the logging system is set
|
// in some cases exceptions are thrown before the logging system is set
|
||||||
// up.
|
// up.
|
||||||
if (OpmLog::hasBackend("STREAMLOG")) {
|
if (OpmLog::hasBackend("STREAMLOG")) {
|
||||||
@ -384,9 +389,9 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeCleanup_(bool output_to_files) {
|
void executeCleanup_() {
|
||||||
// clean up
|
// clean up
|
||||||
mergeParallelLogFiles(output_to_files);
|
mergeParallelLogFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -415,12 +420,12 @@ namespace Opm
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mergeParallelLogFiles(bool output_to_files)
|
void mergeParallelLogFiles()
|
||||||
{
|
{
|
||||||
// force closing of all log files.
|
// force closing of all log files.
|
||||||
OpmLog::removeAllBackends();
|
OpmLog::removeAllBackends();
|
||||||
|
|
||||||
if (mpi_rank_ != 0 || mpi_size_ < 2 || !output_to_files) {
|
if (mpi_rank_ != 0 || mpi_size_ < 2 || !this->output_files_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,9 +502,9 @@ namespace Opm
|
|||||||
// Run diagnostics.
|
// Run diagnostics.
|
||||||
// Writes to:
|
// Writes to:
|
||||||
// OpmLog singleton.
|
// OpmLog singleton.
|
||||||
void runDiagnostics(bool output_cout)
|
void runDiagnostics()
|
||||||
{
|
{
|
||||||
if (!output_cout) {
|
if (!this->output_cout_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,24 +528,24 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the simulator.
|
// Run the simulator.
|
||||||
int runSimulator(bool output_cout)
|
int runSimulator()
|
||||||
{
|
{
|
||||||
return runSimulatorInitOrRun_(output_cout, &FlowMainEbos::runSimulatorRunCallback_);
|
return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorRunCallback_);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Callback that will be called from runSimulatorInitOrRun_().
|
// Callback that will be called from runSimulatorInitOrRun_().
|
||||||
int runSimulatorRunCallback_(bool output_cout)
|
int runSimulatorRunCallback_()
|
||||||
{
|
{
|
||||||
SimulatorReport report = simulator_->run(*simtimer_);
|
SimulatorReport report = simulator_->run(*simtimer_);
|
||||||
runSimulatorAfterSim_(output_cout, report);
|
runSimulatorAfterSim_(report);
|
||||||
return report.success.exit_status;
|
return report.success.exit_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output summary after simulation has completed
|
// Output summary after simulation has completed
|
||||||
void runSimulatorAfterSim_(bool output_cout, SimulatorReport &report)
|
void runSimulatorAfterSim_(SimulatorReport &report)
|
||||||
{
|
{
|
||||||
if (output_cout) {
|
if (this->output_cout_) {
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "\n\n================ End of simulation ===============\n\n";
|
ss << "\n\n================ End of simulation ===============\n\n";
|
||||||
ss << "Number of MPI processes: " << std::setw(6) << mpi_size_ << "\n";
|
ss << "Number of MPI processes: " << std::setw(6) << mpi_size_ << "\n";
|
||||||
@ -565,8 +570,7 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the simulator.
|
// Run the simulator.
|
||||||
int runSimulatorInitOrRun_(
|
int runSimulatorInitOrRun_(int (FlowMainEbos::* initOrRunFunc)())
|
||||||
bool output_cout, int (FlowMainEbos::* initOrRunFunc)(bool))
|
|
||||||
{
|
{
|
||||||
|
|
||||||
const auto& schedule = this->schedule();
|
const auto& schedule = this->schedule();
|
||||||
@ -578,7 +582,7 @@ namespace Opm
|
|||||||
const auto& initConfig = eclState().getInitConfig();
|
const auto& initConfig = eclState().getInitConfig();
|
||||||
simtimer_->init(timeMap, (size_t)initConfig.getRestartStep());
|
simtimer_->init(timeMap, (size_t)initConfig.getRestartStep());
|
||||||
|
|
||||||
if (output_cout) {
|
if (this->output_cout_) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
// This allows a user to catch typos and misunderstandings in the
|
// This allows a user to catch typos and misunderstandings in the
|
||||||
@ -591,16 +595,16 @@ namespace Opm
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ioConfig.initOnly()) {
|
if (!ioConfig.initOnly()) {
|
||||||
if (output_cout) {
|
if (this->output_cout_) {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
msg = "\n\n================ Starting main simulation loop ===============\n";
|
msg = "\n\n================ Starting main simulation loop ===============\n";
|
||||||
OpmLog::info(msg);
|
OpmLog::info(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (this->*initOrRunFunc)(output_cout);
|
return (this->*initOrRunFunc)();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (output_cout) {
|
if (this->output_cout_) {
|
||||||
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
@ -637,6 +641,10 @@ namespace Opm
|
|||||||
std::any parallel_information_;
|
std::any parallel_information_;
|
||||||
std::unique_ptr<Simulator> simulator_;
|
std::unique_ptr<Simulator> simulator_;
|
||||||
std::unique_ptr<SimulatorTimer> simtimer_;
|
std::unique_ptr<SimulatorTimer> simtimer_;
|
||||||
|
int argc_;
|
||||||
|
char **argv_;
|
||||||
|
bool output_cout_;
|
||||||
|
bool output_files_;
|
||||||
};
|
};
|
||||||
} // namespace Opm
|
} // namespace Opm
|
||||||
|
|
||||||
|
@ -100,8 +100,8 @@ namespace Opm {
|
|||||||
# else
|
# else
|
||||||
Dune::MPIHelper::instance(argc, argv);
|
Dune::MPIHelper::instance(argc, argv);
|
||||||
# endif
|
# endif
|
||||||
Opm::FlowMainEbos<TypeTag> mainfunc;
|
Opm::FlowMainEbos<TypeTag> mainfunc(argc, argv, outputCout, outputFiles);
|
||||||
return mainfunc.execute(argc, argv, outputCout, outputFiles);
|
return mainfunc.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user