27 #ifndef EWOMS_START_HH
28 #define EWOMS_START_HH
33 #include <opm/material/localad/Evaluation.hpp>
43 #include <opm/material/common/Valgrind.hpp>
45 #include <dune/grid/io/file/dgfparser/dgfparser.hh>
46 #include <dune/common/version.hh>
47 #if DUNE_VERSION_NEWER(DUNE_COMMON, 2,3)
48 #include <dune/common/parallel/mpihelper.hh>
50 #include <dune/common/mpihelper.hh>
52 #include <dune/common/parametertreeparser.hh>
72 namespace Properties {
91 template <
class TypeTag>
92 int setupParameters_(
int argc,
char **argv)
95 typedef typename
GET_PROP_TYPE(TypeTag, ThreadManager) ThreadManager;
96 typedef typename
GET_PROP(TypeTag, ParameterMetaData) ParameterMetaData;
101 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
108 "An .ini file which contains a set of run-time "
111 "Print the values of the compile time properties at "
112 "the start of the simulation");
114 "Print the values of the run-time parameters at the "
115 "start of the simulation");
125 std::string s = Parameters::parseCommandLineOptions<TypeTag>(argc, argv, myRank == 0);
130 std::string paramFileName = EWOMS_GET_PARAM_(TypeTag, std::string, ParameterFile);
131 if (paramFileName !=
"") {
138 tmp.open(paramFileName.c_str());
139 if (!tmp.is_open()) {
140 std::ostringstream oss;
142 oss <<
"Parameter file \"" << paramFileName
143 <<
"\" does not exist or is not readable.";
144 Parameters::printUsage<TypeTag>(argv[0], oss.str());
150 Dune::ParameterTreeParser::readINITree(paramFileName,
151 ParameterMetaData::tree(),
164 static void resetTerminal_(
int signum)
167 signal(signum, SIG_DFL);
168 std::cout <<
"\n\nReceived signal " << signum
169 <<
" (\"" << strsignal(signum) <<
"\")."
170 <<
" Trying to reset the terminal.\n";
175 if (system(
"stty sane") != 0)
176 std::cout <<
"Executing the 'stty' command failed."
177 <<
" Terminal might be left in an undefined state!\n";
195 template <
class TypeTag>
199 typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
200 typedef typename GET_PROP_TYPE(TypeTag, ThreadManager) ThreadManager;
204 if (isatty(STDIN_FILENO)) {
205 signal(SIGINT, resetTerminal_);
206 signal(SIGHUP, resetTerminal_);
207 signal(SIGABRT, resetTerminal_);
208 signal(SIGFPE, resetTerminal_);
209 signal(SIGSEGV, resetTerminal_);
210 signal(SIGPIPE, resetTerminal_);
211 signal(SIGTERM, resetTerminal_);
215 const Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv);
217 int myRank = mpiHelper.rank();
221 int paramStatus = setupParameters_<TypeTag>(argc, argv);
222 if (paramStatus == 1)
224 if (paramStatus == 2)
231 double initialTimeStepSize;
234 if (endTime < -1e50) {
236 Parameters::printUsage<TypeTag>(argv[0],
237 "Mandatory parameter '--end-time' not specified!");
241 initialTimeStepSize =
EWOMS_GET_PARAM(TypeTag, Scalar, InitialTimeStepSize);
242 if (initialTimeStepSize < -1e50) {
244 Parameters::printUsage<TypeTag>(argv[0],
245 "Mandatory parameter '--initial-time-step-size' "
253 <<
" will now start the trip. "
254 <<
"Please sit back, relax and enjoy the ride.\n"
260 std::string endParametersSeparator(
"# [end of parameters]\n");
262 bool printSeparator =
false;
263 if (printParams == 1 || !isatty(fileno(stdout))) {
264 Ewoms::Parameters::printValues<TypeTag>();
265 printSeparator =
true;
271 Ewoms::Parameters::printUnused<TypeTag>();
273 std::cout << endParametersSeparator;
277 if (Ewoms::Parameters::printUnused<TypeTag>())
278 std::cout << endParametersSeparator;
283 if (printProps && myRank == 0) {
284 if (printProps == 1 || !isatty(fileno(stdout)))
285 Ewoms::Properties::printValues<TypeTag>();
295 std::cout <<
"eWoms reached the destination. If it is not the one that was intended, "
296 <<
"change the booking and try again.\n"
301 catch (std::exception &e)
304 std::cout << e.what() <<
". Abort!\n" << std::flush;
307 catch (Dune::Exception &e)
310 std::cout <<
"Dune reported an error: " << e.what() << std::endl << std::flush;
316 std::cout <<
"Unknown exception thrown!\n" << std::flush;
#define GET_PROP(TypeTag, PropTagName)
Retrieve a property for a type tag.
Definition: propertysystem.hh:453
static void registerParameters()
Register all run-time parameters of the thread manager.
Definition: threadmanager.hh:63
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
#define EWOMS_END_PARAM_REGISTRATION(TypeTag)
Indicate that all parameters are registered for a given type tag.
Definition: parametersystem.hh:77
static void init()
Definition: threadmanager.hh:70
Provides an encapsulation to measure the system time.
static void registerParameters()
Registers all runtime parameters used by the simulation.
Definition: simulator.hh:135
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
This file provides the infrastructure to retrieve run-time parameters.
Definition: baseauxiliarymodule.hh:35
Manages the initializing and running of time dependent problems.
#define EWOMS_REGISTER_PARAM(TypeTag, ParamType, ParamName, Description)
Register a run-time parameter.
Definition: parametersystem.hh:64
int start(int argc, char **argv)
Provides a main function which reads in parameters from the command line and a parameter file and run...
Definition: start.hh:196
std::string versionString()
Definition: version.hh:14
Provides the magic behind the eWoms property system.
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95