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 // rbOOmit includes
24 #include "libmesh/rb_parameters.h"
25 
26 
27 
28 namespace libMesh
29 {
30 
32 {
33 }
34 
35 RBParameters::RBParameters(const std::map<std::string, Real> & parameter_map)
36 {
37  _parameters = parameter_map;
38 }
39 
41 {
42  _parameters.clear();
43 }
44 
45 Real RBParameters::get_value(const std::string & param_name) const
46 {
47  // find the parameter value
48  const_iterator it = _parameters.find(param_name);
49 
50  // throw and error if the parameter doesn't exist
51  if (it == _parameters.end())
52  libmesh_error_msg("Error: parameter " << param_name << " does not exist in RBParameters object.");
53 
54  return it->second;
55 }
56 
57 void RBParameters::set_value(const std::string & param_name, Real value)
58 {
59  _parameters[param_name] = value;
60 }
61 
62 unsigned int RBParameters::n_parameters() const
63 {
64  return cast_int<unsigned int>
65  (_parameters.size());
66 }
67 
68 void RBParameters::get_parameter_names(std::set<std::string> & param_names) const
69 {
70  param_names.clear();
71 
72  const_iterator it = _parameters.begin();
73  const_iterator it_end = _parameters.end();
74  for ( ; it != it_end; ++it)
75  {
76  param_names.insert( it->first );
77  }
78 }
79 
81 {
82  return _parameters.begin();
83 }
84 
86 {
87  return _parameters.end();
88 }
89 
90 bool RBParameters::operator==(const RBParameters & rhs) const
91 {
92  return this->_parameters == rhs._parameters;
93 }
94 
95 bool RBParameters::operator!=(const RBParameters & rhs) const
96 {
97  return !(*this == rhs);
98 }
99 
100 std::string RBParameters::get_string(unsigned int precision) const
101 {
102  std::stringstream param_stringstream;
103  param_stringstream.precision(precision);
104 
105  const_iterator it = _parameters.begin();
106  const_iterator it_end = _parameters.end();
107  for ( ; it != it_end; ++it)
108  {
109  param_stringstream << it->first << ": " << std::scientific << it->second << std::endl;
110  }
111  return param_stringstream.str();
112 }
113 
115 {
116  libMesh::out << get_string() << std::endl;
117 }
118 
119 }
Real get_value(const std::string &param_name) const
Get the value of the specific parameter.
Definition: rb_parameters.C:45
std::string get_string(unsigned int precision=6) const
Get a string that specifies the contents of this RBParameters object.
unsigned int n_parameters() const
Get the number of parameters that have been added.
Definition: rb_parameters.C:62
void get_parameter_names(std::set< std::string > &param_names) const
Fill param_names with the names of the parameters.
Definition: rb_parameters.C:68
The libMesh namespace provides an interface to certain functionality in the library.
RBParameters()
Constructor.
Definition: rb_parameters.C:31
const_iterator end() const
Get a constant iterator to the end of this RBParameters object.
Definition: rb_parameters.C:85
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:42
void print() const
Print the parameters.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_value(const std::string &param_name, Real value)
Set the value of the specified parameter.
Definition: rb_parameters.C:57
OStreamProxy out
void clear()
Clear this object.
Definition: rb_parameters.C:40
static const bool value
Definition: xdr_io.C:108
bool operator!=(const RBParameters &node) const
Definition: rb_parameters.C:95
bool operator==(const RBParameters &rhs) const
Two RBParameters are equal if they have the same _parameters map.
Definition: rb_parameters.C:90
const_iterator begin() const
Get a constant iterator to beginning of this RBParameters object.
Definition: rb_parameters.C:80
std::map< std::string, Real >::const_iterator const_iterator
Definition: rb_parameters.h:57
std::map< std::string, Real > _parameters
The map that stores the actual parameters, indexed by names.