23#ifndef OPM_MAIN_HEADER_INCLUDED
24#define OPM_MAIN_HEADER_INCLUDED
26#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
36#include <dune/fem/misc/mpimanager.hh>
38#include <dune/common/parallel/mpihelper.hh>
79namespace Action {
class State; }
84template <
class TypeTag>
85int flowMain(
int argc,
char** argv,
bool outputCout,
bool outputFiles)
91 FlowMain<TypeTag> mainfunc(argc, argv, outputCout, outputFiles);
92 return mainfunc.execute();
105 Main(
int argc,
char** argv,
bool ownMPI =
true);
108 explicit Main(
const std::string& filename,
bool mpi_init =
true,
bool mpi_finalize =
true);
112 Main(
const std::string& filename,
113 std::shared_ptr<EclipseState> eclipseState,
114 std::shared_ptr<Schedule> schedule,
115 std::shared_ptr<SummaryConfig> summaryConfig,
116 bool mpi_init =
true,
117 bool mpi_finalize =
true);
134 int exitCode = EXIT_SUCCESS;
135 if (initialize_<Properties::TTag::FlowEarlyBird>(exitCode)) {
137 if (isSimulationRank_) {
138 return this->dispatchDynamic_();
152 template <
class TypeTag>
155 int exitCode = EXIT_SUCCESS;
156 if (initialize_<TypeTag>(exitCode)) {
157 if (isSimulationRank_) {
158 return this->dispatchStatic_<TypeTag>();
168 int exitCode = EXIT_SUCCESS;
169 initialize_<Properties::TTag::FlowEarlyBird>(exitCode);
181 template <
class TypeTagEarlyBird>
184 Dune::Timer externalSetupTimer;
185 externalSetupTimer.start();
199 typedef TypeTagEarlyBird PreTypeTag;
202 PreProblem::setBriefDescription(
"Flow, an advanced reservoir simulator for ECL-decks provided by the Open Porous Media project.");
210 MPI_Abort(MPI_COMM_WORLD, status);
212 exitCode = (status > 0) ? status : EXIT_SUCCESS;
216 OpmLog::setDebugVerbosityLevel(Parameters::Get<Parameters::DebugVerbosityLevel>());
218 std::string deckFilename;
219 std::string outputDir;
220 if ( eclipseState_ ) {
221 deckFilename = eclipseState_->getIOConfig().fullBasePath();
222 outputDir = eclipseState_->getIOConfig().getOutputDir();
225 deckFilename = Parameters::Get<Parameters::EclDeckFileName>();
226 outputDir = Parameters::Get<Parameters::OutputDir>();
230 enableDamarisOutput_ = Parameters::Get<Parameters::EnableDamarisOutput>();
235 msg =
"\nUse of Damaris (command line argument --enable-damaris-output=true) has been disabled for run with only one rank.\n" ;
236 OpmLog::warning(msg);
237 enableDamarisOutput_ = false ;
240 if (enableDamarisOutput_) {
242 auto damarisOutputDir = outputDir;
243 if (outputDir.empty()) {
244 auto odir = std::filesystem::path{deckFilename}.parent_path();
246 damarisOutputDir =
".";
248 damarisOutputDir = odir.generic_string();
252 this->setupDamaris(damarisOutputDir);
258 if (!isSimulationRank_) {
259 exitCode = EXIT_SUCCESS;
266 outputCout_ = Parameters::Get<Parameters::EnableTerminalOutput>();
268 if (deckFilename.empty()) {
270 std::cerr <<
"No input case given. Try '--help' for a usage description.\n";
272 exitCode = EXIT_FAILURE;
278 deckFilename = PreVanguard::canonicalDeckPath(deckFilename);
280 catch (
const std::exception& e) {
281 if ( mpiRank == 0 ) {
282 std::cerr <<
"Exception received: " << e.what() <<
". Try '--help' for a usage description.\n";
285 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
287 exitCode = EXIT_FAILURE;
291 std::string cmdline_params;
296 std::ostringstream str;
298 cmdline_params = str.str();
303 this->readDeck(deckFilename,
305 Parameters::Get<Parameters::OutputMode>(),
306 !Parameters::Get<Parameters::SchedRestart>(),
307 Parameters::Get<Parameters::EnableLoggingFalloutWarning>(),
308 Parameters::Get<Parameters::ParsingStrictness>(),
309 Parameters::Get<Parameters::ActionParsingStrictness>(),
310 Parameters::Get<Parameters::InputSkipMode>(),
313 Parameters::Get<Parameters::EclOutputInterval>(),
314 Parameters::Get<Parameters::Slave>(),
318 setupTime_ = externalSetupTimer.elapsed();
320 catch (
const std::invalid_argument& e)
323 std::cerr <<
"Failed to create valid EclipseState object." << std::endl;
324 std::cerr <<
"Exception caught: " << e.what() << std::endl;
327 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
329 exitCode = EXIT_FAILURE;
337 exitCode = EXIT_SUCCESS;
351 void handleVersionCmdLine_(
int argc,
char** argv,
360 void handleTestSplitCommunicatorCmdLine_();
367 int dispatchDynamic_();
377 template <
class TypeTag>
378 int dispatchStatic_()
392 int runMICP(
const Phases& phases);
402 int runTwoPhase(
const Phases& phases);
412 int runPolymer(
const Phases& phases);
429 int runWaterOnly(
const Phases& phases);
439 int runWaterOnlyEnergy(
const Phases& phases);
449 int runBrine(
const Phases& phases);
459 int runSolvent(
const Phases& phases);
466 int runExtendedBlackOil();
476 int runThermal(
const Phases& phases);
485 void readDeck(
const std::string& deckFilename,
486 const std::string& outputDir,
487 const std::string& outputMode,
488 const bool init_from_restart_file,
489 const bool allRanksDbgPrtLog,
490 const std::string& parsingStrictness,
491 const std::string& actionParsingStrictness,
492 const std::string& inputSkipMode,
493 const bool keepKeywords,
494 const std::size_t numThreads,
495 const int output_param,
496 const bool slaveMode,
497 const std::string& parameters,
501 static int getNumThreads()
504 return omp_get_max_threads();
511 void setupDamaris(
const std::string& outputDir);
522 double setupTime_{0.0};
523 std::string deckFilename_{};
524 std::string flowProgName_{};
525 char *saveArgs_[3]{
nullptr};
526 std::unique_ptr<UDQState> udqState_{};
527 std::unique_ptr<Action::State> actionState_{};
528 std::unique_ptr<WellTestState> wtestState_{};
531 std::shared_ptr<EclipseState> eclipseState_{};
532 std::shared_ptr<Schedule> schedule_{};
533 std::shared_ptr<SummaryConfig> summaryConfig_{};
534 bool mpi_init_{
true};
535 bool mpi_finalize_{
true};
538 bool test_split_comm_ =
false;
539 bool isSimulationRank_ =
true;
541 std::string reservoirCouplingSlaveOutputFilename_{};
544 bool enableDamarisOutput_ =
false;
static Parallel::Communication & comm()
Obtain global communicator.
Definition: FlowGenericVanguard.hpp:332
int argc_
Definition: Main.hpp:515
int justInitialize()
Used for test_outputdir.
Definition: Main.hpp:166
void maybeSaveReservoirCouplingSlaveLogFilename_()
bool initialize_(int &exitCode, bool keepKeywords=false)
Initialize.
Definition: Main.hpp:182
bool outputFiles_
Definition: Main.hpp:518
void maybeRedirectReservoirCouplingSlaveOutput_()
int runDynamic()
Definition: Main.hpp:132
Main(int argc, char **argv, bool ownMPI=true)
char ** argv_
Definition: Main.hpp:516
Main(const std::string &filename, bool mpi_init=true, bool mpi_finalize=true)
int runStatic()
Definition: Main.hpp:153
void setArgvArgc_(const std::string &filename)
bool outputCout_
Definition: Main.hpp:517
Main(const std::string &filename, std::shared_ptr< EclipseState > eclipseState, std::shared_ptr< Schedule > schedule, std::shared_ptr< SummaryConfig > summaryConfig, bool mpi_init=true, bool mpi_finalize=true)
void printValues(std::ostream &os)
Print values of the run-time parameters.
void reset()
Reset parameter system.
Definition: blackoilmodel.hh:79
Definition: blackoilboundaryratevector.hh:39
std::string moduleVersionName()
int flowMain(int argc, char **argv, bool outputCout, bool outputFiles)
Definition: Main.hpp:85
std::string compileTimestamp()
void printFlowBanner(int nprocs, int threads, std::string_view moduleVersionName)
std::string moduleVersion()
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
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
std::tuple< FlowProblem > InheritsFrom
Definition: Main.hpp:71