33#include <opm/material/densead/Evaluation.hpp>
40#include <opm/material/common/Valgrind.hpp>
42#include <opm/material/common/ResetLocale.hpp>
44#include <dune/grid/io/file/dgfparser/dgfparser.hh>
45#include <dune/common/version.hh>
46#include <dune/common/parametertreeparser.hh>
47#include <dune/common/parallel/mpihelper.hh>
50#include <dune/fem/misc/mpimanager.hh>
75template <
class TypeTag>
76static inline void registerAllParameters_(
bool finalizeRegistration =
true)
78 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
79 using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
81 Parameters::registerParam<TypeTag, Properties::ParameterFile>
82 (
"An .ini file which contains a set of run-time parameters");
83 Parameters::registerParam<TypeTag, Properties::PrintProperties>
84 (
"Print the values of the compile time properties at "
85 "the start of the simulation");
86 Parameters::registerParam<TypeTag, Properties::PrintParameters>
87 (
"Print the values of the run-time parameters at the "
88 "start of the simulation");
93 if (finalizeRegistration) {
94 Parameters::endParamRegistration<TypeTag>();
107template <
class TypeTag>
108static inline int setupParameters_(
int argc,
110 bool registerParams=
true,
111 bool allowUnused=
false,
112 bool handleHelp =
true)
114 using Problem = GetPropType<TypeTag, Properties::Problem>;
123 registerAllParameters_<TypeTag>();
130 const auto& positionalParamCallback = Problem::handlePositionalParameter;
131 std::string helpPreamble =
"";
132 if (myRank == 0 && handleHelp)
133 helpPreamble = Problem::helpPreamble(argc, argv);
135 Parameters::parseCommandLineOptions<TypeTag>(argc,
138 positionalParamCallback);
142 if (s ==
"Help called")
147 MPI_Allreduce(&status, &globalStatus, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
153 const std::string paramFileName = Parameters::get<TypeTag, Properties::ParameterFile>(
false);
154 if (!paramFileName.empty()) {
161 tmp.open(paramFileName.c_str());
162 if (!tmp.is_open()) {
163 std::ostringstream oss;
165 oss <<
"Parameter file \"" << paramFileName
166 <<
"\" does not exist or is not readable.";
167 Parameters::printUsage<TypeTag>(argv[0], oss.str());
173 Parameters::parseParameterFile<TypeTag>(paramFileName,
false);
177 using KeyValuePair = std::pair<std::string, std::string>;
178 using ParamList = std::list<KeyValuePair>;
180 ParamList usedParams;
181 ParamList unusedParams;
183 Parameters::getLists<TypeTag>(usedParams, unusedParams);
184 if (!allowUnused && !unusedParams.empty()) {
186 if (unusedParams.size() == 1)
187 std::cerr <<
"The following explicitly specified parameter is unknown:\n";
189 std::cerr <<
"The following " << unusedParams.size()
190 <<
" explicitly specified parameters are unknown:\n";
193 for (
const auto& keyValue : unusedParams)
194 std::cerr <<
" " << keyValue.first <<
"=\"" << keyValue.second <<
"\"\n";
199 <<
" " << argv[0] <<
" --help\n"
201 <<
"to obtain the list of recognized command line parameters.\n\n";
214static inline void resetTerminal_()
218 std::cerr <<
" \r\n";
220 std::cout <<
" \r\n";
230 if (system(
"stty sane") != 0)
231 std::cout <<
"Executing the 'stty' command failed."
232 <<
" Terminal might be left in an undefined state!\n";
239static inline void resetTerminal_(
int signum)
246 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
255 if (isatty(fileno(stdout)) && isatty(fileno(stdin))) {
256 std::cout <<
"\n\nReceived signal " <<
signum
257 <<
" (\"" << strsignal(
signum) <<
"\")."
258 <<
" Trying to reset the terminal.\n";
279template <
class TypeTag>
280static inline int start(
int argc,
char **argv,
bool registerParams=
true)
282 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
283 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
284 using Problem = GetPropType<TypeTag, Properties::Problem>;
285 using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
289 if (isatty(STDIN_FILENO)) {
290 signal(SIGINT, resetTerminal_);
291 signal(SIGHUP, resetTerminal_);
292 signal(SIGABRT, resetTerminal_);
293 signal(SIGFPE, resetTerminal_);
294 signal(SIGSEGV, resetTerminal_);
295 signal(SIGPIPE, resetTerminal_);
296 signal(SIGTERM, resetTerminal_);
304 int paramStatus = setupParameters_<TypeTag>(argc,
const_cast<const char**
>(argv), registerParams);
305 if (paramStatus == 1)
307 if (paramStatus == 2)
314 Dune::Fem::MPIManager::initialize(argc, argv);
315 myRank = Dune::Fem::MPIManager::rank();
317 myRank = Dune::MPIHelper::instance(argc, argv).rank();
321 Scalar endTime = Parameters::get<TypeTag, Properties::EndTime>();
322 if (endTime < -1e50) {
324 Parameters::printUsage<TypeTag>(argv[0],
325 "Mandatory parameter '--end-time' not specified!");
329 Scalar initialTimeStepSize = Parameters::get<TypeTag, Properties::InitialTimeStepSize>();
330 if (initialTimeStepSize < -1e50) {
332 Parameters::printUsage<TypeTag>(argv[0],
333 "Mandatory parameter '--initial-time-step-size' "
340 std::string versionString = EWOMS_VERSION;
342 std::string versionString =
"";
344 const std::string briefDescription = Problem::briefDescription();
345 if (!briefDescription.empty()) {
349 std::cout << tmp << std::endl << std::endl;
352 std::cout <<
"opm models " << versionString
353 <<
" will now start the simulation. " << std::endl;
357 int printParams = Parameters::get<TypeTag, Properties::PrintParameters>();
359 std::string endParametersSeparator(
"# [end of parameters]\n");
361 bool printSeparator =
false;
362 if (printParams == 1 || !isatty(fileno(stdout))) {
363 Parameters::printValues<TypeTag>();
364 printSeparator =
true;
370 Parameters::printUnused<TypeTag>();
372 std::cout << endParametersSeparator;
376 if (Parameters::printUnused<TypeTag>())
377 std::cout << endParametersSeparator;
381 int printProps = Parameters::get<TypeTag, Properties::PrintProperties>();
382 if (printProps && myRank == 0) {
383 if (printProps == 1 || !isatty(fileno(stdout)))
384 Properties::printValues<TypeTag>(std::cout);
394 std::cout <<
"Simulation completed" << std::endl;
398 catch (std::exception& e)
401 std::cout << e.what() <<
". Abort!\n" << std::flush;
403 std::cout <<
"Trying to reset TTY.\n";
412 std::cout <<
"Unknown exception thrown!\n" << std::flush;
414 std::cout <<
"Trying to reset TTY.\n";
static void registerParameters()
Registers all runtime parameters used by the simulation.
Definition: simulator.hh:255
static void init(bool queryCommandLineParameter=true)
Initialize number of threads used thread manager.
Definition: threadmanager.hh:77
static void registerParameters()
Register all run-time parameters of the thread manager.
Definition: threadmanager.hh:61
static int start(int argc, char **argv, bool registerParams=true)
Provides a main function which reads in parameters from the command line and a parameter file and run...
Definition: start.hh:280
int getTtyWidth_()
Definition: parametersystem.hh:246
std::string breakLines_(const std::string &msg, int indentWidth, int maxWidth)
Definition: parametersystem.hh:197
Definition: blackoilboundaryratevector.hh:37
int signum(Scalar val)
Template function which returns the sign of a floating point value.
Definition: signum.hh:40
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.