Skip to content
Snippets Groups Projects
Commit 34131fce authored by Timo Koch's avatar Timo Koch
Browse files

[start] Refactor parameter parser to not need TypeTag

The parameter parser previously needed a TypeTag traits template argument only
to get the parameter tree type although a parameter tree is already handed it.
This was done to avoid an usused parameter message otherwise issued if the parameter
macros (which need the TypeTag) are not used. Twisted :/ (can't we refactor the parameter system?)

The new implementation has an optional input file name parameter which is taken from the
parametertree if it was provided as command line argument in the default start method. You
can also supply a specific file now statically in the code. If no name is given, the
parameter parser defaults to the <exectuable>.input pattern.
parent d81923d0
No related branches found
No related tags found
1 merge request!247Fix/issue 343 starthh
......@@ -42,7 +42,6 @@ namespace Dumux
* \ingroup Start
* \brief Parses parameters in the command line and input files
*/
template<class TypeTag>
class ParameterParser
{
......@@ -83,32 +82,25 @@ public:
}
/*!
* \brief Parse the input file. If the user didn't specify anything in the parameter tree (that contains
* command line options if parseCommandLineArguments was called before) we default to the
* program name + input. When calling this function we consider it an error if no input file is found.
* \brief Parse the input file.
Throws an error if no input file is found.
*
* \param argc The 'argc' argument of the main function: count of arguments (1 if there are no arguments)
* \param argv The 'argv' argument of the main function: array of pointers to the argument strings
* \param params A parameter tree. It can be filled from an input file or the command line.
* \param usage Callback function for printing the usage message
* \param argc The 'argc' argument of the main function: count of arguments (1 if there are no arguments)
* \param argv The 'argv' argument of the main function: array of pointers to the argument strings
* \param params A parameter tree. It can be filled from an input file or the command line.
* \param usage Optional callback function for printing the usage message
* \param parameterFileName Optional name of the input file. If empty we default to program name + ".input"
*/
static void parseInputFile(int argc,
char **argv,
Dune::ParameterTree &params,
std::string parameterFileName = "",
void (*usage)(const char *, const std::string &) = [](const char *, const std::string &){})
{
const auto& mpiHelper = Dune::MPIHelper::instance(argc, argv);
std::string parameterFileName = "";
// check the parameter tree for a user specified input file
if (params.hasKey("ParameterFile"))
// this is the only reason why this class needs a TypeTag -- sigh
// if the parameter tree is used directly this appears in the unused properties list
parameterFileName = GET_RUNTIME_PARAM(TypeTag, std::string, ParameterFile);
// otherwise use the default
else
// if no parameter file was specified use the default
if (parameterFileName == "")
{
if (mpiHelper.size() > 1)
std::cout << "Rank " << mpiHelper.rank() << ": ";
......
......@@ -83,14 +83,15 @@ int start_(int argc,
////////////////////////////////////////////////////////////
// if the user just wanted to see the help / usage message show usage and stop program
if(!ParameterParser<TypeTag>::parseCommandLineArguments(argc, argv, ParameterTree::tree(), usage))
if(!ParameterParser::parseCommandLineArguments(argc, argv, ParameterTree::tree(), usage))
{
usage(argv[0], defaultUsageMessage(argv[0]));
return 0;
}
// parse the input file into the parameter tree
ParameterParser<TypeTag>::parseInputFile(argc, argv, ParameterTree::tree(), usage);
// check first if the user provided an input file through the command line, if not use the default
const auto parameterFileName = ParameterTree::tree().hasKey("ParameterFile") ? GET_RUNTIME_PARAM(TypeTag, std::string, ParameterFile) : "";
ParameterParser::parseInputFile(argc, argv, ParameterTree::tree(), parameterFileName, usage);
////////////////////////////////////////////////////////////
// check for some user debugging parameters
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment