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::Register<Parameters::ParameterFile>
82 (
"An .ini file which contains a set of run-time parameters");
83 Parameters::Register<Parameters::PrintParameters>
84 (
"Print the values of the run-time parameters at the "
85 "start of the simulation");
90 if (finalizeRegistration) {
104template <
class TypeTag>
105static inline int setupParameters_(
int argc,
107 bool registerParams=
true,
108 bool allowUnused=
false,
109 bool handleHelp =
true)
111 using Problem = GetPropType<TypeTag, Properties::Problem>;
120 registerAllParameters_<TypeTag>();
127 const auto& positionalParamCallback = Problem::handlePositionalParameter;
128 std::string helpPreamble =
"";
129 if (myRank == 0 && handleHelp)
130 helpPreamble = Problem::helpPreamble(argc, argv);
135 positionalParamCallback);
139 if (s ==
"Help called")
144 MPI_Allreduce(&status, &globalStatus, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
150 const std::string paramFileName = Parameters::Get<Parameters::ParameterFile>(
false);
151 if (!paramFileName.empty()) {
158 tmp.open(paramFileName.c_str());
159 if (!tmp.is_open()) {
160 std::ostringstream oss;
162 oss <<
"Parameter file \"" << paramFileName
163 <<
"\" does not exist or is not readable.";
174 using KeyValuePair = std::pair<std::string, std::string>;
175 using ParamList = std::list<KeyValuePair>;
177 ParamList usedParams;
178 ParamList unusedParams;
181 if (!allowUnused && !unusedParams.empty()) {
183 if (unusedParams.size() == 1)
184 std::cerr <<
"The following explicitly specified parameter is unknown:\n";
186 std::cerr <<
"The following " << unusedParams.size()
187 <<
" explicitly specified parameters are unknown:\n";
190 for (
const auto& keyValue : unusedParams)
191 std::cerr <<
" " << keyValue.first <<
"=\"" << keyValue.second <<
"\"\n";
196 <<
" " << argv[0] <<
" --help\n"
198 <<
"to obtain the list of recognized command line parameters.\n\n";
211static inline void resetTerminal_()
215 std::cerr <<
" \r\n";
217 std::cout <<
" \r\n";
227 if (system(
"stty sane") != 0)
228 std::cout <<
"Executing the 'stty' command failed."
229 <<
" Terminal might be left in an undefined state!\n";
236static inline void resetTerminal_(
int signum)
243 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
252 if (isatty(fileno(stdout)) && isatty(fileno(stdin))) {
253 std::cout <<
"\n\nReceived signal " <<
signum
254 <<
" (\"" << strsignal(
signum) <<
"\")."
255 <<
" Trying to reset the terminal.\n";
276template <
class TypeTag>
277static inline int start(
int argc,
char **argv,
bool registerParams=
true)
279 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
280 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
281 using Problem = GetPropType<TypeTag, Properties::Problem>;
282 using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
286 if (isatty(STDIN_FILENO)) {
287 signal(SIGINT, resetTerminal_);
288 signal(SIGHUP, resetTerminal_);
289 signal(SIGABRT, resetTerminal_);
290 signal(SIGFPE, resetTerminal_);
291 signal(SIGSEGV, resetTerminal_);
292 signal(SIGPIPE, resetTerminal_);
293 signal(SIGTERM, resetTerminal_);
301 int paramStatus = setupParameters_<TypeTag>(argc,
const_cast<const char**
>(argv), registerParams);
302 if (paramStatus == 1)
304 if (paramStatus == 2)
311 Dune::Fem::MPIManager::initialize(argc, argv);
312 myRank = Dune::Fem::MPIManager::rank();
314 myRank = Dune::MPIHelper::instance(argc, argv).rank();
318 Scalar endTime = Parameters::Get<Parameters::EndTime<Scalar>>();
319 if (endTime < -1e50) {
322 "Mandatory parameter '--end-time' not specified!");
326 Scalar initialTimeStepSize = Parameters::Get<Parameters::InitialTimeStepSize<Scalar>>();
327 if (initialTimeStepSize < -1e50) {
330 "Mandatory parameter '--initial-time-step-size' "
337 std::string versionString = EWOMS_VERSION;
339 std::string versionString =
"";
341 const std::string briefDescription = Problem::briefDescription();
342 if (!briefDescription.empty()) {
346 std::cout << tmp << std::endl << std::endl;
349 std::cout <<
"opm models " << versionString
350 <<
" will now start the simulation. " << std::endl;
354 int printParams = Parameters::Get<Parameters::PrintParameters>();
356 std::string endParametersSeparator(
"# [end of parameters]\n");
358 bool printSeparator =
false;
359 if (printParams == 1 || !isatty(fileno(stdout))) {
361 printSeparator =
true;
369 std::cout << endParametersSeparator;
374 std::cout << endParametersSeparator;
384 std::cout <<
"Simulation completed" << std::endl;
388 catch (std::exception& e)
391 std::cout << e.what() <<
". Abort!\n" << std::flush;
393 std::cout <<
"Trying to reset TTY.\n";
402 std::cout <<
"Unknown exception thrown!\n" << std::flush;
404 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:277
bool printUnused(std::ostream &os=std::cout)
Print the list of unused run-time parameters.
Definition: parametersystem.hh:815
void printUsage(const std::string &helpPreamble, const std::string &errorMsg="", std::ostream &os=std::cerr, const bool showAll=false)
Print a usage message for all run-time parameters.
Definition: parametersystem.hh:421
void parseParameterFile(const std::string &fileName, bool overwrite=true)
Read the parameters from an INI-style file.
Definition: parametersystem.hh:693
std::string parseCommandLineOptions(int argc, const char **argv, const std::string &helpPreamble="", const PositionalArgumentCallback &posArgCallback=noPositionalParameters_)
Parse the parameters provided on the command line.
Definition: parametersystem.hh:587
void printValues(std::ostream &os=std::cout)
Print values of the run-time parameters.
Definition: parametersystem.hh:758
int getTtyWidth_()
Definition: parametersystem.hh:269
void endRegistration()
Indicate that all parameters are registered for a given type tag.
Definition: parametersystem.hh:1052
std::string breakLines_(const std::string &msg, int indentWidth, int maxWidth)
Definition: parametersystem.hh:220
void getLists(Container &usedParams, Container &unusedParams)
Retrieves the lists of parameters specified at runtime and their values.
Definition: parametersystem.hh:910
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.