diff --git a/dumux/common/parameters.hh b/dumux/common/parameters.hh index 171a0ca7b826436fc7dbb688324b36d519bd4e45..1c4768268f63144398a488a0c5d0ad9c9cf26dd8 100644 --- a/dumux/common/parameters.hh +++ b/dumux/common/parameters.hh @@ -88,18 +88,6 @@ #define GET_RUNTIME_PARAM(TypeTag, ParamType, ParamName) \ Dumux::Parameters::getRuntime<TypeTag, ParamType>(#ParamName) -/*! - * \ingroup Parameter - * \brief Set the defailt value for a runtime parameter - * - * Example: - * - * // -> sets the default value for runtime paramter NumberOfCellsX to 20 - * SET_RUNTIME_DEFAULT(TypeTag, int, NumberOfCellsX, "20"); - */ -#define SET_RUNTIME_DEFAULT(TypeTag, ParamType, ParamName, Value) \ - Dumux::Parameters::setRuntimeDefault<TypeTag, ParamType>(#ParamName, Value) - /*! * \ingroup Parameter * \brief Retrieve a runtime parameter which _does not_ have a default value taken from @@ -116,18 +104,6 @@ #define GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, ParamType, GroupName, ParamName) \ Dumux::Parameters::getRuntime<TypeTag, ParamType>(#GroupName, #ParamName) -/*! - * \ingroup Parameter - * \brief Set the default value for a runtime parameter which is in a grop - * - * Example: - * - * // -> sets the default value for runtime paramter Geometry.NumberOfCellsX to 20 - * SET_GROUP_RUNTIME_DEFAULT(TypeTag, int, Geometry, NumberOfCellsX, "20"); - */ -#define SET_GROUP_ RUNTIME_DEFAULT(TypeTag, ParamType, GroupName, ParamName, Value) \ - Dumux::Parameters::setRuntimeDefault<TypeTag, ParamType>(#GroupName, #ParamName, Value) - namespace Dumux { namespace Properties @@ -258,68 +234,6 @@ public: return retrieveRuntime_<ParamType>(groupOrParamName, paramNameOrNil); } - template <class ParamType> - static void setRuntimeDefault(const char *groupOrParamName, - const char *paramNameOrValue, - const char *valueOrNil = 0) - { - // make sure that the parameter is used consistently. since - // this is potentially quite expensive, it is only done if - // debugging code is not explicitly turned off. - const char *paramName, *groupName, *value; - static const std::string propertyName(""); - if (valueOrNil != 0) { - groupName = groupOrParamName; - paramName = paramNameOrValue; - value = valueOrNil; - } - else { - groupName = ""; - paramName = groupOrParamName; - value = paramNameOrValue; - } - -#ifndef NDEBUG - check_(Dune::className<ParamType>(), propertyName, groupName, paramName); -#endif - - static std::string modelParamGroup(GET_PROP_VALUE(TypeTag, ModelParameterGroup)); - - std::string canonicalName(modelParamGroup); - - // prefix the parameter with the parameter group of the - // model. this allows things like sub-model specific parameters like - // - // [Stokes.Newton] - // WriteConvergence = false - // [Darcy.Newton] - // WriteConvergence = true - if (modelParamGroup.size()) { - canonicalName.push_back('.'); - } - - // prefix the parameter name by 'GroupName.'. E.g. 'Newton' - // and 'WriteConvergence' becomes 'Newton.WriteConvergence' - // with the default value specified by the - // 'NewtonWriteConvergence' property. in an INI file this - // would look like: - // - // [Newton] - // WriteConvergence = true - if (strlen(groupName) > 0) { - canonicalName.append(groupName); - canonicalName.push_back('.'); - } - - // append the name of the parameter - canonicalName.append(paramName); - - // set the parameter if not already specified - if (!Params::tree().hasKey(canonicalName)) { - Params::tree()[canonicalName] = value; - } - } - private: struct Blubb { std::string propertyName; @@ -537,16 +451,6 @@ const ParamType &getRuntime(const char *paramOrGroupName, paramNameOrNil); } -template <class TypeTag, class ParamType> -void setRuntimeDefault(const char *paramOrGroupName, - const char *paramNameOrValue, - const char *valueOrNil = 0) -{ - Param<TypeTag>::template setRuntimeDefault<ParamType>(paramOrGroupName, - paramNameOrValue, - valueOrNil); -} - } // namespace Parameters } // namespace Dumux diff --git a/dumux/common/start.hh b/dumux/common/start.hh index 4d8d529960c173a67af28a652e4d0a4a4382c9b2..e0b429839a8d4aa0017ba2afdc00ee8baaccac10 100644 --- a/dumux/common/start.hh +++ b/dumux/common/start.hh @@ -75,44 +75,6 @@ void printUsageGrid(const char *progname) exit(1); } -/*! - * \ingroup Start - * - * \brief Prints the default usage message for the startWithParameters() function - */ -void usageStartWithParameters(const char *progName, const std::string &errorMsg) -{ - if (errorMsg.size() > 0) { - std::cout << errorMsg << "\n" - << "\n"; - } - std::cout - << - "Usage: " << progName << " [options]\n" - "Mandatory options include:\n" - "\t--t-end=ENDTIME The time of the end of the simlation [s]\n" - "\t--dt-initial=STEPSIZE The initial time step size [s]\n" - "\n" - "Alternativ supported syntax:\n" - "\t-tEnd ENDTIME The time of the end of the simlation [s]\n" - "\t-dtInitial STEPSIZE The initial time step size [s]\n" - "\n" - "If --parameter-file is specified parameters can also be defined there. In this case,\n" - "camel case is used for the parameters (e.g.: --t-end becomes tEnd). Parameters\n" - "specified on the command line have priority over those in the parameter file.\n" - "Important optional options include:\n" - "\t--help,-h Print this usage message and exit\n" - "\t--print-parameters[=true|false] Print the run-time modifiable parameters _after_ \n" - "\t the simulation [default: true]\n" - "\t--print-properties[=true|false] Print the compile-time parameters _before_ \n" - "\t the simulation [default: false]\n" - "\t--parameter-file=FILENAME File with parameter definitions\n" - "\t--restart=RESTARTTIME Restart simulation from a restart file\n" - "\n" - "For the case of no arguments given, the input parameter file is expected to be named './parameter.input' \n" - "\n"; -} - /*! * \ingroup Start * \brief Provides a default main function for simulations requiring @@ -286,7 +248,7 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree ¶mTree) for (int i = 1; i < argc; ++i) { if (argv[i][0] != '-') { std::ostringstream oss; - oss << "Command line argument " << i << " (='" << argv[i] << "') is invalid."; + oss << "\n -> Command line argument " << i << " (='" << argv[i] << "') is invalid. <- \n\n\n\n"; return oss.str(); } @@ -297,12 +259,12 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree ¶mTree) // "abc" if (argv[i][1] == '-') { std::string s(argv[i] + 2); - // There is nothing after the '-' + // There is nothing after the '=' if (s.size() == 0 || s[0] == '=') { std::ostringstream oss; - oss << "Parameter name of argument " << i << " ('" << argv[i] << "')" - << " is empty."; + oss << "\n -> Parameter name of argument " << i << " (='" << argv[i] << "')" + << " is empty. <- \n\n\n\n"; return oss.str(); } @@ -331,18 +293,18 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree ¶mTree) if (s.size() == j) { std::ostringstream oss; - oss << "Parameter name of argument " << i << " ('" << argv[i] << "')" - << " is invalid (ends with a '-' character)."; + oss << "\n -> Parameter name of argument " << i << " ('" << argv[i] << "')" + << " is invalid (ends with a '-' character). <- \n\n\n\n"; return oss.str(); } else if (s[j] == '-') { std::ostringstream oss; - oss << "Malformed parameter name name in argument " << i << " ('" << argv[i] << "'): " - << "'--' in parameter name."; + oss << "\n -> Malformed parameter name name in argument " << i << " ('" << argv[i] << "'): " + << "'--' in parameter name. <- \n\n\n\n"; return oss.str(); } - s[j] = std::toupper(s[j]); + s[j] = toupper(s[j]); } ++j; @@ -354,7 +316,7 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree ¶mTree) if (argc == i + 1 || argv[i+1][0] == '-') { std::ostringstream oss; - oss << "No argument given for parameter '" << argv[i] << "'!"; + oss << "\n -> No argument given for parameter '" << argv[i] << "'! <- \n\n\n\n"; return oss.str(); } @@ -362,15 +324,46 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree ¶mTree) ++i; // In the case of '-myOpt abc' each pair counts as two arguments } - // capitalize first letter of parameter name - paramName[0] = std::toupper(paramName[0]); - // Put the key=value pair into the parameter tree paramTree[paramName] = paramValue; } return ""; } + +/*! + * \ingroup Start + * + * \brief Provides a general text block, that is part of error/ help messages. + * + * \return The string that is the help / error message. + */ +std::string usageTextBlock() +{ + return "Mandatory options include:\n" + "\t--t-end=ENDTIME The time of the end of the simlation [s]\n" + "\t--dt-initial=STEPSIZE The initial time step size [s]\n" + "\n" + "Alternativ supported syntax:\n" + "\t-tEnd ENDTIME The time of the end of the simlation [s]\n" + "\t-dtInitial STEPSIZE The initial time step size [s]\n" + "\n" + "If --parameter-file is specified parameters can also be defined there. In this case,\n" + "camel case is used for the parameters (e.g.: --t-end becomes tEnd). Parameters\n" + "specified on the command line have priority over those in the parameter file.\n" + "Important optional options include:\n" + "\t--help,-h Print this usage message and exit\n" + "\t--print-parameters[=true|false] Print the run-time modifiable parameters _after_ \n" + "\t the simulation [default: true]\n" + "\t--print-properties[=true|false] Print the compile-time parameters _before_ \n" + "\t the simulation [default: false]\n" + "\t--parameter-file=FILENAME File with parameter definitions\n" + "\t--restart=RESTARTTIME Restart simulation from a restart file\n" + "\n" + "For the case of no arguments given, the input parameter file is expected to be named './parameter.input' \n" + "\n"; +} + /*! * \ingroup Start * @@ -386,7 +379,7 @@ std::string readOptions_(int argc, char **argv, Dune::ParameterTree ¶mTree) template <class TypeTag> int startWithParameters_(int argc, char **argv, - void (*usage)(const char *, const std::string &) = 0) + void (*usage)(const char *, const std::string &)) { typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid; @@ -397,10 +390,6 @@ int startWithParameters_(int argc, // initialize MPI, finalize is done automatically on exit const Dune::MPIHelper &mpiHelper = Dune::MPIHelper::instance(argc, argv); - // make sure we have a meaningful usage function - if (!usage) - usage = usageStartWithParameters; - //////////////////////////////////////////////////////////// // parse the command line arguments //////////////////////////////////////////////////////////// @@ -408,13 +397,14 @@ int startWithParameters_(int argc, // check whether the user did not specify any parameter. in this // case print the usage message if (argc == 1) { - std::cout<< "\nNo parameter file given. \n" + std::cout<< "\n No parameter file given. \n" << "Defaulting to './parameter.input' for input file.\n"; std::ifstream parameterFile; // check whether the parameter file exists. parameterFile.open("parameter.input"); if (not parameterFile.is_open()){ - usage(argv[0], "Could not open file './parameter.input'."); + std::cout<< "\n\t -> Could not open file './parameter.input'. <- \n\n\n\n"; + usage(argv[0], usageTextBlock()); return 0; } parameterFile.close(); @@ -425,7 +415,7 @@ int startWithParameters_(int argc, for (int i = 1; i < argc; ++i) { if (std::string("--help") == argv[i] || std::string("-h") == argv[i]) { - usage(argv[0], ""); + usage(argv[0], usageTextBlock()); return 0; } } @@ -434,7 +424,9 @@ int startWithParameters_(int argc, typedef typename GET_PROP(TypeTag, ParameterTree) ParameterTree; std::string s = readOptions_(argc, argv, ParameterTree::tree()); if (!s.empty()) { - usage(argv[0], s); + std::string usageMessage = s ; + usageMessage += usageTextBlock(); + usage(argv[0], usageMessage); return 0; } @@ -452,10 +444,10 @@ int startWithParameters_(int argc, // check whether the parameter file exists. parameterFile.open(inputFileName); if (not parameterFile.is_open()){ - std::cout<< "\n Could not open file" + std::cout<< "\n\t -> Could not open file" << inputFileName - << "\n\n"; - usage(argv[0], ""); + << ". <- \n\n\n\n"; + usage(argv[0], usageTextBlock()); return 0; } parameterFile.close(); @@ -465,7 +457,7 @@ int startWithParameters_(int argc, /*overwrite=*/false); } - bool printProps = true; + bool printProps = false; if (ParameterTree::tree().hasKey("PrintProperties")) printProps = GET_RUNTIME_PARAM(TypeTag, bool, PrintProperies); @@ -476,9 +468,9 @@ int startWithParameters_(int argc, // deal with the restart stuff bool restart = false; Scalar restartTime = 0; - if (ParameterTree::tree().hasKey("Restart")) { + if (ParameterTree::tree().hasKey("restart")) { restart = true; - restartTime = GET_RUNTIME_PARAM(TypeTag, Scalar, Restart); + restartTime = GET_RUNTIME_PARAM(TypeTag, Scalar, restart); } // read the PrintParams parameter @@ -488,21 +480,36 @@ int startWithParameters_(int argc, // try to create a grid (from the given grid file) try { GridCreator::makeGrid(); } - catch (...) { usage(argv[1], "Creation of the grid failed!"); throw; } + catch (...) { + std::string usageMessage = "\n\t -> Creation of the grid failed! <- \n\n\n\n"; + usageMessage += usageTextBlock(); + usage(argv[0], usageMessage); + throw; + } // read the initial time step and the end time double tEnd; double dt; - try { tEnd = GET_RUNTIME_PARAM(TypeTag, Scalar, TEnd); } - catch (...) { usage(argv[1], "Mandatory parameter '--t-end' not specified!"); throw; } + try { tEnd = GET_RUNTIME_PARAM(TypeTag, Scalar, tEnd); } + catch (...) { + std::string usageMessage = "\n\t -> Mandatory parameter '--t-end' not specified! <- \n\n\n\n"; + usageMessage += usageTextBlock(); + usage(argv[0], usageMessage); + throw; + } - try { dt = GET_RUNTIME_PARAM(TypeTag, Scalar, DtInitial); } - catch (...) { usage(argv[1], "Mandatory parameter '--dt-initial' not specified!"); throw; } + try { dt = GET_RUNTIME_PARAM(TypeTag, Scalar, dtInitial); } + catch (...) { + std::string usageMessage = "\n\t -> Mandatory parameter '--dt-initial' not specified! <- \n\n\n\n"; + usageMessage += usageTextBlock(); + usage(argv[0], usageMessage); + throw; + } // instantiate and run the concrete problem TimeManager timeManager; - Problem problem(timeManager); + Problem problem(timeManager, GridCreator::grid().leafView()); timeManager.init(problem, restartTime, dt, tEnd, restart); timeManager.run(); @@ -510,8 +517,11 @@ int startWithParameters_(int argc, Dumux::Parameters::print<TypeTag>(); } return 1; + + } + /*! * \ingroup Start * @@ -546,7 +556,7 @@ bool inDebugger() template <class TypeTag> int startWithParameters(int argc, char **argv, - void (*usage)(const char *, const std::string &) = 0) + void (*usage)(const char *, const std::string &)) { if (!inDebugger()) { try { @@ -569,6 +579,192 @@ int startWithParameters(int argc, return startWithParameters_<TypeTag>(argc, argv, usage); } +/*! + * \ingroup Start + * + * \brief Provides a main function which reads in parameters from the + * command line and a parameter file. The grid however, is created + * in the 'real' main function. + * + * \tparam TypeTag The type tag of the problem which needs to be solved + * \tparam Scalar The type for floating point values + * + * \param argc The number of command line arguments of the program + * \param argv The contents of the command line arguments of the program + * \param usage Callback function for printing the usage message + * \param tEnd End of simulation time + * \param dt First time step size + * \param restart Should we restart a simulation? + * \param restartTime At which time should the simulation be restarted? + */ +template <class TypeTag, class Scalar> +int startWithParametersProvideMyOwnGrid_(int argc, + char **argv, + void (*usage)(const char *, const std::string &), + Scalar & tEnd, + Scalar & dt, + bool & restart, + Scalar & restartTime) +{ + typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid; + typedef typename GET_PROP_TYPE(TypeTag, GridCreator) GridCreator; // Set by default (dumux/common/basicproperties.hh) to DgfGridCreator (dumux/common/dgfgridcreator.hh) + typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem; + typedef typename GET_PROP_TYPE(TypeTag, TimeManager) TimeManager; + + // initialize MPI, finalize is done automatically on exit + const Dune::MPIHelper &mpiHelper = Dune::MPIHelper::instance(argc, argv); + + //////////////////////////////////////////////////////////// + // parse the command line arguments + //////////////////////////////////////////////////////////// + + // check whether the user did not specify any parameter. in this + // case print the usage message + if (argc == 1) { + std::cout<< "\nNo parameter file given. \n" + << "Defaulting to './parameter.input' for input file.\n"; + std::ifstream parameterFile; + // check whether the parameter file exists. + parameterFile.open("parameter.input"); + if (not parameterFile.is_open()){ + std::cout<< "\n\t -> Could not open file './parameter.input'. <- \n\n\n\n"; + usage(argv[0], usageTextBlock()); + exit(1); + } + parameterFile.close(); + } + + + // check whether the user wanted to see the help message + for (int i = 1; i < argc; ++i) { + if (std::string("--help") == argv[i] || std::string("-h") == argv[i]) + { + usage(argv[0], usageTextBlock()); + exit(0); + } + } + + // fill the parameter tree with the options from the command line + typedef typename GET_PROP(TypeTag, ParameterTree) ParameterTree; + std::string s = readOptions_(argc, argv, ParameterTree::tree()); + if (!s.empty()) { + std::string usageMessage = s ; + usageMessage += usageTextBlock(); + usage(argv[0], usageMessage); + exit(1); + } + + if (ParameterTree::tree().hasKey("parameterFile") or argc==1) { + // read input file, but do not overwrite options specified + // on the command line, since the latter have precedence. + std::string inputFileName ; + if(argc==1) // if there are no arguments given (and there is a file ./parameter.input) we use it as input file + inputFileName="parameter.input"; + else + inputFileName = GET_RUNTIME_PARAM(TypeTag, std::string, parameterFile); // otherwise we try + + std::ifstream parameterFile; + + // check whether the parameter file exists. + parameterFile.open(inputFileName); + if (not parameterFile.is_open()){ + std::cout<< "\n\t -> Could not open file" + << inputFileName + << ". <- \n\n\n\n"; + usage(argv[0], usageTextBlock()); + exit(1); + } + parameterFile.close(); + + Dune::ParameterTreeParser::readINITree(inputFileName, + ParameterTree::tree(), + /*overwrite=*/false); + } + + + bool printProps = false; + if (ParameterTree::tree().hasKey("PrintProperties")) + printProps = GET_RUNTIME_PARAM(TypeTag, bool, PrintProperies); + + if (printProps && mpiHelper.rank() == 0) { + Dumux::Properties::print<TypeTag>(); + } + + // deal with the restart stuff + if (ParameterTree::tree().hasKey("restart")) { + restart = true; + restartTime = GET_RUNTIME_PARAM(TypeTag, Scalar, restart); + } + + try { tEnd = GET_RUNTIME_PARAM(TypeTag, Scalar, tEnd); } + catch (...) { + std::string usageMessage = "\n\t -> Mandatory parameter '--t-end' not specified! <- \n\n\n\n"; + usageMessage += usageTextBlock(); + usage(argv[0], usageMessage); + throw; + } + + try { dt = GET_RUNTIME_PARAM(TypeTag, Scalar, dtInitial); } + catch (...) { + std::string usageMessage = "\n\t -> Mandatory parameter '--dt-initial' not specified! <- \n\n\n\n"; + usageMessage += usageTextBlock(); + usage(argv[0], usageMessage); + throw; + } + + return 0; +} + +/*! + * \ingroup Start + * + * \brief Provides a main function which reads in parameters from the + * command line and a parameter file. The Grid however is created + * in the 'real' main function. + * + * In this function only the differentiation between debugger + * or not is made. + * + * \tparam TypeTag The type tag of the problem which needs to be solved + * + * \param argc The number of command line arguments of the program + * \param argv The contents of the command line arguments of the program + * \param usage Callback function for printing the usage message + * \param tEnd End of simulation time + * \param dt First time step size + * \param restart Should we restart a simulation? + * \param restartTime At which time should the simulation be restarted? + */ +template <class TypeTag, class Scalar> +int startWithParametersProvideMyOwnGrid(int argc, + char **argv, + void (*usage)(const char *, const std::string &), + Scalar & tEnd, + Scalar & dt, + bool & restart, + Scalar & restartTime) +{ + if (not inDebugger()) { + try { + return startWithParametersProvideMyOwnGrid_<TypeTag, Scalar>(argc, argv, usage, tEnd, dt, restart, restartTime); + } + catch (Dumux::ParameterException &e) { + std::cerr << e << ". Abort!\n"; + exit(1); + } + catch (Dune::Exception &e) { + std::cerr << "Dune reported error: " << e << std::endl; + exit(2); + } + catch (...) { + std::cerr << "Unknown exception thrown!\n"; + exit(3); + } + } + else + return startWithParametersProvideMyOwnGrid_<TypeTag, Scalar>(argc, argv, usage, tEnd, dt, restart, restartTime); +} + } // namespace Dumux #endif diff --git a/test/boxmodels/1p/1ptestproblem.hh b/test/boxmodels/1p/1ptestproblem.hh index 1abfddb6d31829f9f8b164330ce9ed7164955d20..cec00d040876dfe7dd79982611ebc2dd237908a5 100644 --- a/test/boxmodels/1p/1ptestproblem.hh +++ b/test/boxmodels/1p/1ptestproblem.hh @@ -138,8 +138,8 @@ class OnePTestProblem : public OnePBoxProblem<TypeTag> typedef Dune::FieldVector<Scalar, dimWorld> GlobalPosition; public: - OnePTestProblem(TimeManager &timeManager) - : ParentType(timeManager, GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + OnePTestProblem(TimeManager &timeManager, const GridView &gridView) + : ParentType(timeManager, gridView) { } diff --git a/test/boxmodels/1p/test_1p.cc b/test/boxmodels/1p/test_1p.cc index 7b6b28def36b5852abd9fc59c6eff84454a11fbe..643c7fcf8ad40d6fa1bb961145017d94b9fee218 100644 --- a/test/boxmodels/1p/test_1p.cc +++ b/test/boxmodels/1p/test_1p.cc @@ -29,8 +29,35 @@ #include "1ptestproblem.hh" #include <dumux/common/start.hh> +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(OnePTestProblem) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); } diff --git a/test/boxmodels/1p2c/test_1p2c.cc b/test/boxmodels/1p2c/test_1p2c.cc index 780f8f969a8b7a4fec6b2c756eb416cec117ef18..e9df4cd7f3d3a553df949a1bc236113f024c283e 100644 --- a/test/boxmodels/1p2c/test_1p2c.cc +++ b/test/boxmodels/1p2c/test_1p2c.cc @@ -30,8 +30,35 @@ #include "tissue_tumor_problem.hh" #include <dumux/common/start.hh> +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(TissueTumorProblem) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); } diff --git a/test/boxmodels/1p2c/tissue_tumor_problem.hh b/test/boxmodels/1p2c/tissue_tumor_problem.hh index f495d5cc7c4f4457aa57ea5ab05e80ec2281bf18..f11bec689b7a65829dee47cc4bc4a08fb44b3367 100644 --- a/test/boxmodels/1p2c/tissue_tumor_problem.hh +++ b/test/boxmodels/1p2c/tissue_tumor_problem.hh @@ -157,16 +157,16 @@ class TissueTumorProblem : public OnePTwoCBoxProblem<TypeTag> typedef Dune::FieldVector<Scalar, dimWorld> GlobalPosition; public: - TissueTumorProblem(TimeManager &timeManager) - : ParentType(timeManager, GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + TissueTumorProblem(TimeManager &timeManager, const GridView &gridView) + : ParentType(timeManager, gridView) { // calculate the injection volume totalInjectionVolume_ = 0; FVElementGeometry fvGeom; - ElementIterator elemIt = this->gridView().template begin<0>(); - const ElementIterator endIt = this->gridView().template end<0>(); + ElementIterator elemIt = gridView.template begin<0>(); + const ElementIterator endIt = gridView.template end<0>(); for (; elemIt != endIt; ++ elemIt) { - fvGeom.update(this->gridView(), *elemIt); + fvGeom.update(gridView, *elemIt); for (int i = 0; i < fvGeom.numVertices; ++i) { const GlobalPosition &pos = fvGeom.subContVol[i].global; if (inInjectionVolume_(pos)) diff --git a/test/boxmodels/2p/lensproblem.hh b/test/boxmodels/2p/lensproblem.hh index 79c0f9c27123dfd0053a87bbb3c8068ff5f253a0..9f80b4009bc61cdd036d09dad03c9ef193583cf0 100644 --- a/test/boxmodels/2p/lensproblem.hh +++ b/test/boxmodels/2p/lensproblem.hh @@ -60,7 +60,7 @@ namespace Properties NEW_TYPE_TAG(LensProblem, INHERITS_FROM(BoxTwoP, LensSpatialParameters)); // Set the grid type -#if HAVE_UG +#if 0// HAVE_UG SET_TYPE_PROP(LensProblem, Grid, Dune::UGGrid<2>); #else SET_TYPE_PROP(LensProblem, Grid, Dune::YaspGrid<2>); @@ -153,18 +153,16 @@ template <class TypeTag > class LensProblem : public TwoPProblem<TypeTag> { typedef TwoPProblem<TypeTag> ParentType; - - typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView; + typedef typename GET_PROP_TYPE(TypeTag, TwoPIndices) Indices; + typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem; typedef typename GET_PROP_TYPE(TypeTag, WettingPhase) WettingPhase; typedef typename GET_PROP_TYPE(TypeTag, NonwettingPhase) NonwettingPhase; - typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables; - typedef typename GET_PROP_TYPE(TypeTag, BoundaryTypes) BoundaryTypes; - typedef typename GET_PROP_TYPE(TypeTag, TimeManager) TimeManager; enum { + // primary variable indices pwIdx = Indices::pwIdx, SnIdx = Indices::SnIdx, @@ -176,11 +174,21 @@ class LensProblem : public TwoPProblem<TypeTag> wPhaseIdx = Indices::wPhaseIdx, nPhaseIdx = Indices::nPhaseIdx, + // Grid and world dimension dim = GridView::dimension, dimWorld = GridView::dimensionworld }; + + typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables; + typedef typename GET_PROP_TYPE(TypeTag, BoundaryTypes) BoundaryTypes; + typedef typename GET_PROP_TYPE(TypeTag, TimeManager) TimeManager; + + + + + typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; typedef Dune::FieldVector<Scalar, dimWorld> GlobalPosition; public: @@ -189,26 +197,17 @@ public: * * \param timeManager The time manager * \param gridView The grid view + * \param lensLowerLeft Global position of the lenses lower left corner + * \param lensUpperRight Global position of the lenses upper right corner */ - LensProblem(TimeManager &timeManager) - : ParentType(timeManager, GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + LensProblem(TimeManager &timeManager, + const GridView &gridView, + const GlobalPosition &lensLowerLeft, + const GlobalPosition &lensUpperRight) + : ParentType(timeManager, gridView) { eps_ = 3e-6; temperature_ = 273.15 + 20; // -> 20°C - - SET_RUNTIME_DEFAULT(TypeTag, Scalar, LensLowerLeftX, "1.0"); - SET_RUNTIME_DEFAULT(TypeTag, Scalar, LensLowerLeftY, "2.0"); - SET_RUNTIME_DEFAULT(TypeTag, Scalar, LensUpperRightX, "4.0"); - SET_RUNTIME_DEFAULT(TypeTag, Scalar, LensUpperRightY, "3.0"); - - GlobalPosition lensLowerLeft; - lensLowerLeft[0] = GET_RUNTIME_PARAM(TypeTag, Scalar, LensLowerLeftX); - lensLowerLeft[1] = GET_RUNTIME_PARAM(TypeTag, Scalar, LensLowerLeftY); - - GlobalPosition lensUpperRight; - lensUpperRight[0] = GET_RUNTIME_PARAM(TypeTag, Scalar, LensUpperRightX); - lensUpperRight[1] = GET_RUNTIME_PARAM(TypeTag, Scalar, LensUpperRightY); - this->spatialParameters().setLensCoords(lensLowerLeft, lensUpperRight); } diff --git a/test/boxmodels/2p/test_2p.cc b/test/boxmodels/2p/test_2p.cc index fa0a4b0897e42cb31434375e1c5d80921da75b2b..d2eb46bd2a924fe478f0781e553b0a7006732b92 100644 --- a/test/boxmodels/2p/test_2p.cc +++ b/test/boxmodels/2p/test_2p.cc @@ -49,44 +49,18 @@ void usage(const char *progName, const std::string &errorMsg) { if (errorMsg.size() > 0) { - std::cout << errorMsg << "\n" + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial\n" + "(or -tEnd, -dtInitial)\n" + "\n"; + + std::cout << errorMessageOut << "\n"; } - std::cout - << "Usage: " << progName << " [options]\n" - << "Mandatory options are:\n" - << "\t--t-end=ENDTIME The time of the end of the simlation [s]\n" - << "\t--dt-initial=STEPSIZE The initial time step size [s]\n" - << "\n" - << "Important optional options include:\n" - << "\t--help,-h Print this usage message and exit\n" - << "\t--print-parameters[=true|false] Print the run-time modifiable parameters _after_ \n" - << "\t the simulation [default: true]\n" - << "\t--print-properties[=true|false] Print the compile-time parameters _before_ \n" - << "\t the simulation [default: true]\n" - << "\t--parameter-file=FILENAME File with parameter definitions\n" - << "\t--restart=RESTARTTIME Restart simulation from a restart file\n" - << "\t--cells-x=NUM Number of cells in horizontal direction\n" - << "\t--cells-y=NUM Number of cells in vertical direction\n" - << "\t--lens-lower-left-x=VALUE X-Coordinate of the lower-left corner\n" - << " of the low permeability lens\n" - << "\t--lens-lower-left-y=VALUE Y-Coordinate of the lower-left corner\n" - << " of the low permeability lens\n" - << "\t--lens-upper-right-x=VALUE X-Coordinate of the upper-right corner\n" - << " of the low permeability lens\n" - << "\t--lens-upper-right-y=VALUE Y-Coordinate of the upper-right corner\n" - << " of the low permeability lens\n" - << "\n" - << "All parameters can also be specified using the alternative syntax:\n" - << "\t-tEnd ENDTIME The time of the end of the simlation [s]\n" - << "\t-dtInitial STEPSIZE The initial time step size [s]\n" - << "\n" - << "If --parameter-file is specified, parameters can also be defined there. In this case,\n" - << "camel case is used for the parameters (e.g.: --grid-file becomes GridFile). Parameters\n" - << "specified on the command line have priority over those in the parameter file.\n" - << "\n" - << "For the case of no arguments given, the input parameter file is expected to be named './parameter.input' \n" - << "\n"; } @@ -94,34 +68,19 @@ void usage(const char *progName, const std::string &errorMsg) //////////////////////// // helper class for grid instantiation //////////////////////// -template <class TypeTag, class Grid = typename GET_PROP_TYPE(TypeTag, Grid)> -class LensGridCreator; +template <class Grid, class Scalar> +class CreateGrid +{ +}; #if HAVE_UG -template <class TypeTag> -class LensGridCreator<TypeTag, Dune::UGGrid<2> > +template <class Scalar> +class CreateGrid<Dune::UGGrid<2>, Scalar> { - typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; - typedef Dune::UGGrid<2> Grid; - public: - /*! - * \brief Create the Grid - */ - static void makeGrid() + static Dune::UGGrid<2> *create(const Dune::FieldVector<Scalar, 2> &upperRight, + const Dune::FieldVector<int, 2> &cellRes) { - Dune::FieldVector<int, 2> cellRes; - Dune::FieldVector<Scalar, 2> upperRight; - Dune::FieldVector<Scalar, 2> lowerLeft; - - lowerLeft[0] = 0.0; - lowerLeft[1] = 0.0; - upperRight[0] = 6.0; - upperRight[1] = 4.0; - - cellRes[0] = GET_RUNTIME_PARAM(TypeTag, int, CellsX); - cellRes[1] = GET_RUNTIME_PARAM(TypeTag, int, CellsY); - Dune::GridFactory<Dune::UGGrid<2> > factory; for (int i=0; i<=cellRes[0]; i++) { for (int j=0; j<=cellRes[1]; j++) { @@ -165,51 +124,21 @@ public: } } - grid_ = factory.createGrid(); - grid_->loadBalance(); + Dune::UGGrid<2> *grid = factory.createGrid(); + grid->loadBalance(); + return grid; } - - /*! - * \brief Returns a reference to the grid. - */ - static Grid &grid() - { - return *grid_; - }; - -private: - static Grid *grid_; }; - -template <class TypeTag> -Dune::UGGrid<2> *LensGridCreator<TypeTag, Dune::UGGrid<2> >::grid_; #endif -template <class TypeTag> -class LensGridCreator<TypeTag, Dune::YaspGrid<2> > +template <class Scalar> +class CreateGrid<Dune::YaspGrid<2>, Scalar> { - typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; - typedef Dune::YaspGrid<2> Grid; - public: - /*! - * \brief Create the Grid - */ - static void makeGrid() + static Dune::YaspGrid<2> *create(const Dune::FieldVector<Scalar, 2> &upperRight, + const Dune::FieldVector<int, 2> &cellRes) { - Dune::FieldVector<int, 2> cellRes; - Dune::FieldVector<Scalar, 2> upperRight; - Dune::FieldVector<Scalar, 2> lowerLeft; - - lowerLeft[0] = 0.0; - lowerLeft[1] = 0.0; - upperRight[0] = 6.0; - upperRight[1] = 4.0; - - cellRes[0] = GET_RUNTIME_PARAM(TypeTag, int, CellsX); - cellRes[1] = GET_RUNTIME_PARAM(TypeTag, int, CellsY); - - grid_ = new Dune::YaspGrid<2>( + return new Dune::YaspGrid<2>( #ifdef HAVE_MPI Dune::MPIHelper::getCommunicator(), #endif @@ -218,29 +147,26 @@ public: Dune::FieldVector<bool,2>(false), // periodic 0); // overlap }; +}; - /*! - * \brief Returns a reference to the grid. - */ - static Grid &grid() +template <class Scalar> +class CreateGrid<Dune::SGrid<2, 2>, Scalar> +{ +public: + static Dune::SGrid<2, 2> *create(const Dune::FieldVector<Scalar, 2> &upperRight, + const Dune::FieldVector<int, 2> &cellRes) { - return *grid_; - }; + return new Dune::SGrid<2,2>(cellRes, // number of cells + Dune::FieldVector<Scalar, 2>(0.0), // lower left + upperRight); // upper right -private: - static Grid *grid_; + }; }; +//! \endcond + -template <class TypeTag> -Dune::YaspGrid<2> *LensGridCreator<TypeTag, Dune::YaspGrid<2> >::grid_; -// set the GridCreator property -namespace Dumux { -namespace Properties { -SET_TYPE_PROP(LensProblem, GridCreator, LensGridCreator<TypeTag>); -}} -//! \endcond //////////////////////// @@ -248,10 +174,111 @@ SET_TYPE_PROP(LensProblem, GridCreator, LensGridCreator<TypeTag>); //////////////////////// int main(int argc, char** argv) { - typedef TTAG(LensProblem) TypeTag; +#ifdef NDEBUG + try { +#endif + typedef TTAG(LensProblem) TypeTag; + typedef GET_PROP_TYPE(TypeTag, Scalar) Scalar; + typedef GET_PROP_TYPE(TypeTag, Grid) Grid; + typedef GET_PROP_TYPE(TypeTag, Problem) Problem; + typedef GET_PROP_TYPE(TypeTag, TimeManager) TimeManager; + typedef Dune::FieldVector<Scalar, Grid::dimensionworld> GlobalPosition; + + static const int dim = Grid::dimension; + + // initialize MPI, finalize is done automatically on exit + const Dune::MPIHelper& mpiHelper = Dune::MPIHelper::instance(argc, argv); + + Scalar tEnd, dt; + Scalar restartTime=0; + bool restart = false; + Dumux::startWithParametersProvideMyOwnGrid<TypeTag, Scalar>(argc, + argv, + usage, + tEnd, + dt, + restart, + restartTime); + + //////////////////////////////////////////////////////////// + // create the grid + //////////////////////////////////////////////////////////// + GlobalPosition lowerLeft(0.0); + GlobalPosition upperRight; + Dune::FieldVector<int,dim> res; // cell resolution + upperRight[0] = 6.0; + upperRight[1] = 4.0; + + /* + res[0] = 48*4; + res[1] = 32*4; + */ + + /* + res[0] = 96; + res[1] = 64; + */ + + res[0] = 48; + res[1] = 32; + + /* + res[0] = 24; + res[1] = 16; + */ + + /* + res[0] = 6; + res[1] = 4; + */ + + /* + res[0] = 1; + res[1] = 2; + */ + + std::auto_ptr<Grid> grid(CreateGrid<Grid, Scalar>::create(upperRight, res)); + //grid->globalRefine(2); + + //////////////////////////////////////////////////////////// + // instantiate and run the concrete problem + //////////////////////////////////////////////////////////// + + // specify dimensions of the low-permeable lens + GlobalPosition lowerLeftLens, upperRightLens; + lowerLeftLens[0] = 1.0; + lowerLeftLens[1] = 2.0; + upperRightLens[0] = 4.0; + upperRightLens[1] = 3.0; + + // instantiate and run the concrete problem + TimeManager timeManager; + Problem problem(timeManager, grid->leafView(), lowerLeftLens, upperRightLens); + timeManager.init(problem, restartTime, dt, tEnd, restart); + timeManager.run(); + + // read the PrintParams parameter + bool printParams = true ; + typedef typename GET_PROP(TypeTag, ParameterTree) ParameterTree; + if (ParameterTree::tree().hasKey("PrintParameters")) + printParams = GET_RUNTIME_PARAM(TypeTag, bool, PrintParameters); + + if (printParams && mpiHelper.rank() == 0) { + Dumux::Parameters::print<TypeTag>(); + } + + return 0; + +#ifdef NDEBUG + } + catch (Dune::Exception &e) { + std::cerr << "Dune reported error: " << e << std::endl; + } + catch (...) { + std::cerr << "Unknown exception thrown!\n"; + throw; + } +#endif // NDEBUG - SET_RUNTIME_DEFAULT(TypeTag, int, CellsX, "48"); - SET_RUNTIME_DEFAULT(TypeTag, int, CellsY, "32"); - - return Dumux::startWithParameters<TypeTag>(argc, argv, usage); + return 3; } diff --git a/test/boxmodels/2p2c/injectionproblem.hh b/test/boxmodels/2p2c/injectionproblem.hh index 5f275a9618de83b76c3f391cf1310d41b905e92e..96c64f75bf11c256738444fe542e09ec3c5d0124 100644 --- a/test/boxmodels/2p2c/injectionproblem.hh +++ b/test/boxmodels/2p2c/injectionproblem.hh @@ -121,6 +121,7 @@ class InjectionProblem : public TwoPTwoCProblem<TypeTag> contiN2EqIdx = conti0EqIdx + N2Idx }; + typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables; typedef typename GET_PROP_TYPE(TypeTag, BoundaryTypes) BoundaryTypes; typedef typename GET_PROP_TYPE(TypeTag, TimeManager) TimeManager; @@ -130,6 +131,7 @@ class InjectionProblem : public TwoPTwoCProblem<TypeTag> typedef typename GridView::Intersection Intersection; typedef typename GET_PROP_TYPE(TypeTag, FVElementGeometry) FVElementGeometry; + typedef typename GET_PROP_TYPE(TypeTag, GridCreator) GridCreator; typedef Dune::FieldVector<Scalar, dimWorld> GlobalPosition; @@ -140,8 +142,9 @@ public: * \param timeManager The time manager * \param gridView The grid view */ - InjectionProblem(TimeManager &timeManager) - : ParentType(timeManager, GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + InjectionProblem(TimeManager &timeManager, + const GridView &gridView) + : ParentType(timeManager, GridCreator::grid().leafView()) { try { diff --git a/test/boxmodels/2p2c/test_2p2c.cc b/test/boxmodels/2p2c/test_2p2c.cc index 6a27fb91d45c9352385532ffdb6a8af8483e18f1..dbde5ff351591e2b6a8d62aba9fe8cc3852d5f5a 100644 --- a/test/boxmodels/2p2c/test_2p2c.cc +++ b/test/boxmodels/2p2c/test_2p2c.cc @@ -28,8 +28,35 @@ #include "injectionproblem.hh" #include <dumux/common/start.hh> +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(InjectionProblem) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); } diff --git a/test/boxmodels/2p2cni/test_2p2cni.cc b/test/boxmodels/2p2cni/test_2p2cni.cc index f506c6e08e6367c45da0209ded87e254a2b635fc..7a5c4fc085ff6e36533c4407369b9a9460649aa6 100644 --- a/test/boxmodels/2p2cni/test_2p2cni.cc +++ b/test/boxmodels/2p2cni/test_2p2cni.cc @@ -31,8 +31,35 @@ #include "waterairproblem.hh" #include <dumux/common/start.hh> +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(WaterAirProblem) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); } diff --git a/test/boxmodels/2p2cni/waterairproblem.hh b/test/boxmodels/2p2cni/waterairproblem.hh index 3070d47b2d32f58a06425e35810c2303ce880539..40c3aa7d3abd6d4b326bd9ab366ccaf1fc352efb 100644 --- a/test/boxmodels/2p2cni/waterairproblem.hh +++ b/test/boxmodels/2p2cni/waterairproblem.hh @@ -158,8 +158,8 @@ public: * \param timeManager The time manager * \param gridView The grid view */ - WaterAirProblem(TimeManager &timeManager) - : ParentType(timeManager, GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + WaterAirProblem(TimeManager &timeManager, const GridView &gridView) + : ParentType(timeManager, gridView) { maxDepth_ = 1000.0; // [m] eps_ = 1e-6; diff --git a/test/boxmodels/2pni/injectionproblem2pni.hh b/test/boxmodels/2pni/injectionproblem2pni.hh index c6072c541dc051f5d64cd500ef3caa9d38e3e2b4..9975b2ef4a64a6b0a2ff9c7388bfc5d1311af26c 100644 --- a/test/boxmodels/2pni/injectionproblem2pni.hh +++ b/test/boxmodels/2pni/injectionproblem2pni.hh @@ -190,9 +190,8 @@ public: * \param timeManager The time manager * \param gridView The grid view */ - InjectionProblem2PNI(TimeManager &timeManager) - : ParentType(timeManager, - GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + InjectionProblem2PNI(TimeManager &timeManager, const GridView &gridView) + : ParentType(timeManager, gridView) { maxDepth_ = 2700.0; // [m] eps_ = 1e-6; diff --git a/test/boxmodels/2pni/test_2pni.cc b/test/boxmodels/2pni/test_2pni.cc index 51e1fb536c47f05894e52499374affa6be54ea02..13a9587e8357a852d8e36b7507ec22eadd888808 100644 --- a/test/boxmodels/2pni/test_2pni.cc +++ b/test/boxmodels/2pni/test_2pni.cc @@ -30,8 +30,36 @@ #include "injectionproblem2pni.hh" #include <dumux/common/start.hh> + +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(InjectionProblem2PNI) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); } diff --git a/test/boxmodels/3p3c/infiltrationproblem.hh b/test/boxmodels/3p3c/infiltrationproblem.hh index 165bb40d14d6dba60d0e209741c9a909f3eb0c35..48d3d1edd2b154116a9bc9f24b18e7375729d183 100644 --- a/test/boxmodels/3p3c/infiltrationproblem.hh +++ b/test/boxmodels/3p3c/infiltrationproblem.hh @@ -122,9 +122,8 @@ public: * \param timeManager The time manager * \param gridView The grid view */ - InfiltrationProblem(TimeManager &timeManager) - : ParentType(timeManager, - GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + InfiltrationProblem(TimeManager &timeManager, const GridView &gridView) + : ParentType(timeManager, gridView) , eps_(1e-6) { temperature_ = 273.15 + 10.0; // -> 10 degrees Celsius diff --git a/test/boxmodels/3p3c/test_3p3c.cc b/test/boxmodels/3p3c/test_3p3c.cc index 3aabe3397a48819dbf1e09a63835765c39f39e6d..9c3867815c5b13da44682990b815e5d09a3d862c 100644 --- a/test/boxmodels/3p3c/test_3p3c.cc +++ b/test/boxmodels/3p3c/test_3p3c.cc @@ -32,9 +32,36 @@ #include "infiltrationproblem.hh" #include <dumux/common/start.hh> +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(InfiltrationProblem) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); } diff --git a/test/boxmodels/3p3cni/kuevetteproblem.hh b/test/boxmodels/3p3cni/kuevetteproblem.hh index f1d14e57c3b7dd7e22ab33c116f7e96d05a05ca8..39d631ee0e07f6b5928f701e33c7b0ee793a7430 100644 --- a/test/boxmodels/3p3cni/kuevetteproblem.hh +++ b/test/boxmodels/3p3cni/kuevetteproblem.hh @@ -139,9 +139,8 @@ public: * \param timeManager The time manager * \param gridView The grid view */ - KuevetteProblem(TimeManager &timeManager) - : ParentType(timeManager, - GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + KuevetteProblem(TimeManager &timeManager, const GridView &gridView) + : ParentType(timeManager, gridView) { FluidSystem::init(); } diff --git a/test/boxmodels/3p3cni/test_3p3cni.cc b/test/boxmodels/3p3cni/test_3p3cni.cc index bd31b8d20da3ec0915e3637e3d40781cf72bf02b..8d1ce6fd0f414583ad5b452eab8710318215affd 100644 --- a/test/boxmodels/3p3cni/test_3p3cni.cc +++ b/test/boxmodels/3p3cni/test_3p3cni.cc @@ -33,9 +33,37 @@ //#include "columnxylolproblem.hh" #include <dumux/common/start.hh> + +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(KuevetteProblem) ProblemTypeTag; // typedef TTAG(ColumnProblem) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); } diff --git a/test/boxmodels/MpNc/obstacleproblem.hh b/test/boxmodels/MpNc/obstacleproblem.hh index 5d1909e45888e117e946c9ebd962154675821f42..038e293462e782d953e41ff58085fcc639168f7b 100644 --- a/test/boxmodels/MpNc/obstacleproblem.hh +++ b/test/boxmodels/MpNc/obstacleproblem.hh @@ -174,9 +174,8 @@ class ObstacleProblem }; public: - ObstacleProblem(TimeManager &timeManager) - : ParentType(timeManager, - GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + ObstacleProblem(TimeManager &timeManager, const GridView &gridView) + : ParentType(timeManager, gridView) { eps_ = 1e-6; temperature_ = 273.15 + 25; // -> 25°C diff --git a/test/boxmodels/MpNc/test_MpNc.cc b/test/boxmodels/MpNc/test_MpNc.cc index 324e645ffa58255605c786ae161c523f54f801e2..733774ba87add8435c6e34b0dcb42c65a62cec03 100644 --- a/test/boxmodels/MpNc/test_MpNc.cc +++ b/test/boxmodels/MpNc/test_MpNc.cc @@ -19,17 +19,45 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * *****************************************************************************/ -/*! + +/** * \file * - * \brief Test for the M-phase N-component box model. + * \brief Test for the MpNc box model. */ #include "config.h" #include "obstacleproblem.hh" #include <dumux/common/start.hh> +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(ObstacleProblem) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); } diff --git a/test/boxmodels/richards/richardslensproblem.hh b/test/boxmodels/richards/richardslensproblem.hh index 6c9ad31b2c18e8abd252c650180d6763e1f94d80..bb404033550eac9caaeccbf2a84f12c72ef892b4 100644 --- a/test/boxmodels/richards/richardslensproblem.hh +++ b/test/boxmodels/richards/richardslensproblem.hh @@ -153,9 +153,9 @@ public: * \param timeManager The Dumux TimeManager for simulation management. * \param gridView The grid view on the spatial domain of the problem */ - RichardsLensProblem(TimeManager &timeManager) - : ParentType(timeManager, - GET_PROP_TYPE(TypeTag, GridCreator)::grid().leafView()) + RichardsLensProblem(TimeManager &timeManager, + const GridView &gridView) + : ParentType(timeManager, gridView) { eps_ = 3e-6; pnRef_ = 1e5; diff --git a/test/boxmodels/richards/test_richards.cc b/test/boxmodels/richards/test_richards.cc index 8677018ccb42c0eb62ebb8de4a13e03166a22d30..6b2bcc9a9d869c29d09beadd73b5ebc3b7abce35 100644 --- a/test/boxmodels/richards/test_richards.cc +++ b/test/boxmodels/richards/test_richards.cc @@ -29,8 +29,35 @@ #include "richardslensproblem.hh" #include <dumux/common/start.hh> +/*! + * \brief Provides an interface for customizing error messages associated with + * reading in parameters. + * + * \param progname The name of the program, that was tried to be started. + * \param errorMsg The error message that was issued by the start function. + * Comprises the thing that went wrong and a general help message. + */ +void usage(const char *progName, const std::string &errorMsg) +{ + if (errorMsg.size() > 0) { + std::string errorMessageOut = "\nUsage: "; + errorMessageOut += progName; + errorMessageOut += " [options]\n"; + errorMessageOut += errorMsg; + errorMessageOut += "\n\nThe List of Mandatory arguments for this program is:\n" + "--t-end, --dt-initial, --grid-file\n" + "(or -tEnd, -dtInitial, -gridFile)\n" + "\n" + "\t--grid-file=FILENAME The file name of the file containing the grid \n" + "\t definition in DGF format\n" ; + + std::cout << errorMessageOut + << "\n"; + } +} + int main(int argc, char** argv) { typedef TTAG(RichardsLensProblem) ProblemTypeTag; - return Dumux::startWithParameters<ProblemTypeTag>(argc, argv); + return Dumux::startWithParameters<ProblemTypeTag>(argc, argv, usage); }