My Project
FlowMainEbos.hpp
1 /*
2  Copyright 2013, 2014, 2015 SINTEF ICT, Applied Mathematics.
3  Copyright 2014 Dr. Blatt - HPC-Simulation-Software & Services
4  Copyright 2015 IRIS AS
5  Copyright 2014 STATOIL ASA.
6 
7  This file is part of the Open Porous Media project (OPM).
8 
9  OPM is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OPM is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OPM. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
23 #define OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
24 
25 
26 #include <sys/utsname.h>
27 
28 #include <opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp>
29 #include <opm/simulators/utils/ParallelFileMerger.hpp>
30 #include <opm/simulators/utils/moduleVersion.hpp>
31 #include <opm/simulators/utils/ParallelEclipseState.hpp>
32 
33 #include <opm/input/eclipse/EclipseState/EclipseState.hpp>
34 #include <opm/input/eclipse/EclipseState/IOConfig/IOConfig.hpp>
35 #include <opm/input/eclipse/EclipseState/InitConfig/InitConfig.hpp>
36 #include <opm/input/eclipse/Schedule/UDQ/UDQState.hpp>
37 #include <opm/common/utility/String.hpp>
38 
39 #include <fmt/format.h>
40 #include <filesystem>
41 
42 #if HAVE_DUNE_FEM
43 #include <dune/fem/misc/mpimanager.hh>
44 #else
45 #include <dune/common/parallel/mpihelper.hh>
46 #endif
47 
48 namespace Opm::Properties {
49 
50 template<class TypeTag, class MyTypeTag>
51 struct EnableDryRun {
52  using type = UndefinedProperty;
53 };
54 template<class TypeTag, class MyTypeTag>
56  using type = UndefinedProperty;
57 };
58 template<class TypeTag, class MyTypeTag>
60  using type = UndefinedProperty;
61 };
62 
63 // TODO: enumeration parameters. we use strings for now.
64 template<class TypeTag>
65 struct EnableDryRun<TypeTag, TTag::EclFlowProblem> {
66  static constexpr auto value = "auto";
67 };
68 // Do not merge parallel output files or warn about them
69 template<class TypeTag>
70 struct EnableLoggingFalloutWarning<TypeTag, TTag::EclFlowProblem> {
71  static constexpr bool value = false;
72 };
73 template<class TypeTag>
74 struct OutputInterval<TypeTag, TTag::EclFlowProblem> {
75  static constexpr int value = 1;
76 };
77 
78 } // namespace Opm::Properties
79 
80 namespace Opm
81 {
82 
83  class Deck;
84 
85  // The FlowMain class is the ebos based black-oil simulator.
86  template <class TypeTag>
88  {
89  public:
90  using MaterialLawManager = typename GetProp<TypeTag, Properties::MaterialLaw>::EclMaterialLawManager;
91  using EbosSimulator = GetPropType<TypeTag, Properties::Simulator>;
92  using Grid = GetPropType<TypeTag, Properties::Grid>;
93  using GridView = GetPropType<TypeTag, Properties::GridView>;
94  using Problem = GetPropType<TypeTag, Properties::Problem>;
95  using Scalar = GetPropType<TypeTag, Properties::Scalar>;
96  using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
97 
99 
100  FlowMainEbos(int argc, char **argv, bool output_cout, bool output_files )
101  : argc_{argc}, argv_{argv},
102  output_cout_{output_cout}, output_files_{output_files}
103  {
104 
105  }
106 
107  // Read the command line parameters. Throws an exception if something goes wrong.
108  static int setupParameters_(int argc, char** argv, Parallel::Communication comm)
109  {
110  using ParamsMeta = GetProp<TypeTag, Properties::ParameterMetaData>;
111  if (!ParamsMeta::registrationOpen()) {
112  // We have already successfully run setupParameters_().
113  // For the dynamically chosen runs (as from the main flow
114  // executable) we must run this function again with the
115  // real typetag to be used, as the first time was with the
116  // "FlowEarlyBird" typetag. However, for the static ones (such
117  // as 'flow_onephase_energy') it has already been run with the
118  // correct typetag.
119  return EXIT_SUCCESS;
120  }
121  // register the flow specific parameters
122  EWOMS_REGISTER_PARAM(TypeTag, std::string, EnableDryRun,
123  "Specify if the simulation ought to be actually run, or just pretended to be");
124  EWOMS_REGISTER_PARAM(TypeTag, int, OutputInterval,
125  "Specify the number of report steps between two consecutive writes of restart data");
126  EWOMS_REGISTER_PARAM(TypeTag, bool, EnableLoggingFalloutWarning,
127  "Developer option to see whether logging was on non-root processors. In that case it will be appended to the *.DBG or *.PRT files");
128 
129  Simulator::registerParameters();
130 
131  // register the parameters inherited from ebos
132  registerAllParameters_<TypeTag>(/*finalizeRegistration=*/false);
133 
134  // hide the parameters unused by flow. TODO: this is a pain to maintain
135  EWOMS_HIDE_PARAM(TypeTag, EnableGravity);
136  EWOMS_HIDE_PARAM(TypeTag, EnableGridAdaptation);
137 
138  // this parameter is actually used in eWoms, but the flow well model
139  // hard-codes the assumption that the intensive quantities cache is enabled,
140  // so flow crashes. Let's hide the parameter for that reason.
141  EWOMS_HIDE_PARAM(TypeTag, EnableIntensiveQuantityCache);
142 
143  // thermodynamic hints are not implemented/required by the eWoms blackoil
144  // model
145  EWOMS_HIDE_PARAM(TypeTag, EnableThermodynamicHints);
146 
147  // in flow only the deck file determines the end time of the simulation
148  EWOMS_HIDE_PARAM(TypeTag, EndTime);
149 
150  // time stepping is not done by the eWoms code in flow
151  EWOMS_HIDE_PARAM(TypeTag, InitialTimeStepSize);
152  EWOMS_HIDE_PARAM(TypeTag, MaxTimeStepDivisions);
153  EWOMS_HIDE_PARAM(TypeTag, MaxTimeStepSize);
154  EWOMS_HIDE_PARAM(TypeTag, MinTimeStepSize);
155  EWOMS_HIDE_PARAM(TypeTag, PredeterminedTimeStepsFile);
156 
157  EWOMS_HIDE_PARAM(TypeTag, EclMaxTimeStepSizeAfterWellEvent);
158  EWOMS_HIDE_PARAM(TypeTag, EclRestartShrinkFactor);
159  EWOMS_HIDE_PARAM(TypeTag, EclEnableTuning);
160 
161  // flow also does not use the eWoms Newton method
162  EWOMS_HIDE_PARAM(TypeTag, NewtonMaxError);
163  EWOMS_HIDE_PARAM(TypeTag, NewtonMaxIterations);
164  EWOMS_HIDE_PARAM(TypeTag, NewtonTolerance);
165  EWOMS_HIDE_PARAM(TypeTag, NewtonTargetIterations);
166  EWOMS_HIDE_PARAM(TypeTag, NewtonVerbose);
167  EWOMS_HIDE_PARAM(TypeTag, NewtonWriteConvergence);
168  EWOMS_HIDE_PARAM(TypeTag, EclNewtonSumTolerance);
169  EWOMS_HIDE_PARAM(TypeTag, EclNewtonSumToleranceExponent);
170  EWOMS_HIDE_PARAM(TypeTag, EclNewtonStrictIterations);
171  EWOMS_HIDE_PARAM(TypeTag, EclNewtonRelaxedVolumeFraction);
172  EWOMS_HIDE_PARAM(TypeTag, EclNewtonRelaxedTolerance);
173 
174  // the default eWoms checkpoint/restart mechanism does not work with flow
175  EWOMS_HIDE_PARAM(TypeTag, RestartTime);
176  EWOMS_HIDE_PARAM(TypeTag, RestartWritingInterval);
177  // hide all vtk related it is not currently possible to do this dependet on if the vtk writing is used
178  //if(not(EWOMS_GET_PARAM(TypeTag,bool,EnableVtkOutput))){
179  EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilFormationVolumeFactor);
180  EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilSaturationPressure);
181  EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilVaporizationFactor);
182  EWOMS_HIDE_PARAM(TypeTag, VtkWritePorosity);
183  EWOMS_HIDE_PARAM(TypeTag, VtkWritePotentialGradients);
184  EWOMS_HIDE_PARAM(TypeTag, VtkWritePressures);
185  EWOMS_HIDE_PARAM(TypeTag, VtkWritePrimaryVars);
186  EWOMS_HIDE_PARAM(TypeTag, VtkWritePrimaryVarsMeaning);
187  EWOMS_HIDE_PARAM(TypeTag, VtkWriteProcessRank);
188  EWOMS_HIDE_PARAM(TypeTag, VtkWriteRelativePermeabilities);
189  EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturatedGasOilVaporizationFactor);
190  EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturatedOilGasDissolutionFactor);
191  EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturationRatios);
192  EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturations);
193  EWOMS_HIDE_PARAM(TypeTag, VtkWriteTemperature);
194  EWOMS_HIDE_PARAM(TypeTag, VtkWriteViscosities);
195  EWOMS_HIDE_PARAM(TypeTag, VtkWriteWaterFormationVolumeFactor);
196  EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasDissolutionFactor);
197  EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasFormationVolumeFactor);
198  EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasSaturationPressure);
199  EWOMS_HIDE_PARAM(TypeTag, VtkWriteIntrinsicPermeabilities);
200  EWOMS_HIDE_PARAM(TypeTag, VtkWriteEclTracerConcentration);
201  EWOMS_HIDE_PARAM(TypeTag, VtkWriteExtrusionFactor);
202  EWOMS_HIDE_PARAM(TypeTag, VtkWriteFilterVelocities);
203  EWOMS_HIDE_PARAM(TypeTag, VtkWriteDensities);
204  EWOMS_HIDE_PARAM(TypeTag, VtkWriteDofIndex);
205  EWOMS_HIDE_PARAM(TypeTag, VtkWriteMobilities);
206  //}
207  EWOMS_HIDE_PARAM(TypeTag, VtkWriteAverageMolarMasses);
208  EWOMS_HIDE_PARAM(TypeTag, VtkWriteFugacities);
209  EWOMS_HIDE_PARAM(TypeTag, VtkWriteFugacityCoeffs);
210  EWOMS_HIDE_PARAM(TypeTag, VtkWriteMassFractions);
211  EWOMS_HIDE_PARAM(TypeTag, VtkWriteMolarities);
212  EWOMS_HIDE_PARAM(TypeTag, VtkWriteMoleFractions);
213  EWOMS_HIDE_PARAM(TypeTag, VtkWriteTotalMassFractions);
214  EWOMS_HIDE_PARAM(TypeTag, VtkWriteTotalMoleFractions);
215 
216  EWOMS_END_PARAM_REGISTRATION(TypeTag);
217 
218  int mpiRank = comm.rank();
219 
220  // read in the command line parameters
221  int status = ::Opm::setupParameters_<TypeTag>(argc, const_cast<const char**>(argv), /*doRegistration=*/false, /*allowUnused=*/true, /*handleHelp=*/(mpiRank==0));
222  if (status == 0) {
223 
224  // deal with unknown parameters.
225 
226  int unknownKeyWords = 0;
227  if (mpiRank == 0) {
228  unknownKeyWords = Parameters::printUnused<TypeTag>(std::cerr);
229  }
230  int globalUnknownKeyWords = comm.sum(unknownKeyWords);
231  unknownKeyWords = globalUnknownKeyWords;
232  if ( unknownKeyWords )
233  {
234  if ( mpiRank == 0 )
235  {
236  std::string msg = "Aborting simulation due to unknown "
237  "parameters. Please query \"flow --help\" for "
238  "supported command line parameters.";
239  if (OpmLog::hasBackend("STREAMLOG"))
240  {
241  OpmLog::error(msg);
242  }
243  else {
244  std::cerr << msg << std::endl;
245  }
246  }
247  return EXIT_FAILURE;
248  }
249 
250  // deal with --print-properties and --print-parameters and unknown parameters.
251 
252  bool doExit = false;
253 
254  if (EWOMS_GET_PARAM(TypeTag, int, PrintProperties) == 1) {
255  doExit = true;
256  if (mpiRank == 0)
257  Properties::printValues<TypeTag>();
258  }
259 
260  if (EWOMS_GET_PARAM(TypeTag, int, PrintParameters) == 1) {
261  doExit = true;
262  if (mpiRank == 0)
263  Parameters::printValues<TypeTag>();
264  }
265 
266  if (doExit)
267  return -1;
268  }
269 
270  return status;
271  }
272 
273  static void printBanner(Parallel::Communication comm)
274  {
275  const int lineLen = 70;
276  const std::string version = moduleVersionName();
277  const std::string banner = "This is flow "+version;
278  const int bannerPreLen = (lineLen - 2 - banner.size())/2;
279  const int bannerPostLen = bannerPreLen + (lineLen - 2 - banner.size())%2;
280  std::cout << "**********************************************************************\n";
281  std::cout << "* *\n";
282  std::cout << "*" << std::string(bannerPreLen, ' ') << banner << std::string(bannerPostLen, ' ') << "*\n";
283  std::cout << "* *\n";
284  std::cout << "* Flow is a simulator for fully implicit three-phase black-oil flow, *\n";
285  std::cout << "* including solvent and polymer capabilities. *\n";
286  std::cout << "* For more information, see https://opm-project.org *\n";
287  std::cout << "* *\n";
288  std::cout << "**********************************************************************\n\n";
289 
290  int threads = 1;
291 
292 #ifdef _OPENMP
293  // This function is called before the parallel OpenMP stuff gets initialized.
294  // That initialization happends after the deck is read and we want this message.
295  // Hence we duplicate the code of setupParallelism to get the number of threads.
296  if (getenv("OMP_NUM_THREADS"))
297  threads = omp_get_max_threads();
298  else
299  threads = std::min(2, omp_get_max_threads());
300 
301  const int input_threads = EWOMS_GET_PARAM(TypeTag, int, ThreadsPerProcess);
302 
303  if (input_threads > 0)
304  threads = std::min(input_threads, omp_get_max_threads());
305 #endif
306 
307  int mpiSize = comm.size();
308 
309  std::cout << "Using "<< mpiSize << " MPI processes with "<< threads <<" OMP threads on each \n\n";
310  }
311 
315  int execute()
316  {
317  return execute_(&FlowMainEbos::runSimulator, /*cleanup=*/true);
318  }
319 
320  int executeInitStep()
321  {
322  return execute_(&FlowMainEbos::runSimulatorInit, /*cleanup=*/false);
323  }
324 
325  // Returns true unless "EXIT" was encountered in the schedule
326  // section of the input datafile.
327  int executeStep()
328  {
329  return simulator_->runStep(*simtimer_);
330  }
331 
332  // Called from Python to cleanup after having executed the last
333  // executeStep()
334  int executeStepsCleanup()
335  {
336  SimulatorReport report = simulator_->finalize();
337  runSimulatorAfterSim_(report);
338  return report.success.exit_status;
339  }
340 
341  // Print an ASCII-art header to the PRT and DEBUG files.
342  // \return Whether unkown keywords were seen during parsing.
343  static void printPRTHeader(bool output_cout)
344  {
345  if (output_cout) {
346  const std::string version = moduleVersion();
347  const double megabyte = 1024 * 1024;
348  unsigned num_cpu = std::thread::hardware_concurrency();
349  struct utsname arch;
350  const char* user = getlogin();
351  time_t now = std::time(0);
352  struct tm tstruct;
353  char tmstr[80];
354  tstruct = *localtime(&now);
355  strftime(tmstr, sizeof(tmstr), "%d-%m-%Y at %X", &tstruct);
356  const double mem_size = getTotalSystemMemory() / megabyte;
357  std::ostringstream ss;
358  ss << "\n\n\n";
359  ss << " ######## # ###### # #\n";
360  ss << " # # # # # # \n";
361  ss << " ##### # # # # # # \n";
362  ss << " # # # # # # # # \n";
363  ss << " # ####### ###### # # \n\n";
364  ss << "Flow is a simulator for fully implicit three-phase black-oil flow,";
365  ss << " and is part of OPM.\nFor more information visit: https://opm-project.org \n\n";
366  ss << "Flow Version = " + version + "\n";
367  if (uname(&arch) == 0) {
368  ss << "Machine name = " << arch.nodename << " (Number of logical cores: " << num_cpu;
369  ss << ", Memory size: " << std::fixed << std::setprecision (2) << mem_size << " MB) \n";
370  ss << "Operating system = " << arch.sysname << " " << arch.machine << " (Kernel: " << arch.release;
371  ss << ", " << arch.version << " )\n";
372  ss << "Build time = " << compileTimestamp() << "\n";
373  }
374  if (user) {
375  ss << "User = " << user << std::endl;
376  }
377  ss << "Simulation started on " << tmstr << " hrs\n";
378 
379  ss << "Parameters used by Flow:\n";
380  Parameters::printValues<TypeTag>(ss);
381 
382  OpmLog::note(ss.str());
383  }
384  }
385 
386  EbosSimulator *getSimulatorPtr() {
387  return ebosSimulator_.get();
388  }
389 
390  private:
391  // called by execute() or executeInitStep()
392  int execute_(int (FlowMainEbos::* runOrInitFunc)(), bool cleanup)
393  {
394  try {
395  // deal with some administrative boilerplate
396 
397  int status = setupParameters_(this->argc_, this->argv_, EclGenericVanguard::comm());
398  if (status)
399  return status;
400 
401  setupParallelism();
402  setupEbosSimulator();
403  createSimulator();
404 
405  // if run, do the actual work, else just initialize
406  int exitCode = (this->*runOrInitFunc)();
407  if (cleanup) {
408  executeCleanup_();
409  }
410  return exitCode;
411  }
412  catch (const std::exception& e) {
413  std::ostringstream message;
414  message << "Program threw an exception: " << e.what();
415 
416  if (this->output_cout_) {
417  // in some cases exceptions are thrown before the logging system is set
418  // up.
419  if (OpmLog::hasBackend("STREAMLOG")) {
420  OpmLog::error(message.str());
421  }
422  else {
423  std::cout << message.str() << "\n";
424  }
425  }
426 #if HAVE_MPI
427  if (this->mpi_size_ > 1)
428  MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
429 #endif
430  return EXIT_FAILURE;
431  }
432  }
433 
434  void executeCleanup_() {
435  // clean up
436  mergeParallelLogFiles();
437  }
438 
439  protected:
440  void setupParallelism()
441  {
442  // determine the rank of the current process and the number of processes
443  // involved in the simulation. MPI must have already been initialized
444  // here. (yes, the name of this method is misleading.)
445  auto comm = EclGenericVanguard::comm();
446  mpi_rank_ = comm.rank();
447  mpi_size_ = comm.size();
448 
449 #if _OPENMP
450  // if openMP is available, default to 2 threads per process.
451  if (!getenv("OMP_NUM_THREADS"))
452  omp_set_num_threads(std::min(2, omp_get_num_procs()));
453 #endif
454 
455  using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
456  ThreadManager::init();
457  }
458 
459 
460 
461  void mergeParallelLogFiles()
462  {
463  // force closing of all log files.
464  OpmLog::removeAllBackends();
465 
466  if (mpi_rank_ != 0 || mpi_size_ < 2 || !this->output_files_) {
467  return;
468  }
469 
470  namespace fs = ::std::filesystem;
471  const std::string& output_dir = eclState().getIOConfig().getOutputDir();
472  fs::path output_path(output_dir);
473  fs::path deck_filename(EWOMS_GET_PARAM(TypeTag, std::string, EclDeckFileName));
474  std::string basename;
475  // Strip extension "." and ".DATA"
476  std::string extension = uppercase(deck_filename.extension().string());
477  if ( extension == ".DATA" || extension == "." )
478  {
479  basename = uppercase(deck_filename.stem().string());
480  }
481  else
482  {
483  basename = uppercase(deck_filename.filename().string());
484  }
485  std::for_each(fs::directory_iterator(output_path),
486  fs::directory_iterator(),
487  detail::ParallelFileMerger(output_path, basename,
488  EWOMS_GET_PARAM(TypeTag, bool, EnableLoggingFalloutWarning)));
489  }
490 
491  void setupEbosSimulator()
492  {
493  ebosSimulator_.reset(new EbosSimulator(EclGenericVanguard::comm(), /*verbose=*/false));
494  ebosSimulator_->executionTimer().start();
495  ebosSimulator_->model().applyInitialSolution();
496 
497  try {
498  // Possible to force initialization only behavior (NOSIM).
499  const std::string& dryRunString = EWOMS_GET_PARAM(TypeTag, std::string, EnableDryRun);
500  if (dryRunString != "" && dryRunString != "auto") {
501  bool yesno;
502  if (dryRunString == "true"
503  || dryRunString == "t"
504  || dryRunString == "1")
505  yesno = true;
506  else if (dryRunString == "false"
507  || dryRunString == "f"
508  || dryRunString == "0")
509  yesno = false;
510  else
511  throw std::invalid_argument("Invalid value for parameter EnableDryRun: '"
512  +dryRunString+"'");
513  auto& ioConfig = eclState().getIOConfig();
514  ioConfig.overrideNOSIM(yesno);
515  }
516  }
517  catch (const std::invalid_argument& e) {
518  std::cerr << "Failed to create valid EclipseState object" << std::endl;
519  std::cerr << "Exception caught: " << e.what() << std::endl;
520  throw;
521  }
522  }
523 
524  const Deck& deck() const
525  { return ebosSimulator_->vanguard().deck(); }
526 
527  Deck& deck()
528  { return ebosSimulator_->vanguard().deck(); }
529 
530  const EclipseState& eclState() const
531  { return ebosSimulator_->vanguard().eclState(); }
532 
533  EclipseState& eclState()
534  { return ebosSimulator_->vanguard().eclState(); }
535 
536  const Schedule& schedule() const
537  { return ebosSimulator_->vanguard().schedule(); }
538 
539  // Run the simulator.
540  int runSimulator()
541  {
542  return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorRunCallback_);
543  }
544 
545  int runSimulatorInit()
546  {
547  return runSimulatorInitOrRun_(&FlowMainEbos::runSimulatorInitCallback_);
548  }
549 
550  private:
551  // Callback that will be called from runSimulatorInitOrRun_().
552  int runSimulatorRunCallback_()
553  {
554  SimulatorReport report = simulator_->run(*simtimer_);
555  runSimulatorAfterSim_(report);
556  return report.success.exit_status;
557  }
558 
559  // Callback that will be called from runSimulatorInitOrRun_().
560  int runSimulatorInitCallback_()
561  {
562  simulator_->init(*simtimer_);
563  return EXIT_SUCCESS;
564  }
565 
566  // Output summary after simulation has completed
567  void runSimulatorAfterSim_(SimulatorReport &report)
568  {
569  if (this->output_cout_) {
570  std::ostringstream ss;
571  ss << "\n\n================ End of simulation ===============\n\n";
572  ss << fmt::format("Number of MPI processes: {:9}\n", mpi_size_ );
573 #if _OPENMP
574  int threads = omp_get_max_threads();
575 #else
576  int threads = 1;
577 #endif
578  ss << fmt::format("Threads per MPI process: {:9}\n", threads);
579  report.reportFullyImplicit(ss);
580  OpmLog::info(ss.str());
581  const std::string dir = eclState().getIOConfig().getOutputDir();
582  namespace fs = ::std::filesystem;
583  fs::path output_dir(dir);
584  {
585  std::string filename = eclState().getIOConfig().getBaseName() + ".INFOSTEP";
586  fs::path fullpath = output_dir / filename;
587  std::ofstream os(fullpath.string());
588  report.fullReports(os);
589  }
590  }
591  }
592 
593  // Run the simulator.
594  int runSimulatorInitOrRun_(int (FlowMainEbos::* initOrRunFunc)())
595  {
596 
597  const auto& schedule = this->schedule();
598  auto& ioConfig = eclState().getIOConfig();
599  simtimer_ = std::make_unique<SimulatorTimer>();
600 
601  // initialize variables
602  const auto& initConfig = eclState().getInitConfig();
603  simtimer_->init(schedule, (size_t)initConfig.getRestartStep());
604 
605  if (this->output_cout_) {
606  std::ostringstream oss;
607 
608  // This allows a user to catch typos and misunderstandings in the
609  // use of simulator parameters.
610  if (Parameters::printUnused<TypeTag>(oss)) {
611  std::cout << "----------------- Unrecognized parameters: -----------------\n";
612  std::cout << oss.str();
613  std::cout << "----------------------------------------------------------------" << std::endl;
614  }
615  }
616 
617  if (!ioConfig.initOnly()) {
618  if (this->output_cout_) {
619  std::string msg;
620  msg = "\n\n================ Starting main simulation loop ===============\n";
621  OpmLog::info(msg);
622  }
623 
624  return (this->*initOrRunFunc)();
625  }
626  else {
627  if (this->output_cout_) {
628  std::cout << "\n\n================ Simulation turned off ===============\n" << std::flush;
629  }
630  return EXIT_SUCCESS;
631  }
632  }
633 
634  protected:
635 
637  // Create simulator instance.
638  // Writes to:
639  // simulator_
641  {
642  // Create the simulator instance.
643  simulator_.reset(new Simulator(*ebosSimulator_));
644  }
645 
646  static unsigned long long getTotalSystemMemory()
647  {
648  long pages = sysconf(_SC_PHYS_PAGES);
649  long page_size = sysconf(_SC_PAGE_SIZE);
650  return pages * page_size;
651  }
652 
653 
654  Grid& grid()
655  { return ebosSimulator_->vanguard().grid(); }
656 
657  private:
658  std::unique_ptr<EbosSimulator> ebosSimulator_;
659  int mpi_rank_ = 0;
660  int mpi_size_ = 1;
661  std::any parallel_information_;
662  std::unique_ptr<Simulator> simulator_;
663  std::unique_ptr<SimulatorTimer> simtimer_;
664  int argc_;
665  char **argv_;
666  bool output_cout_;
667  bool output_files_;
668  };
669 } // namespace Opm
670 
671 #endif // OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
Definition: FlowMainEbos.hpp:88
int execute()
This is the main function of Flow.
Definition: FlowMainEbos.hpp:315
void createSimulator()
This is the main function of Flow.
Definition: FlowMainEbos.hpp:640
a simulator for the blackoil model
Definition: SimulatorFullyImplicitBlackoilEbos.hpp:72
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
std::string moduleVersionName()
Return the version name of the module, for example "2015.10" (for a release branch) or "2016....
Definition: moduleVersion.cpp:29
std::string compileTimestamp()
Return a string "dd-mm-yyyy at HH::MM::SS hrs" which is the time the binary was compiled.
Definition: moduleVersion.cpp:52
std::string moduleVersion()
Return a string containing both the name and hash, if N is the name and H is the hash it will be "N (...
Definition: moduleVersion.cpp:45
Definition: FlowMainEbos.hpp:51
Definition: FlowMainEbos.hpp:59
Definition: FlowMainEbos.hpp:55