libMesh
rb_parameters.C
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 // C++ includes
21 #include <sstream>
22 
23 // libmesh includes
24 #include "libmesh/rb_parameters.h"
25 #include "libmesh/utility.h"
26 
27 namespace libMesh
28 {
29 
30 RBParameters::RBParameters(const std::map<std::string, Real> & parameter_map)
31 {
32  _parameters = parameter_map;
33 }
34 
36 {
37  _parameters.clear();
38  _extra_parameters.clear();
39 }
40 
41 Real RBParameters::get_value(const std::string & param_name) const
42 {
43  // find the parameter value, throwing an error if it doesn't exist.
44  return libmesh_map_find(_parameters, param_name);
45 }
46 
47 void RBParameters::set_value(const std::string & param_name, Real value)
48 {
49  _parameters[param_name] = value;
50 }
51 
52 Real RBParameters::get_extra_value(const std::string & param_name) const
53 {
54  // find the parameter value, throwing an error if it doesn't exist.
55  return libmesh_map_find(_extra_parameters, param_name);
56 }
57 
58 void RBParameters::set_extra_value(const std::string & param_name, Real value)
59 {
60  _extra_parameters[param_name] = value;
61 }
62 
63 unsigned int RBParameters::n_parameters() const
64 {
65  return cast_int<unsigned int>
66  (_parameters.size());
67 }
68 
69 void RBParameters::get_parameter_names(std::set<std::string> & param_names) const
70 {
71  param_names.clear();
72 
73  const_iterator it = _parameters.begin();
74  const_iterator it_end = _parameters.end();
75  for ( ; it != it_end; ++it)
76  {
77  param_names.insert( it->first );
78  }
79 }
80 
81 void RBParameters::get_extra_parameter_names(std::set<std::string> & param_names) const
82 {
83  param_names.clear();
84 
85  for (const auto & pr : _extra_parameters)
86  param_names.insert(pr.first);
87 }
88 
90 {
91  return _parameters.begin();
92 }
93 
95 {
96  return _parameters.end();
97 }
98 
100 {
101  return _extra_parameters.begin();
102 }
103 
105 {
106  return _extra_parameters.end();
107 }
108 
109 bool RBParameters::operator==(const RBParameters & rhs) const
110 {
111  return (this->_parameters == rhs._parameters &&
112  this->_extra_parameters == rhs._extra_parameters);
113 }
114 
115 bool RBParameters::operator!=(const RBParameters & rhs) const
116 {
117  return !(*this == rhs);
118 }
119 
120 std::string RBParameters::get_string(unsigned int precision) const
121 {
122  std::stringstream param_stringstream;
123  param_stringstream.precision(precision);
124 
125  const_iterator it = _parameters.begin();
126  const_iterator it_end = _parameters.end();
127  for ( ; it != it_end; ++it)
128  {
129  param_stringstream << it->first << ": " << std::scientific << it->second << std::endl;
130  }
131  return param_stringstream.str();
132 }
133 
135 {
136  libMesh::out << get_string() << std::endl;
137 }
138 
139 }
libMesh::RBParameters::set_extra_value
void set_extra_value(const std::string &param_name, Real value)
Set the value of the specified extra parameter.
Definition: rb_parameters.C:58
libMesh::RBParameters::print
void print() const
Print the parameters.
Definition: rb_parameters.C:134
libMesh::RBParameters::operator==
bool operator==(const RBParameters &rhs) const
Two RBParameters are equal if they have the same _parameters map.
Definition: rb_parameters.C:109
libMesh::RBParameters::_extra_parameters
std::map< std::string, Real > _extra_parameters
The map that stores extra parameters not used for RB training, indexed by names.
Definition: rb_parameters.h:151
libMesh::RBParameters::begin
const_iterator begin() const
Get const_iterator access to the parameters stored in this RBParameters object.
Definition: rb_parameters.C:89
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::RBParameters
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:42
libMesh::RBParameters::n_parameters
unsigned int n_parameters() const
Get the number of parameters that have been added.
Definition: rb_parameters.C:63
libMesh::RBParameters::get_extra_parameter_names
void get_extra_parameter_names(std::set< std::string > &param_names) const
Fill param_names with the names of the extra parameters.
Definition: rb_parameters.C:81
libMesh::RBParameters::get_string
std::string get_string(unsigned int precision=6) const
Get a string that specifies the contents of this RBParameters object.
Definition: rb_parameters.C:120
libMesh::RBParameters::RBParameters
RBParameters()=default
The special functions can be defaulted for this class, as it does not manage any memory itself.
libMesh::RBParameters::set_value
void set_value(const std::string &param_name, Real value)
Set the value of the specified parameter.
Definition: rb_parameters.C:47
libMesh::RBParameters::get_parameter_names
void get_parameter_names(std::set< std::string > &param_names) const
Fill param_names with the names of the parameters.
Definition: rb_parameters.C:69
libMesh::RBParameters::const_iterator
std::map< std::string, Real >::const_iterator const_iterator
Definition: rb_parameters.h:63
value
static const bool value
Definition: xdr_io.C:56
libMesh::RBParameters::operator!=
bool operator!=(const RBParameters &node) const
Definition: rb_parameters.C:115
libMesh::RBParameters::get_extra_value
Real get_extra_value(const std::string &param_name) const
Get the value of the specific extra parameter.
Definition: rb_parameters.C:52
libMesh::RBParameters::clear
void clear()
Clear this object.
Definition: rb_parameters.C:35
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::RBParameters::extra_begin
const_iterator extra_begin() const
Get const_iterator access to the extra parameters stored in this RBParameters object.
Definition: rb_parameters.C:99
libMesh::RBParameters::end
const_iterator end() const
Definition: rb_parameters.C:94
libMesh::out
OStreamProxy out
libMesh::RBParameters::_parameters
std::map< std::string, Real > _parameters
The map that stores the actual parameters, indexed by names.
Definition: rb_parameters.h:146
libMesh::RBParameters::extra_end
const_iterator extra_end() const
Definition: rb_parameters.C:104
libMesh::RBParameters::get_value
Real get_value(const std::string &param_name) const
Get the value of the specific parameter.
Definition: rb_parameters.C:41