30#include <dune/common/parallel/mpihelper.hh>
32#include <opm/material/common/ResetLocale.hpp>
37#include <opm/models/utils/terminal.hpp>
40#include <opm/simulators/utils/readDeck.hpp>
43#include <dune/fem/misc/mpimanager.hh>
62template <
class TypeTag>
63static inline void registerAllParameters_(
bool finalizeRegistration)
69 (
"An .ini file which contains a set of run-time parameters");
71 (
"Print the values of the run-time parameters at the "
72 "start of the simulation");
74 TM::registerParameters();
77 if (finalizeRegistration) {
91template <
class TypeTag>
92static inline int setupParameters_(
int argc,
104 if (registerParams) {
105 registerAllParameters_<TypeTag>(
true);
113 const auto& positionalParamCallback = Problem::handlePositionalParameter;
114 std::string helpPreamble;
115 if (myRank == 0 && handleHelp) {
116 helpPreamble = Problem::helpPreamble(argc, argv);
118 const std::string s =
121 positionalParamCallback,
125 if (s ==
"Help called") {
131 MPI_Allreduce(&status, &globalStatus, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
138 if (!paramFileName.empty()) {
145 std::ostringstream oss;
147 oss <<
"Parameter file \"" << paramFileName
148 <<
"\" does not exist or is not readable.";
156 using ParamList = std::vector<Parameters::Parameter>;
158 ParamList usedParams;
159 ParamList unusedParams;
162 if (!allowUnused && !unusedParams.empty()) {
164 if (unusedParams.size() == 1) {
165 std::cerr <<
"The following explicitly specified parameter is unknown:\n";
168 std::cerr <<
"The following " << unusedParams.size()
169 <<
" explicitly specified parameters are unknown:\n";
173 for (
const auto& keyValue : unusedParams) {
174 std::cerr <<
" " << keyValue <<
"\n";
180 <<
" " << argv[0] <<
" --help\n"
182 <<
"to obtain the list of recognized command line parameters.\n\n";
201template <
class TypeTag>
202static inline int start(
int argc,
char **argv,
bool registerParams)
217 Dune::Fem::MPIManager::initialize(argc, argv);
218 myRank = Dune::Fem::MPIManager::rank();
220 myRank = Dune::MPIHelper::instance(argc, argv).rank();
222 const int paramStatus =
223 setupParameters_<TypeTag>(argc,
224 const_cast<const char**
>(argv),
229 if (paramStatus == 1) {
232 if (paramStatus == 2) {
240 setupStreamLogging(
"STDOUT_LOGGER");
245 if (endTime < -1e50) {
248 "Mandatory parameter '--end-time' not specified!");
254 if (initialTimeStepSize < -1e50) {
257 "Mandatory parameter '--initial-time-step-size' "
265 const std::string versionString = EWOMS_VERSION;
267 const std::string versionString;
269 const std::string briefDescription = Problem::briefDescription();
270 if (!briefDescription.empty()) {
271 const std::string tmp =
breakLines(briefDescription,
274 std::cout << tmp << std::endl << std::endl;
277 std::cout <<
"opm models " << versionString
278 <<
" will now start the simulation. " << std::endl;
285 const std::string endParametersSeparator(
"# [end of parameters]\n");
287 bool printSeparator =
false;
288 if (printParams == 1 || !isatty(fileno(stdout))) {
290 printSeparator =
true;
296 if (printSeparator) {
297 std::cout << endParametersSeparator;
303 std::cout << endParametersSeparator;
315 std::cout <<
"Simulation completed" << std::endl;
319 catch (std::exception& e) {
321 std::cout << e.what() <<
". Abort!\n" << std::flush;
323 std::cout <<
"Trying to reset TTY.\n";
331 std::cout <<
"Unknown exception thrown!\n" << std::flush;
333 std::cout <<
"Trying to reset TTY.\n";
Manages the initializing and running of time dependent problems.
Definition simulator.hh:84
void run()
Runs the simulation using a given problem class.
Definition simulator.hh:592
static void registerParameters()
Registers all runtime parameters used by the simulation.
Definition simulator.hh:214
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
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
void resetTerminal()
Resets the current TTY to a usable state if the program was aborted.
Definition terminal.cpp:123
std::string breakLines(const std::string &msg, int indentWidth, int maxWidth)
Break up a string in lines suitable for terminal output.
Definition terminal.cpp:39
void assignResetTerminalSignalHandlers()
Assign signal handlers that reset the terminal on errors.
Definition terminal.cpp:108
int getTtyWidth()
Get the width of the tty we are attached to.
Definition terminal.cpp:90
std::string parseCommandLineOptions(int argc, const char **argv, const PositionalArgumentCallback &posArgCallback, const std::string &helpPreamble)
Parse the parameters provided on the command line.
Definition parametersystem.cpp:636
void printValues(std::ostream &os)
Print values of the run-time parameters.
Definition parametersystem.cpp:741
void endRegistration()
Indicate that all parameters are registered for a given type tag.
Definition parametersystem.cpp:495
bool parseParameterFile(const std::string &fileName, bool overwrite)
Read the parameters from an INI-style file.
Definition parametersystem.cpp:563
void getLists(std::vector< Parameter > &usedParams, std::vector< Parameter > &unusedParams)
Retrieves the lists of parameters specified at runtime and their values.
Definition parametersystem.cpp:505
void printUsage(const std::string &helpPreamble, std::ostream &os, const std::string &errorMsg, const bool showAll)
Print a usage message for all run-time parameters.
Definition parametersystem.cpp:532
bool printUnused(std::ostream &os)
Print the list of unused run-time parameters.
Definition parametersystem.cpp:790
This file provides the infrastructure to retrieve run-time parameters.
void Register(const char *usageString)
Register a run-time parameter.
Definition parametersystem.hpp:292
auto Get(bool errorIfNotRegistered=true)
Retrieve a runtime parameter.
Definition parametersystem.hpp:187
The Opm property system, traits with inheritance.
Manages the initializing and running of time dependent problems.