21 #include "libmesh/int_range.h" 22 #include "libmesh/libmesh_common.h" 23 #include "libmesh/rb_parameters.h" 24 #include "libmesh/utility.h" 44 for (
const auto & [key, val] : parameter_map)
68 libmesh_error_msg_if(this->
n_samples() != 1,
69 "Requesting value for parameter " << param_name <<
", but parameter contains multiple samples.");
76 libmesh_error_msg_if(this->
n_samples() != 1,
77 "Requesting value for parameter " << param_name <<
", but parameter contains multiple sample.");
84 libmesh_error_msg_if(this->
n_samples() != 1,
85 "Requesting value for parameter " << param_name <<
", but parameter contains multiple samples.");
92 libmesh_error_msg_if(this->
n_samples() != 1,
93 "Requesting value for parameter " << param_name <<
", but parameter contains multiple samples.");
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];
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];
116 if (it ==
_parameters.end() || sample_idx >= it->second.size())
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];
126 if (it ==
_parameters.end() || sample_idx >= it->second.size())
128 return it->second[sample_idx];
149 const std::string & param_name,
150 const std::size_t index,
155 auto & sample_vec = map[param_name];
158 if (sample_vec.size() > index)
159 sample_vec[index] = std::move(
value);
162 else if (sample_vec.size() == index)
163 sample_vec.emplace_back(std::move(
value));
170 sample_vec.resize(index+1, zero_parameter);
171 sample_vec[index] = std::move(
value);
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];
238 libmesh_error_msg_if(sample_vec.size() == 0,
"Error getting value for extra parameter " << param_name);
239 return sample_vec[0];
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];
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];
268 libmesh_error_msg_if(sample_idx >= sample_vec.size(),
"Error getting value for extra parameter " << param_name);
269 return sample_vec[sample_idx];
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];
284 const std::string ¶m_name,
285 std::size_t sample_idx,
291 return it->second[sample_idx];
327 auto size_first =
_parameters.begin()->second.size();
332 libmesh_assert_msg(pr.second.size() == size_first,
"All parameters must have the same number of samples.");
342 std::set<std::string> param_names;
344 param_names.insert(pr.first);
350 std::set<std::string> param_names;
352 param_names.insert(pr.first);
418 return !(*
this == rhs);
424 "Can only append RBParameters objects with matching numbers of samples.");
437 std::stringstream param_stringstream;
438 param_stringstream << std::setprecision(static_cast<int>(precision)) << std::scientific;
440 for (
const auto & [param_name, sample_vec] :
_parameters)
443 param_stringstream << param_name <<
": ";
444 std::string separator =
"";
445 for (
const auto & value_vec : sample_vec)
447 param_stringstream << separator;
448 if (value_vec.size() == 1)
449 param_stringstream << value_vec[0];
452 param_stringstream <<
"[ ";
455 if (max_values < 0 || val_idx < static_cast<unsigned>(max_values))
456 param_stringstream << value_vec[val_idx] <<
" ";
459 param_stringstream <<
"... ";
463 param_stringstream <<
"]";
467 param_stringstream << std::endl;
470 return param_stringstream.str();
Real get_value(const std::string ¶m_name) const
Get the value of the specified parameter, throw an error if it does not exist.
bool operator!=(const RBParameters &rhs) const
Real get_extra_sample_value(const std::string ¶m_name, std::size_t sample_idx) const
Get the value of the specified "extra" parameter at the specified sample index, throwing an error if ...
bool has_value(const std::string ¶m_name) const
std::set< std::string > get_parameter_names() const
void erase_extra_parameter(const std::string ¶m_name)
Erase param_name from _extra_parameters.
const RBParameter & get_extra_sample_vector_value(const std::string ¶m_name, std::size_t sample_idx) const
const_iterator begin_serialized() const
Get const_iterator access to the parameters stored in this RBParameters object.
std::map< std::string, std::vector< RBParameter > >::const_iterator extra_begin() const
std::map< std::string, std::vector< RBParameter > >::const_iterator end() const
std::map< std::string, std::vector< RBParameter > > _parameters
Actual parameter values (in std::vector<RBParameter> form) across a vector of samples.
unsigned int _n_samples
The number of samples represented by this RBParameters object, in the case where there are no paramet...
bool operator==(const RBParameters &rhs) const
Two RBParameters are equal if they have the same _parameters map.
const RBParameter & get_vector_value(const std::string ¶m_name) const
std::map< std::string, std::vector< RBParameter > > _extra_parameters
Extra parameter vectors not used for RB training.
The libMesh namespace provides an interface to certain functionality in the library.
RBParameters & operator+=(const RBParameters &rhs)
Append "rhs" to "*this".
void print(unsigned precision=6, int max_values=5) const
Print the parameters.
const RBParameter & get_extra_vector_value(const std::string ¶m_name) const
RBParameters()
Constructor.
std::map< std::string, std::vector< RBParameter > >::const_iterator extra_end() const
unsigned int n_parameters() const
Get the number of parameters that have been added.
std::set< std::string > get_extra_parameter_names() const
Define a constant iterator for iterating over the map of parameters.
const RBParameter & get_sample_vector_value(const std::string ¶m_name, std::size_t sample_idx) const
std::vector< Real > RBParameter
Typedef for an individual RB parameter.
std::string get_string(unsigned precision=6, int max_values=5) const
Get a string that specifies the contents of this RBParameters object.
This class is part of the rbOOmit framework.
const_iterator end_serialized_extra() const
bool has_extra_value(const std::string ¶m_name) const
void set_value_helper(std::map< std::string, std::vector< RBParameter >> &map, const std::string ¶m_name, const std::size_t index, RBParameter value)
Helper function for the 3-parameter versions of set_value() and set_extra_value().
unsigned int n_samples() const
Returns the number of samples stored for all parameters.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_extra_value(const std::string ¶m_name, Real value)
Set the value of the specified extra parameter.
Real get_sample_value(const std::string ¶m_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...
const_iterator begin_serialized_extra() const
Get const_iterator access to the extra parameters stored in this RBParameters object.
void push_back_extra_value(const std::string ¶m_name, Real value)
Same as push_back_value(), but for "extra" parameters.
void set_value(const std::string ¶m_name, Real value)
Set the value of the specified parameter.
void clear()
Clear this object.
const_iterator end_serialized() const
void erase_parameter(const std::string ¶m_name)
Erase param_name from _parameters.
Real get_extra_value(const std::string ¶m_name) const
Get the value of the specified extra parameter, throwing an error if it does not exist.
void push_back_value(const std::string ¶m_name, Real value)
Similar to set_value(name, index, value) but instead of specifying a particular index, just appends one more.
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 a...
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
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 nam...