diff --git a/include/reduced_basis/rb_parameters.h b/include/reduced_basis/rb_parameters.h index 8048240c218..5410eeae0f2 100644 --- a/include/reduced_basis/rb_parameters.h +++ b/include/reduced_basis/rb_parameters.h @@ -198,14 +198,14 @@ class RBParameters * Get the value of the specified parameter at the specified step, * throwing an error if it does not exist. */ - Real get_step_value(const std::string & param_name, std::size_t index) const; + Real get_step_value(const std::string & param_name, std::size_t step) const; /** * Get the value of the specified parameter at the specified step, * returning the provided default value if either the parameter is * not defined or the step is invalid. */ - Real get_step_value(const std::string & param_name, std::size_t index, const Real & default_val) const; + Real get_step_value(const std::string & param_name, std::size_t step, const Real & default_val) const; /** * Set the value of the specified parameter. If param_name @@ -232,6 +232,11 @@ class RBParameters */ void push_back_value(const std::string & param_name, Real value); + /** + * Same as push_back_value(), but for "extra" parameters. + */ + void push_back_extra_value(const std::string & param_name, Real value); + /** * Get the value of the specified extra parameter, throwing an error * if it does not exist. @@ -244,6 +249,19 @@ class RBParameters */ Real get_extra_value(const std::string & param_name, const Real & default_val) const; + /** + * Get the value of the specified "extra" parameter at the specified step, + * throwing an error if it does not exist. + */ + Real get_extra_step_value(const std::string & param_name, std::size_t step) const; + + /** + * Get the value of the specified extra parameter at the specified step, + * returning the provided default value if either the parameter is + * not defined or the step is invalid. + */ + Real get_extra_step_value(const std::string & param_name, std::size_t step, const Real & default_val) const; + /** * Set the value of the specified extra parameter. If param_name * doesn't already exist, it is added to the extra parameters. diff --git a/src/reduced_basis/rb_parameters.C b/src/reduced_basis/rb_parameters.C index 1ee9f00bdee..23a1b1ade33 100644 --- a/src/reduced_basis/rb_parameters.C +++ b/src/reduced_basis/rb_parameters.C @@ -139,6 +139,13 @@ void RBParameters::push_back_value(const std::string & param_name, Real value) _parameters[param_name].push_back(value); } +void RBParameters::push_back_extra_value(const std::string & param_name, Real value) +{ + // Get reference to vector of values for this extra parameter, creating it + // if it does not already exist, and push back the specified value. + _extra_parameters[param_name].push_back(value); +} + Real RBParameters::get_extra_value(const std::string & param_name) const { // Same as get_value(param_name) but for the map of extra parameters @@ -154,6 +161,20 @@ Real RBParameters::get_extra_value(const std::string & param_name, const Real & return ((it != _extra_parameters.end() && it->second.size() != 0) ? it->second[0] : default_val); } +Real RBParameters::get_extra_step_value(const std::string & param_name, std::size_t step) const +{ + const auto & vec = libmesh_map_find(_extra_parameters, param_name); + libmesh_error_msg_if(step >= vec.size(), "Error getting value for parameter " << param_name); + return vec[step]; +} + +Real RBParameters::get_extra_step_value(const std::string & param_name, std::size_t step, const Real & default_val) const +{ + // same as get_step_value(param_name, index, default_val) but for the map of extra parameters + auto it = _extra_parameters.find(param_name); + return ((it != _extra_parameters.end() && step < it->second.size()) ? it->second[step] : default_val); +} + void RBParameters::set_extra_value(const std::string & param_name, Real value) { // Same as set_value(param_name, value) but for the map of extra parameters diff --git a/tests/utils/rb_parameters_test.C b/tests/utils/rb_parameters_test.C index 275185f9380..c57d624bc54 100644 --- a/tests/utils/rb_parameters_test.C +++ b/tests/utils/rb_parameters_test.C @@ -105,7 +105,10 @@ public: // (must have same number of steps) RBParameters params2; for (int i=0; i<3; ++i) - params2.push_back_value("b", Real(i+3)); + { + params2.push_back_value("b", Real(i+3)); + params2.push_back_extra_value("c", Real(i*i)); + } // Append second onto first params1 += params2; @@ -115,8 +118,12 @@ public: // Check that the desired appending happened CPPUNIT_ASSERT(params1.has_value("b")); + CPPUNIT_ASSERT(params1.has_extra_value("c")); for (int i=0; i<3; ++i) - CPPUNIT_ASSERT_EQUAL(params1.get_step_value("b", i), Real(i+3)); + { + CPPUNIT_ASSERT_EQUAL(params1.get_step_value("b", i), static_cast(i+3)); + CPPUNIT_ASSERT_EQUAL(params1.get_extra_step_value("c", i), static_cast(i*i)); + } } void testNSteps()