Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions include/reduced_basis/rb_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions src/reduced_basis/rb_parameters.C
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 9 additions & 2 deletions tests/utils/rb_parameters_test.C
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Real>(i+3));
CPPUNIT_ASSERT_EQUAL(params1.get_extra_step_value("c", i), static_cast<Real>(i*i));
}
}

void testNSteps()
Expand Down