Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
39 namespace 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
102 
103  private:
104 
107 
110 
111  };
112 
113 }
114 
115 
116 template <typename EvalTypeTraits>
117 void
119 setRealValueForAllTypes(const std::string& name, double value)
120 {
121  typename BaseT::FamilyMap::iterator it = this->library.find(name);
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 
130 template <typename EvalTypeTraits>
131 template <class EvalType>
132 void
134 setRealValue(const std::string& name, double value)
135 {
136  typename BaseT::FamilyMap::iterator it = this->library.find(name);
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 
145 template <typename EvalTypeTraits>
146 template <class EvalType>
147 void
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);
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 
162 template <typename EvalTypeTraits>
163 template <class EvalType>
164 double
166 getRealValue(const std::string& name) const
167 {
168  typename BaseT::FamilyMap::const_iterator it = this->library.find(name);
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 
177 template <typename EvalTypeTraits>
178 template <class EvalType>
179 const typename EvalTypeTraits::template apply<EvalType>::type&
181 getValue(const std::string& name) const
182 {
183  typename BaseT::FamilyMap::const_iterator it = this->library.find(name);
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 
192 template <typename EvalTypeTraits>
193 template <class EvalType>
194 void
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]);
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
void setRealValue(const std::string &name, double value)
Set real parameter to value value.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
double getRealValue(const std::string &name) const
Get parameter value.
void addParam(const Teuchos::RCP< ScalarParameterFamily< EvalTypeTraits > > &family, doublebaseValue)
Add entry.
ScalarParameterLibrary & operator=(const ScalarParameterLibrary &)
Private to prohibit copying.
Class to provide a centralized library for setting/retrieving numerical parameter values...
A base class for scalar parameter values.
Specialization of Sacado::ParameterVectorBase for scalar parameters.
void fillVector(const Teuchos::Array< std::string > &names, ScalarParameterVector< EvalTypeTraits > &pv)
Fill a vector with the supplied parameter names.
ParameterLibraryBase< ScalarParameterFamily< EvalTypeTraits >, ScalarParameterEntry< _, EvalTypeTraits > > BaseT
Typename synonym of base class.
size_type size() const
void setRealValueForAllTypes(const std::string &name, double value)
Set paramter value using a real number.
Specialization of Sacado::ParameterLibraryBase for scalar parameters.
void setValue(const std::string &name, const typename EvalTypeTraits::template apply< EvalType >::type &value)
Set parameter to value value.
static ScalarParameterLibrary & getInstance()
Returns a parameter library (singleton object).
const EvalTypeTraits::template apply< EvalType >::type & getValue(const std::string &name) const
Get parameter value.