23 #ifndef OPM_MAIN_HEADER_INCLUDED 24 #define OPM_MAIN_HEADER_INCLUDED 26 #include <opm/input/eclipse/EclipseState/EclipseState.hpp> 27 #include <opm/input/eclipse/Schedule/Action/State.hpp> 28 #include <opm/input/eclipse/Schedule/UDQ/UDQState.hpp> 33 #include <opm/simulators/flow/Banners.hpp> 34 #include <opm/simulators/flow/FlowMain.hpp> 38 #include <dune/fem/misc/mpimanager.hh> 40 #include <dune/common/parallel/mpihelper.hh> 44 #include <opm/simulators/utils/ParallelEclipseState.hpp> 45 #include <opm/simulators/flow/rescoup/ReservoirCoupling.hpp> 49 #include <opm/simulators/linalg/gpuistl/device_management.hpp> 53 #include <opm/simulators/utils/DamarisKeywords.hpp> 64 #include <string_view> 65 #include <type_traits> 75 using InheritsFrom = std::tuple<FlowProblem>;
81 template<
class TypeTag>
83 {
static constexpr
bool value =
false; };
86 template<
class TypeTag>
88 {
static constexpr
bool value =
false; };
94 namespace Action {
class State; }
99 template <
class TypeTag>
100 int flowMain(
int argc,
char** argv,
bool outputCout,
bool outputFiles)
106 FlowMain<TypeTag> mainfunc(argc, argv, outputCout, outputFiles);
107 return mainfunc.execute();
120 Main(
int argc,
char** argv,
bool ownMPI =
true);
123 explicit Main(
const std::string& filename,
bool mpi_init =
true,
bool mpi_finalize =
true);
127 Main(
const std::string& filename,
128 std::shared_ptr<EclipseState> eclipseState,
129 std::shared_ptr<Schedule> schedule,
130 std::shared_ptr<SummaryConfig> summaryConfig,
131 bool mpi_init =
true,
132 bool mpi_finalize =
true);
136 void setArgvArgc_(
const std::string& filename);
137 void maybeSaveReservoirCouplingSlaveLogFilename_();
138 void maybeRedirectReservoirCouplingSlaveOutput_();
149 int exitCode = EXIT_SUCCESS;
150 if (initialize_<Properties::TTag::FlowEarlyBird>(exitCode)) {
152 if (isSimulationRank_) {
153 return this->dispatchDynamic_();
167 template <
class TypeTag>
170 int exitCode = EXIT_SUCCESS;
171 if (initialize_<TypeTag>(exitCode)) {
172 if (isSimulationRank_) {
173 return this->dispatchStatic_<TypeTag>();
183 int exitCode = EXIT_SUCCESS;
184 initialize_<Properties::TTag::FlowEarlyBird>(exitCode);
196 template <
class TypeTagEarlyBird>
199 Dune::Timer externalSetupTimer;
200 externalSetupTimer.start();
214 typedef TypeTagEarlyBird PreTypeTag;
217 PreProblem::setBriefDescription(
"Flow, an advanced reservoir simulator for ECL-decks provided by the Open Porous Media project.");
225 MPI_Abort(MPI_COMM_WORLD, status);
227 exitCode = (status > 0) ? status : EXIT_SUCCESS;
231 OpmLog::setDebugVerbosityLevel(Parameters::Get<Parameters::DebugVerbosityLevel>());
233 std::string deckFilename;
234 std::string outputDir;
235 if ( eclipseState_ ) {
236 deckFilename = eclipseState_->getIOConfig().fullBasePath();
237 outputDir = eclipseState_->getIOConfig().getOutputDir();
240 deckFilename = Parameters::Get<Parameters::EclDeckFileName>();
241 outputDir = Parameters::Get<Parameters::OutputDir>();
245 enableDamarisOutput_ = Parameters::Get<Parameters::EnableDamarisOutput>();
250 msg =
"\nUse of Damaris (command line argument --enable-damaris-output=true) has been disabled for run with only one rank.\n" ;
251 OpmLog::warning(msg);
252 enableDamarisOutput_ = false ;
255 if (enableDamarisOutput_) {
257 auto damarisOutputDir = outputDir;
258 if (outputDir.empty()) {
259 auto odir = std::filesystem::path{deckFilename}.parent_path();
261 damarisOutputDir =
".";
263 damarisOutputDir = odir.generic_string();
267 this->setupDamaris(damarisOutputDir);
269 #endif // HAVE_DAMARIS 273 if (!isSimulationRank_) {
274 exitCode = EXIT_SUCCESS;
281 outputCout_ = Parameters::Get<Parameters::EnableTerminalOutput>();
283 if (deckFilename.empty()) {
285 std::cerr <<
"No input case given. Try '--help' for a usage description.\n";
287 exitCode = EXIT_FAILURE;
293 deckFilename = PreVanguard::canonicalDeckPath(deckFilename);
295 catch (
const std::exception& e) {
296 if ( mpiRank == 0 ) {
297 std::cerr <<
"Exception received: " << e.what() <<
". Try '--help' for a usage description.\n";
300 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
302 exitCode = EXIT_FAILURE;
306 std::string cmdline_params;
311 std::ostringstream str;
312 Parameters::printValues(str);
313 cmdline_params = str.str();
318 this->readDeck(deckFilename,
320 Parameters::Get<Parameters::OutputMode>(),
321 !Parameters::Get<Parameters::SchedRestart>(),
322 Parameters::Get<Parameters::EnableLoggingFalloutWarning>(),
323 Parameters::Get<Parameters::ParsingStrictness>(),
324 Parameters::Get<Parameters::ActionParsingStrictness>(),
325 Parameters::Get<Parameters::InputSkipMode>(),
328 Parameters::Get<Parameters::EclOutputInterval>(),
329 Parameters::Get<Parameters::Slave>(),
333 setupTime_ = externalSetupTimer.elapsed();
339 catch (
const std::runtime_error& e)
342 std::cerr <<
"Failed to create valid EclipseState object." << std::endl;
343 std::cerr << e.what() << std::endl;
349 notifyMasterSlaveInitFailed_();
351 exitCode = EXIT_FAILURE;
357 catch (
const std::exception& e)
360 std::cerr <<
"Unexpected error during initialization." << std::endl;
361 std::cerr <<
"Exception caught: " << e.what() << std::endl;
364 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
366 exitCode = EXIT_FAILURE;
371 Opm::gpuistl::printDevice();
374 exitCode = EXIT_SUCCESS;
378 void setupVanguard();
388 void handleVersionCmdLine_(
int argc,
char** argv,
397 void handleTestSplitCommunicatorCmdLine_();
401 void notifyMasterSlaveInitFailed_();
408 int dispatchDynamic_();
418 template <
class TypeTag>
419 int dispatchStatic_()
421 this->setupVanguard();
422 return flowMain<TypeTag>(argc_, argv_, outputCout_, outputFiles_);
433 int runMICP(
const Phases& phases);
443 int runTwoPhase(
const Phases& phases);
453 int runBiofilm(
const Phases& phases);
463 int runPolymer(
const Phases& phases);
480 int runWaterOnly(
const Phases& phases);
490 int runWaterOnlyEnergy(
const Phases& phases);
500 int runBrine(
const Phases& phases);
510 int runSolvent(
const Phases& phases);
517 int runExtendedBlackOil();
527 int runThermal(
const Phases& phases);
535 int runBlackOilTemp();
546 void readDeck(
const std::string& deckFilename,
547 const std::string& outputDir,
548 const std::string& outputMode,
549 const bool init_from_restart_file,
550 const bool allRanksDbgPrtLog,
551 const std::string& parsingStrictness,
552 const std::string& actionParsingStrictness,
553 const std::string& inputSkipMode,
554 const bool keepKeywords,
555 const std::size_t numThreads,
556 const int output_param,
557 const bool slaveMode,
558 const std::string& parameters,
562 static int getNumThreads();
565 void setupDamaris(
const std::string& outputDir);
570 char** argv_{
nullptr};
571 bool outputCout_{
false};
572 bool outputFiles_{
false};
576 double setupTime_{0.0};
577 std::string deckFilename_{};
578 std::string flowProgName_{};
579 char *saveArgs_[3]{
nullptr};
580 std::unique_ptr<UDQState> udqState_{};
581 std::unique_ptr<Action::State> actionState_{};
582 std::unique_ptr<WellTestState> wtestState_{};
585 std::shared_ptr<EclipseState> eclipseState_{};
586 std::shared_ptr<Schedule> schedule_{};
587 std::shared_ptr<SummaryConfig> summaryConfig_{};
588 bool mpi_init_{
true};
589 bool mpi_finalize_{
true};
592 bool test_split_comm_ =
false;
593 bool isSimulationRank_ =
true;
595 std::string reservoirCouplingSlaveOutputFilename_{};
598 bool enableDamarisOutput_ =
false;
604 #endif // OPM_MAIN_HEADER_INCLUDED typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
std::string moduleVersionName()
Return the version name of the module, for example "2015.10" (for a release branch) or "2016...
Definition: moduleVersion.cpp:34
int runDynamic()
Run simulation.
Definition: Main.hpp:147
This file provides the infrastructure to retrieve run-time parameters.
Definition: FlowMain.hpp:66
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
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
static Parallel::Communication & comm()
Obtain global communicator.
Definition: FlowGenericVanguard.hpp:336
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
int runStatic()
Run simulation.
Definition: Main.hpp:168
int justInitialize()
Used for test_outputdir.
Definition: Main.hpp:181
bool initialize_(int &exitCode, bool keepKeywords=false)
Initialize.
Definition: Main.hpp:197
The Opm property system, traits with inheritance.
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
Definition: blackoilmodel.hh:75
Enable diffusive fluxes?
Definition: multiphasebaseproperties.hh:91
Enable convective mixing?
Definition: multiphasebaseproperties.hh:99