33#include <opm/material/densead/Evaluation.hpp>
36#include <opm/models/utils/terminal.hpp>
39#include <opm/simulators/utils/readDeck.hpp>
41#include <opm/material/common/ResetLocale.hpp>
43#include <dune/common/parallel/mpihelper.hh>
46#include <dune/fem/misc/mpimanager.hh>
65template <
class TypeTag>
66static inline void registerAllParameters_(
bool finalizeRegistration =
true)
68 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
69 using TM = GetPropType<TypeTag, Properties::ThreadManager>;
71 Parameters::Register<Parameters::ParameterFile>
72 (
"An .ini file which contains a set of run-time parameters");
73 Parameters::Register<Parameters::PrintParameters>
74 (
"Print the values of the run-time parameters at the "
75 "start of the simulation");
77 TM::registerParameters();
80 if (finalizeRegistration) {
81 Parameters::endRegistration();
94template <
class TypeTag>
95static inline int setupParameters_(
int argc,
97 bool registerParams=
true,
98 bool allowUnused=
false,
99 bool handleHelp =
true)
101 using Problem = GetPropType<TypeTag, Properties::Problem>;
110 registerAllParameters_<TypeTag>();
117 const auto& positionalParamCallback = Problem::handlePositionalParameter;
118 std::string helpPreamble =
"";
119 if (myRank == 0 && handleHelp)
120 helpPreamble = Problem::helpPreamble(argc, argv);
122 Parameters::parseCommandLineOptions(argc,
124 positionalParamCallback,
129 if (s ==
"Help called")
134 MPI_Allreduce(&status, &globalStatus, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
140 const std::string paramFileName = Parameters::Get<Parameters::ParameterFile>(
false);
141 if (!paramFileName.empty()) {
147 if (!Parameters::parseParameterFile(paramFileName,
false)) {
148 std::ostringstream oss;
150 oss <<
"Parameter file \"" << paramFileName
151 <<
"\" does not exist or is not readable.";
152 Parameters::printUsage(argv[0], std::cerr, oss.str());
159 using ParamList = std::vector<Parameters::Parameter>;
161 ParamList usedParams;
162 ParamList unusedParams;
164 Parameters::getLists(usedParams, unusedParams);
165 if (!allowUnused && !unusedParams.empty()) {
167 if (unusedParams.size() == 1)
168 std::cerr <<
"The following explicitly specified parameter is unknown:\n";
170 std::cerr <<
"The following " << unusedParams.size()
171 <<
" explicitly specified parameters are unknown:\n";
174 for (
const auto& keyValue : unusedParams)
175 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=
true)
204 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
205 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
206 using Problem = GetPropType<TypeTag, Properties::Problem>;
207 using TM = GetPropType<TypeTag, Properties::ThreadManager>;
216 int paramStatus = setupParameters_<TypeTag>(argc,
const_cast<const char**
>(argv), registerParams);
217 if (paramStatus == 1)
219 if (paramStatus == 2)
226 Dune::Fem::MPIManager::initialize(argc, argv);
227 myRank = Dune::Fem::MPIManager::rank();
229 myRank = Dune::MPIHelper::instance(argc, argv).rank();
233 setupStreamLogging(
"STDOUT_LOGGER");
237 Scalar endTime = Parameters::Get<Parameters::EndTime<Scalar>>();
238 if (endTime < -1e50) {
240 Parameters::printUsage(argv[0], std::cerr,
241 "Mandatory parameter '--end-time' not specified!");
246 Scalar initialTimeStepSize = Parameters::Get<Parameters::InitialTimeStepSize<Scalar>>();
247 if (initialTimeStepSize < -1e50) {
249 Parameters::printUsage(argv[0], std::cerr,
250 "Mandatory parameter '--initial-time-step-size' "
258 std::string versionString = EWOMS_VERSION;
260 std::string versionString =
"";
262 const std::string briefDescription = Problem::briefDescription();
263 if (!briefDescription.empty()) {
264 std::string tmp =
breakLines(briefDescription,
267 std::cout << tmp << std::endl << std::endl;
270 std::cout <<
"opm models " << versionString
271 <<
" will now start the simulation. " << std::endl;
275 int printParams = Parameters::Get<Parameters::PrintParameters>();
277 std::string endParametersSeparator(
"# [end of parameters]\n");
279 bool printSeparator =
false;
280 if (printParams == 1 || !isatty(fileno(stdout))) {
281 Parameters::printValues(std::cout);
282 printSeparator =
true;
288 Parameters::printUnused(std::cout);
290 std::cout << endParametersSeparator;
294 if (Parameters::printUnused(std::cout))
295 std::cout << endParametersSeparator;
305 std::cout <<
"Simulation completed" << std::endl;
309 catch (std::exception& e)
312 std::cout << e.what() <<
". Abort!\n" << std::flush;
314 std::cout <<
"Trying to reset TTY.\n";
323 std::cout <<
"Unknown exception thrown!\n" << std::flush;
325 std::cout <<
"Trying to reset TTY.\n";
static void registerParameters()
Registers all runtime parameters used by the simulation.
Definition simulator.hh:240
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
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
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
Manages the initializing and running of time dependent problems.