22 #ifndef OPM_MAIN_HEADER_INCLUDED
23 #define OPM_MAIN_HEADER_INCLUDED
25 #include <flow/flow_ebos_blackoil.hpp>
27 #include <flow/flow_ebos_gasoil.hpp>
28 #include <flow/flow_ebos_gasoil_energy.hpp>
29 #include <flow/flow_ebos_oilwater.hpp>
30 #include <flow/flow_ebos_gaswater.hpp>
31 #include <flow/flow_ebos_solvent.hpp>
32 #include <flow/flow_ebos_polymer.hpp>
33 #include <flow/flow_ebos_extbo.hpp>
34 #include <flow/flow_ebos_foam.hpp>
35 #include <flow/flow_ebos_brine.hpp>
36 #include <flow/flow_ebos_brine_saltprecipitation.hpp>
37 #include <flow/flow_ebos_gaswater_saltprec_vapwat.hpp>
38 #include <flow/flow_ebos_onephase.hpp>
39 #include <flow/flow_ebos_onephase_energy.hpp>
40 #include <flow/flow_ebos_oilwater_brine.hpp>
41 #include <flow/flow_ebos_gaswater_brine.hpp>
42 #include <flow/flow_ebos_energy.hpp>
43 #include <flow/flow_ebos_oilwater_polymer.hpp>
44 #include <flow/flow_ebos_oilwater_polymer_injectivity.hpp>
45 #include <flow/flow_ebos_micp.hpp>
47 #include <opm/input/eclipse/Deck/Deck.hpp>
48 #include <opm/input/eclipse/Parser/ErrorGuard.hpp>
49 #include <opm/input/eclipse/Parser/Parser.hpp>
50 #include <opm/input/eclipse/Parser/ParseContext.hpp>
51 #include <opm/input/eclipse/EclipseState/EclipseState.hpp>
52 #include <opm/input/eclipse/EclipseState/checkDeck.hpp>
53 #include <opm/input/eclipse/Schedule/ArrayDimChecker.hpp>
54 #include <opm/input/eclipse/Schedule/UDQ/UDQState.hpp>
55 #include <opm/input/eclipse/Schedule/Action/State.hpp>
56 #include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
58 #include <opm/models/utils/propertysystem.hh>
59 #include <opm/models/utils/parametersystem.hh>
61 #include <opm/simulators/flow/FlowMainEbos.hpp>
62 #include <opm/simulators/utils/readDeck.hpp>
65 #include <dune/fem/misc/mpimanager.hh>
67 #include <dune/common/parallel/mpihelper.hh>
71 #include <opm/simulators/utils/ParallelEclipseState.hpp>
81 #include <type_traits>
84 namespace Opm::Properties {
90 using InheritsFrom = std::tuple<EclFlowProblem>;
98 template <
class TypeTag>
99 void flowEbosSetDeck(std::shared_ptr<Deck> deck,
100 std::shared_ptr<EclipseState> eclState,
101 std::shared_ptr<Schedule> schedule,
102 std::shared_ptr<SummaryConfig> summaryConfig)
104 using Vanguard = GetPropType<TypeTag, Properties::Vanguard>;
106 Vanguard::setExternalDeck(deck);
107 Vanguard::setExternalEclState(eclState);
108 Vanguard::setExternalSchedule(schedule);
109 Vanguard::setExternalSummaryConfig(summaryConfig);
113 template <
class TypeTag>
114 int flowEbosMain(
int argc,
char** argv,
bool outputCout,
bool outputFiles)
120 FlowMainEbos<TypeTag> mainfunc(argc, argv, outputCout, outputFiles);
121 return mainfunc.execute();
137 Main(
int argc,
char** argv) : argc_(argc), argv_(argv) { initMPI(); }
140 Main(
const std::string& filename)
142 setArgvArgc_(filename);
148 Main(std::shared_ptr<Deck> deck,
149 std::shared_ptr<EclipseState> eclipseState,
150 std::shared_ptr<Schedule> schedule,
151 std::shared_ptr<SummaryConfig> summaryConfig)
152 : deck_{std::move(deck)}
153 , eclipseState_{std::move(eclipseState)}
154 , schedule_{std::move(schedule)}
155 , summaryConfig_{std::move(summaryConfig)}
157 setArgvArgc_(deck_->getDataFile());
165 if (test_split_comm_) {
170 MPI_Comm_size(MPI_COMM_WORLD, &world_size);
171 if (world_size > 1) {
172 MPI_Comm new_comm = EclGenericVanguard::comm();
174 MPI_Comm_compare(MPI_COMM_WORLD, new_comm, &result);
175 assert(result == MPI_UNEQUAL);
176 MPI_Comm_free(&new_comm);
181 EclGenericVanguard::setCommunication(
nullptr);
183 #if HAVE_MPI && !HAVE_DUNE_FEM
188 void setArgvArgc_(
const std::string& filename)
190 this->deckFilename_ = filename;
191 this->flowProgName_ =
"flow";
194 this->saveArgs_[0] =
const_cast<char *
>(this->flowProgName_.c_str());
195 this->saveArgs_[1] =
const_cast<char *
>(this->deckFilename_.c_str());
198 assert ((
sizeof this->saveArgs_) > (this->argc_ *
sizeof this->saveArgs_[0]));
199 this->saveArgs_[this->argc_] =
nullptr;
201 this->argv_ = this->saveArgs_;
207 Dune::Fem::MPIManager::initialize(argc_, argv_);
209 MPI_Init(&argc_, &argv_);
211 EclGenericVanguard::setCommunication(std::make_unique<Parallel::Communication>());
213 handleTestSplitCommunicatorCmdLine_();
216 if (test_split_comm_ && EclGenericVanguard::comm().size() > 1) {
217 int world_rank = EclGenericVanguard::comm().rank();
218 int color = (world_rank == 0);
220 MPI_Comm_split(EclGenericVanguard::comm(), color, world_rank, &new_comm);
221 isSimulationRank_ = (world_rank > 0);
222 EclGenericVanguard::setCommunication(std::make_unique<Parallel::Communication>(new_comm));
229 int exitCode = EXIT_SUCCESS;
230 if (isSimulationRank_) {
231 if (initialize_<Properties::TTag::FlowEarlyBird>(exitCode)) {
232 return this->dispatchDynamic_();
239 template <
class TypeTag>
242 int exitCode = EXIT_SUCCESS;
243 if (isSimulationRank_) {
244 if (initialize_<TypeTag>(exitCode)) {
245 return this->dispatchStatic_<TypeTag>();
256 std::unique_ptr<FlowMainEbosType> initFlowEbosBlackoil(
int& exitCode)
258 exitCode = EXIT_SUCCESS;
259 if (initialize_<Properties::TTag::FlowEarlyBird>(exitCode)) {
262 flowEbosBlackoilSetDeck(
267 std::move(udqState_),
268 std::move(this->actionState_),
269 std::move(this->wtestState_),
271 return flowEbosBlackoilMainInit(
272 argc_, argv_, outputCout_, outputFiles_);
275 return std::unique_ptr<FlowMainEbosType>();
280 int dispatchDynamic_()
282 const auto& rspec = this->eclipseState_->runspec();
283 const auto& phases = rspec.phases();
292 return this->runMICP(phases);
296 else if(phases.size() == 1 && phases.active(Phase::WATER) && !eclipseState_->getSimulationConfig().isThermal()) {
297 return this->runWaterOnly(phases);
301 else if(phases.size() == 2 && phases.active(Phase::WATER) && eclipseState_->getSimulationConfig().isThermal()) {
302 return this->runWaterOnlyEnergy(phases);
306 else if (phases.size() == 2 && !eclipseState_->getSimulationConfig().isThermal()) {
307 return this->runTwoPhase(phases);
311 else if (phases.active(Phase::POLYMER)) {
312 return this->runPolymer(phases);
316 else if (phases.active(Phase::FOAM)) {
317 return this->runFoam();
321 else if (phases.active(Phase::BRINE)) {
322 return this->runBrine(phases);
326 else if (phases.active(Phase::SOLVENT)) {
327 return this->runSolvent();
331 else if (phases.active(Phase::ZFRACTION)) {
332 return this->runExtendedBlackOil();
336 else if (eclipseState_->getSimulationConfig().isThermal()) {
337 return this->runThermal(phases);
341 else if (phases.size() == 3) {
342 return this->runBlackOil();
347 std::cerr <<
"No suitable configuration found, valid are "
348 <<
"Twophase, polymer, foam, brine, solvent, "
349 <<
"energy, and blackoil.\n";
356 template <
class TypeTag>
357 int dispatchStatic_()
359 flowEbosSetDeck<TypeTag>(
360 deck_, eclipseState_, schedule_, summaryConfig_);
361 return flowEbosMain<TypeTag>(argc_, argv_, outputCout_, outputFiles_);
370 template <
class TypeTagEarlyBird>
371 bool initialize_(
int& exitCode)
373 Dune::Timer externalSetupTimer;
374 externalSetupTimer.start();
376 handleVersionCmdLine_(argc_, argv_);
378 int mpiRank = Dune::Fem::MPIManager::rank();
380 int mpiRank = EclGenericVanguard::comm().rank();
393 typedef TypeTagEarlyBird PreTypeTag;
394 using PreProblem = GetPropType<PreTypeTag, Properties::Problem>;
396 PreProblem::setBriefDescription(
"Flow, an advanced reservoir simulator for ECL-decks provided by the Open Porous Media project.");
404 MPI_Abort(MPI_COMM_WORLD, status);
406 exitCode = (status > 0) ? status : EXIT_SUCCESS;
413 outputCout_ = EWOMS_GET_PARAM(PreTypeTag,
bool, EnableTerminalOutput);
415 std::string deckFilename;
416 std::string outputDir;
417 if ( eclipseState_ ) {
418 deckFilename = eclipseState_->getIOConfig().fullBasePath();
419 outputDir = eclipseState_->getIOConfig().getOutputDir();
422 deckFilename = EWOMS_GET_PARAM(PreTypeTag, std::string, EclDeckFileName);
425 if (deckFilename.empty()) {
427 std::cerr <<
"No input case given. Try '--help' for a usage description.\n";
429 exitCode = EXIT_FAILURE;
433 using PreVanguard = GetPropType<PreTypeTag, Properties::Vanguard>;
435 deckFilename = PreVanguard::canonicalDeckPath(deckFilename);
437 catch (
const std::exception& e) {
438 if ( mpiRank == 0 ) {
439 std::cerr <<
"Exception received: " << e.what() <<
". Try '--help' for a usage description.\n";
442 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
444 exitCode = EXIT_FAILURE;
452 auto python = std::make_shared<Python>();
453 const bool init_from_restart_file = !EWOMS_GET_PARAM(PreTypeTag,
bool, SchedRestart);
454 if (outputDir.empty())
455 outputDir = EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir);
457 const bool allRanksDbgPrtLog = EWOMS_GET_PARAM(PreTypeTag,
bool,
458 EnableLoggingFalloutWarning);
459 outputMode = setupLogging(mpiRank,
462 EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
463 outputCout_,
"STDOUT_LOGGER", allRanksDbgPrtLog);
465 std::make_unique<ParseContext>(std::vector<std::pair<std::string , InputError::Action>>
466 {{ParseContext::PARSE_RANDOM_SLASH, InputError::IGNORE},
467 {ParseContext::PARSE_MISSING_DIMS_KEYWORD, InputError::WARN},
468 {ParseContext::SUMMARY_UNKNOWN_WELL, InputError::WARN},
469 {ParseContext::SUMMARY_UNKNOWN_GROUP, InputError::WARN}});
470 if (EWOMS_GET_PARAM(PreTypeTag,
bool, EclStrictParsing))
471 parseContext->update(InputError::DELAYED_EXIT1);
476 OpmLog::info(
"Reading deck file '" + deckFilename +
"'");
479 std::optional<int> outputInterval;
480 int output_param = EWOMS_GET_PARAM(PreTypeTag,
int, EclOutputInterval);
481 if (output_param >= 0)
482 outputInterval = output_param;
484 readDeck(EclGenericVanguard::comm(), deckFilename, deck_, eclipseState_, schedule_, udqState_, actionState_, wtestState_,
485 summaryConfig_,
nullptr, python, std::move(parseContext),
486 init_from_restart_file, outputCout_, outputInterval);
488 verifyValidCellGeometry(EclGenericVanguard::comm(), *this->eclipseState_);
490 setupTime_ = externalSetupTimer.elapsed();
493 catch (
const std::invalid_argument& e)
496 std::cerr <<
"Failed to create valid EclipseState object." << std::endl;
497 std::cerr <<
"Exception caught: " << e.what() << std::endl;
500 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
502 exitCode = EXIT_FAILURE;
506 exitCode = EXIT_SUCCESS;
510 std::filesystem::path simulationCaseName_(
const std::string& casename)
512 namespace fs = ::std::filesystem;
514 auto exists = [](
const fs::path& f)
516 return (fs::exists(f) && fs::is_regular_file(f))
517 || (fs::is_symlink(f) &&
518 fs::is_regular_file(fs::read_symlink(f)));
521 auto simcase = fs::path { casename };
523 if (exists(simcase)) {
527 for (
const auto& ext : { std::string(
"DATA"), std::string(
"data") }) {
528 if (exists(simcase.replace_extension(ext))) {
533 throw std::invalid_argument {
534 "Cannot find input case '" + casename +
'\''
545 void handleVersionCmdLine_(
int argc,
char** argv)
547 auto pos = std::find_if(argv, argv + argc,
550 return std::strcmp(arg,
"--version") == 0;
553 if (pos != argv + argc) {
555 std::exit(EXIT_SUCCESS);
565 void handleTestSplitCommunicatorCmdLine_()
567 if (argc_ >= 2 && std::strcmp(argv_[1],
"--test-split-communicator=true") == 0) {
568 test_split_comm_ =
true;
575 int runMICP(
const Phases& phases)
577 if (!phases.active(Phase::WATER) || (phases.size() > 2)) {
579 std::cerr <<
"No valid configuration is found for MICP simulation, "
580 <<
"the only valid option is water + MICP\n";
586 flowEbosMICPSetDeck(this->setupTime_,
590 this->summaryConfig_);
592 return flowEbosMICPMain(this->argc_,
598 int runTwoPhase(
const Phases& phases)
601 if (phases.active( Phase::OIL ) && phases.active( Phase::GAS )) {
602 flowEbosGasOilSetDeck(
603 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
604 return flowEbosGasOilMain(argc_, argv_, outputCout_, outputFiles_);
608 else if ( phases.active( Phase::OIL ) && phases.active( Phase::WATER ) ) {
609 flowEbosOilWaterSetDeck(
610 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
611 return flowEbosOilWaterMain(argc_, argv_, outputCout_, outputFiles_);
615 else if ( phases.active( Phase::GAS ) && phases.active( Phase::WATER ) ) {
616 flowEbosGasWaterSetDeck(
617 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
618 return flowEbosGasWaterMain(argc_, argv_, outputCout_, outputFiles_);
622 std::cerr <<
"No suitable configuration found, valid are Twophase (oilwater, oilgas and gaswater), polymer, solvent, or blackoil" << std::endl;
629 int runPolymer(
const Phases& phases)
631 if (! phases.active(Phase::WATER)) {
633 std::cerr <<
"No valid configuration is found for polymer simulation, valid options include "
634 <<
"oilwater + polymer and blackoil + polymer" << std::endl;
641 if (phases.active(Phase::POLYMW)) {
643 assert (phases.size() == 4);
644 return flowEbosOilWaterPolymerInjectivityMain(argc_, argv_, outputCout_, outputFiles_);
647 if (phases.size() == 3) {
648 flowEbosOilWaterPolymerSetDeck(
649 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
650 return flowEbosOilWaterPolymerMain(argc_, argv_, outputCout_, outputFiles_);
653 flowEbosPolymerSetDeck(
654 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
655 return flowEbosPolymerMain(argc_, argv_, outputCout_, outputFiles_);
662 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
664 return flowEbosFoamMain(argc_, argv_, outputCout_, outputFiles_);
667 int runWaterOnly(
const Phases& phases)
669 if (!phases.active(Phase::WATER) || phases.size() != 1) {
671 std::cerr <<
"No valid configuration is found for water-only simulation, valid options include "
672 <<
"water, water + thermal" << std::endl;
676 flowEbosWaterOnlySetDeck(
677 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
679 return flowEbosWaterOnlyMain(argc_, argv_, outputCout_, outputFiles_);
682 int runWaterOnlyEnergy(
const Phases& phases)
684 if (!phases.active(Phase::WATER) || phases.size() != 2) {
686 std::cerr <<
"No valid configuration is found for water-only simulation, valid options include "
687 <<
"water, water + thermal" << std::endl;
691 flowEbosWaterOnlyEnergySetDeck(
692 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
694 return flowEbosWaterOnlyEnergyMain(argc_, argv_, outputCout_, outputFiles_);
697 int runBrine(
const Phases& phases)
699 if (! phases.active(Phase::WATER) || phases.size() == 2) {
701 std::cerr <<
"No valid configuration is found for brine simulation, valid options include "
702 <<
"oilwater + brine, gaswater + brine and blackoil + brine" << std::endl;
707 if (phases.size() == 3) {
709 if (phases.active(Phase::OIL)){
710 flowEbosOilWaterBrineSetDeck(
711 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
712 return flowEbosOilWaterBrineMain(argc_, argv_, outputCout_, outputFiles_);
714 if (phases.active(Phase::GAS)){
715 if (eclipseState_->getSimulationConfig().hasPRECSALT() &&
716 eclipseState_->getSimulationConfig().hasVAPWAT()) {
718 flowEbosGasWaterSaltprecVapwatSetDeck(
719 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
720 return flowEbosGasWaterSaltprecVapwatMain(argc_, argv_, outputCout_, outputFiles_);
723 flowEbosGasWaterBrineSetDeck(
724 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
725 return flowEbosGasWaterBrineMain(argc_, argv_, outputCout_, outputFiles_);
729 else if (eclipseState_->getSimulationConfig().hasPRECSALT()) {
730 flowEbosBrineSaltPrecipitationSetDeck(
731 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
732 return flowEbosBrineSaltPrecipitationMain(argc_, argv_, outputCout_, outputFiles_);
735 flowEbosBrineSetDeck(
736 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
737 return flowEbosBrineMain(argc_, argv_, outputCout_, outputFiles_);
745 flowEbosSolventSetDeck(
746 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
748 return flowEbosSolventMain(argc_, argv_, outputCout_, outputFiles_);
751 int runExtendedBlackOil()
753 flowEbosExtboSetDeck(
754 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
756 return flowEbosExtboMain(argc_, argv_, outputCout_, outputFiles_);
759 int runThermal(
const Phases& phases)
762 if (!phases.active( Phase::WATER ) && phases.active( Phase::OIL ) && phases.active( Phase::GAS )) {
763 flowEbosGasOilEnergySetDeck(
764 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
765 return flowEbosGasOilEnergyMain(argc_, argv_, outputCout_, outputFiles_);
768 flowEbosEnergySetDeck(
769 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
771 return flowEbosEnergyMain(argc_, argv_, outputCout_, outputFiles_);
776 flowEbosBlackoilSetDeck(this->setupTime_,
780 std::move(this->udqState_),
781 std::move(this->actionState_),
782 std::move(this->wtestState_),
783 this->summaryConfig_);
785 return flowEbosBlackoilMain(argc_, argv_, outputCout_, outputFiles_);
789 char** argv_{
nullptr};
790 bool outputCout_{
false};
791 bool outputFiles_{
false};
792 double setupTime_{0.0};
793 std::string deckFilename_{};
794 std::string flowProgName_{};
795 char *saveArgs_[3]{
nullptr};
796 std::unique_ptr<UDQState> udqState_{};
797 std::unique_ptr<Action::State> actionState_{};
798 std::unique_ptr<WellTestState> wtestState_{};
801 std::shared_ptr<Deck> deck_{};
802 std::shared_ptr<EclipseState> eclipseState_{};
803 std::shared_ptr<Schedule> schedule_{};
804 std::shared_ptr<SummaryConfig> summaryConfig_{};
807 bool test_split_comm_ =
false;
808 bool isSimulationRank_ =
true;
Definition: FlowMainEbos.hpp:88
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
FileOutputMode
Definition: readDeck.hpp:49
@ OUTPUT_NONE
No file output.
void readDeck(Parallel::Communication comm, const std::string &deckFilename, std::shared_ptr< Deck > &deck, std::shared_ptr< EclipseState > &eclipseState, std::shared_ptr< Schedule > &schedule, std::unique_ptr< UDQState > &udqState, std::unique_ptr< Action::State > &actionState, std::unique_ptr< WellTestState > &wtestState, std::shared_ptr< SummaryConfig > &summaryConfig, std::unique_ptr< ErrorGuard > errorGuard, std::shared_ptr< Python > python, std::unique_ptr< ParseContext > parseContext, bool initFromRestart, bool checkDeck, const std::optional< int > &outputInterval)
Reads the deck and creates all necessary objects if needed.
Definition: readDeck.cpp:476