22#ifndef OPM_MAIN_HEADER_INCLUDED
23#define OPM_MAIN_HEADER_INCLUDED
25#include <flow/flow_ebos_blackoil.hpp>
26#include <flow/flow_ebos_blackoil_legacyassembly.hpp>
28#include <flow/flow_ebos_gasoil.hpp>
29#include <flow/flow_ebos_gasoildiffuse.hpp>
30#include <flow/flow_ebos_gasoil_energy.hpp>
31#include <flow/flow_ebos_oilwater.hpp>
32#include <flow/flow_ebos_gaswater.hpp>
33#include <flow/flow_ebos_solvent.hpp>
34#include <flow/flow_ebos_polymer.hpp>
35#include <flow/flow_ebos_extbo.hpp>
36#include <flow/flow_ebos_foam.hpp>
37#include <flow/flow_ebos_brine.hpp>
38#include <flow/flow_ebos_brine_saltprecipitation.hpp>
39#include <flow/flow_ebos_gaswater_saltprec_vapwat.hpp>
40#include <flow/flow_ebos_brine_precsalt_vapwat.hpp>
41#include <flow/flow_ebos_onephase.hpp>
42#include <flow/flow_ebos_onephase_energy.hpp>
43#include <flow/flow_ebos_oilwater_brine.hpp>
44#include <flow/flow_ebos_gaswater_brine.hpp>
45#include <flow/flow_ebos_gaswater_energy.hpp>
46#include <flow/flow_ebos_gaswater_dissolution.hpp>
47#include <flow/flow_ebos_gaswater_dissolution_diffuse.hpp>
48#include <flow/flow_ebos_energy.hpp>
49#include <flow/flow_ebos_oilwater_polymer.hpp>
50#include <flow/flow_ebos_oilwater_polymer_injectivity.hpp>
51#include <flow/flow_ebos_micp.hpp>
53#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
55#include <opm/models/utils/propertysystem.hh>
56#include <opm/models/utils/parametersystem.hh>
58#include <opm/simulators/flow/Banners.hpp>
59#include <opm/simulators/flow/FlowMainEbos.hpp>
62#include <dune/fem/misc/mpimanager.hh>
64#include <dune/common/parallel/mpihelper.hh>
68#include <opm/simulators/utils/ParallelEclipseState.hpp>
81namespace Opm::Properties {
87 using InheritsFrom = std::tuple<EclFlowProblem>;
95namespace Action {
class State; }
100template <
class TypeTag>
101int flowEbosMain(
int argc,
char** argv,
bool outputCout,
bool outputFiles)
107 FlowMainEbos<TypeTag> mainfunc(argc, argv, outputCout, outputFiles);
108 return mainfunc.execute();
121 Main(
int argc,
char** argv);
124 Main(
const std::string& filename);
128 Main(
const std::string& filename,
129 std::shared_ptr<EclipseState> eclipseState,
130 std::shared_ptr<Schedule> schedule,
131 std::shared_ptr<SummaryConfig> summaryConfig);
135 void setArgvArgc_(
const std::string& filename);
141 int exitCode = EXIT_SUCCESS;
142 if (isSimulationRank_) {
143 if (initialize_<Properties::TTag::FlowEarlyBird>(exitCode)) {
144 return this->dispatchDynamic_();
151 template <
class TypeTag>
154 int exitCode = EXIT_SUCCESS;
155 if (isSimulationRank_) {
156 if (initialize_<TypeTag>(exitCode)) {
157 return this->dispatchStatic_<TypeTag>();
169 std::unique_ptr<FlowMainEbosType> initFlowEbosBlackoil(
int& exitCode)
171 exitCode = EXIT_SUCCESS;
172 if (initialize_<Properties::TTag::FlowEarlyBird>(exitCode)) {
175 this->setupVanguard();
176 return flowEbosBlackoilTpfaMainInit(
177 argc_, argv_, outputCout_, outputFiles_);
180 return std::unique_ptr<FlowMainEbosType>();
185 int dispatchDynamic_()
187 const auto& rspec = this->eclipseState_->runspec();
188 const auto& phases = rspec.phases();
190 this->setupVanguard();
196 const bool thermal = eclipseState_->getSimulationConfig().isThermal();
200 return this->runMICP(phases);
204 else if (phases.size() == 1 && phases.active(Phase::WATER) && !thermal) {
205 return this->runWaterOnly(phases);
209 else if (phases.size() == 2 && phases.active(Phase::WATER) && thermal) {
210 return this->runWaterOnlyEnergy(phases);
214 else if (phases.size() == 2 && !thermal) {
215 return this->runTwoPhase(phases);
219 else if (phases.active(Phase::POLYMER)) {
220 return this->runPolymer(phases);
224 else if (phases.active(Phase::FOAM)) {
225 return this->runFoam();
229 else if (phases.active(Phase::BRINE)) {
230 return this->runBrine(phases);
234 else if (phases.active(Phase::SOLVENT)) {
235 return this->runSolvent();
239 else if (phases.active(Phase::ZFRACTION)) {
240 return this->runExtendedBlackOil();
245 return this->runThermal(phases);
249 else if (phases.size() == 3) {
250 return this->runBlackOil();
255 std::cerr <<
"No suitable configuration found, valid are "
256 <<
"Twophase, polymer, foam, brine, solvent, "
257 <<
"energy, and blackoil.\n";
264 template <
class TypeTag>
265 int dispatchStatic_()
267 this->setupVanguard();
268 return flowEbosMain<TypeTag>(argc_, argv_, outputCout_, outputFiles_);
277 template <
class TypeTagEarlyBird>
278 bool initialize_(
int& exitCode)
280 Dune::Timer externalSetupTimer;
281 externalSetupTimer.start();
295 typedef TypeTagEarlyBird PreTypeTag;
296 using PreProblem = GetPropType<PreTypeTag, Properties::Problem>;
298 PreProblem::setBriefDescription(
"Flow, an advanced reservoir simulator for ECL-decks provided by the Open Porous Media project.");
306 MPI_Abort(MPI_COMM_WORLD, status);
308 exitCode = (status > 0) ? status : EXIT_SUCCESS;
312 std::string deckFilename;
313 std::string outputDir;
314 if ( eclipseState_ ) {
315 deckFilename = eclipseState_->getIOConfig().fullBasePath();
316 outputDir = eclipseState_->getIOConfig().getOutputDir();
319 deckFilename = EWOMS_GET_PARAM(PreTypeTag, std::string, EclDeckFileName);
320 outputDir = EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir);
324 enableDamarisOutput_ = EWOMS_GET_PARAM(PreTypeTag,
bool, EnableDamarisOutput);
325 if (enableDamarisOutput_) {
326 this->setupDamaris(outputDir,
327 EWOMS_GET_PARAM(PreTypeTag,
bool, EnableDamarisOutputCollective));
331 int mpiRank = EclGenericVanguard::comm().rank();
334 outputCout_ = EWOMS_GET_PARAM(PreTypeTag,
bool, EnableTerminalOutput);
337 if (deckFilename.empty()) {
339 std::cerr <<
"No input case given. Try '--help' for a usage description.\n";
341 exitCode = EXIT_FAILURE;
345 using PreVanguard = GetPropType<PreTypeTag, Properties::Vanguard>;
347 deckFilename = PreVanguard::canonicalDeckPath(deckFilename);
349 catch (
const std::exception& e) {
350 if ( mpiRank == 0 ) {
351 std::cerr <<
"Exception received: " << e.what() <<
". Try '--help' for a usage description.\n";
354 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
356 exitCode = EXIT_FAILURE;
360 std::string cmdline_params;
362 printFlowBanner(EclGenericVanguard::comm().size(),
363 getNumThreads<PreTypeTag>(),
365 std::ostringstream str;
366 Parameters::printValues<PreTypeTag>(str);
367 cmdline_params = str.str();
372 this->readDeck(deckFilename,
374 EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
375 !EWOMS_GET_PARAM(PreTypeTag,
bool, SchedRestart),
376 EWOMS_GET_PARAM(PreTypeTag,
bool, EnableLoggingFalloutWarning),
377 EWOMS_GET_PARAM(PreTypeTag, std::string, ParsingStrictness),
379 EWOMS_GET_PARAM(PreTypeTag,
int, EclOutputInterval),
383 setupTime_ = externalSetupTimer.elapsed();
385 catch (
const std::invalid_argument& e)
388 std::cerr <<
"Failed to create valid EclipseState object." << std::endl;
389 std::cerr <<
"Exception caught: " << e.what() << std::endl;
392 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
394 exitCode = EXIT_FAILURE;
398 exitCode = EXIT_SUCCESS;
409 void handleVersionCmdLine_(
int argc,
char** argv,
418 void handleTestSplitCommunicatorCmdLine_();
420 int runMICP(
const Phases& phases)
422 if (!phases.active(Phase::WATER) || (phases.size() > 2)) {
424 std::cerr <<
"No valid configuration is found for MICP simulation, "
425 <<
"the only valid option is water + MICP\n";
431 return flowEbosMICPMain(this->argc_,
437 int runTwoPhase(
const Phases& phases)
439 const bool diffusive = eclipseState_->getSimulationConfig().isDiffusive();
440 const bool disgasw = eclipseState_->getSimulationConfig().hasDISGASW();
443 if (phases.active( Phase::OIL ) && phases.active( Phase::GAS )) {
445 return flowEbosGasOilDiffuseMain(argc_, argv_, outputCout_, outputFiles_);
447 return flowEbosGasOilMain(argc_, argv_, outputCout_, outputFiles_);
452 else if ( phases.active( Phase::OIL ) && phases.active( Phase::WATER ) ) {
455 std::cerr <<
"The DIFFUSE option is not available for the two-phase water/oil model." << std::endl;
459 return flowEbosOilWaterMain(argc_, argv_, outputCout_, outputFiles_);
463 else if ( phases.active( Phase::GAS ) && phases.active( Phase::WATER ) ) {
466 return flowEbosGasWaterDissolutionDiffuseMain(argc_, argv_, outputCout_, outputFiles_);
468 return flowEbosGasWaterDissolutionMain(argc_, argv_, outputCout_, outputFiles_);
472 std::cerr <<
"The DIFFUSE option is not available for the two-phase gas/water model without disgasw." << std::endl;
477 return flowEbosGasWaterMain(argc_, argv_, outputCout_, outputFiles_);
481 std::cerr <<
"No suitable configuration found, valid are Twophase (oilwater, oilgas and gaswater), polymer, solvent, or blackoil" << std::endl;
488 int runPolymer(
const Phases& phases)
490 if (! phases.active(Phase::WATER)) {
492 std::cerr <<
"No valid configuration is found for polymer simulation, valid options include "
493 <<
"oilwater + polymer and blackoil + polymer" << std::endl;
500 if (phases.active(Phase::POLYMW)) {
502 assert (phases.size() == 4);
503 return flowEbosOilWaterPolymerInjectivityMain(argc_, argv_, outputCout_, outputFiles_);
506 if (phases.size() == 3) {
507 return flowEbosOilWaterPolymerMain(argc_, argv_, outputCout_, outputFiles_);
510 return flowEbosPolymerMain(argc_, argv_, outputCout_, outputFiles_);
516 return flowEbosFoamMain(argc_, argv_, outputCout_, outputFiles_);
519 int runWaterOnly(
const Phases& phases)
521 if (!phases.active(Phase::WATER) || phases.size() != 1) {
523 std::cerr <<
"No valid configuration is found for water-only simulation, valid options include "
524 <<
"water, water + thermal" << std::endl;
529 return flowEbosWaterOnlyMain(argc_, argv_, outputCout_, outputFiles_);
532 int runWaterOnlyEnergy(
const Phases& phases)
534 if (!phases.active(Phase::WATER) || phases.size() != 2) {
536 std::cerr <<
"No valid configuration is found for water-only simulation, valid options include "
537 <<
"water, water + thermal" << std::endl;
542 return flowEbosWaterOnlyEnergyMain(argc_, argv_, outputCout_, outputFiles_);
545 int runBrine(
const Phases& phases)
547 if (! phases.active(Phase::WATER) || phases.size() == 2) {
549 std::cerr <<
"No valid configuration is found for brine simulation, valid options include "
550 <<
"oilwater + brine, gaswater + brine and blackoil + brine" << std::endl;
555 if (phases.size() == 3) {
557 if (phases.active(Phase::OIL)){
558 return flowEbosOilWaterBrineMain(argc_, argv_, outputCout_, outputFiles_);
560 if (phases.active(Phase::GAS)){
561 if (eclipseState_->getSimulationConfig().hasPRECSALT() &&
562 eclipseState_->getSimulationConfig().hasVAPWAT()) {
564 return flowEbosGasWaterSaltprecVapwatMain(argc_, argv_, outputCout_, outputFiles_);
567 return flowEbosGasWaterBrineMain(argc_, argv_, outputCout_, outputFiles_);
571 else if (eclipseState_->getSimulationConfig().hasPRECSALT()) {
572 if (eclipseState_->getSimulationConfig().hasVAPWAT()) {
574 return flowEbosBrinePrecsaltVapwatMain(argc_, argv_, outputCout_, outputFiles_);
577 return flowEbosBrineSaltPrecipitationMain(argc_, argv_, outputCout_, outputFiles_);
581 return flowEbosBrineMain(argc_, argv_, outputCout_, outputFiles_);
589 return flowEbosSolventMain(argc_, argv_, outputCout_, outputFiles_);
592 int runExtendedBlackOil()
594 return flowEbosExtboMain(argc_, argv_, outputCout_, outputFiles_);
597 int runThermal(
const Phases& phases)
600 if (!phases.active( Phase::WATER ) && phases.active( Phase::OIL ) && phases.active( Phase::GAS )) {
601 return flowEbosGasOilEnergyMain(argc_, argv_, outputCout_, outputFiles_);
605 if (!phases.active( Phase::OIL ) && phases.active( Phase::WATER ) && phases.active( Phase::GAS )) {
606 return flowEbosGasWaterEnergyMain(argc_, argv_, outputCout_, outputFiles_);
609 return flowEbosEnergyMain(argc_, argv_, outputCout_, outputFiles_);
614 const bool diffusive = eclipseState_->getSimulationConfig().isDiffusive();
618 return flowEbosBlackoilMain(argc_, argv_, outputCout_, outputFiles_);
620 return flowEbosBlackoilTpfaMain(argc_, argv_, outputCout_, outputFiles_);
624 void readDeck(
const std::string& deckFilename,
625 const std::string& outputDir,
626 const std::string& outputMode,
627 const bool init_from_restart_file,
628 const bool allRanksDbgPrtLog,
629 const std::string& parsingStrictness,
631 const int output_param,
632 const std::string& parameters,
636 void setupVanguard();
638 template<
class TypeTag>
639 static int getNumThreads()
648 if (std::getenv(
"OMP_NUM_THREADS"))
649 threads = omp_get_max_threads();
651 threads = std::min(2, omp_get_max_threads());
653 const int input_threads = EWOMS_GET_PARAM(TypeTag,
int, ThreadsPerProcess);
655 if (input_threads > 0)
656 threads = std::min(input_threads, omp_get_max_threads());
663 void setupDamaris(
const std::string& outputDir,
664 const bool enableDamarisOutputCollective);
668 char** argv_{
nullptr};
669 bool outputCout_{
false};
670 bool outputFiles_{
false};
671 double setupTime_{0.0};
672 std::string deckFilename_{};
673 std::string flowProgName_{};
674 char *saveArgs_[3]{
nullptr};
675 std::unique_ptr<UDQState> udqState_{};
676 std::unique_ptr<Action::State> actionState_{};
677 std::unique_ptr<WellTestState> wtestState_{};
680 std::shared_ptr<EclipseState> eclipseState_{};
681 std::shared_ptr<Schedule> schedule_{};
682 std::shared_ptr<SummaryConfig> summaryConfig_{};
685 bool test_split_comm_ =
false;
686 bool isSimulationRank_ =
true;
688 bool enableDamarisOutput_ =
false;
Definition: FlowMainEbos.hpp:93
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:34
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:57
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:50