Skip to content

Commit 22174ac

Browse files
authored
Merge pull request #3576 from jwpeterson/get_extra_step_value
Add some missing RBParameters APIs for "extra" parameters
2 parents 7aa5322 + 8710a46 commit 22174ac

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

include/reduced_basis/rb_parameters.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ class RBParameters
198198
* Get the value of the specified parameter at the specified step,
199199
* throwing an error if it does not exist.
200200
*/
201-
Real get_step_value(const std::string & param_name, std::size_t index) const;
201+
Real get_step_value(const std::string & param_name, std::size_t step) const;
202202

203203
/**
204204
* Get the value of the specified parameter at the specified step,
205205
* returning the provided default value if either the parameter is
206206
* not defined or the step is invalid.
207207
*/
208-
Real get_step_value(const std::string & param_name, std::size_t index, const Real & default_val) const;
208+
Real get_step_value(const std::string & param_name, std::size_t step, const Real & default_val) const;
209209

210210
/**
211211
* Set the value of the specified parameter. If param_name
@@ -232,6 +232,11 @@ class RBParameters
232232
*/
233233
void push_back_value(const std::string & param_name, Real value);
234234

235+
/**
236+
* Same as push_back_value(), but for "extra" parameters.
237+
*/
238+
void push_back_extra_value(const std::string & param_name, Real value);
239+
235240
/**
236241
* Get the value of the specified extra parameter, throwing an error
237242
* if it does not exist.
@@ -244,6 +249,19 @@ class RBParameters
244249
*/
245250
Real get_extra_value(const std::string & param_name, const Real & default_val) const;
246251

252+
/**
253+
* Get the value of the specified "extra" parameter at the specified step,
254+
* throwing an error if it does not exist.
255+
*/
256+
Real get_extra_step_value(const std::string & param_name, std::size_t step) const;
257+
258+
/**
259+
* Get the value of the specified extra parameter at the specified step,
260+
* returning the provided default value if either the parameter is
261+
* not defined or the step is invalid.
262+
*/
263+
Real get_extra_step_value(const std::string & param_name, std::size_t step, const Real & default_val) const;
264+
247265
/**
248266
* Set the value of the specified extra parameter. If param_name
249267
* doesn't already exist, it is added to the extra parameters.

src/reduced_basis/rb_parameters.C

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ void RBParameters::push_back_value(const std::string & param_name, Real value)
139139
_parameters[param_name].push_back(value);
140140
}
141141

142+
void RBParameters::push_back_extra_value(const std::string & param_name, Real value)
143+
{
144+
// Get reference to vector of values for this extra parameter, creating it
145+
// if it does not already exist, and push back the specified value.
146+
_extra_parameters[param_name].push_back(value);
147+
}
148+
142149
Real RBParameters::get_extra_value(const std::string & param_name) const
143150
{
144151
// 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 &
154161
return ((it != _extra_parameters.end() && it->second.size() != 0) ? it->second[0] : default_val);
155162
}
156163

164+
Real RBParameters::get_extra_step_value(const std::string & param_name, std::size_t step) const
165+
{
166+
const auto & vec = libmesh_map_find(_extra_parameters, param_name);
167+
libmesh_error_msg_if(step >= vec.size(), "Error getting value for parameter " << param_name);
168+
return vec[step];
169+
}
170+
171+
Real RBParameters::get_extra_step_value(const std::string & param_name, std::size_t step, const Real & default_val) const
172+
{
173+
// same as get_step_value(param_name, index, default_val) but for the map of extra parameters
174+
auto it = _extra_parameters.find(param_name);
175+
return ((it != _extra_parameters.end() && step < it->second.size()) ? it->second[step] : default_val);
176+
}
177+
157178
void RBParameters::set_extra_value(const std::string & param_name, Real value)
158179
{
159180
// Same as set_value(param_name, value) but for the map of extra parameters

tests/utils/rb_parameters_test.C

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ public:
105105
// (must have same number of steps)
106106
RBParameters params2;
107107
for (int i=0; i<3; ++i)
108-
params2.push_back_value("b", Real(i+3));
108+
{
109+
params2.push_back_value("b", Real(i+3));
110+
params2.push_back_extra_value("c", Real(i*i));
111+
}
109112

110113
// Append second onto first
111114
params1 += params2;
@@ -115,8 +118,12 @@ public:
115118

116119
// Check that the desired appending happened
117120
CPPUNIT_ASSERT(params1.has_value("b"));
121+
CPPUNIT_ASSERT(params1.has_extra_value("c"));
118122
for (int i=0; i<3; ++i)
119-
CPPUNIT_ASSERT_EQUAL(params1.get_step_value("b", i), Real(i+3));
123+
{
124+
CPPUNIT_ASSERT_EQUAL(params1.get_step_value("b", i), static_cast<Real>(i+3));
125+
CPPUNIT_ASSERT_EQUAL(params1.get_extra_step_value("c", i), static_cast<Real>(i*i));
126+
}
120127
}
121128

122129
void testNSteps()

0 commit comments

Comments
 (0)