mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Refactor runSimulator().
A resubmission of commit b25f489
in PR #2403 and PR #2441 to work with
the current master.
Continues the work in PR #2619 to refactor FlowMainEbos.hpp to work with
the Python bindings.
We need to refactor runSimulator() to avoid code duplication when
executeStepInit() is implemented (see later commit). Here, runSimulator()
is refactored into a runSimulatorInitOrRun() that takes a callback
function. When runSimulatorInit() is implemented it will pass a different
callback that only initializes the simulator. Currently, runSimulator()
passes the callback runSimulatorRunCallback_() which runs the whole
simulation. The code outputting the simulation summary in runSimulator()
is also refactored into a runSimulatorAfterSim_() method.
This commit is contained in:
parent
94ea40b253
commit
2734445bf5
@ -488,35 +488,21 @@ namespace Opm
|
||||
// Run the simulator.
|
||||
int runSimulator(bool output_cout)
|
||||
{
|
||||
const auto& schedule = this->schedule();
|
||||
const auto& timeMap = schedule.getTimeMap();
|
||||
auto& ioConfig = eclState().getIOConfig();
|
||||
SimulatorTimer simtimer;
|
||||
|
||||
// initialize variables
|
||||
const auto& initConfig = eclState().getInitConfig();
|
||||
simtimer.init(timeMap, (size_t)initConfig.getRestartStep());
|
||||
|
||||
if (output_cout) {
|
||||
std::ostringstream oss;
|
||||
|
||||
// This allows a user to catch typos and misunderstandings in the
|
||||
// use of simulator parameters.
|
||||
if (Opm::Parameters::printUnused<TypeTag>(oss)) {
|
||||
std::cout << "----------------- Unrecognized parameters: -----------------\n";
|
||||
std::cout << oss.str();
|
||||
std::cout << "----------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
return runSimulatorInitOrRun_(output_cout, &FlowMainEbos::runSimulatorRunCallback_);
|
||||
}
|
||||
|
||||
if (!ioConfig.initOnly()) {
|
||||
if (output_cout) {
|
||||
std::string msg;
|
||||
msg = "\n\n================ Starting main simulation loop ===============\n";
|
||||
OpmLog::info(msg);
|
||||
private:
|
||||
// Callback that will be called from runSimulatorInitOrRun_().
|
||||
int runSimulatorRunCallback_(bool output_cout)
|
||||
{
|
||||
SimulatorReport report = simulator_->run(*simtimer_);
|
||||
runSimulatorAfterSim_(output_cout, report);
|
||||
return report.success.exit_status;
|
||||
}
|
||||
|
||||
SimulatorReport report = simulator_->run(simtimer);
|
||||
// Output summary after simulation has completed
|
||||
void runSimulatorAfterSim_(bool output_cout, SimulatorReport &report)
|
||||
{
|
||||
if (output_cout) {
|
||||
std::ostringstream ss;
|
||||
ss << "\n\n================ End of simulation ===============\n\n";
|
||||
@ -539,8 +525,44 @@ namespace Opm
|
||||
report.fullReports(os);
|
||||
}
|
||||
}
|
||||
return report.success.exit_status;
|
||||
} else {
|
||||
}
|
||||
|
||||
// Run the simulator.
|
||||
int runSimulatorInitOrRun_(
|
||||
bool output_cout, int (FlowMainEbos::* initOrRunFunc)(bool))
|
||||
{
|
||||
|
||||
const auto& schedule = this->schedule();
|
||||
const auto& timeMap = schedule.getTimeMap();
|
||||
auto& ioConfig = eclState().getIOConfig();
|
||||
simtimer_ = std::make_unique<SimulatorTimer>();
|
||||
|
||||
// initialize variables
|
||||
const auto& initConfig = eclState().getInitConfig();
|
||||
simtimer_->init(timeMap, (size_t)initConfig.getRestartStep());
|
||||
|
||||
if (output_cout) {
|
||||
std::ostringstream oss;
|
||||
|
||||
// This allows a user to catch typos and misunderstandings in the
|
||||
// use of simulator parameters.
|
||||
if (Opm::Parameters::printUnused<TypeTag>(oss)) {
|
||||
std::cout << "----------------- Unrecognized parameters: -----------------\n";
|
||||
std::cout << oss.str();
|
||||
std::cout << "----------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ioConfig.initOnly()) {
|
||||
if (output_cout) {
|
||||
std::string msg;
|
||||
msg = "\n\n================ Starting main simulation loop ===============\n";
|
||||
OpmLog::info(msg);
|
||||
}
|
||||
|
||||
return (this->*initOrRunFunc)(output_cout);
|
||||
}
|
||||
else {
|
||||
if (output_cout) {
|
||||
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
||||
}
|
||||
@ -548,6 +570,8 @@ namespace Opm
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/// This is the main function of Flow.
|
||||
// Create simulator instance.
|
||||
// Writes to:
|
||||
@ -575,6 +599,7 @@ namespace Opm
|
||||
int mpi_size_ = 1;
|
||||
std::any parallel_information_;
|
||||
std::unique_ptr<Simulator> simulator_;
|
||||
std::unique_ptr<SimulatorTimer> simtimer_;
|
||||
};
|
||||
} // namespace Opm
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user