libMesh
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
libMesh::RBParameters Class Reference

This class is part of the rbOOmit framework. More...

#include <rb_parameters.h>

Classes

class  const_iterator
 Define a constant iterator for iterating over the map of parameters. More...
 

Public Member Functions

 RBParameters ()
 Constructor.
 
 RBParameters (RBParameters &&)=default
 The special functions can be defaulted for this class, as it does not manage any memory itself.
 
 RBParameters (const RBParameters &)=default
 
RBParametersoperator= (const RBParameters &)=default
 
RBParametersoperator= (RBParameters &&)=default
 
 ~RBParameters ()=default
 
 RBParameters (const std::map< std::string, Real > &parameter_map)
 Constructor.
 
std::map< std::string, std::vector< RBParameter > >::const_iterator begin () const
 Return const_iterators to the internal parameter map, as a convenient way to access the parameter names and values.
 
std::map< std::string, std::vector< RBParameter > >::const_iterator end () const
 
std::map< std::string, std::vector< RBParameter > >::const_iterator extra_begin () const
 
std::map< std::string, std::vector< RBParameter > >::const_iterator extra_end () const
 
const_iterator begin_serialized () const
 Get const_iterator access to the parameters stored in this RBParameters object.
 
const_iterator end_serialized () const
 
const_iterator begin_serialized_extra () const
 Get const_iterator access to the extra parameters stored in this RBParameters object.
 
const_iterator end_serialized_extra () const
 
void clear ()
 Clear this object.
 
bool has_value (const std::string &param_name) const
 
bool has_extra_value (const std::string &param_name) const
 
Real get_value (const std::string &param_name) const
 Get the value of the specified parameter, throw an error if it does not exist.
 
const RBParameterget_vector_value (const std::string &param_name) const
 
Real get_value (const std::string &param_name, const Real &default_val) const
 Get the value of the specified parameter, returning the provided default value if it does not exist.
 
const RBParameterget_vector_value (const std::string &param_name, const RBParameter &default_val) const
 
Real get_sample_value (const std::string &param_name, std::size_t sample_idx) const
 Get the value of the specified parameter at the specified sample, throwing an error if it does not exist.
 
const RBParameterget_sample_vector_value (const std::string &param_name, std::size_t sample_idx) const
 
Real get_sample_value (const std::string &param_name, std::size_t sample_idx, const Real &default_val) const
 Get the value of the specified parameter at the specified sample, returning the provided default value if either the parameter is not defined or the sample is invalid.
 
const RBParameterget_sample_vector_value (const std::string &param_name, std::size_t sample_idx, const RBParameter &default_val) const
 
void set_value (const std::string &param_name, Real value)
 Set the value of the specified parameter.
 
void set_value (const std::string &param_name, const RBParameter &value)
 
void set_value (const std::string &param_name, std::size_t index, Real value)
 Set the value of the specified parameter at the specified sample index.
 
void set_value (const std::string &param_name, std::size_t index, const RBParameter &value)
 
void push_back_value (const std::string &param_name, Real value)
 Similar to set_value(name, index, value) but instead of specifying a particular index, just appends one more.
 
void push_back_value (const std::string &param_name, const RBParameter &value)
 
void push_back_extra_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, const RBParameter &value)
 
Real get_extra_value (const std::string &param_name) const
 Get the value of the specified extra parameter, throwing an error if it does not exist.
 
const RBParameterget_extra_vector_value (const std::string &param_name) const
 
Real get_extra_value (const std::string &param_name, const Real &default_val) const
 Get the value of the specified extra parameter, returning the provided default value if it does not exist.
 
const RBParameterget_extra_vector_value (const std::string &param_name, const RBParameter &default_val) const
 
Real get_extra_sample_value (const std::string &param_name, std::size_t sample_idx) const
 Get the value of the specified "extra" parameter at the specified sample index, throwing an error if it does not exist.
 
const RBParameterget_extra_sample_vector_value (const std::string &param_name, std::size_t sample_idx) const
 
Real get_extra_sample_value (const std::string &param_name, std::size_t sample_idx, const Real &default_val) const
 Get the value of the specified extra parameter at the specified sample index, returning the provided default value if either the parameter is not defined or the sample index is invalid.
 
const RBParameterget_extra_sample_vector_value (const std::string &param_name, std::size_t sample_idx, const RBParameter &default_val) const
 
void set_extra_value (const std::string &param_name, Real value)
 Set the value of the specified extra parameter.
 
void set_extra_value (const std::string &param_name, const RBParameter &value)
 
void set_extra_value (const std::string &param_name, std::size_t index, Real value)
 Set the value of the specified extra parameter at the specified sample index.
 
void set_extra_value (const std::string &param_name, std::size_t index, const RBParameter &value)
 
unsigned int n_parameters () const
 Get the number of parameters that have been added.
 
void set_n_samples (unsigned int n_samples)
 Set the number of samples this RBParameters object is intended to represent, in the case that there are no actual parameters stored on it.
 
unsigned int n_samples () const
 Returns the number of samples stored for all parameters.
 
std::set< std::string > get_parameter_names () const
 
std::set< std::string > get_extra_parameter_names () const
 
void erase_parameter (const std::string &param_name)
 Erase param_name from _parameters.
 
void erase_extra_parameter (const std::string &param_name)
 Erase param_name from _extra_parameters.
 
bool operator== (const RBParameters &rhs) const
 Two RBParameters are equal if they have the same _parameters map.
 
bool operator!= (const RBParameters &rhs) const
 
RBParametersoperator+= (const RBParameters &rhs)
 Append "rhs" to "*this".
 
std::string get_string (unsigned precision=6, int max_values=5) const
 Get a string that specifies the contents of this RBParameters object.
 
void print (unsigned precision=6, int max_values=5) const
 Print the parameters.
 

Private Member Functions

void set_value_helper (std::map< std::string, std::vector< RBParameter > > &map, const std::string &param_name, const std::size_t index, RBParameter value)
 Helper function for the 3-parameter versions of set_value() and set_extra_value().
 

Private Attributes

unsigned int _n_samples
 The number of samples represented by this RBParameters object, in the case where there are no parameters actually stored on it.
 
std::map< std::string, std::vector< RBParameter > > _parameters
 Actual parameter values (in std::vector<RBParameter> form) across a vector of samples.
 
std::map< std::string, std::vector< RBParameter > > _extra_parameters
 Extra parameter vectors not used for RB training.
 

Detailed Description

This class is part of the rbOOmit framework.

This class defines a set of parameters indexed by strings. Multiple samples can be defined, where a sample is a set of values for each parameter. The parameters themselves can be multi-valued, e.g. for storing a matrix-type parameter.

Author
David J. Knezevic
Date
2012

Definition at line 52 of file rb_parameters.h.

Constructor & Destructor Documentation

◆ RBParameters() [1/4]

libMesh::RBParameters::RBParameters ( )

Constructor.

Initializes the _n_samples parameter to 1 for backwards compatibility, but the set_n_samples() function can always be called later to update this value.

Definition at line 33 of file rb_parameters.C.

33 :
34 _n_samples(1)
35{
36}
unsigned int _n_samples
The number of samples represented by this RBParameters object, in the case where there are no paramet...

◆ RBParameters() [2/4]

libMesh::RBParameters::RBParameters ( RBParameters &&  )
default

The special functions can be defaulted for this class, as it does not manage any memory itself.

◆ RBParameters() [3/4]

libMesh::RBParameters::RBParameters ( const RBParameters )
default

◆ ~RBParameters()

libMesh::RBParameters::~RBParameters ( )
default

◆ RBParameters() [4/4]

libMesh::RBParameters::RBParameters ( const std::map< std::string, Real > &  parameter_map)

Constructor.

Set parameters based on the std::map parameter_map.

It sets the values as the 0th entry of the sample-vector corresponding to each parameter name.

Definition at line 38 of file rb_parameters.C.

38 :
39 _n_samples(1)
40{
41 // Backwards compatible support for constructing an RBParameters
42 // object from a map<string, Real>. We store a single entry in each
43 // vector in the map.
44 for (const auto & [key, val] : parameter_map)
45 _parameters[key] = {{val}};
46}
std::map< std::string, std::vector< RBParameter > > _parameters
Actual parameter values (in std::vector<RBParameter> form) across a vector of samples.

References _parameters.

Member Function Documentation

◆ begin()

std::map< std::string, std::vector< RBParameter > >::const_iterator libMesh::RBParameters::begin ( ) const

Return const_iterators to the internal parameter map, as a convenient way to access the parameter names and values.

For example: for (const auto & [param_name, sample_vec] : my_parameters)

Definition at line 366 of file rb_parameters.C.

367{
368 return _parameters.cbegin();
369}

References _parameters.

◆ begin_serialized()

RBParameters::const_iterator libMesh::RBParameters::begin_serialized ( ) const

Get const_iterator access to the parameters stored in this RBParameters object.

This gives serialized access to all the individual Real values in the nested vector<vector<Real>>. Use this in a for loop with the following syntax, for example: for (const auto &[key,val] : as_range(rb_parameters.begin_serialized(), rb_parameters.end_serialized())

Definition at line 386 of file rb_parameters.C.

387{
388 return {_parameters.cbegin(), 0, 0};
389}

References _parameters.

Referenced by libMesh::RBParametrized::initialize_parameters(), RBParametersTest::testIterators(), and RBParametersTest::testIteratorsWithSamples().

◆ begin_serialized_extra()

RBParameters::const_iterator libMesh::RBParameters::begin_serialized_extra ( ) const

Get const_iterator access to the extra parameters stored in this RBParameters object.

This gives serialized access to all the individual Real values in the nested vector<vector<Real>>. Use this in a for loop with the following syntax, for example: for (const auto &[key,val] : as_range(rb_parameters.begin_serialized_extra(), rb_parameters.end_serialized_extra())

Definition at line 398 of file rb_parameters.C.

399{
400 return {_extra_parameters.cbegin(), 0, 0};
401}
std::map< std::string, std::vector< RBParameter > > _extra_parameters
Extra parameter vectors not used for RB training.

References _extra_parameters.

◆ clear()

void libMesh::RBParameters::clear ( )

Clear this object.

Definition at line 48 of file rb_parameters.C.

49{
50 _n_samples = 1;
51 _parameters.clear();
52 _extra_parameters.clear();
53}

References _extra_parameters, _n_samples, and _parameters.

Referenced by libMesh::RBParametrized::clear().

◆ end()

std::map< std::string, std::vector< RBParameter > >::const_iterator libMesh::RBParameters::end ( ) const

Definition at line 371 of file rb_parameters.C.

372{
373 return _parameters.cend();
374}

References _parameters.

◆ end_serialized()

RBParameters::const_iterator libMesh::RBParameters::end_serialized ( ) const

Definition at line 391 of file rb_parameters.C.

392{
393 // Note: the index 0 is irrelevant here since _parameters.end() does
394 // not refer to a valid vector entry in the map.
395 return {_parameters.cend(), 0, 0};
396}

References _parameters.

Referenced by libMesh::RBParametrized::initialize_parameters(), RBParametersTest::testIterators(), and RBParametersTest::testIteratorsWithSamples().

◆ end_serialized_extra()

RBParameters::const_iterator libMesh::RBParameters::end_serialized_extra ( ) const

Definition at line 403 of file rb_parameters.C.

404{
405 // Note: the index 0 is irrelevant here since _parameters.end() does
406 // not refer to a valid vector entry in the map.
407 return {_extra_parameters.cend(), 0, 0};
408}

References _extra_parameters.

◆ erase_extra_parameter()

void libMesh::RBParameters::erase_extra_parameter ( const std::string &  param_name)

Erase param_name from _extra_parameters.

If param_name is not present in _extra_parameters, then do nothing.

Definition at line 361 of file rb_parameters.C.

362{
363 _extra_parameters.erase(param_name);
364}

References _extra_parameters.

◆ erase_parameter()

void libMesh::RBParameters::erase_parameter ( const std::string &  param_name)

Erase param_name from _parameters.

If param_name is not present in _parameters, then do nothing.

Definition at line 356 of file rb_parameters.C.

357{
358 _parameters.erase(param_name);
359}

References _parameters.

◆ extra_begin()

std::map< std::string, std::vector< RBParameter > >::const_iterator libMesh::RBParameters::extra_begin ( ) const

Definition at line 376 of file rb_parameters.C.

377{
378 return _extra_parameters.cbegin();
379}

References _extra_parameters.

◆ extra_end()

std::map< std::string, std::vector< RBParameter > >::const_iterator libMesh::RBParameters::extra_end ( ) const

Definition at line 381 of file rb_parameters.C.

382{
383 return _extra_parameters.cend();
384}

References _extra_parameters.

◆ get_extra_parameter_names()

std::set< std::string > libMesh::RBParameters::get_extra_parameter_names ( ) const
Returns
a set with the names of the extra parameters.

Note that instead of creating a new set of strings here, it's better to iterate over the RBParameters extra object directly, using the iterators from the extra_begin()/extra_end() functions. The .first will provide the parameter name, .second can be ignored as needed.

Definition at line 348 of file rb_parameters.C.

349{
350 std::set<std::string> param_names;
351 for (const auto & pr : _extra_parameters)
352 param_names.insert(pr.first);
353 return param_names;
354}

References _extra_parameters.

◆ get_extra_sample_value() [1/2]

Real libMesh::RBParameters::get_extra_sample_value ( const std::string &  param_name,
std::size_t  sample_idx 
) const

Get the value of the specified "extra" parameter at the specified sample index, throwing an error if it does not exist.

Definition at line 256 of file rb_parameters.C.

257{
258 const auto & sample_vec = libmesh_map_find(_extra_parameters, param_name);
259 libmesh_error_msg_if(sample_idx >= sample_vec.size(), "Error getting value for extra parameter " << param_name);
260 libmesh_error_msg_if(sample_vec[sample_idx].size() != 1,
261 "Requesting Real value for extra parameter " << param_name << ", but parameter contains multiple values.");
262 return sample_vec[sample_idx][0];
263}

References _extra_parameters.

Referenced by RBParametersTest::testAppend().

◆ get_extra_sample_value() [2/2]

Real libMesh::RBParameters::get_extra_sample_value ( const std::string &  param_name,
std::size_t  sample_idx,
const Real default_val 
) const

Get the value of the specified extra parameter at the specified sample index, returning the provided default value if either the parameter is not defined or the sample index is invalid.

Definition at line 272 of file rb_parameters.C.

273{
274 // same as get_sample_value(param_name, index, default_val) but for the map of extra parameters
275 auto it = _extra_parameters.find(param_name);
276 if (it==_extra_parameters.end() || sample_idx >= it->second.size())
277 return default_val;
278 libmesh_error_msg_if(it->second[sample_idx].size() != 1,
279 "Requesting Real value for extra parameter " << param_name << ", but parameter contains multiple values.");
280 return it->second[sample_idx][0];
281}

References _extra_parameters.

◆ get_extra_sample_vector_value() [1/2]

const RBParameter & libMesh::RBParameters::get_extra_sample_vector_value ( const std::string &  param_name,
std::size_t  sample_idx 
) const

Definition at line 265 of file rb_parameters.C.

266{
267 const auto & sample_vec = libmesh_map_find(_extra_parameters, param_name);
268 libmesh_error_msg_if(sample_idx >= sample_vec.size(), "Error getting value for extra parameter " << param_name);
269 return sample_vec[sample_idx];
270}

References _extra_parameters.

◆ get_extra_sample_vector_value() [2/2]

const RBParameter & libMesh::RBParameters::get_extra_sample_vector_value ( const std::string &  param_name,
std::size_t  sample_idx,
const RBParameter default_val 
) const

Definition at line 283 of file rb_parameters.C.

287{
288 auto it = _extra_parameters.find(param_name);
289 if (it == _extra_parameters.end() || sample_idx >= it->second.size())
290 return default_val;
291 return it->second[sample_idx];
292}

References _extra_parameters.

◆ get_extra_value() [1/2]

Real libMesh::RBParameters::get_extra_value ( const std::string &  param_name) const

Get the value of the specified extra parameter, throwing an error if it does not exist.

Definition at line 223 of file rb_parameters.C.

224{
225 // Same as get_value(param_name) but for the map of extra parameters
226 const auto & sample_vec = libmesh_map_find(_extra_parameters, param_name);
227 libmesh_error_msg_if(sample_vec.size() != 1,
228 "Requesting value for extra parameter " << param_name << ", but parameter contains multiple samples.");
229 libmesh_error_msg_if(sample_vec[0].size() != 1,
230 "Requesting Real value for extra parameter " << param_name << ", but parameter contains multiple values.");
231 return sample_vec[0][0];
232}

References _extra_parameters.

◆ get_extra_value() [2/2]

Real libMesh::RBParameters::get_extra_value ( const std::string &  param_name,
const Real default_val 
) const

Get the value of the specified extra parameter, returning the provided default value if it does not exist.

Definition at line 242 of file rb_parameters.C.

243{
244 // same as get_value(param_name, default_val) but for the map of extra parameters
245 auto it = _extra_parameters.find(param_name);
246 if (it == _extra_parameters.end())
247 return default_val;
248
249 libmesh_error_msg_if(it->second.size() != 1,
250 "Requesting value for extra parameter " << param_name << ", but parameter contains multiple samples.");
251 libmesh_error_msg_if(it->second[0].size() != 1,
252 "Requesting Real value for extra parameter " << param_name << ", but parameter contains multiple values.");
253 return it->second[0][0];
254}

References _extra_parameters.

◆ get_extra_vector_value() [1/2]

const RBParameter & libMesh::RBParameters::get_extra_vector_value ( const std::string &  param_name) const

Definition at line 234 of file rb_parameters.C.

235{
236 // Same as get_value(param_name) but for the map of extra parameters
237 const auto & sample_vec = libmesh_map_find(_extra_parameters, param_name);
238 libmesh_error_msg_if(sample_vec.size() == 0, "Error getting value for extra parameter " << param_name);
239 return sample_vec[0];
240}

References _extra_parameters.

◆ get_extra_vector_value() [2/2]

const RBParameter & libMesh::RBParameters::get_extra_vector_value ( const std::string &  param_name,
const RBParameter default_val 
) const

◆ get_parameter_names()

std::set< std::string > libMesh::RBParameters::get_parameter_names ( ) const
Returns
a set with the names of the parameters.

Note that instead of creating a new set of strings here, it's better to iterate over the RBParameters object directly, using the iterators from the begin()/end() functions. The .first will provide the parameter name, .second can be ignored as needed.

Definition at line 340 of file rb_parameters.C.

341{
342 std::set<std::string> param_names;
343 for (const auto & pr : _parameters)
344 param_names.insert(pr.first);
345 return param_names;
346}

References _parameters.

◆ get_sample_value() [1/2]

Real libMesh::RBParameters::get_sample_value ( const std::string &  param_name,
std::size_t  sample_idx 
) const

Get the value of the specified parameter at the specified sample, throwing an error if it does not exist.

The Real-returning version throws an error if the parameter exists but contains multiple values.

Definition at line 97 of file rb_parameters.C.

98{
99 const auto & sample_vec = libmesh_map_find(_parameters, param_name);
100 libmesh_error_msg_if(sample_idx >= sample_vec.size(), "Error getting value for parameter " << param_name);
101 libmesh_error_msg_if(sample_vec[sample_idx].size() != 1,
102 "Requesting Real value for parameter " << param_name << ", but parameter contains multiple values.");
103 return sample_vec[sample_idx][0];
104}

References _parameters.

Referenced by libMesh::RBParametrized::check_if_valid_params(), ShiftedGaussian::evaluate(), get_value(), get_value(), RBParametersTest::testAppend(), RBParametersTest::testMultiValued(), and RBParametersTest::testNSamples().

◆ get_sample_value() [2/2]

Real libMesh::RBParameters::get_sample_value ( const std::string &  param_name,
std::size_t  sample_idx,
const Real default_val 
) const

Get the value of the specified parameter at the specified sample, returning the provided default value if either the parameter is not defined or the sample is invalid.

The Real-returning version throws an error if the parameter exists but contains multiple values.

Definition at line 113 of file rb_parameters.C.

114{
115 auto it = _parameters.find(param_name);
116 if (it == _parameters.end() || sample_idx >= it->second.size())
117 return default_val;
118 libmesh_error_msg_if(it->second[sample_idx].size() != 1,
119 "Requesting Real value for parameter " << param_name << ", but parameter contains multiple values.");
120 return it->second[sample_idx][0];
121}

References _parameters.

◆ get_sample_vector_value() [1/2]

const RBParameter & libMesh::RBParameters::get_sample_vector_value ( const std::string &  param_name,
std::size_t  sample_idx 
) const

Definition at line 106 of file rb_parameters.C.

107{
108 const auto & sample_vec = libmesh_map_find(_parameters, param_name);
109 libmesh_error_msg_if(sample_idx >= sample_vec.size(), "Error getting value for parameter " << param_name);
110 return sample_vec[sample_idx];
111}

References _parameters.

Referenced by get_vector_value(), get_vector_value(), and RBParametersTest::testMultiValued().

◆ get_sample_vector_value() [2/2]

const RBParameter & libMesh::RBParameters::get_sample_vector_value ( const std::string &  param_name,
std::size_t  sample_idx,
const RBParameter default_val 
) const

Definition at line 123 of file rb_parameters.C.

124{
125 auto it = _parameters.find(param_name);
126 if (it == _parameters.end() || sample_idx >= it->second.size())
127 return default_val;
128 return it->second[sample_idx];
129}

References _parameters.

◆ get_string()

std::string libMesh::RBParameters::get_string ( unsigned  precision = 6,
int  max_values = 5 
) const

Get a string that specifies the contents of this RBParameters object.

precision specifies the number of digits of precision we use in scientific notation in the string. max_values is the max number of values to print out if the parameter is vector-valued. Set to negative value to print all.

Definition at line 435 of file rb_parameters.C.

436{
437 std::stringstream param_stringstream;
438 param_stringstream << std::setprecision(static_cast<int>(precision)) << std::scientific;
439
440 for (const auto & [param_name, sample_vec] : _parameters)
441 {
442 // Write the param name, followed by a comma-separated list of the sample/vector values.
443 param_stringstream << param_name << ": ";
444 std::string separator = "";
445 for (const auto & value_vec : sample_vec)
446 {
447 param_stringstream << separator;
448 if (value_vec.size() == 1)
449 param_stringstream << value_vec[0];
450 else
451 {
452 param_stringstream << "[ ";
453 for (const auto val_idx : index_range(value_vec))
454 {
455 if (max_values < 0 || val_idx < static_cast<unsigned>(max_values))
456 param_stringstream << value_vec[val_idx] << " ";
457 else
458 {
459 param_stringstream << "... ";
460 break;
461 }
462 }
463 param_stringstream << "]";
464 }
465 separator = ", ";
466 }
467 param_stringstream << std::endl;
468 }
469
470 return param_stringstream.str();
471}
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153

References _parameters, and libMesh::index_range().

Referenced by print().

◆ get_value() [1/2]

Real libMesh::RBParameters::get_value ( const std::string &  param_name) const

Get the value of the specified parameter, throw an error if it does not exist.

Here we assume that there is only one sample, throw an error otherwise. The Real-returning version also throws an error if the parameter exists but contains multiple values.

Definition at line 65 of file rb_parameters.C.

66{
67 // Simply return the [0]th entry of the vector if possible, otherwise error.
68 libmesh_error_msg_if(this->n_samples() != 1,
69 "Requesting value for parameter " << param_name << ", but parameter contains multiple samples.");
70 return this->get_sample_value(param_name, /*sample_idx=*/0);
71}
Real get_sample_value(const std::string &param_name, std::size_t sample_idx) const
Get the value of the specified parameter at the specified sample, throwing an error if it does not ex...
unsigned int n_samples() const
Returns the number of samples stored for all parameters.

References get_sample_value(), and n_samples().

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), libMesh::RBSCMConstruction::enrich_C_J(), ThetaA1::evaluate(), ThetaA2::evaluate(), ThetaA0::evaluate(), ThetaF0::evaluate(), ThetaF1::evaluate(), ThetaF2::evaluate(), ThetaPointLoadX::evaluate(), ThetaPointLoadY::evaluate(), ThetaPointLoadZ::evaluate(), ThetaEIM::evaluate(), ThetaA3::evaluate(), Gxyz::evaluate(), libMesh::RBConstructionBase< Base >::generate_training_parameters_deterministic(), libMesh::RBConstructionBase< Base >::generate_training_parameters_random(), libMesh::RBParametrized::get_parameter_max(), libMesh::RBParametrized::get_parameter_min(), scale_mesh_and_plot(), RBParametersTest::testMultiValued(), RBParametersTest::testNSamples(), RBParametersTest::testOldConstructor(), RBParametersTest::testScalar(), and libMesh::RBParametrized::write_parameter_ranges_to_file().

◆ get_value() [2/2]

Real libMesh::RBParameters::get_value ( const std::string &  param_name,
const Real default_val 
) const

Get the value of the specified parameter, returning the provided default value if it does not exist.

If the value does exist, we assume that there is only one sample, and throw an error otherwise. The Real-returning version also throws an error if the parameter exists but contains multiple values.

Definition at line 81 of file rb_parameters.C.

82{
83 // Simply return the [0]th entry of the vector if possible, otherwise error.
84 libmesh_error_msg_if(this->n_samples() != 1,
85 "Requesting value for parameter " << param_name << ", but parameter contains multiple samples.");
86 return this->get_sample_value(param_name, /*sample_idx=*/0, default_val);
87}

References get_sample_value(), and n_samples().

◆ get_vector_value() [1/2]

const RBParameter & libMesh::RBParameters::get_vector_value ( const std::string &  param_name) const

Definition at line 73 of file rb_parameters.C.

74{
75 // Simply return the [0]th entry of the vector if possible, otherwise error.
76 libmesh_error_msg_if(this->n_samples() != 1,
77 "Requesting value for parameter " << param_name << ", but parameter contains multiple sample.");
78 return this->get_sample_vector_value(param_name, /*sample_idx=*/0);
79}
const RBParameter & get_sample_vector_value(const std::string &param_name, std::size_t sample_idx) const

References get_sample_vector_value(), and n_samples().

◆ get_vector_value() [2/2]

const RBParameter & libMesh::RBParameters::get_vector_value ( const std::string &  param_name,
const RBParameter default_val 
) const

Definition at line 89 of file rb_parameters.C.

90{
91 // Simply return the [0]th entry of the vector if possible, otherwise error.
92 libmesh_error_msg_if(this->n_samples() != 1,
93 "Requesting value for parameter " << param_name << ", but parameter contains multiple samples.");
94 return this->get_sample_vector_value(param_name, /*sample_idx=*/0, default_val);
95}

References get_sample_vector_value(), and n_samples().

◆ has_extra_value()

bool libMesh::RBParameters::has_extra_value ( const std::string &  param_name) const
Returns
true if there is an extra parameter named "param_name" present in this class, false otherwise.

Definition at line 60 of file rb_parameters.C.

61{
62 return _extra_parameters.count(param_name);
63}

References _extra_parameters.

Referenced by RBParametersTest::testAppend().

◆ has_value()

bool libMesh::RBParameters::has_value ( const std::string &  param_name) const
Returns
true if there is a parameter named "param_name" present in this class, false otherwise.

Definition at line 55 of file rb_parameters.C.

56{
57 return _parameters.count(param_name);
58}

References _parameters.

Referenced by RBParametersTest::testAppend(), RBParametersTest::testOldConstructor(), and RBParametersTest::testScalar().

◆ n_parameters()

unsigned int libMesh::RBParameters::n_parameters ( ) const

◆ n_samples()

unsigned int libMesh::RBParameters::n_samples ( ) const

Returns the number of samples stored for all parameters.

For simplicity, we require all parameters to store the same number of "samples" ("sample" here may refer to, e.g., time step or load step) and in debug mode we actually verify that is the case.

Definition at line 320 of file rb_parameters.C.

321{
322 // Quick return if there are no parameters
323 if (_parameters.empty())
324 return _n_samples;
325
326 // If _parameters is not empty, we can check the number of samples in the first param
327 auto size_first = _parameters.begin()->second.size();
328
329#ifdef DEBUG
330 // In debug mode, verify that all parameters have the same number of samples
331 for (const auto & pr : _parameters)
332 libmesh_assert_msg(pr.second.size() == size_first, "All parameters must have the same number of samples.");
333#endif
334
335 // If we made it here in DEBUG mode, then all parameters were
336 // verified to have the same number of samples.
337 return size_first;
338}

References _n_samples, and _parameters.

Referenced by libMesh::RBConstructionBase< Base >::broadcast_parameters(), libMesh::RBTheta::evaluate(), ThetaConstant::evaluate(), ShiftedGaussian::evaluate(), get_value(), get_value(), get_vector_value(), get_vector_value(), libMesh::RBParametrized::initialize_parameters(), main(), operator+=(), set_n_samples(), RBParametersTest::testNSamples(), and RBParametersTest::testOldConstructor().

◆ operator!=()

bool libMesh::RBParameters::operator!= ( const RBParameters rhs) const
Returns
!(*this == rhs).

Definition at line 416 of file rb_parameters.C.

417{
418 return !(*this == rhs);
419}

◆ operator+=()

RBParameters & libMesh::RBParameters::operator+= ( const RBParameters rhs)

Append "rhs" to "*this".

Both RBParameters objects must have the same n_samples(), otherwise an error is thrown. If some of the parameter names overlap, then the values from rhs overwrite *this. Both parameters and "extra" parameters are appended.

Definition at line 421 of file rb_parameters.C.

422{
423 libmesh_error_msg_if(this->n_samples() != rhs.n_samples(),
424 "Can only append RBParameters objects with matching numbers of samples.");
425
426 // Overwrite or add each (key, vec) pair in rhs to *this.
427 for (const auto & [key, vec] : rhs._parameters)
428 _parameters[key] = vec;
429 for (const auto & [key, vec] : rhs._extra_parameters)
430 _extra_parameters[key] = vec;
431
432 return *this;
433}

References _extra_parameters, _parameters, and n_samples().

◆ operator=() [1/2]

RBParameters & libMesh::RBParameters::operator= ( const RBParameters )
default

◆ operator=() [2/2]

RBParameters & libMesh::RBParameters::operator= ( RBParameters &&  )
default

◆ operator==()

bool libMesh::RBParameters::operator== ( const RBParameters rhs) const

Two RBParameters are equal if they have the same _parameters map.

Definition at line 410 of file rb_parameters.C.

411{
412 return (this->_parameters == rhs._parameters &&
413 this->_extra_parameters == rhs._extra_parameters);
414}

References _extra_parameters, and _parameters.

◆ print()

void libMesh::RBParameters::print ( unsigned  precision = 6,
int  max_values = 5 
) const

Print the parameters.

Definition at line 473 of file rb_parameters.C.

474{
475 libMesh::out << get_string(precision, max_values);
476}
std::string get_string(unsigned precision=6, int max_values=5) const
Get a string that specifies the contents of this RBParameters object.
OStreamProxy out

References get_string(), and libMesh::out.

Referenced by libMesh::RBParametrized::print_parameters().

◆ push_back_extra_value() [1/2]

void libMesh::RBParameters::push_back_extra_value ( const std::string &  param_name,
const RBParameter value 
)

Definition at line 216 of file rb_parameters.C.

217{
218 // Get reference to vector of values for this extra parameter, creating it
219 // if it does not already exist, and push back the specified value.
220 _extra_parameters[param_name].push_back(value);
221}
static const bool value
Definition xdr_io.C:55

References _extra_parameters, and value.

◆ push_back_extra_value() [2/2]

void libMesh::RBParameters::push_back_extra_value ( const std::string &  param_name,
Real  value 
)

Same as push_back_value(), but for "extra" parameters.

Definition at line 209 of file rb_parameters.C.

210{
211 // Get reference to vector of values for this extra parameter, creating it
212 // if it does not already exist, and push back the specified value.
213 _extra_parameters[param_name].push_back({value});
214}

References _extra_parameters, and value.

Referenced by RBParametersTest::testAppend().

◆ push_back_value() [1/2]

void libMesh::RBParameters::push_back_value ( const std::string &  param_name,
const RBParameter value 
)

Definition at line 202 of file rb_parameters.C.

203{
204 // Get reference to vector of values for this parameter, creating it
205 // if it does not already exist, and push back the specified value.
206 _parameters[param_name].push_back(value);
207}

References _parameters, and value.

◆ push_back_value() [2/2]

void libMesh::RBParameters::push_back_value ( const std::string &  param_name,
Real  value 
)

Similar to set_value(name, index, value) but instead of specifying a particular index, just appends one more.

Calling push_back_value() many times is more efficient than calling set_value(name, index, value) many times because it takes advantage of the std::vector's size-doubling t reduce allocations.

Definition at line 195 of file rb_parameters.C.

196{
197 // Get reference to vector of values for this parameter, creating it
198 // if it does not already exist, and push back the specified value.
199 _parameters[param_name].push_back({value});
200}

References _parameters, and value.

Referenced by main(), RBParametersTest::testAppend(), RBParametersTest::testMultiValued(), and RBParametersTest::testNSamples().

◆ set_extra_value() [1/4]

void libMesh::RBParameters::set_extra_value ( const std::string &  param_name,
const RBParameter value 
)

Definition at line 302 of file rb_parameters.C.

303{
304 // This version of set_extra_value() does not take an index and is provided
305 // for backwards compatibility. It creates a vector entry for the specified
306 // param_name, overwriting any value(s) that were present.
307 _extra_parameters[param_name] = {value};
308}

References _extra_parameters, and value.

◆ set_extra_value() [2/4]

void libMesh::RBParameters::set_extra_value ( const std::string &  param_name,
Real  value 
)

Set the value of the specified extra parameter.

If param_name doesn't already exist, it is added to the extra parameters.

Definition at line 294 of file rb_parameters.C.

295{
296 // This version of set_extra_value() does not take an index and is provided
297 // for backwards compatibility. It creates a vector entry for the specified
298 // param_name, overwriting any value(s) that were present.
299 _extra_parameters[param_name] = {{value}};
300}

References _extra_parameters, and value.

◆ set_extra_value() [3/4]

void libMesh::RBParameters::set_extra_value ( const std::string &  param_name,
std::size_t  index,
const RBParameter value 
)

Definition at line 190 of file rb_parameters.C.

191{
192 this->set_value_helper(_extra_parameters, param_name, index, value);
193}
void set_value_helper(std::map< std::string, std::vector< RBParameter > > &map, const std::string &param_name, const std::size_t index, RBParameter value)
Helper function for the 3-parameter versions of set_value() and set_extra_value().

References _extra_parameters, set_value_helper(), and value.

◆ set_extra_value() [4/4]

void libMesh::RBParameters::set_extra_value ( const std::string &  param_name,
std::size_t  index,
Real  value 
)

Set the value of the specified extra parameter at the specified sample index.

The sample index can refer to, e.g., load or time steps.

Definition at line 185 of file rb_parameters.C.

186{
187 this->set_value_helper(_extra_parameters, param_name, index, {value});
188}

References _extra_parameters, set_value_helper(), and value.

◆ set_n_samples()

void libMesh::RBParameters::set_n_samples ( unsigned int  n_samples)

Set the number of samples this RBParameters object is intended to represent, in the case that there are no actual parameters stored on it.

Note: this value will only be used in the no-parameters case; if there are actual parameters specified in this class, the number set via this API is ignored. All parameters stored within the RBParameters object must have n_samples() samples.

Definition at line 315 of file rb_parameters.C.

316{
318}

References _n_samples, and n_samples().

Referenced by RBParametersTest::testNSamples().

◆ set_value() [1/4]

void libMesh::RBParameters::set_value ( const std::string &  param_name,
const RBParameter value 
)

Definition at line 139 of file rb_parameters.C.

140{
141 // This version of set_value() does not take an index and is provided
142 // for backwards compatibility. It creates a vector entry for the specified
143 // param_name, overwriting any value(s) that were present.
144 _parameters[param_name] = {value};
145}

References _parameters, and value.

◆ set_value() [2/4]

void libMesh::RBParameters::set_value ( const std::string &  param_name,
Real  value 
)

Set the value of the specified parameter.

If param_name doesn't already exist, it is added to the RBParameters object. For backwards compatibility, calling this function sets up "param_name" to be a single-entry vector with "value" as the only entry.

Definition at line 131 of file rb_parameters.C.

132{
133 // This version of set_value() does not take an index and is provided
134 // for backwards compatibility. It creates a vector entry for the specified
135 // param_name, overwriting any value(s) that were present.
136 _parameters[param_name] = {{value}};
137}

References _parameters, and value.

Referenced by libMesh::RBConstructionBase< Base >::broadcast_parameters(), libMesh::RBParametrized::initialize_parameters(), libMesh::RBDataDeserialization::load_parameter_ranges(), main(), libMesh::RBConstruction::process_parameters_file(), libMesh::RBEIMConstruction::process_parameters_file(), libMesh::RBSCMConstruction::process_parameters_file(), libMesh::RBParametrized::read_parameter_ranges_from_file(), RBParametersTest::testIterators(), RBParametersTest::testIteratorsWithSamples(), RBParametersTest::testMultiValued(), RBParametersTest::testNSamples(), RBParametersTest::testRBParametrized(), and RBParametersTest::testScalar().

◆ set_value() [3/4]

void libMesh::RBParameters::set_value ( const std::string &  param_name,
std::size_t  index,
const RBParameter value 
)

Definition at line 180 of file rb_parameters.C.

181{
182 this->set_value_helper(_parameters, param_name, index, value);
183}

References _parameters, set_value_helper(), and value.

◆ set_value() [4/4]

void libMesh::RBParameters::set_value ( const std::string &  param_name,
std::size_t  index,
Real  value 
)

Set the value of the specified parameter at the specified sample index.

The sample index can refer to, e.g., load or time steps.

Definition at line 175 of file rb_parameters.C.

176{
177 this->set_value_helper(_parameters, param_name, index, {value});
178}

References _parameters, set_value_helper(), and value.

◆ set_value_helper()

void libMesh::RBParameters::set_value_helper ( std::map< std::string, std::vector< RBParameter > > &  map,
const std::string &  param_name,
const std::size_t  index,
RBParameter  value 
)
private

Helper function for the 3-parameter versions of set_value() and set_extra_value().

Definition at line 148 of file rb_parameters.C.

152{
153 // Get reference to vector of values for this parameter, creating it
154 // if it does not already exist.
155 auto & sample_vec = map[param_name];
156
157 // If vec is already big enough, just set the value
158 if (sample_vec.size() > index)
159 sample_vec[index] = std::move(value);
160
161 // Otherwise push_back() if the vec is just barely not big enough
162 else if (sample_vec.size() == index)
163 sample_vec.emplace_back(std::move(value));
164
165 // Otherwise, allocate more space (padding with 0s) if vector is not
166 // big enough to fit the user's requested index.
167 else
168 {
169 RBParameter zero_parameter(value.size(), 0.0);
170 sample_vec.resize(index+1, zero_parameter);
171 sample_vec[index] = std::move(value);
172 }
173}
std::vector< Real > RBParameter
Typedef for an individual RB parameter.

References value.

Referenced by set_extra_value(), set_extra_value(), set_value(), and set_value().

Member Data Documentation

◆ _extra_parameters

std::map<std::string, std::vector<RBParameter> > libMesh::RBParameters::_extra_parameters
private

◆ _n_samples

unsigned int libMesh::RBParameters::_n_samples
private

The number of samples represented by this RBParameters object, in the case where there are no parameters actually stored on it.

If there are parameters stored on this RBParameters object, then the n_samples() API returns that number of samples instead.

Definition at line 453 of file rb_parameters.h.

Referenced by clear(), n_samples(), and set_n_samples().

◆ _parameters

std::map<std::string, std::vector<RBParameter> > libMesh::RBParameters::_parameters
private

Actual parameter values (in std::vector<RBParameter> form) across a vector of samples.

Each vector is indexed by a name. Note that the number of samples in the outer vector should be the same across all parameters, however, this is not necessary for the inner "value-vector".

Definition at line 462 of file rb_parameters.h.

Referenced by begin(), begin_serialized(), clear(), end(), end_serialized(), erase_parameter(), get_parameter_names(), get_sample_value(), get_sample_value(), get_sample_vector_value(), get_sample_vector_value(), get_string(), has_value(), n_parameters(), n_samples(), operator+=(), operator==(), push_back_value(), push_back_value(), RBParameters(), set_value(), set_value(), set_value(), and set_value().


The documentation for this class was generated from the following files: