mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Refactor runSimulator()
As discussed in the previous commit 224ddd9
runSimulator() needs to be
refactored 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 final output of the simulation summary in runSimulator() is also
refactored into a runSimulatorAfterSim_() method.
This commit is contained in:
parent
224ddd9b73
commit
b25f48971c
@ -468,15 +468,49 @@ namespace Opm
|
|||||||
|
|
||||||
// Run the simulator.
|
// Run the simulator.
|
||||||
void runSimulator(bool output_cout)
|
void runSimulator(bool output_cout)
|
||||||
|
{
|
||||||
|
runSimulatorInitOrRun_(output_cout, &FlowMainEbos::runSimulatorRunCallback_);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Callback that will be called from runSimulatorInitOrRun_().
|
||||||
|
void runSimulatorRunCallback_(bool output_cout)
|
||||||
|
{
|
||||||
|
SimulatorReport successReport = simulator_->run(*simtimer_);
|
||||||
|
runSimulatorAfterSim_(output_cout, successReport);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output summary after simulation has completed
|
||||||
|
void runSimulatorAfterSim_(bool output_cout, SimulatorReport &successReport)
|
||||||
|
{
|
||||||
|
SimulatorReport failureReport = simulator_->failureReport();
|
||||||
|
if (output_cout) {
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "\n\n================ End of simulation ===============\n\n";
|
||||||
|
ss << "Number of MPI processes: " << std::setw(6) << mpi_size_ << "\n";
|
||||||
|
#if _OPENMP
|
||||||
|
int threads = omp_get_max_threads();
|
||||||
|
#else
|
||||||
|
int threads = 1;
|
||||||
|
#endif
|
||||||
|
ss << "Threads per MPI process: " << std::setw(5) << threads << "\n";
|
||||||
|
successReport.reportFullyImplicit(ss, &failureReport);
|
||||||
|
OpmLog::info(ss.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the simulator.
|
||||||
|
void runSimulatorInitOrRun_(
|
||||||
|
bool output_cout, void (FlowMainEbos::* initOrRunFunc)(bool))
|
||||||
{
|
{
|
||||||
const auto& schedule = this->schedule();
|
const auto& schedule = this->schedule();
|
||||||
const auto& timeMap = schedule.getTimeMap();
|
const auto& timeMap = schedule.getTimeMap();
|
||||||
auto& ioConfig = eclState().getIOConfig();
|
auto& ioConfig = eclState().getIOConfig();
|
||||||
SimulatorTimer simtimer;
|
simtimer_ = std::make_unique<SimulatorTimer>();
|
||||||
|
|
||||||
// initialize variables
|
// initialize variables
|
||||||
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 (output_cout) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
@ -496,31 +530,16 @@ namespace Opm
|
|||||||
msg = "\n\n================ Starting main simulation loop ===============\n";
|
msg = "\n\n================ Starting main simulation loop ===============\n";
|
||||||
OpmLog::info(msg);
|
OpmLog::info(msg);
|
||||||
}
|
}
|
||||||
|
(this->*initOrRunFunc)(output_cout);
|
||||||
SimulatorReport successReport = simulator_->run(simtimer);
|
}
|
||||||
SimulatorReport failureReport = simulator_->failureReport();
|
else {
|
||||||
if (output_cout) {
|
|
||||||
std::ostringstream ss;
|
|
||||||
ss << "\n\n================ End of simulation ===============\n\n";
|
|
||||||
ss << "Number of MPI processes: " << std::setw(6) << mpi_size_ << "\n";
|
|
||||||
#if _OPENMP
|
|
||||||
int threads = omp_get_max_threads();
|
|
||||||
#else
|
|
||||||
int threads = 1;
|
|
||||||
#endif
|
|
||||||
ss << "Threads per MPI process: " << std::setw(5) << threads << "\n";
|
|
||||||
successReport.reportFullyImplicit(ss, &failureReport);
|
|
||||||
OpmLog::info(ss.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (output_cout) {
|
if (output_cout) {
|
||||||
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
/// This is the main function of Flow.
|
/// This is the main function of Flow.
|
||||||
// Create simulator instance.
|
// Create simulator instance.
|
||||||
// Writes to:
|
// Writes to:
|
||||||
@ -548,6 +567,7 @@ namespace Opm
|
|||||||
int mpi_size_ = 1;
|
int mpi_size_ = 1;
|
||||||
boost::any parallel_information_;
|
boost::any parallel_information_;
|
||||||
std::unique_ptr<Simulator> simulator_;
|
std::unique_ptr<Simulator> simulator_;
|
||||||
|
std::unique_ptr<SimulatorTimer> simtimer_;
|
||||||
};
|
};
|
||||||
} // namespace Opm
|
} // namespace Opm
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user