libMesh
Loading...
Searching...
No Matches
rb_parameters.h
Go to the documentation of this file.
1// rbOOmit: An implementation of the Certified Reduced Basis method.
2// Copyright (C) 2009, 2010 David J. Knezevic
3
4// This file is part of rbOOmit.
5
6// rbOOmit is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 2.1 of the License, or (at your option) any later version.
10
11// rbOOmit is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15
16// You should have received a copy of the GNU Lesser General Public
17// License along with this library; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20#ifndef LIBMESH_RB_PARAMETERS_H
21#define LIBMESH_RB_PARAMETERS_H
22
23// libMesh includes
24#include "libmesh/libmesh_common.h"
25
26// C++ includes
27#include <string>
28#include <map>
29#include <set>
30#include <vector>
31
32namespace libMesh
33{
34
39using RBParameter = std::vector<Real>;
40
53{
54public:
55
62
67 RBParameters (RBParameters &&) = default;
68 RBParameters (const RBParameters &) = default;
69 RBParameters & operator= (const RBParameters &) = default;
71 ~RBParameters() = default;
72
79 RBParameters(const std::map<std::string, Real> & parameter_map);
80
86 std::map<std::string,std::vector<RBParameter>>::const_iterator begin() const;
87 std::map<std::string,std::vector<RBParameter>>::const_iterator end() const;
88 std::map<std::string,std::vector<RBParameter>>::const_iterator extra_begin() const;
89 std::map<std::string,std::vector<RBParameter>>::const_iterator extra_end() const;
90
98 {
99 public:
100 // Typedefs needed for interoperating with other STL algorithms and containers.
101 typedef std::forward_iterator_tag iterator_category;
102 typedef std::pair<std::string, Real> value_type;
103 typedef std::ptrdiff_t difference_type;
106
107 // Underlying iterator type, must match the container type of _parameters.
108 typedef std::map<std::string, std::vector<RBParameter>>::const_iterator MapIter;
109
110 // Constructor
112 const std::size_t sample_vec_index,
113 const std::size_t value_vec_index)
114 : _it(it),
115 _sample_vec_index(sample_vec_index),
116 _value_vec_index(value_vec_index)
117 {}
118
119 // Copy ctor
120 const_iterator(const const_iterator & i) = default;
121
122 // Prefix increment operator "++it"
124 {
125 // First increment the value-vector index.
126 // If _value_vec_index goes beyond the current value-vector, reset to the next one.
128 if (_value_vec_index >= _it->second[_sample_vec_index].size())
129 {
131 // Now increment the sample-vector index, and do the same check.
132 // If we go beyond the current sample-vector, reset to the next one.
134 if (_sample_vec_index >= _it->second.size())
135 {
137 ++_it;
138 }
139 }
140
141 return *this;
142 }
143
144 // Postfix increment operator "it++". This is actually less
145 // efficient than doing the prefix increment, so if nothing
146 // requires it, let's skip defining it.
147 // const_iterator operator++(int)
148 // {
149 // const_iterator i = *this;
150 // ++(*this);
151 // return i;
152 // }
153
154 // Dereference operator - returns a const reference to the value
155 // indexed by it and _vec_index. Note: this is needed for backwards
156 // compatibility but it is not the most efficient thing since we
157 // need to construct a std::pair every time we dereference a
158 // const_iterator.
159 const value_type & operator*() const
160 {
161 _emulator = std::make_pair(_it->first, _it->second[_sample_vec_index][_value_vec_index]);
162 return _emulator;
163 }
164
165 // Equivalence comparison operator.
166 bool operator==(const const_iterator & other) const
167 {
168 return (_it == other._it && _sample_vec_index == other._sample_vec_index);
169 }
170
171 // Non-equvialence comparison operator
172 bool operator!=(const const_iterator & other) const
173 {
174 return !(other == *this);
175 }
176
177 private:
178 // Give RBParameters access to our private members. At the moment
179 // this is not needed since the RBParameters class does not really
180 // need to know anything about the const_iterator once it has been
181 // created.
182 // friend class RBParameters;
183
184 // Iterator into real container
186
187 // Accompanying current sample-vector index into it->second
188 std::size_t _sample_vec_index;
189
190 // Accompanying current value-vector index into it->second[_sample_vec_index]
191 std::size_t _value_vec_index;
192
193 // Returned by the operator* function. Emulates dereferencing a
194 // map<string, Real> iterator.
196 }; // end const_iterator
197
207
217
221 void clear();
222
227 bool has_value(const std::string & param_name) const;
228
233 bool has_extra_value(const std::string & param_name) const;
234
241 Real get_value(const std::string & param_name) const;
242 const RBParameter & get_vector_value(const std::string & param_name) const;
243
252 Real get_value(const std::string & param_name, const Real & default_val) const;
253 const RBParameter & get_vector_value(const std::string & param_name, const RBParameter & default_val) const;
254
261 Real get_sample_value(const std::string & param_name, std::size_t sample_idx) const;
262 const RBParameter & get_sample_vector_value(const std::string & param_name, std::size_t sample_idx) const;
263
271 Real get_sample_value(const std::string & param_name, std::size_t sample_idx, const Real & default_val) const;
272 const RBParameter & get_sample_vector_value(const std::string & param_name, std::size_t sample_idx, const RBParameter & default_val) const;
273
281 void set_value(const std::string & param_name, Real value);
282 void set_value(const std::string & param_name, const RBParameter & value);
283
288 void set_value(const std::string & param_name, std::size_t index, Real value);
289 void set_value(const std::string & param_name, std::size_t index, const RBParameter & value);
290
297 void push_back_value(const std::string & param_name, Real value);
298 void push_back_value(const std::string & param_name, const RBParameter & value);
299
303 void push_back_extra_value(const std::string & param_name, Real value);
304 void push_back_extra_value(const std::string & param_name, const RBParameter & value);
305
310 Real get_extra_value(const std::string & param_name) const;
311 const RBParameter & get_extra_vector_value(const std::string & param_name) const;
312
317 Real get_extra_value(const std::string & param_name, const Real & default_val) const;
318 const RBParameter & get_extra_vector_value(const std::string & param_name, const RBParameter & default_val) const;
319
324 Real get_extra_sample_value(const std::string & param_name, std::size_t sample_idx) const;
325 const RBParameter & get_extra_sample_vector_value(const std::string & param_name, std::size_t sample_idx) const;
326
332 Real get_extra_sample_value(const std::string & param_name, std::size_t sample_idx, const Real & default_val) const;
333 const RBParameter & get_extra_sample_vector_value(const std::string & param_name, std::size_t sample_idx, const RBParameter & default_val) const;
334
339 void set_extra_value(const std::string & param_name, Real value);
340 void set_extra_value(const std::string & param_name, const RBParameter & value);
341
346 void set_extra_value(const std::string & param_name, std::size_t index, Real value);
347 void set_extra_value(const std::string & param_name, std::size_t index, const RBParameter & value);
348
352 unsigned int n_parameters() const;
353
362 void set_n_samples(unsigned int n_samples);
363
370 unsigned int n_samples() const;
371
380 std::set<std::string> get_parameter_names() const;
381
390 std::set<std::string> get_extra_parameter_names() const;
391
396 void erase_parameter(const std::string & param_name);
397
402 void erase_extra_parameter(const std::string & param_name);
403
407 bool operator== (const RBParameters & rhs) const;
408
412 bool operator!= (const RBParameters & rhs) const;
413
421
429 std::string get_string(unsigned precision=6, int max_values=5) const;
430
434 void print(unsigned precision=6, int max_values=5) const;
435
436private:
437
442 void set_value_helper(std::map<std::string, std::vector<RBParameter>> & map,
443 const std::string & param_name,
444 const std::size_t index,
446
453 unsigned int _n_samples;
454
462 std::map<std::string, std::vector<RBParameter>> _parameters;
463
468 std::map<std::string, std::vector<RBParameter>> _extra_parameters;
469};
470
471} // namespace libMesh
472
473
474#endif // LIBMESH_RB_PARAMETERS_H
Define a constant iterator for iterating over the map of parameters.
bool operator==(const const_iterator &other) const
std::map< std::string, std::vector< RBParameter > >::const_iterator MapIter
const_iterator(const const_iterator &i)=default
std::forward_iterator_tag iterator_category
std::pair< std::string, Real > value_type
const value_type & operator*() const
bool operator!=(const const_iterator &other) const
const_iterator(const MapIter &it, const std::size_t sample_vec_index, const std::size_t value_vec_index)
This class is part of the rbOOmit framework.
std::map< std::string, std::vector< RBParameter > >::const_iterator extra_end() const
RBParameters & operator=(const RBParameters &)=default
void erase_extra_parameter(const std::string &param_name)
Erase param_name from _extra_parameters.
std::map< std::string, std::vector< RBParameter > >::const_iterator extra_begin() const
unsigned int n_parameters() const
Get the number of parameters that have been added.
const RBParameter & get_vector_value(const std::string &param_name) 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 ...
bool operator!=(const RBParameters &rhs) const
RBParameters & operator+=(const RBParameters &rhs)
Append "rhs" to "*this".
RBParameters()
Constructor.
std::set< std::string > get_extra_parameter_names() const
bool has_value(const std::string &param_name) const
const_iterator end_serialized_extra() const
const RBParameter & get_sample_vector_value(const std::string &param_name, std::size_t sample_idx) 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.
std::set< std::string > get_parameter_names() const
RBParameters(RBParameters &&)=default
The special functions can be defaulted for this class, as it does not manage any memory itself.
std::string get_string(unsigned precision=6, int max_values=5) const
Get a string that specifies the contents of this RBParameters object.
bool has_extra_value(const std::string &param_name) const
void clear()
Clear this object.
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...
const RBParameter & get_extra_sample_vector_value(const std::string &param_name, std::size_t sample_idx) const
void push_back_extra_value(const std::string &param_name, Real value)
Same as push_back_value(), but for "extra" parameters.
const RBParameter & get_extra_vector_value(const std::string &param_name, const RBParameter &default_val) const
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().
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...
unsigned int _n_samples
The number of samples represented by this RBParameters object, in the case where there are no paramet...
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,...
unsigned int n_samples() const
Returns the number of samples stored for all parameters.
const RBParameter & get_extra_vector_value(const std::string &param_name) const
const_iterator begin_serialized_extra() const
Get const_iterator access to the extra parameters stored in this RBParameters object.
bool operator==(const RBParameters &rhs) const
Two RBParameters are equal if they have the same _parameters map.
std::map< std::string, std::vector< RBParameter > > _extra_parameters
Extra parameter vectors not used for RB training.
RBParameters(const RBParameters &)=default
const_iterator end_serialized() const
void print(unsigned precision=6, int max_values=5) const
Print the parameters.
void set_extra_value(const std::string &param_name, Real value)
Set the value of the specified extra parameter.
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.
std::map< std::string, std::vector< RBParameter > >::const_iterator end() const
void erase_parameter(const std::string &param_name)
Erase param_name from _parameters.
const_iterator begin_serialized() const
Get const_iterator access to the parameters stored in this RBParameters object.
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...
std::map< std::string, std::vector< RBParameter > > _parameters
Actual parameter values (in std::vector<RBParameter> form) across a vector of samples.
void set_value(const std::string &param_name, Real value)
Set the value of the specified parameter.
The libMesh namespace provides an interface to certain functionality in the library.
std::vector< Real > RBParameter
Typedef for an individual RB parameter.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const bool value
Definition xdr_io.C:55