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 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_SCALARPARAMETERLIBRARY_HPP
11 #define SACADO_SCALARPARAMETERLIBRARY_HPP
12 
16 
17 #include "Teuchos_Assert.hpp"
18 
19 namespace Sacado {
20 
25  template <typename EvalTypeTraits = DefaultEvalTypeTraits>
27  public ParameterLibraryBase<ScalarParameterFamily<EvalTypeTraits>,
28  ScalarParameterEntry<_,EvalTypeTraits> > {
29 
30  public:
31 
36 
39 
42 
44  void setRealValueForAllTypes(const std::string& name, double value);
45 
47  template <class EvalType>
48  void
49  setRealValue(const std::string& name, double value);
50 
52  template <class EvalType>
53  void
54  setValue(const std::string& name,
55  const typename EvalTypeTraits::template apply<EvalType>::type& value);
56 
58  template <class EvalType>
59  double
60  getRealValue(const std::string& name) const;
61 
63  template <class EvalType>
64  const typename EvalTypeTraits::template apply<EvalType>::type&
65  getValue(const std::string& name) const;
66 
69  static ScalarParameterLibrary instance;
70  return instance;
71  }
72 
74 
78  template <class EvalType>
79  void
82 
83  private:
84 
87 
90 
91  };
92 
93 }
94 
95 
96 template <typename EvalTypeTraits>
97 void
99 setRealValueForAllTypes(const std::string& name, double value)
100 {
101  typename BaseT::FamilyMap::iterator it = this->library.find(name);
103  it == this->library.end(),
104  std::logic_error,
105  std::string("Sacado::ScalararameterLibrary::setRealValueForAllTypes(): ")
106  + "Invalid parameter family " + name);
107  (*it).second->setRealValueForAllTypes(value);
108 }
109 
110 template <typename EvalTypeTraits>
111 template <class EvalType>
112 void
114 setRealValue(const std::string& name, double value)
115 {
116  typename BaseT::FamilyMap::iterator it = this->library.find(name);
118  it == this->library.end(),
119  std::logic_error,
120  std::string("Sacado::ScalarParameterLibrary::setValueAsConstant(): ")
121  + "Invalid parameter family " + name);
122  (*it).second-> template setRealValue<EvalType>(value);
123 }
124 
125 template <typename EvalTypeTraits>
126 template <class EvalType>
127 void
130  const std::string& name,
131  const typename EvalTypeTraits::template apply<EvalType>::type& value)
132 {
133  typename BaseT::FamilyMap::iterator it = this->library.find(name);
135  it == this->library.end(),
136  std::logic_error,
137  std::string("Sacado::ScalarParameterLibrary::setValueAsIndependent(): ")
138  + "Invalid parameter family " + name);
139  (*it).second-> template setValue<EvalType>(value);
140 }
141 
142 template <typename EvalTypeTraits>
143 template <class EvalType>
144 double
146 getRealValue(const std::string& name) const
147 {
148  typename BaseT::FamilyMap::const_iterator it = this->library.find(name);
150  it == this->library.end(),
151  std::logic_error,
152  std::string("Sacado::ScalarParameterLibrary::getValue(): ")
153  + "Invalid parameter family " + name);
154  return (*it).second-> template getRealValue<EvalType>();
155 }
156 
157 template <typename EvalTypeTraits>
158 template <class EvalType>
159 const typename EvalTypeTraits::template apply<EvalType>::type&
161 getValue(const std::string& name) const
162 {
163  typename BaseT::FamilyMap::const_iterator it = this->library.find(name);
165  it == this->library.end(),
166  std::logic_error,
167  std::string("Sacado::ScalarParameterLibrary::getValue(): ")
168  + "Invalid parameter family " + name);
169  return (*it).second->template getValue<EvalType>();
170 }
171 
172 template <typename EvalTypeTraits>
173 template <class EvalType>
174 void
178 {
179  typename BaseT::FamilyMap::iterator it;
180 
181  // Fill in parameters
182  for (unsigned int i=0; i<names.size(); i++) {
183  it = this->library.find(names[i]);
185  it == this->library.end(),
186  std::logic_error,
187  std::string("Sacado::ParameterLibraryBase::fillVector(): ")
188  + "Invalid parameter family " + names[i]);
189  pv.addParam((*it).second, 0.0);
190  pv[i].baseValue = (*it).second->template getRealValue<EvalType>();
191  }
192 }
193 
194 
195 #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.
int value
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.