22 #ifndef OPM_MAIN_HEADER_INCLUDED
23 #define OPM_MAIN_HEADER_INCLUDED
25 #include <flow/flow_ebos_blackoil.hpp>
27 # ifndef FLOW_BLACKOIL_ONLY
28 # include <flow/flow_ebos_gasoil.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_oilwater_brine.hpp>
37 # include <flow/flow_ebos_energy.hpp>
38 # include <flow/flow_ebos_oilwater_polymer.hpp>
39 # include <flow/flow_ebos_oilwater_polymer_injectivity.hpp>
40 # include <flow/flow_ebos_micp.hpp>
43 #include <opm/parser/eclipse/Deck/Deck.hpp>
44 #include <opm/parser/eclipse/Parser/ErrorGuard.hpp>
45 #include <opm/parser/eclipse/Parser/Parser.hpp>
46 #include <opm/parser/eclipse/Parser/ParseContext.hpp>
47 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
48 #include <opm/parser/eclipse/EclipseState/checkDeck.hpp>
49 #include <opm/parser/eclipse/EclipseState/Schedule/ArrayDimChecker.hpp>
50 #include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQState.hpp>
51 #include <opm/parser/eclipse/EclipseState/Schedule/Action/State.hpp>
52 #include <opm/parser/eclipse/EclipseState/Schedule/Well/WellTestState.hpp>
54 #include <opm/models/utils/propertysystem.hh>
55 #include <opm/models/utils/parametersystem.hh>
57 #include <opm/simulators/flow/FlowMainEbos.hpp>
58 #include <opm/simulators/utils/readDeck.hpp>
61 #include <dune/fem/misc/mpimanager.hh>
63 #include <dune/common/parallel/mpihelper.hh>
67 #include <opm/simulators/utils/ParallelEclipseState.hpp>
76 #include <type_traits>
79 namespace Opm::Properties {
85 using InheritsFrom = std::tuple<EclFlowProblem>;
92 template <
class TypeTag>
93 void flowEbosSetDeck(std::shared_ptr<Deck> deck,
94 std::shared_ptr<EclipseState> eclState,
95 std::shared_ptr<Schedule> schedule,
96 std::shared_ptr<SummaryConfig> summaryConfig)
98 using Vanguard = GetPropType<TypeTag, Properties::Vanguard>;
100 Vanguard::setExternalDeck(deck);
101 Vanguard::setExternalEclState(eclState);
102 Vanguard::setExternalSchedule(schedule);
103 Vanguard::setExternalSummaryConfig(summaryConfig);
107 template <
class TypeTag>
108 int flowEbosMain(
int argc,
char** argv,
bool outputCout,
bool outputFiles)
114 FlowMainEbos<TypeTag> mainfunc(argc, argv, outputCout, outputFiles);
115 return mainfunc.execute();
136 Main(
int argc,
char** argv) : argc_(argc), argv_(argv) { initMPI(); }
139 Main(
const std::string& filename)
141 setArgvArgc_(filename);
147 Main(std::shared_ptr<Deck> deck,
148 std::shared_ptr<EclipseState> eclipseState,
149 std::shared_ptr<Schedule> schedule,
150 std::shared_ptr<SummaryConfig> summaryConfig)
151 : deck_{std::move(deck)}
152 , eclipseState_{std::move(eclipseState)}
153 , schedule_{std::move(schedule)}
154 , summaryConfig_{std::move(summaryConfig)}
156 setArgvArgc_(deck_->getDataFile());
160 #define DEMONSTRATE_RUN_WITH_NONWORLD_COMM 0
164 #if DEMONSTRATE_RUN_WITH_NONWORLD_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 #if DEMONSTRATE_RUN_WITH_NONWORLD_COMM
215 if (EclGenericVanguard::comm().size() > 1) {
216 int world_rank = EclGenericVanguard::comm().rank();
217 int color = (world_rank == 0);
219 MPI_Comm_split(EclGenericVanguard::comm(), color, world_rank, &new_comm);
220 isSimulationRank_ = (world_rank > 0);
221 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& phases = eclipseState_->runspec().phases();
291 #ifndef FLOW_BLACKOIL_ONLY
293 else if( eclipseState_->runspec().micp() ) {
295 if ( !phases.active( Phase::WATER) || phases.size() > 2) {
297 std::cerr <<
"No valid configuration is found for MICP simulation, the only valid option is "
298 <<
"water + MICP" << std::endl;
302 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
303 return flowEbosMICPMain(argc_, argv_, outputCout_, outputFiles_);
306 else if (phases.size() == 2) {
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();
342 else if (phases.size() == 3) {
343 return this->runBlackOil();
348 std::cerr <<
"No suitable configuration found, valid are "
349 <<
"Twophase, polymer, foam, brine, solvent, "
350 <<
"energy, and blackoil.\n";
357 template <
class TypeTag>
358 int dispatchStatic_()
360 flowEbosSetDeck<TypeTag>(
361 deck_, eclipseState_, schedule_, summaryConfig_);
362 return flowEbosMain<TypeTag>(argc_, argv_, outputCout_, outputFiles_);
371 template <
class TypeTagEarlyBird>
372 bool initialize_(
int& exitCode)
374 Dune::Timer externalSetupTimer;
375 externalSetupTimer.start();
377 handleVersionCmdLine_(argc_, argv_);
379 int mpiRank = Dune::Fem::MPIManager::rank();
381 int mpiRank = EclGenericVanguard::comm().rank();
394 typedef TypeTagEarlyBird PreTypeTag;
395 using PreProblem = GetPropType<PreTypeTag, Properties::Problem>;
397 PreProblem::setBriefDescription(
"Flow, an advanced reservoir simulator for ECL-decks provided by the Open Porous Media project.");
405 MPI_Abort(MPI_COMM_WORLD, status);
407 exitCode = (status > 0) ? status : EXIT_SUCCESS;
414 outputCout_ = EWOMS_GET_PARAM(PreTypeTag,
bool, EnableTerminalOutput);
416 std::string deckFilename;
417 std::string outputDir;
418 if ( eclipseState_ ) {
419 deckFilename = eclipseState_->getIOConfig().fullBasePath();
420 outputDir = eclipseState_->getIOConfig().getOutputDir();
423 deckFilename = EWOMS_GET_PARAM(PreTypeTag, std::string, EclDeckFileName);
426 if (deckFilename.empty()) {
428 std::cerr <<
"No input case given. Try '--help' for a usage description.\n";
430 exitCode = EXIT_FAILURE;
434 using PreVanguard = GetPropType<PreTypeTag, Properties::Vanguard>;
436 deckFilename = PreVanguard::canonicalDeckPath(deckFilename);
438 catch (
const std::exception& e) {
439 if ( mpiRank == 0 ) {
440 std::cerr <<
"Exception received: " << e.what() <<
". Try '--help' for a usage description.\n";
443 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
445 exitCode = EXIT_FAILURE;
453 auto python = std::make_shared<Python>();
454 const bool init_from_restart_file = !EWOMS_GET_PARAM(PreTypeTag,
bool, SchedRestart);
455 if (outputDir.empty())
456 outputDir = EWOMS_GET_PARAM(PreTypeTag, std::string, OutputDir);
457 outputMode = setupLogging(mpiRank,
460 EWOMS_GET_PARAM(PreTypeTag, std::string, OutputMode),
461 outputCout_,
"STDOUT_LOGGER");
463 std::make_unique<ParseContext>(std::vector<std::pair<std::string , InputError::Action>>
464 {{ParseContext::PARSE_RANDOM_SLASH, InputError::IGNORE},
465 {ParseContext::PARSE_MISSING_DIMS_KEYWORD, InputError::WARN},
466 {ParseContext::SUMMARY_UNKNOWN_WELL, InputError::WARN},
467 {ParseContext::SUMMARY_UNKNOWN_GROUP, InputError::WARN}});
468 if (EWOMS_GET_PARAM(PreTypeTag,
bool, EclStrictParsing))
469 parseContext->update(InputError::DELAYED_EXIT1);
474 OpmLog::info(
"Reading deck file '" + deckFilename +
"'");
477 std::optional<int> outputInterval;
478 int output_param = EWOMS_GET_PARAM(PreTypeTag,
int, EclOutputInterval);
479 if (output_param >= 0)
480 outputInterval = output_param;
482 readDeck(EclGenericVanguard::comm(), deckFilename, deck_, eclipseState_, schedule_, udqState_, actionState_, wtestState_,
483 summaryConfig_,
nullptr, python, std::move(parseContext),
484 init_from_restart_file, outputCout_, outputInterval);
486 setupTime_ = externalSetupTimer.elapsed();
489 catch (
const std::invalid_argument& e)
492 std::cerr <<
"Failed to create valid EclipseState object." << std::endl;
493 std::cerr <<
"Exception caught: " << e.what() << std::endl;
496 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
498 exitCode = EXIT_FAILURE;
502 exitCode = EXIT_SUCCESS;
506 filesystem::path simulationCaseName_(
const std::string& casename)
508 namespace fs = ::Opm::filesystem;
510 auto exists = [](
const fs::path& f)
512 return (fs::exists(f) && fs::is_regular_file(f))
513 || (fs::is_symlink(f) &&
514 fs::is_regular_file(fs::read_symlink(f)));
517 auto simcase = fs::path { casename };
519 if (exists(simcase)) {
523 for (
const auto& ext : { std::string(
"DATA"), std::string(
"data") }) {
524 if (exists(simcase.replace_extension(ext))) {
529 throw std::invalid_argument {
530 "Cannot find input case '" + casename +
'\''
541 void handleVersionCmdLine_(
int argc,
char** argv)
543 auto pos = std::find_if(argv, argv + argc,
546 return std::strcmp(arg,
"--version") == 0;
549 if (pos != argv + argc) {
551 std::exit(EXIT_SUCCESS);
555 #ifndef FLOW_BLACKOIL_ONLY
556 int runTwoPhase(
const Phases& phases)
559 if (phases.active( Phase::OIL ) && phases.active( Phase::GAS )) {
560 flowEbosGasOilSetDeck(
561 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
562 return flowEbosGasOilMain(argc_, argv_, outputCout_, outputFiles_);
566 else if ( phases.active( Phase::OIL ) && phases.active( Phase::WATER ) ) {
567 flowEbosOilWaterSetDeck(
568 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
569 return flowEbosOilWaterMain(argc_, argv_, outputCout_, outputFiles_);
573 else if ( phases.active( Phase::GAS ) && phases.active( Phase::WATER ) ) {
574 flowEbosGasWaterSetDeck(
575 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
576 return flowEbosGasWaterMain(argc_, argv_, outputCout_, outputFiles_);
580 std::cerr <<
"No suitable configuration found, valid are Twophase (oilwater, oilgas and gaswater), polymer, solvent, or blackoil" << std::endl;
587 int runPolymer(
const Phases& phases)
589 if (! phases.active(Phase::WATER)) {
591 std::cerr <<
"No valid configuration is found for polymer simulation, valid options include "
592 <<
"oilwater + polymer and blackoil + polymer" << std::endl;
599 if (phases.active(Phase::POLYMW)) {
601 assert (phases.size() == 4);
602 return flowEbosOilWaterPolymerInjectivityMain(argc_, argv_, outputCout_, outputFiles_);
605 if (phases.size() == 3) {
606 flowEbosOilWaterPolymerSetDeck(
607 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
608 return flowEbosOilWaterPolymerMain(argc_, argv_, outputCout_, outputFiles_);
611 flowEbosPolymerSetDeck(
612 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
613 return flowEbosPolymerMain(argc_, argv_, outputCout_, outputFiles_);
620 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
622 return flowEbosFoamMain(argc_, argv_, outputCout_, outputFiles_);
625 int runBrine(
const Phases& phases)
627 if (! phases.active(Phase::WATER)) {
629 std::cerr <<
"No valid configuration is found for brine simulation, valid options include "
630 <<
"oilwater + brine and blackoil + brine" << std::endl;
635 if (phases.size() == 3) {
636 flowEbosOilWaterBrineSetDeck(
637 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
638 return flowEbosOilWaterBrineMain(argc_, argv_, outputCout_, outputFiles_);
641 flowEbosBrineSetDeck(
642 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
643 return flowEbosBrineMain(argc_, argv_, outputCout_, outputFiles_);
649 flowEbosSolventSetDeck(
650 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
652 return flowEbosSolventMain(argc_, argv_, outputCout_, outputFiles_);
655 int runExtendedBlackOil()
657 flowEbosExtboSetDeck(
658 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
660 return flowEbosExtboMain(argc_, argv_, outputCout_, outputFiles_);
665 flowEbosEnergySetDeck(
666 setupTime_, deck_, eclipseState_, schedule_, summaryConfig_);
668 return flowEbosEnergyMain(argc_, argv_, outputCout_, outputFiles_);
674 flowEbosBlackoilSetDeck(this->setupTime_,
678 std::move(this->udqState_),
679 std::move(this->actionState_),
680 std::move(this->wtestState_),
681 this->summaryConfig_);
683 return flowEbosBlackoilMain(argc_, argv_, outputCout_, outputFiles_);
687 char** argv_{
nullptr};
688 bool outputCout_{
false};
689 bool outputFiles_{
false};
690 double setupTime_{0.0};
691 std::string deckFilename_{};
692 std::string flowProgName_{};
693 char *saveArgs_[3]{
nullptr};
694 std::unique_ptr<UDQState> udqState_{};
695 std::unique_ptr<Action::State> actionState_{};
696 std::unique_ptr<WellTestState> wtestState_{};
699 std::shared_ptr<Deck> deck_{};
700 std::shared_ptr<EclipseState> eclipseState_{};
701 std::shared_ptr<Schedule> schedule_{};
702 std::shared_ptr<SummaryConfig> summaryConfig_{};
705 bool isSimulationRank_ =
true;
Definition: FlowMainEbos.hpp:87
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:26
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:424