118 static int setupParameters_(
int argc,
char**
argv, Parallel::Communication comm)
121 if (!ParamsMeta::registrationOpen()) {
133 "Specify if the simulation ought to be actually run, or just pretended to be");
135 "Specify the number of report steps between two consecutive writes of restart data");
137 "Developer option to see whether logging was on non-root processors. In that case it will be appended to the *.DBG or *.PRT files");
139 Simulator::registerParameters();
250 std::string
msg =
"Aborting simulation due to unknown "
251 "parameters. Please query \"flow --help\" for "
252 "supported command line parameters.";
253 if (OpmLog::hasBackend(
"STREAMLOG"))
258 std::cerr <<
msg << std::endl;
271 Properties::printValues<TypeTag>(std::cout);
277 Parameters::printValues<TypeTag>();
292 return execute_(&FlowMainEbos::runSimulator,
true);
295 int executeInitStep()
297 return execute_(&FlowMainEbos::runSimulatorInit,
false);
304 return simulator_->runStep(*simtimer_);
309 int executeStepsCleanup()
311 SimulatorReport report = simulator_->finalize();
312 runSimulatorAfterSim_(report);
313 return report.success.exit_status;
316 EbosSimulator *getSimulatorPtr() {
317 return ebosSimulator_.get();
320 SimulatorTimer* getSimTimer() {
321 return simtimer_.get();
326 int execute_(
int (FlowMainEbos::* runOrInitFunc)(), bool cleanup)
328 auto logger = [
this](
const std::exception& e,
const std::string& message_start) {
329 std::ostringstream message;
330 message << message_start << e.what();
332 if (this->output_cout_) {
335 if (OpmLog::hasBackend(
"STREAMLOG")) {
336 OpmLog::error(message.str());
339 std::cout << message.str() <<
"\n";
342 detail::checkAllMPIProcesses();
349 int status = setupParameters_(this->argc_, this->argv_, EclGenericVanguard::comm());
354 setupEbosSimulator();
358 int exitCode = (this->*runOrInitFunc)();
364 catch (
const TimeSteppingBreakdown& e) {
365 auto exitCode = logger(e,
"Simulation aborted: ");
369 catch (
const std::exception& e) {
370 auto exitCode = logger(e,
"Simulation aborted as program threw an unexpected exception: ");
376 void executeCleanup_() {
378 mergeParallelLogFiles();
382 void setupParallelism()
387 auto comm = EclGenericVanguard::comm();
388 mpi_rank_ = comm.rank();
389 mpi_size_ = comm.size();
394 if (!getenv(
"OMP_NUM_THREADS"))
397 const int requested_threads = EWOMS_GET_PARAM(TypeTag,
int, ThreadsPerProcess);
398 if (requested_threads > 0)
399 threads = requested_threads;
404 omp_set_num_threads(threads);
408 using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
409 ThreadManager::init(
false);
412 void mergeParallelLogFiles()
415 OpmLog::removeAllBackends();
417 if (mpi_rank_ != 0 || mpi_size_ < 2 || !this->output_files_ || !ebosSimulator_) {
421 detail::mergeParallelLogFiles(eclState().getIOConfig().getOutputDir(),
422 EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName),
423 EWOMS_GET_PARAM(TypeTag,
bool, EnableLoggingFalloutWarning));
426 void setupEbosSimulator()
428 ebosSimulator_ = std::make_unique<EbosSimulator>(EclGenericVanguard::comm(),
false);
429 ebosSimulator_->executionTimer().start();
430 ebosSimulator_->model().applyInitialSolution();
434 const std::string& dryRunString = EWOMS_GET_PARAM(TypeTag, std::string, EnableDryRun);
435 if (dryRunString !=
"" && dryRunString !=
"auto") {
437 if (dryRunString ==
"true"
438 || dryRunString ==
"t"
439 || dryRunString ==
"1")
441 else if (dryRunString ==
"false"
442 || dryRunString ==
"f"
443 || dryRunString ==
"0")
446 throw std::invalid_argument(
"Invalid value for parameter EnableDryRun: '"
448 auto& ioConfig = eclState().getIOConfig();
449 ioConfig.overrideNOSIM(yesno);
452 catch (
const std::invalid_argument& e) {
453 std::cerr <<
"Failed to create valid EclipseState object" << std::endl;
454 std::cerr <<
"Exception caught: " << e.what() << std::endl;
459 const EclipseState& eclState()
const
460 {
return ebosSimulator_->vanguard().eclState(); }
462 EclipseState& eclState()
463 {
return ebosSimulator_->vanguard().eclState(); }
465 const Schedule& schedule()
const
466 {
return ebosSimulator_->vanguard().schedule(); }
471 return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorRunCallback_);
474 int runSimulatorInit()
476 return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorInitCallback_);
481 int runSimulatorRunCallback_()
483 SimulatorReport report = simulator_->run(*simtimer_);
484 runSimulatorAfterSim_(report);
485 return report.success.exit_status;
489 int runSimulatorInitCallback_()
491 simulator_->init(*simtimer_);
496 void runSimulatorAfterSim_(SimulatorReport &report)
498 if (! this->output_cout_) {
503#if !defined(_OPENMP) || !_OPENMP
506 = omp_get_max_threads();
509 printFlowTrailer(mpi_size_, threads, report, simulator_->model().localAccumulatedReports());
511 detail::handleExtraConvergenceOutput(report,
512 EWOMS_GET_PARAM(TypeTag, std::string, OutputExtraConvergenceInfo),
513 R
"(OutputExtraConvergenceInfo (--output-extra-convergence-info))",
514 eclState().getIOConfig().getOutputDir(),
515 eclState().getIOConfig().getBaseName());
519 int runSimulatorInitOrRun_(
int (FlowMainEbos::* initOrRunFunc)())
522 const auto& schedule = this->schedule();
523 auto& ioConfig = eclState().getIOConfig();
524 simtimer_ = std::make_unique<SimulatorTimer>();
527 const auto& initConfig = eclState().getInitConfig();
528 simtimer_->init(schedule,
static_cast<std::size_t
>(initConfig.getRestartStep()));
530 if (this->output_cout_) {
531 std::ostringstream oss;
535 if (Parameters::printUnused<TypeTag>(oss)) {
536 std::cout <<
"----------------- Unrecognized parameters: -----------------\n";
537 std::cout << oss.str();
538 std::cout <<
"----------------------------------------------------------------" << std::endl;
542 if (!ioConfig.initOnly()) {
543 if (this->output_cout_) {
545 msg =
"\n\n================ Starting main simulation loop ===============\n";
549 return (this->*initOrRunFunc)();
552 if (this->output_cout_) {
553 std::cout <<
"\n\n================ Simulation turned off ===============\n" << std::flush;
568 simulator_ = std::make_unique<Simulator>(*ebosSimulator_);
572 {
return ebosSimulator_->vanguard().grid(); }
575 std::unique_ptr<EbosSimulator> ebosSimulator_;
578 std::any parallel_information_;
579 std::unique_ptr<Simulator> simulator_;
580 std::unique_ptr<SimulatorTimer> simtimer_;
Definition FlowMainEbos.hpp:98
int execute()
This is the main function of Flow.
Definition FlowMainEbos.hpp:290
void createSimulator()
This is the main function of Flow.
Definition FlowMainEbos.hpp:565