22#ifndef OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
23#define OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED
25#include <opm/simulators/flow/Banners.hpp>
26#include <opm/simulators/flow/SimulatorFullyImplicitBlackoilEbos.hpp>
28#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
29#include <opm/input/eclipse/EclipseState/IOConfig/IOConfig.hpp>
30#include <opm/input/eclipse/EclipseState/InitConfig/InitConfig.hpp>
33#include <dune/fem/misc/mpimanager.hh>
35#include <dune/common/parallel/mpihelper.hh>
41namespace Opm::Properties {
43template<
class TypeTag,
class MyTypeTag>
45 using type = UndefinedProperty;
47template<
class TypeTag,
class MyTypeTag>
49 using type = UndefinedProperty;
51template<
class TypeTag,
class MyTypeTag>
53 using type = UndefinedProperty;
57template<
class TypeTag>
59 static constexpr auto value =
"auto";
62template<
class TypeTag>
64 static constexpr bool value =
false;
66template<
class TypeTag>
68 static constexpr int value = 1;
76void mergeParallelLogFiles(std::string_view output_dir,
77 std::string_view deck_filename,
78 bool enableLoggingFalloutWarning);
81 std::string_view option,
82 std::string_view optionName,
83 std::string_view output_dir,
84 std::string_view base_name);
91 template <
class TypeTag>
95 using MaterialLawManager =
typename GetProp<TypeTag, Properties::MaterialLaw>::EclMaterialLawManager;
96 using EbosSimulator = GetPropType<TypeTag, Properties::Simulator>;
97 using Grid = GetPropType<TypeTag, Properties::Grid>;
98 using GridView = GetPropType<TypeTag, Properties::GridView>;
99 using Problem = GetPropType<TypeTag, Properties::Problem>;
100 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
101 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
105 FlowMainEbos(
int argc,
char **argv,
bool output_cout,
bool output_files )
106 : argc_{argc}, argv_{argv},
107 output_cout_{output_cout}, output_files_{output_files}
113 static int setupParameters_(
int argc,
char** argv, Parallel::Communication comm)
115 using ParamsMeta = GetProp<TypeTag, Properties::ParameterMetaData>;
116 if (!ParamsMeta::registrationOpen()) {
127 EWOMS_REGISTER_PARAM(TypeTag, std::string, EnableDryRun,
128 "Specify if the simulation ought to be actually run, or just pretended to be");
129 EWOMS_REGISTER_PARAM(TypeTag,
int, OutputInterval,
130 "Specify the number of report steps between two consecutive writes of restart data");
131 EWOMS_REGISTER_PARAM(TypeTag,
bool, EnableLoggingFalloutWarning,
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();
137 registerAllParameters_<TypeTag>(
false);
140 EWOMS_HIDE_PARAM(TypeTag, EnableGravity);
141 EWOMS_HIDE_PARAM(TypeTag, EnableGridAdaptation);
146 EWOMS_HIDE_PARAM(TypeTag, EnableIntensiveQuantityCache);
150 EWOMS_HIDE_PARAM(TypeTag, EnableThermodynamicHints);
153 EWOMS_HIDE_PARAM(TypeTag, EndTime);
156 EWOMS_HIDE_PARAM(TypeTag, InitialTimeStepSize);
157 EWOMS_HIDE_PARAM(TypeTag, MaxTimeStepDivisions);
158 EWOMS_HIDE_PARAM(TypeTag, MaxTimeStepSize);
159 EWOMS_HIDE_PARAM(TypeTag, MinTimeStepSize);
160 EWOMS_HIDE_PARAM(TypeTag, PredeterminedTimeStepsFile);
162 EWOMS_HIDE_PARAM(TypeTag, EclMaxTimeStepSizeAfterWellEvent);
163 EWOMS_HIDE_PARAM(TypeTag, EclRestartShrinkFactor);
164 EWOMS_HIDE_PARAM(TypeTag, EclEnableTuning);
167 EWOMS_HIDE_PARAM(TypeTag, NewtonMaxError);
168 EWOMS_HIDE_PARAM(TypeTag, NewtonTolerance);
169 EWOMS_HIDE_PARAM(TypeTag, NewtonTargetIterations);
170 EWOMS_HIDE_PARAM(TypeTag, NewtonVerbose);
171 EWOMS_HIDE_PARAM(TypeTag, NewtonWriteConvergence);
172 EWOMS_HIDE_PARAM(TypeTag, EclNewtonSumTolerance);
173 EWOMS_HIDE_PARAM(TypeTag, EclNewtonSumToleranceExponent);
174 EWOMS_HIDE_PARAM(TypeTag, EclNewtonStrictIterations);
175 EWOMS_HIDE_PARAM(TypeTag, EclNewtonRelaxedVolumeFraction);
176 EWOMS_HIDE_PARAM(TypeTag, EclNewtonRelaxedTolerance);
179 EWOMS_HIDE_PARAM(TypeTag, RestartTime);
180 EWOMS_HIDE_PARAM(TypeTag, RestartWritingInterval);
183 EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilFormationVolumeFactor);
184 EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilSaturationPressure);
185 EWOMS_HIDE_PARAM(TypeTag, VtkWriteOilVaporizationFactor);
186 EWOMS_HIDE_PARAM(TypeTag, VtkWritePorosity);
187 EWOMS_HIDE_PARAM(TypeTag, VtkWritePotentialGradients);
188 EWOMS_HIDE_PARAM(TypeTag, VtkWritePressures);
189 EWOMS_HIDE_PARAM(TypeTag, VtkWritePrimaryVars);
190 EWOMS_HIDE_PARAM(TypeTag, VtkWritePrimaryVarsMeaning);
191 EWOMS_HIDE_PARAM(TypeTag, VtkWriteProcessRank);
192 EWOMS_HIDE_PARAM(TypeTag, VtkWriteRelativePermeabilities);
193 EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturatedGasOilVaporizationFactor);
194 EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturatedOilGasDissolutionFactor);
195 EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturationRatios);
196 EWOMS_HIDE_PARAM(TypeTag, VtkWriteSaturations);
197 EWOMS_HIDE_PARAM(TypeTag, VtkWriteTemperature);
198 EWOMS_HIDE_PARAM(TypeTag, VtkWriteViscosities);
199 EWOMS_HIDE_PARAM(TypeTag, VtkWriteWaterFormationVolumeFactor);
200 EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasDissolutionFactor);
201 EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasFormationVolumeFactor);
202 EWOMS_HIDE_PARAM(TypeTag, VtkWriteGasSaturationPressure);
203 EWOMS_HIDE_PARAM(TypeTag, VtkWriteIntrinsicPermeabilities);
204 EWOMS_HIDE_PARAM(TypeTag, VtkWriteEclTracerConcentration);
205 EWOMS_HIDE_PARAM(TypeTag, VtkWriteExtrusionFactor);
206 EWOMS_HIDE_PARAM(TypeTag, VtkWriteFilterVelocities);
207 EWOMS_HIDE_PARAM(TypeTag, VtkWriteDensities);
208 EWOMS_HIDE_PARAM(TypeTag, VtkWriteDofIndex);
209 EWOMS_HIDE_PARAM(TypeTag, VtkWriteMobilities);
211 EWOMS_HIDE_PARAM(TypeTag, VtkWriteAverageMolarMasses);
212 EWOMS_HIDE_PARAM(TypeTag, VtkWriteFugacities);
213 EWOMS_HIDE_PARAM(TypeTag, VtkWriteFugacityCoeffs);
214 EWOMS_HIDE_PARAM(TypeTag, VtkWriteMassFractions);
215 EWOMS_HIDE_PARAM(TypeTag, VtkWriteMolarities);
216 EWOMS_HIDE_PARAM(TypeTag, VtkWriteMoleFractions);
217 EWOMS_HIDE_PARAM(TypeTag, VtkWriteTotalMassFractions);
218 EWOMS_HIDE_PARAM(TypeTag, VtkWriteTotalMoleFractions);
220 EWOMS_HIDE_PARAM(TypeTag, VtkWriteTortuosities);
221 EWOMS_HIDE_PARAM(TypeTag, VtkWriteDiffusionCoefficients);
222 EWOMS_HIDE_PARAM(TypeTag, VtkWriteEffectiveDiffusionCoefficients);
224 EWOMS_END_PARAM_REGISTRATION(TypeTag);
226 int mpiRank = comm.rank();
229 int status = ::Opm::setupParameters_<TypeTag>(argc,
const_cast<const char**
>(argv),
false,
true, (mpiRank==0));
234 int unknownKeyWords = 0;
236 unknownKeyWords = Parameters::printUnused<TypeTag>(std::cerr);
238 int globalUnknownKeyWords = comm.sum(unknownKeyWords);
239 unknownKeyWords = globalUnknownKeyWords;
240 if ( unknownKeyWords )
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;
262 if (EWOMS_GET_PARAM(TypeTag,
int, PrintProperties) == 1) {
265 Properties::printValues<TypeTag>(std::cout);
268 if (EWOMS_GET_PARAM(TypeTag,
int, PrintParameters) == 1) {
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
a simulator for the blackoil model
Definition: SimulatorFullyImplicitBlackoilEbos.hpp:144
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27
Definition: FlowMainEbos.hpp:44
Definition: FlowMainEbos.hpp:52
Definition: FlowMainEbos.hpp:48
Definition: SimulatorReport.hpp:100