27 #ifndef EWOMS_START_HH 28 #define EWOMS_START_HH 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> 63 template <
class TypeTag>
64 static inline void registerAllParameters_(
bool finalizeRegistration)
66 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
67 using TM = GetPropType<TypeTag, Properties::ThreadManager>;
69 Parameters::Register<Parameters::ParameterFile>
70 (
"An .ini file which contains a set of run-time parameters");
71 Parameters::Register<Parameters::PrintParameters>
72 (
"Print the values of the run-time parameters at the " 73 "start of the simulation");
75 TM::registerParameters();
78 if (finalizeRegistration) {
79 Parameters::endRegistration();
92 template <
class TypeTag>
93 static inline int setupParameters_(
int argc,
100 using Problem = GetPropType<TypeTag, Properties::Problem>;
105 if (registerParams) {
106 registerAllParameters_<TypeTag>(
true);
114 const auto& positionalParamCallback = Problem::handlePositionalParameter;
115 std::string helpPreamble;
116 if (myRank == 0 && handleHelp) {
117 helpPreamble = Problem::helpPreamble(argc, argv);
119 const std::string s =
120 Parameters::parseCommandLineOptions(argc,
122 positionalParamCallback,
126 if (s ==
"Help called") {
132 MPI_Allreduce(&status, &globalStatus, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
138 const std::string paramFileName = Parameters::Get<Parameters::ParameterFile>(
false);
139 if (!paramFileName.empty()) {
145 if (!Parameters::parseParameterFile(paramFileName,
false)) {
146 std::ostringstream oss;
148 oss <<
"Parameter file \"" << paramFileName
149 <<
"\" does not exist or is not readable.";
150 Parameters::printUsage(argv[0], std::cerr, oss.str());
157 const char* home = std::getenv(
"HOME");
158 if (home !=
nullptr) {
159 const std::string userRcFilename = std::string(home) +
"/.config/OpmFlow/user_parameters.param";
160 const bool readFromUserRc = Parameters::parseParameterFile(userRcFilename,
false);
161 if (readFromUserRc && myRank == 0) {
162 std::cerr <<
"Read parameters from " << userRcFilename <<
".\n";
168 using ParamList = std::vector<Parameters::Parameter>;
170 ParamList usedParams;
171 ParamList unusedParams;
173 Parameters::getLists(usedParams, unusedParams);
174 if (!allowUnused && !unusedParams.empty()) {
176 if (unusedParams.size() == 1) {
177 std::cerr <<
"The following explicitly specified parameter is unknown:\n";
180 std::cerr <<
"The following " << unusedParams.size()
181 <<
" explicitly specified parameters are unknown:\n";
185 for (
const auto& keyValue : unusedParams) {
186 std::cerr <<
" " << keyValue <<
"\n";
192 <<
" " << argv[0] <<
" --help\n" 194 <<
"to obtain the list of recognized command line parameters.\n\n";
213 template <
class TypeTag>
214 static inline int start(
int argc,
char **argv,
bool registerParams)
216 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
217 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
218 using Problem = GetPropType<TypeTag, Properties::Problem>;
219 using TM = GetPropType<TypeTag, Properties::ThreadManager>;
229 Dune::Fem::MPIManager::initialize(argc, argv);
230 myRank = Dune::Fem::MPIManager::rank();
232 myRank = Dune::MPIHelper::instance(argc, argv).rank();
234 const int paramStatus =
235 setupParameters_<TypeTag>(argc,
236 const_cast<const char**
>(argv),
241 if (paramStatus == 1) {
244 if (paramStatus == 2) {
252 setupStreamLogging(
"STDOUT_LOGGER");
256 const Scalar endTime = Parameters::Get<Parameters::EndTime<Scalar>>();
257 if (endTime < -1e50) {
259 Parameters::printUsage(argv[0], std::cerr,
260 "Mandatory parameter '--end-time' not specified!");
265 const Scalar initialTimeStepSize = Parameters::Get<Parameters::InitialTimeStepSize<Scalar>>();
266 if (initialTimeStepSize < -1e50) {
268 Parameters::printUsage(argv[0], std::cerr,
269 "Mandatory parameter '--initial-time-step-size' " 277 const std::string versionString = EWOMS_VERSION;
279 const std::string versionString;
281 const std::string briefDescription = Problem::briefDescription();
282 if (!briefDescription.empty()) {
283 const std::string tmp =
breakLines(briefDescription,
286 std::cout << tmp << std::endl << std::endl;
289 std::cout <<
"opm models " << versionString
290 <<
" will now start the simulation. " << std::endl;
295 const int printParams = Parameters::Get<Parameters::PrintParameters>();
297 const std::string endParametersSeparator(
"# [end of parameters]\n");
299 bool printSeparator =
false;
300 if (printParams == 1 || !isatty(fileno(stdout))) {
301 Parameters::printValues(std::cout);
302 printSeparator =
true;
306 printSeparator = printSeparator || Parameters::printUnused(std::cout);
308 if (printSeparator) {
309 std::cout << endParametersSeparator;
314 if (Parameters::printUnused(std::cout)) {
315 std::cout << endParametersSeparator;
327 std::cout <<
"Simulation completed" << std::endl;
331 catch (std::exception& e) {
333 std::cout << e.what() <<
". Abort!\n" << std::flush;
335 std::cout <<
"Trying to reset TTY.\n";
343 std::cout <<
"Unknown exception thrown!\n" << std::flush;
345 std::cout <<
"Trying to reset TTY.\n";
Manages the initializing and running of time dependent problems.
This file provides the infrastructure to retrieve run-time parameters.
void assignResetTerminalSignalHandlers()
Assign signal handlers that reset the terminal on errors.
Definition: terminal.cpp:128
static void registerParameters()
Registers all runtime parameters used by the simulation.
Definition: simulator.hh:215
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
void resetTerminal()
Resets the current TTY to a usable state if the program was aborted.
Definition: terminal.cpp:143
int getTtyWidth()
Get the width of the tty we are attached to.
Definition: terminal.cpp:110
std::string breakLines(const std::string &msg, int indentWidth, int maxWidth)
Break up a string in lines suitable for terminal output.
Definition: terminal.cpp:59
The Opm property system, traits with inheritance.