diff --git a/dumux/common/basicproperties.hh b/dumux/common/basicproperties.hh index 201e251302ada770791ad3a303c9b17317e9d9f3..608836546a123052c70f47c19f76191451b30963 100644 --- a/dumux/common/basicproperties.hh +++ b/dumux/common/basicproperties.hh @@ -86,36 +86,24 @@ SET_PROP(NumericModel, ParameterTree) static Dune::ParameterTree &tree() { - if (initFinished_) { - DUNE_THROW(Dune::InvalidStateException, - "The ParameterTree cannot be accessed after " - "the initialization phase of the simulation!"); - } - - return parameterTree_; + static Dune::ParameterTree obj_; + return obj_; }; - static void initFinished() - { initFinished_ = true; } + static Dune::ParameterTree &compileTimeParams() + { + static Dune::ParameterTree obj_; + return obj_; + }; -private: - static Dune::ParameterTree parameterTree_; - static bool initFinished_; + static Dune::ParameterTree &runTimeParams() + { + static Dune::ParameterTree obj_; + return obj_; + }; }; -// allocate space for the static parameter tree object -template<class TypeTag> -Dune::ParameterTree - Property<TypeTag, - TTAG(NumericModel), - PTAG(ParameterTree)>::parameterTree_; - -template<class TypeTag> -bool Property<TypeTag, - TTAG(NumericModel), - PTAG(ParameterTree)>::initFinished_ = false; - // use the global group as default for the model's parameter group SET_PROP(NumericModel, ModelParameterGroup) { static const char *value() { return ""; }; }; diff --git a/dumux/common/parameters.hh b/dumux/common/parameters.hh index 0a4a03708f190d6f7a40941b0295a1228c16875d..b6edfae17736a9cec60c3af1b7c8d03db5a8c6ce 100644 --- a/dumux/common/parameters.hh +++ b/dumux/common/parameters.hh @@ -27,11 +27,12 @@ #ifndef DUMUX_PARAMETERS_HH #define DUMUX_PARAMETERS_HH +#include "propertysystem.hh" + #include <dune/common/parametertree.hh> #include <sstream> - -#include "propertysystem.hh" +#include <list> /*! * \brief Retrieve a runtime parameter which _does_ have a default value taken from @@ -69,6 +70,47 @@ NEW_PROP_TAG(ModelParameterGroup); } // namespace Properties namespace Parameters { +template <class TypeTag> +void print(std::ostream &os = std::cout) +{ + typedef typename GET_PROP(TypeTag, PTAG(ParameterTree)) Params; + + const Dune::ParameterTree &tree = Params::tree(); + const Dune::ParameterTree &rt = Params::runTimeParams(); + const Dune::ParameterTree &ct = Params::compileTimeParams(); + + os << "###############################\n"; + os << "# Run-time parameters:\n"; + os << "###############################\n"; + rt.report(os); + os << "###############################\n"; + os << "# Compile-time parameters:\n"; + os << "###############################\n"; + ct.report(os); + + std::list<std::string> unusedParams; + int n = 0; + const Dune::ParameterTree::KeyVector &keys = + Params::tree().getValueKeys(); + for (int i = 0; i < keys.size(); ++i) { + // check wheter the key was accessed + if (rt.hasKey(keys[i])) + continue; + ++n; + unusedParams.push_back(keys[i]); + } + + if (unusedParams.size() > 0) { + os << "###############################\n"; + os << "# UNUSED PARAMETERS:\n"; + os << "###############################\n"; + std::list<std::string>::const_iterator it = unusedParams.begin(); + for (; it != unusedParams.end(); ++it) { + os << *it << " = \"" << tree.get(*it, "") << "\"\n"; + }; + } +}; + const char *getString_(const char *foo = 0) { return foo; } @@ -154,8 +196,8 @@ private: // remember whether the parameter was taken from the parameter // tree or the default from the property system was taken. - Dune::ParameterTree &rt = Params::tree().sub("RunTimeParams"); - Dune::ParameterTree &ct = Params::tree().sub("DefaultParams"); + Dune::ParameterTree &rt = Params::runTimeParams(); + Dune::ParameterTree &ct = Params::compileTimeParams(); if (Params::tree().hasKey(finalName)) { rt[finalName] = Params::tree()[finalName]; }