From ece71ceee0cec9e732220d13c8640c30d81402e0 Mon Sep 17 00:00:00 2001 From: Andreas Lauser <and@poware.org> Date: Mon, 15 Aug 2011 09:40:49 +0000 Subject: [PATCH] add a function which prints which parameters came from where just call Dumux::Parameters::print<TypeTag>() after the end of the simulation and you will get a full report. git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@6484 2fb0f335-1f38-0410-981e-8018bf24f1b0 --- dumux/common/basicproperties.hh | 36 ++++++++---------------- dumux/common/parameters.hh | 50 ++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 28 deletions(-) diff --git a/dumux/common/basicproperties.hh b/dumux/common/basicproperties.hh index 201e251302..608836546a 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 0a4a03708f..b6edfae177 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]; } -- GitLab