diff --git a/opm/models/utils/basicproperties.hh b/opm/models/utils/basicproperties.hh index cb97c8cea..2451d4d95 100644 --- a/opm/models/utils/basicproperties.hh +++ b/opm/models/utils/basicproperties.hh @@ -56,11 +56,13 @@ namespace Opm::Properties { // Create new type tags namespace TTag { + //! Type tag for all models. -struct NumericModel { using InheritsFrom = std::tuple; }; +struct NumericModel {}; //! Type tag for all fully coupled models. struct ImplicitModel { using InheritsFrom = std::tuple; }; + } // end namespace TTag /////////////////////////////////// diff --git a/opm/models/utils/parametersystem.hh b/opm/models/utils/parametersystem.hh index bf9f5b0dd..f5f489132 100644 --- a/opm/models/utils/parametersystem.hh +++ b/opm/models/utils/parametersystem.hh @@ -26,8 +26,8 @@ * \brief This file provides the infrastructure to retrieve run-time parameters * * Internally, runtime parameters are implemented using - * Dune::ParameterTree with the default value taken from the property - * system. + * Dune::ParameterTree with the default value taken from the parameter + * definition. */ #ifndef OPM_PARAMETER_SYSTEM_HH #define OPM_PARAMETER_SYSTEM_HH @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -55,8 +56,35 @@ #include #include -namespace Opm { -namespace Parameters { +namespace Opm::Parameters { + +namespace detail { + +template +struct has_name : public std::false_type {}; + +template +struct has_name().name)>> +: public std::true_type {}; + +//! get the name data member of a parameter +template +auto getParamName() +{ + if constexpr (has_name::value) { + return Parameter::name; + } else { + std::string paramName = Dune::className(); + paramName.replace(0, std::strlen("Opm::Parameters::"), ""); + const auto pos = paramName.find_first_of('<'); + if (pos != std::string::npos) { + paramName.erase(pos); + } + return paramName; + } +} + +} struct ParamInfo { @@ -95,6 +123,41 @@ struct ParamInfo template class Property> auto get(bool errorIfNotRegistered = true); +/*! + * \ingroup Parameter + * + * \brief Retrieve a runtime parameter. + * + * The default value is specified in the parameter struct. + * + * Example: + * + * \code + * // Retrieves value UpwindWeight, default + * // is taken from the property UpwindWeight + * ::Opm::Parameters::get<::Opm::Parameters::UpwindWeight>(); + * \endcode + */ +template +auto Get(bool errorIfNotRegistered = true); + +/*! + * \ingroup Parameter + * + * \brief Set a runtime parameter. + * + * Override the default value specified. + * + * Example: + * + * \code + * // Set the value UpwindWeight + * ::Opm::Parameters::Set<::Opm::Parameters::UpwindWeight>(3.0); + * \endcode + */ +template +auto SetDefault(decltype(Param::value) new_value); + class ParamRegFinalizerBase_ { public: @@ -104,7 +167,7 @@ public: }; template class Property> -class ParamRegFinalizer_ : public ParamRegFinalizerBase_ +class ParamRegFinalizerTT_ : public ParamRegFinalizerBase_ { public: void retrieve() override @@ -114,40 +177,33 @@ public: std::ignore = get(/*errorIfNotRegistered=*/true); } }; -} // namespace Parameters -} // namespace Opm +template +class ParamRegFinalizer_ : public ParamRegFinalizerBase_ +{ +public: + void retrieve() override + { + // retrieve the parameter once to make sure that its value does + // not contain a syntax error. + std::ignore = Get(/*errorIfNotRegistered=*/true); + } +}; -namespace Opm::Properties { - -namespace TTag { - -// type tag which is supposed to spliced in or inherited from if the -// parameter system is to be used -struct ParameterSystem {}; - -} // namespace TTag - -template -struct ParameterMetaData { using type = UndefinedProperty; }; - - -//! Set the ParameterMetaData property -template -struct ParameterMetaData +struct MetaData { using type = Dune::ParameterTree; static Dune::ParameterTree& tree() { return *storage_().tree; } - static std::map& mutableRegistry() + static std::map& mutableRegistry() { return storage_().registry; } - static const std::map& registry() + static const std::map& registry() { return storage_().registry; } - static std::list > ®istrationFinalizers() + static std::list> ®istrationFinalizers() { return storage_().finalizers; } static bool& registrationOpen() @@ -155,7 +211,7 @@ struct ParameterMetaData static void clear() { - storage_().tree.reset(new Dune::ParameterTree()); + storage_().tree = std::make_unique(); storage_().finalizers.clear(); storage_().registrationOpen = true; storage_().registry.clear(); @@ -166,28 +222,27 @@ private: // member functions of the ParameterMetaData property class triggers a bug in clang // 3.5's address sanitizer which causes these variables to be initialized multiple // times... - struct Storage_ { + struct Storage_ + { Storage_() { - tree.reset(new Dune::ParameterTree()); + tree = std::make_unique(); registrationOpen = true; } std::unique_ptr tree; - std::map registry; - std::list > finalizers; + std::map registry; + std::list> finalizers; bool registrationOpen; }; - static Storage_& storage_() { + + static Storage_& storage_() + { static Storage_ obj; return obj; } }; -} // namespace Opm::Properties - -namespace Opm::Parameters { - // function prototype declarations void printParamUsage_(std::ostream& os, const ParamInfo& paramInfo); void getFlattenedKeyList_(std::list& dest, @@ -365,15 +420,14 @@ inline void getFlattenedKeyList_(std::list& dest, } // print the values of a list of parameters -template -void printParamList_(std::ostream& os, const std::list& keyList, bool printDefaults = false) +inline void printParamList_(std::ostream& os, + const std::list& keyList, + bool printDefaults = false) { - using ParamsMeta = GetProp; - - const Dune::ParameterTree& tree = ParamsMeta::tree(); + const Dune::ParameterTree& tree = MetaData::tree(); for (const auto& key : keyList) { - const auto& paramInfo = ParamsMeta::registry().at(key); + const auto& paramInfo = MetaData::registry().at(key); const std::string& defaultValue = paramInfo.compileTimeValue; std::string value = defaultValue; if (tree.hasKey(key)) @@ -396,17 +450,13 @@ void printParamList_(std::ostream& os, const std::list& keyList, bo * \param errorMsg The error message to be printed, if any * \param os The \c std::ostream which should be used. */ -template -void printUsage(const std::string& helpPreamble, - const std::string& errorMsg = "", - std::ostream& os = std::cerr, - const bool showAll = false) +inline void printUsage(const std::string& helpPreamble, + const std::string& errorMsg = "", + std::ostream& os = std::cerr, + const bool showAll = false) { - using ParamsMeta = GetProp; - - if (errorMsg != "") { - os << errorMsg << "\n" - << "\n"; + if (!errorMsg.empty()) { + os << errorMsg << "\n\n"; } os << breakLines_(helpPreamble, /*indent=*/2, /*maxWidth=*/getTtyWidth_()); @@ -424,11 +474,9 @@ void printUsage(const std::string& helpPreamble, printParamUsage_(os, pInfo); } - auto paramIt = ParamsMeta::registry().begin(); - const auto& paramEndIt = ParamsMeta::registry().end(); - for (; paramIt != paramEndIt; ++paramIt) { - if (showAll || !paramIt->second.isHidden) - printParamUsage_(os, paramIt->second); + for (const auto& param : MetaData::registry()) { + if (showAll || !param.second.isHidden) + printParamUsage_(os, param.second); } } @@ -567,24 +615,22 @@ inline std::string parseUnquotedValue_(std::string& s, const std::string&) * \return Empty string if everything worked out. Otherwise the thing that could * not be read. */ -template +template std::string parseCommandLineOptions(int argc, const char **argv, const std::string& helpPreamble = "", const PositionalArgumentCallback& posArgCallback = noPositionalParameters_) { - Dune::ParameterTree& paramTree = GetProp::tree(); - // handle the "--help" parameter if (!helpPreamble.empty()) { for (int i = 1; i < argc; ++i) { if (std::string("-h") == argv[i] || std::string("--help") == argv[i]) { - printUsage(helpPreamble, /*errorMsg=*/"", std::cout); + printUsage(helpPreamble, /*errorMsg=*/"", std::cout); return "Help called"; } if (std::string("--help-all") == argv[i]) { - printUsage(helpPreamble, /*errorMsg=*/"", std::cout, true); + printUsage(helpPreamble, /*errorMsg=*/"", std::cout, true); return "Help called"; } } @@ -599,13 +645,14 @@ std::string parseCommandLineOptions(int argc, || argv[i][1] != '-') { std::string errorMsg; - int numHandled = posArgCallback(seenKeys, errorMsg, argc, argv, i, numPositionalParams); + int numHandled = posArgCallback(seenKeys, errorMsg, argc, argv, + i, numPositionalParams); if (numHandled < 1) { std::ostringstream oss; if (!helpPreamble.empty()) - printUsage(helpPreamble, errorMsg, std::cerr); + printUsage(helpPreamble, errorMsg, std::cerr); return errorMsg; } @@ -630,7 +677,7 @@ std::string parseCommandLineOptions(int argc, << "is invalid because it does not start with a letter."; if (!helpPreamble.empty()) - printUsage(helpPreamble, oss.str(), std::cerr); + printUsage(helpPreamble, oss.str(), std::cerr); return oss.str(); } @@ -646,7 +693,7 @@ std::string parseCommandLineOptions(int argc, "command line parameter"; if (!helpPreamble.empty()) - printUsage(helpPreamble, msg, std::cerr); + printUsage(helpPreamble, msg, std::cerr); return msg; } seenKeys.insert(paramName); @@ -657,14 +704,14 @@ std::string parseCommandLineOptions(int argc, +" Please use "+argv[i]+"=value."; if (!helpPreamble.empty()) - printUsage(helpPreamble, msg, std::cerr); + printUsage(helpPreamble, msg, std::cerr); return msg; } paramValue = s.substr(1); // Put the key=value pair into the parameter tree - paramTree[paramName] = paramValue; + MetaData::tree()[paramName] = paramValue; } return ""; } @@ -675,11 +722,8 @@ std::string parseCommandLineOptions(int argc, * * This function does some basic syntax checks. */ -template -void parseParameterFile(const std::string& fileName, bool overwrite = true) +inline void parseParameterFile(const std::string& fileName, bool overwrite = true) { - Dune::ParameterTree& paramTree = GetProp::tree(); - std::set seenKeys; std::ifstream ifs(fileName); unsigned curLineNum = 0; @@ -731,8 +775,9 @@ void parseParameterFile(const std::string& fileName, bool overwrite = true) std::runtime_error(errorPrefix+"Syntax error, expecting 'key=value'"); // all went well, add the parameter to the database object - if (overwrite || !paramTree.hasKey(canonicalKey)) - paramTree[canonicalKey] = value; + if (overwrite || !MetaData::tree().hasKey(canonicalKey)) { + MetaData::tree()[canonicalKey] = value; + } } } @@ -742,20 +787,15 @@ void parseParameterFile(const std::string& fileName, bool overwrite = true) * * \param os The \c std::ostream on which the message should be printed */ -template -void printValues(std::ostream& os = std::cout) +inline void printValues(std::ostream& os = std::cout) { - using ParamsMeta = GetProp; - - const Dune::ParameterTree& tree = ParamsMeta::tree(); - std::list runTimeAllKeyList; std::list runTimeKeyList; std::list unknownKeyList; - getFlattenedKeyList_(runTimeAllKeyList, tree); + getFlattenedKeyList_(runTimeAllKeyList, MetaData::tree()); for (const auto& key : runTimeAllKeyList) { - if (ParamsMeta::registry().find(key) == ParamsMeta::registry().end()) { + if (MetaData::registry().find(key) == MetaData::registry().end()) { // key was not registered by the program! unknownKeyList.push_back(key); } @@ -767,9 +807,9 @@ void printValues(std::ostream& os = std::cout) // loop over all registered parameters std::list compileTimeKeyList; - for (const auto& reg : ParamsMeta::registry()) { + for (const auto& reg : MetaData::registry()) { // check whether the key was specified at run-time - if (tree.hasKey(reg.first)) { + if (MetaData::tree().hasKey(reg.first)) { continue; } else { compileTimeKeyList.push_back(reg.first); @@ -780,18 +820,18 @@ void printValues(std::ostream& os = std::cout) // parameters if (runTimeKeyList.size() > 0) { os << "# [known parameters which were specified at run-time]\n"; - printParamList_(os, runTimeKeyList, /*printDefaults=*/true); + printParamList_(os, runTimeKeyList, /*printDefaults=*/true); } if (compileTimeKeyList.size() > 0) { os << "# [parameters which were specified at compile-time]\n"; - printParamList_(os, compileTimeKeyList, /*printDefaults=*/false); + printParamList_(os, compileTimeKeyList, /*printDefaults=*/false); } if (unknownKeyList.size() > 0) { os << "# [unused run-time specified parameters]\n"; for (const auto& unused : unknownKeyList) { - os << unused << "=\"" << tree.get(unused, "") << "\"\n" << std::flush; + os << unused << "=\"" << MetaData::tree().get(unused, "") << "\"\n" << std::flush; } } } @@ -804,18 +844,14 @@ void printValues(std::ostream& os = std::cout) * * \return true if something was printed */ -template -bool printUnused(std::ostream& os = std::cout) +inline bool printUnused(std::ostream& os = std::cout) { - using ParamsMeta = GetProp; - - const Dune::ParameterTree& tree = ParamsMeta::tree(); std::list runTimeAllKeyList; std::list unknownKeyList; - getFlattenedKeyList_(runTimeAllKeyList, tree); + getFlattenedKeyList_(runTimeAllKeyList, MetaData::tree()); for (const auto& key : runTimeAllKeyList) { - if (ParamsMeta::registry().find(key) == ParamsMeta::registry().end()) { + if (MetaData::registry().find(key) == MetaData::registry().end()) { // key was not registered by the program! unknownKeyList.push_back(key); } @@ -824,7 +860,8 @@ bool printUnused(std::ostream& os = std::cout) if (unknownKeyList.size() > 0) { os << "# [unused run-time specified parameters]\n"; for (const auto& unused : unknownKeyList) { - os << unused << "=\"" << tree.get(unused, "") << "\"\n" << std::flush; + os << unused << "=\"" + << MetaData::tree().get(unused, "") << "\"\n" << std::flush; } return true; } @@ -834,20 +871,20 @@ bool printUnused(std::ostream& os = std::cout) template class Param> auto get(bool errorIfNotRegistered) { - using ParamsMeta = GetProp; const std::string paramName = getPropName(); const auto defaultValue = getPropValue(); using ParamType = std::conditional_t, std::string, std::remove_const_t>; if (errorIfNotRegistered) { - if (ParamsMeta::registrationOpen()) + if (MetaData::registrationOpen()) throw std::runtime_error("Parameters can only retrieved after _all_ of them have " "been registered."); - if (ParamsMeta::registry().find(paramName) == ParamsMeta::registry().end()) + if (MetaData::registry().find(paramName) == MetaData::registry().end()) { throw std::runtime_error("Accessing parameter " + paramName +" without prior registration is not allowed."); + } } // prefix the parameter name by the model's GroupName. E.g. If @@ -857,7 +894,60 @@ auto get(bool errorIfNotRegistered) // [Stokes] // NewtonWriteConvergence = true // retrieve actual parameter from the parameter tree - return ParamsMeta::tree().template get(paramName, defaultValue); + return MetaData::tree().template get(paramName, defaultValue); +} + +template +auto Get(bool errorIfNotRegistered) +{ + const std::string paramName = detail::getParamName(); + if (errorIfNotRegistered) { + if (MetaData::registrationOpen()) + throw std::runtime_error("Parameters can only retrieved after _all_ of them have " + "been registered."); + + if (MetaData::registry().find(paramName) == MetaData::registry().end()) { + throw std::runtime_error("Accessing parameter " + paramName + +" without prior registration is not allowed."); + } + } + + using ParamType = std::conditional_t, std::string, + std::remove_const_t>; + ParamType defaultValue = Param::value; + const std::string& defVal = MetaData::mutableRegistry()[paramName].compileTimeValue; + if constexpr (std::is_same_v) { + defaultValue = defVal; + } + else if constexpr (std::is_same_v) { + defaultValue = defVal == "1"; + } + else { + std::from_chars(defVal.data(), defVal.data() + defVal.size(), defaultValue); + } + + // prefix the parameter name by the model's GroupName. E.g. If + // the model specifies its group name to be 'Stokes', in an + // INI file this would result in something like: + // + // [Stokes] + // NewtonWriteConvergence = true + // retrieve actual parameter from the parameter tree + return MetaData::tree().template get(paramName, defaultValue); +} + +template +auto SetDefault(decltype(Param::value) new_value) +{ + const std::string paramName = detail::getParamName(); + if (MetaData::registry().find(paramName) == MetaData::registry().end()) { + throw std::runtime_error("Accessing parameter " + paramName + + " without prior registration is not allowed."); + } + std::ostringstream oss; + oss << new_value; + MetaData::mutableRegistry()[paramName].compileTimeValue = oss.str(); } /*! @@ -866,39 +956,36 @@ auto get(bool errorIfNotRegistered) * The two arguments besides the TypeTag are assumed to be STL containers which store * std::pair. */ -template +template void getLists(Container& usedParams, Container& unusedParams) { usedParams.clear(); unusedParams.clear(); - using ParamsMeta = GetProp; - if (ParamsMeta::registrationOpen()) - throw std::runtime_error("Parameter lists can only retieved after _all_ of them have " + if (MetaData::registrationOpen()) { + throw std::runtime_error("Parameter lists can only retrieved after _all_ of them have " "been registered."); + } // get all parameter keys std::list allKeysList; - const auto& paramTree = ParamsMeta::tree(); - getFlattenedKeyList_(allKeysList, paramTree); + getFlattenedKeyList_(allKeysList, MetaData::tree()); for (const auto& key : allKeysList) { - if (ParamsMeta::registry().find(key) == ParamsMeta::registry().end()) { + if (MetaData::registry().find(key) == MetaData::registry().end()) { // key was not registered - unusedParams.emplace_back(key, paramTree[key]); + unusedParams.emplace_back(key, MetaData::tree()[key]); } else { // key was registered - usedParams.emplace_back(key, paramTree[key]); + usedParams.emplace_back(key, MetaData::tree()[key]); } } } -template -void reset() +inline void reset() { - using ParamsMeta = GetProp; - ParamsMeta::clear(); + MetaData::clear(); } /*! @@ -910,21 +997,47 @@ void reset() template class Param> bool isSet(bool errorIfNotRegistered = true) { - using ParamsMeta = GetProp; const std::string paramName = getPropName(); if (errorIfNotRegistered) { - if (ParamsMeta::registrationOpen()) + if (MetaData::registrationOpen()) { throw std::runtime_error("Parameters can only checked after _all_ of them have " "been registered."); + } - if (ParamsMeta::registry().find(paramName) == ParamsMeta::registry().end()) - throw std::runtime_error("Accessing parameter "+std::string(paramName) - +" without prior registration is not allowed."); + if (MetaData::registry().find(paramName) == MetaData::registry().end()) + throw std::runtime_error("Accessing parameter " + std::string(paramName) + + " without prior registration is not allowed."); } // check whether the parameter is in the parameter tree - return ParamsMeta::tree().hasKey(paramName); + return MetaData::tree().hasKey(paramName); +} + +/*! + * \brief Returns true if a parameter has been specified at runtime, false + * otherwise. + * + * If the parameter in question has not been registered, this throws an exception. + */ +template +bool IsSet(bool errorIfNotRegistered = true) +{ + const std::string paramName = detail::getParamName(); + + if (errorIfNotRegistered) { + if (MetaData::registrationOpen()) { + throw std::runtime_error("Parameters can only checked after _all_ of them have " + "been registered."); + } + + if (MetaData::registry().find(paramName) == MetaData::registry().end()) + throw std::runtime_error("Accessing parameter " + std::string(paramName) + + " without prior registration is not allowed."); + } + + // check whether the parameter is in the parameter tree + return MetaData::tree().hasKey(paramName); } /*! @@ -946,9 +1059,8 @@ bool isSet(bool errorIfNotRegistered = true) template class Param> void registerParam(const char* usageString) { - using ParamsMeta = GetProp; const std::string paramName = getPropName(); - if (!ParamsMeta::registrationOpen()) { + if (!MetaData::registrationOpen()) { throw std::logic_error("Parameter registration was already closed before " "the parameter '" + paramName + "' was registered."); } @@ -957,8 +1069,8 @@ void registerParam(const char* usageString) using ParamType = std::conditional_t, std::string, std::remove_const_t>; - ParamsMeta::registrationFinalizers().push_back( - std::make_unique>()); + MetaData::registrationFinalizers().push_back( + std::make_unique>()); ParamInfo paramInfo; paramInfo.paramName = paramName; @@ -970,16 +1082,70 @@ void registerParam(const char* usageString) oss << defaultValue; paramInfo.compileTimeValue = oss.str(); paramInfo.isHidden = false; - if (ParamsMeta::registry().find(paramName) != ParamsMeta::registry().end()) { + if (MetaData::registry().find(paramName) != MetaData::registry().end()) { // allow to register a parameter twice, but only if the // parameter name, type and usage string are exactly the same. - if (ParamsMeta::registry().at(paramName) == paramInfo) + if (MetaData::registry().at(paramName) == paramInfo) { return; + } throw std::logic_error("Parameter " + paramName +" registered twice with non-matching characteristics."); } - ParamsMeta::mutableRegistry()[paramName] = paramInfo; + MetaData::mutableRegistry()[paramName] = paramInfo; +} + +/*! + * \ingroup Parameter + * + * \brief Register a run-time parameter. + * + * In OPM, parameters can only be used after they have been + * registered. + * + * Example: + * + * \code + * // Registers a run-time parameter "UpwindWeight" + * and the description "Relative weight of the upwind node." + * registerParam("Relative weight of the upwind node."); + * \endcode + */ +template +void Register(const char* usageString) +{ + const std::string paramName = detail::getParamName(); + if (!MetaData::registrationOpen()) { + throw std::logic_error("Parameter registration was already closed before " + "the parameter '" + paramName + "' was registered."); + } + + const auto defaultValue = Param::value; + using ParamType = std::conditional_t, std::string, + std::remove_const_t>; + MetaData::registrationFinalizers().push_back( + std::make_unique>()); + + ParamInfo paramInfo; + paramInfo.paramName = paramName; + paramInfo.paramTypeName = Dune::className(); + paramInfo.usageString = usageString; + std::ostringstream oss; + oss << defaultValue; + paramInfo.compileTimeValue = oss.str(); + paramInfo.isHidden = false; + if (MetaData::registry().find(paramName) != MetaData::registry().end()) { + // allow to register a parameter twice, but only if the + // parameter name, type and usage string are exactly the same. + if (MetaData::registry().at(paramName) == paramInfo) { + return; + } + throw std::logic_error("Parameter " + paramName + +" registered twice with non-matching characteristics."); + } + + MetaData::mutableRegistry()[paramName] = paramInfo; } /*! @@ -991,15 +1157,40 @@ template class Param> void hideParam() { const std::string paramName = getPropName(); - using ParamsMeta = GetProp; - if (!ParamsMeta::registrationOpen()) + if (!MetaData::registrationOpen()) { throw std::logic_error("Parameter '" +paramName + "' declared as hidden" " when parameter registration was already closed."); + } - auto paramInfoIt = ParamsMeta::mutableRegistry().find(paramName); - if (paramInfoIt == ParamsMeta::mutableRegistry().end()) + auto paramInfoIt = MetaData::mutableRegistry().find(paramName); + if (paramInfoIt == MetaData::mutableRegistry().end()) { throw std::logic_error("Tried to declare unknown parameter '" + paramName + "' hidden."); + } + + auto& paramInfo = paramInfoIt->second; + paramInfo.isHidden = true; +} + +/*! + * \brief Indicate that a given parameter should not be mentioned in the help message + * + * This allows to deal with unused parameters + */ +template +void Hide() +{ + const std::string paramName = detail::getParamName(); + if (!MetaData::registrationOpen()) { + throw std::logic_error("Parameter '" +paramName + "' declared as hidden" + " when parameter registration was already closed."); + } + + auto paramInfoIt = MetaData::mutableRegistry().find(paramName); + if (paramInfoIt == MetaData::mutableRegistry().end()) { + throw std::logic_error("Tried to declare unknown parameter '" + + paramName + "' hidden."); + } auto& paramInfo = paramInfoIt->second; paramInfo.isHidden = true; @@ -1012,22 +1203,21 @@ void hideParam() * \c endParamRegistration, a std::logic_error exception * will be thrown. */ -template -void endParamRegistration() +inline void endRegistration() { - using ParamsMeta = GetProp; - if (!ParamsMeta::registrationOpen()) + if (!MetaData::registrationOpen()) { throw std::logic_error("Parameter registration was already closed. It is only possible " "to close it once."); + } - ParamsMeta::registrationOpen() = false; + MetaData::registrationOpen() = false; // loop over all parameters and retrieve their values to make sure // that there is no syntax error - for (const auto& param : ParamsMeta::registrationFinalizers()) { + for (const auto& param : MetaData::registrationFinalizers()) { param->retrieve(); } - ParamsMeta::registrationFinalizers().clear(); + MetaData::registrationFinalizers().clear(); } //! \endcond diff --git a/opm/models/utils/start.hh b/opm/models/utils/start.hh index dacab2471..b2d99e588 100644 --- a/opm/models/utils/start.hh +++ b/opm/models/utils/start.hh @@ -88,7 +88,7 @@ static inline void registerAllParameters_(bool finalizeRegistration = true) ThreadManager::registerParameters(); if (finalizeRegistration) { - Parameters::endParamRegistration(); + Parameters::endRegistration(); } } @@ -129,10 +129,10 @@ static inline int setupParameters_(int argc, if (myRank == 0 && handleHelp) helpPreamble = Problem::helpPreamble(argc, argv); std::string s = - Parameters::parseCommandLineOptions(argc, - argv, - helpPreamble, - positionalParamCallback); + Parameters::parseCommandLineOptions(argc, + argv, + helpPreamble, + positionalParamCallback); if (!s.empty()) { int status = 1; @@ -161,13 +161,13 @@ static inline int setupParameters_(int argc, if (myRank == 0) { oss << "Parameter file \"" << paramFileName << "\" does not exist or is not readable."; - Parameters::printUsage(argv[0], oss.str()); + Parameters::printUsage(argv[0], oss.str()); } return /*status=*/1; } // read the parameter file. - Parameters::parseParameterFile(paramFileName, /*overwrite=*/false); + Parameters::parseParameterFile(paramFileName, /*overwrite=*/false); } // make sure that no unknown parameters are encountered @@ -177,7 +177,7 @@ static inline int setupParameters_(int argc, ParamList usedParams; ParamList unusedParams; - Parameters::getLists(usedParams, unusedParams); + Parameters::getLists(usedParams, unusedParams); if (!allowUnused && !unusedParams.empty()) { if (myRank == 0) { if (unusedParams.size() == 1) @@ -318,17 +318,17 @@ static inline int start(int argc, char **argv, bool registerParams=true) Scalar endTime = Parameters::get(); if (endTime < -1e50) { if (myRank == 0) - Parameters::printUsage(argv[0], - "Mandatory parameter '--end-time' not specified!"); + Parameters::printUsage(argv[0], + "Mandatory parameter '--end-time' not specified!"); return 1; } Scalar initialTimeStepSize = Parameters::get(); if (initialTimeStepSize < -1e50) { if (myRank == 0) - Parameters::printUsage(argv[0], - "Mandatory parameter '--initial-time-step-size' " - "not specified!"); + Parameters::printUsage(argv[0], + "Mandatory parameter '--initial-time-step-size' " + "not specified!"); return 1; } @@ -357,20 +357,20 @@ static inline int start(int argc, char **argv, bool registerParams=true) if (printParams) { bool printSeparator = false; if (printParams == 1 || !isatty(fileno(stdout))) { - Parameters::printValues(); + Parameters::printValues(); printSeparator = true; } else // always print the list of specified but unused parameters printSeparator = printSeparator || - Parameters::printUnused(); + Parameters::printUnused(); if (printSeparator) std::cout << endParametersSeparator; } else // always print the list of specified but unused parameters - if (Parameters::printUnused()) + if (Parameters::printUnused()) std::cout << endParametersSeparator; }