diff --git a/dumux/common/loggingparametertree.hh b/dumux/common/loggingparametertree.hh index 8ba886d35c3eec7205cbc2280cd6c0a054564d8e..ca50911ec16a9d2464ec36476f950923117f66b0 100644 --- a/dumux/common/loggingparametertree.hh +++ b/dumux/common/loggingparametertree.hh @@ -62,6 +62,40 @@ public: bool hasKey(const std::string& key) const { return params_.hasKey(key) || defaultParams_.hasKey(key); } + /** \brief test for key in group + * + * Tests whether given key exists in a group. + * Given a group this function starts to look from the back + * for dots. In G1.G2.G3 the function first looks if the key + * "G3.Key" exists, then "G2.Key", ... + * + * \param key key name + * \param groupPrefix the group prefix name + * \return true if key exists in structure, otherwise false + */ + bool hasKeyInGroup(const std::string& key, + const std::string& groupPrefix) const + { + if (groupPrefix == "") + return hasKey(key); + + if (hasKey(key)) + return true; + + auto compoundKey = groupPrefix + "." + key; + if (params_.hasKey(compoundKey) || defaultParams_.hasKey(compoundKey)) + return true; + + compoundKey = findKeyInGroup(params_, key, groupPrefix); + if (compoundKey != "") + return true; + + compoundKey = findKeyInGroup(defaultParams_, key, groupPrefix); + if (compoundKey != "") + return true; + + return false; + } /** \brief print the hierarchical parameter tree to stream * diff --git a/dumux/common/parameters.hh b/dumux/common/parameters.hh index d82d32f1833859aa859cb0ea001e6488313f26c0..9e4c1926272926800334180ec53d37e684171e23 100644 --- a/dumux/common/parameters.hh +++ b/dumux/common/parameters.hh @@ -389,11 +389,7 @@ bool hasParam(const std::string& param) template<typename... Args> bool hasParamInGroup(const std::string& paramGroup, const std::string& param) { - const auto& p = Parameters::getTree(); - if (paramGroup == "") - return p.hasKey(param); - else - return p.hasKey(paramGroup + "." + param); + return Parameters::getTree().hasKeyInGroup(param, paramGroup); } DUNE_DEPRECATED_MSG("haveParam is deprecated, please use hasParam instead.")