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
RBParameters(const std::map<std::string,Real> & parameter_map)30 RBParameters::RBParameters(const std::map<std::string, Real> & parameter_map)
31 {
32 _parameters = parameter_map;
33 }
34
clear()35 void RBParameters::clear()
36 {
37 _parameters.clear();
38 _extra_parameters.clear();
39 }
40
get_parameters_map()41 const std::map<std::string, Real> & RBParameters::get_parameters_map() const
42 {
43 return _parameters;
44 }
45
get_extra_parameters_map()46 const std::map<std::string, Real> & RBParameters::get_extra_parameters_map() const
47 {
48 return _extra_parameters;
49 }
50
get_value(const std::string & param_name)51 Real RBParameters::get_value(const std::string & param_name) const
52 {
53 // find the parameter value, throwing an error if it doesn't exist.
54 return libmesh_map_find(_parameters, param_name);
55 }
56
set_value(const std::string & param_name,Real value)57 void RBParameters::set_value(const std::string & param_name, Real value)
58 {
59 _parameters[param_name] = value;
60 }
61
get_extra_value(const std::string & param_name)62 Real RBParameters::get_extra_value(const std::string & param_name) const
63 {
64 // find the parameter value, throwing an error if it doesn't exist.
65 return libmesh_map_find(_extra_parameters, param_name);
66 }
67
set_extra_value(const std::string & param_name,Real value)68 void RBParameters::set_extra_value(const std::string & param_name, Real value)
69 {
70 _extra_parameters[param_name] = value;
71 }
72
n_parameters()73 unsigned int RBParameters::n_parameters() const
74 {
75 return cast_int<unsigned int>
76 (_parameters.size());
77 }
78
get_parameter_names(std::set<std::string> & param_names)79 void RBParameters::get_parameter_names(std::set<std::string> & param_names) const
80 {
81 libmesh_deprecated();
82
83 param_names.clear();
84 for (const auto & pr : _parameters)
85 param_names.insert(pr.first);
86 }
87
get_extra_parameter_names(std::set<std::string> & param_names)88 void RBParameters::get_extra_parameter_names(std::set<std::string> & param_names) const
89 {
90 libmesh_deprecated();
91
92 param_names.clear();
93 for (const auto & pr : _extra_parameters)
94 param_names.insert(pr.first);
95 }
96
begin()97 RBParameters::const_iterator RBParameters::begin() const
98 {
99 return _parameters.begin();
100 }
101
end()102 RBParameters::const_iterator RBParameters::end() const
103 {
104 return _parameters.end();
105 }
106
extra_begin()107 RBParameters::const_iterator RBParameters::extra_begin() const
108 {
109 return _extra_parameters.begin();
110 }
111
extra_end()112 RBParameters::const_iterator RBParameters::extra_end() const
113 {
114 return _extra_parameters.end();
115 }
116
117 bool RBParameters::operator==(const RBParameters & rhs) const
118 {
119 return (this->_parameters == rhs._parameters &&
120 this->_extra_parameters == rhs._extra_parameters);
121 }
122
123 bool RBParameters::operator!=(const RBParameters & rhs) const
124 {
125 return !(*this == rhs);
126 }
127
get_string(unsigned int precision)128 std::string RBParameters::get_string(unsigned int precision) const
129 {
130 std::stringstream param_stringstream;
131 param_stringstream.precision(precision);
132
133 const_iterator it = _parameters.begin();
134 const_iterator it_end = _parameters.end();
135 for ( ; it != it_end; ++it)
136 {
137 param_stringstream << it->first << ": " << std::scientific << it->second << std::endl;
138 }
139 return param_stringstream.str();
140 }
141
print()142 void RBParameters::print() const
143 {
144 libMesh::out << get_string() << std::endl;
145 }
146
147 }
148