Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Sacado_ScalarParameterLibrary.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Sacado Package
5// Copyright (2006) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// This library is free software; you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as
12// published by the Free Software Foundation; either version 2.1 of the
13// License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23// USA
24// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25// (etphipp@sandia.gov).
26//
27// ***********************************************************************
28// @HEADER
29
30#ifndef SACADO_SCALARPARAMETERLIBRARY_HPP
31#define SACADO_SCALARPARAMETERLIBRARY_HPP
32
36
37#include "Teuchos_Assert.hpp"
38
39namespace Sacado {
40
45 template <typename EvalTypeTraits = DefaultEvalTypeTraits>
47 public ParameterLibraryBase<ScalarParameterFamily<EvalTypeTraits>,
48 ScalarParameterEntry<_,EvalTypeTraits> > {
49
50 public:
51
56
59
62
64 void setRealValueForAllTypes(const std::string& name, double value);
65
67 template <class EvalType>
68 void
69 setRealValue(const std::string& name, double value);
70
72 template <class EvalType>
73 void
74 setValue(const std::string& name,
75 const typename EvalTypeTraits::template apply<EvalType>::type& value);
76
78 template <class EvalType>
79 double
80 getRealValue(const std::string& name) const;
81
83 template <class EvalType>
84 const typename EvalTypeTraits::template apply<EvalType>::type&
85 getValue(const std::string& name) const;
86
89 static ScalarParameterLibrary instance;
90 return instance;
91 }
92
94
98 template <class EvalType>
99 void
100 fillVector(const Teuchos::Array<std::string>& names,
102
103 private:
104
107
110
111 };
112
113}
114
115
116template <typename EvalTypeTraits>
117void
119setRealValueForAllTypes(const std::string& name, double value)
120{
121 typename BaseT::FamilyMap::iterator it = this->library.find(name);
122 TEUCHOS_TEST_FOR_EXCEPTION(
123 it == this->library.end(),
124 std::logic_error,
125 std::string("Sacado::ScalararameterLibrary::setRealValueForAllTypes(): ")
126 + "Invalid parameter family " + name);
127 (*it).second->setRealValueForAllTypes(value);
128}
129
130template <typename EvalTypeTraits>
131template <class EvalType>
132void
134setRealValue(const std::string& name, double value)
135{
136 typename BaseT::FamilyMap::iterator it = this->library.find(name);
137 TEUCHOS_TEST_FOR_EXCEPTION(
138 it == this->library.end(),
139 std::logic_error,
140 std::string("Sacado::ScalarParameterLibrary::setValueAsConstant(): ")
141 + "Invalid parameter family " + name);
142 (*it).second-> template setRealValue<EvalType>(value);
143}
144
145template <typename EvalTypeTraits>
146template <class EvalType>
147void
150 const std::string& name,
151 const typename EvalTypeTraits::template apply<EvalType>::type& value)
152{
153 typename BaseT::FamilyMap::iterator it = this->library.find(name);
154 TEUCHOS_TEST_FOR_EXCEPTION(
155 it == this->library.end(),
156 std::logic_error,
157 std::string("Sacado::ScalarParameterLibrary::setValueAsIndependent(): ")
158 + "Invalid parameter family " + name);
159 (*it).second-> template setValue<EvalType>(value);
160}
161
162template <typename EvalTypeTraits>
163template <class EvalType>
164double
166getRealValue(const std::string& name) const
167{
168 typename BaseT::FamilyMap::const_iterator it = this->library.find(name);
169 TEUCHOS_TEST_FOR_EXCEPTION(
170 it == this->library.end(),
171 std::logic_error,
172 std::string("Sacado::ScalarParameterLibrary::getValue(): ")
173 + "Invalid parameter family " + name);
174 return (*it).second-> template getRealValue<EvalType>();
175}
176
177template <typename EvalTypeTraits>
178template <class EvalType>
179const typename EvalTypeTraits::template apply<EvalType>::type&
181getValue(const std::string& name) const
182{
183 typename BaseT::FamilyMap::const_iterator it = this->library.find(name);
184 TEUCHOS_TEST_FOR_EXCEPTION(
185 it == this->library.end(),
186 std::logic_error,
187 std::string("Sacado::ScalarParameterLibrary::getValue(): ")
188 + "Invalid parameter family " + name);
189 return (*it).second->template getValue<EvalType>();
190}
191
192template <typename EvalTypeTraits>
193template <class EvalType>
194void
196fillVector(const Teuchos::Array<std::string>& names,
198{
199 typename BaseT::FamilyMap::iterator it;
200
201 // Fill in parameters
202 for (unsigned int i=0; i<names.size(); i++) {
203 it = this->library.find(names[i]);
204 TEUCHOS_TEST_FOR_EXCEPTION(
205 it == this->library.end(),
206 std::logic_error,
207 std::string("Sacado::ParameterLibraryBase::fillVector(): ")
208 + "Invalid parameter family " + names[i]);
209 pv.addParam((*it).second, 0.0);
210 pv[i].baseValue = (*it).second->template getRealValue<EvalType>();
211 }
212}
213
214
215#endif
Class to provide a centralized library for setting/retrieving numerical parameter values.
FamilyMap::const_iterator const_iterator
Const iterator typename.
FamilyMap::iterator iterator
Iterator typename.
void addParam(const Teuchos::RCP< FamilyType > &family, BaseValueType baseValue)
Add entry.
A base class for scalar parameter values.
Specialization of Sacado::ParameterLibraryBase for scalar parameters.
double getRealValue(const std::string &name) const
Get parameter value.
void setRealValue(const std::string &name, double value)
Set real parameter to value value.
ParameterLibraryBase< ScalarParameterFamily< EvalTypeTraits >, ScalarParameterEntry< _, EvalTypeTraits > > BaseT
Typename synonym of base class.
void fillVector(const Teuchos::Array< std::string > &names, ScalarParameterVector< EvalTypeTraits > &pv)
Fill a vector with the supplied parameter names.
const EvalTypeTraits::template apply< EvalType >::type & getValue(const std::string &name) const
Get parameter value.
void setValue(const std::string &name, const typename EvalTypeTraits::template apply< EvalType >::type &value)
Set parameter to value value.
void setRealValueForAllTypes(const std::string &name, double value)
Set paramter value using a real number.
static ScalarParameterLibrary & getInstance()
Returns a parameter library (singleton object).
ScalarParameterLibrary(const ScalarParameterLibrary &)
Private to prohibit copying.
ScalarParameterLibrary & operator=(const ScalarParameterLibrary &)
Private to prohibit copying.
Specialization of Sacado::ParameterVectorBase for scalar parameters.
int value