113 static int setupParameters_(
int argc,
char**
argv, Parallel::Communication comm)
116 if (!ParamsMeta::registrationOpen()) {
128 "Specify if the simulation ought to be actually run, or just pretended to be");
130 "Specify the number of report steps between two consecutive writes of restart data");
132 "Developer option to see whether logging was on non-root processors. In that case it will be appended to the *.DBG or *.PRT files");
134 Simulator::registerParameters();
244 std::string
msg =
"Aborting simulation due to unknown "
245 "parameters. Please query \"flow --help\" for "
246 "supported command line parameters.";
247 if (OpmLog::hasBackend(
"STREAMLOG"))
252 std::cerr <<
msg << std::endl;
265 Properties::printValues<TypeTag>(std::cout);
271 Parameters::printValues<TypeTag>();
286 return execute_(&FlowMainEbos::runSimulator,
true);
289 int executeInitStep()
291 return execute_(&FlowMainEbos::runSimulatorInit,
false);
298 return simulator_->runStep(*simtimer_);
303 int executeStepsCleanup()
305 SimulatorReport report = simulator_->finalize();
306 runSimulatorAfterSim_(report);
307 return report.success.exit_status;
310 EbosSimulator *getSimulatorPtr() {
311 return ebosSimulator_.get();
314 SimulatorTimer* getSimTimer() {
315 return simtimer_.get();
320 int execute_(
int (FlowMainEbos::* runOrInitFunc)(), bool cleanup)
325 int status = setupParameters_(this->argc_, this->argv_, EclGenericVanguard::comm());
330 setupEbosSimulator();
334 int exitCode = (this->*runOrInitFunc)();
340 catch (
const std::exception& e) {
341 std::ostringstream message;
342 message <<
"Program threw an exception: " << e.what();
344 if (this->output_cout_) {
347 if (OpmLog::hasBackend(
"STREAMLOG")) {
348 OpmLog::error(message.str());
351 std::cout << message.str() <<
"\n";
355 if (this->mpi_size_ > 1)
356 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
362 void executeCleanup_() {
364 mergeParallelLogFiles();
368 void setupParallelism()
373 auto comm = EclGenericVanguard::comm();
374 mpi_rank_ = comm.rank();
375 mpi_size_ = comm.size();
379 if (!getenv(
"OMP_NUM_THREADS"))
380 omp_set_num_threads(std::min(2, omp_get_num_procs()));
383 using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
384 ThreadManager::init();
387 void mergeParallelLogFiles()
390 OpmLog::removeAllBackends();
392 if (mpi_rank_ != 0 || mpi_size_ < 2 || !this->output_files_) {
396 detail::mergeParallelLogFiles(eclState().getIOConfig().getOutputDir(),
397 EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName),
398 EWOMS_GET_PARAM(TypeTag,
bool, EnableLoggingFalloutWarning));
401 void setupEbosSimulator()
403 ebosSimulator_ = std::make_unique<EbosSimulator>(EclGenericVanguard::comm(),
false);
404 ebosSimulator_->executionTimer().start();
405 ebosSimulator_->model().applyInitialSolution();
409 const std::string& dryRunString = EWOMS_GET_PARAM(TypeTag, std::string, EnableDryRun);
410 if (dryRunString !=
"" && dryRunString !=
"auto") {
412 if (dryRunString ==
"true"
413 || dryRunString ==
"t"
414 || dryRunString ==
"1")
416 else if (dryRunString ==
"false"
417 || dryRunString ==
"f"
418 || dryRunString ==
"0")
421 throw std::invalid_argument(
"Invalid value for parameter EnableDryRun: '"
423 auto& ioConfig = eclState().getIOConfig();
424 ioConfig.overrideNOSIM(yesno);
427 catch (
const std::invalid_argument& e) {
428 std::cerr <<
"Failed to create valid EclipseState object" << std::endl;
429 std::cerr <<
"Exception caught: " << e.what() << std::endl;
434 const Deck& deck()
const
435 {
return ebosSimulator_->vanguard().deck(); }
438 {
return ebosSimulator_->vanguard().deck(); }
440 const EclipseState& eclState()
const
441 {
return ebosSimulator_->vanguard().eclState(); }
443 EclipseState& eclState()
444 {
return ebosSimulator_->vanguard().eclState(); }
446 const Schedule& schedule()
const
447 {
return ebosSimulator_->vanguard().schedule(); }
452 return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorRunCallback_);
455 int runSimulatorInit()
457 return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorInitCallback_);
462 int runSimulatorRunCallback_()
464 SimulatorReport report = simulator_->run(*simtimer_);
465 runSimulatorAfterSim_(report);
466 return report.success.exit_status;
470 int runSimulatorInitCallback_()
472 simulator_->init(*simtimer_);
477 void runSimulatorAfterSim_(SimulatorReport &report)
479 if (! this->output_cout_) {
484#if !defined(_OPENMP) || !_OPENMP
487 = omp_get_max_threads();
490 printFlowTrailer(mpi_size_, threads, report);
492 detail::handleExtraConvergenceOutput(report,
493 EWOMS_GET_PARAM(TypeTag, std::string, OutputExtraConvergenceInfo),
494 R
"(OutputExtraConvergenceInfo (--output-extra-convergence-info))",
495 eclState().getIOConfig().getOutputDir(),
496 eclState().getIOConfig().getBaseName());
500 int runSimulatorInitOrRun_(
int (FlowMainEbos::* initOrRunFunc)())
503 const auto& schedule = this->schedule();
504 auto& ioConfig = eclState().getIOConfig();
505 simtimer_ = std::make_unique<SimulatorTimer>();
508 const auto& initConfig = eclState().getInitConfig();
509 simtimer_->init(schedule, (
size_t)initConfig.getRestartStep());
511 if (this->output_cout_) {
512 std::ostringstream oss;
516 if (Parameters::printUnused<TypeTag>(oss)) {
517 std::cout <<
"----------------- Unrecognized parameters: -----------------\n";
518 std::cout << oss.str();
519 std::cout <<
"----------------------------------------------------------------" << std::endl;
523 if (!ioConfig.initOnly()) {
524 if (this->output_cout_) {
526 msg =
"\n\n================ Starting main simulation loop ===============\n";
530 return (this->*initOrRunFunc)();
533 if (this->output_cout_) {
534 std::cout <<
"\n\n================ Simulation turned off ===============\n" << std::flush;
549 simulator_ = std::make_unique<Simulator>(*ebosSimulator_);
553 {
return ebosSimulator_->vanguard().grid(); }
556 std::unique_ptr<EbosSimulator> ebosSimulator_;
559 std::any parallel_information_;
560 std::unique_ptr<Simulator> simulator_;
561 std::unique_ptr<SimulatorTimer> simtimer_;
Definition FlowMainEbos.hpp:93
int execute()
This is the main function of Flow.
Definition FlowMainEbos.hpp:284
void createSimulator()
This is the main function of Flow.
Definition FlowMainEbos.hpp:546