Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_ParameterRegistration.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_PARAMETERREGISTRATION_HPP
31 #define SACADO_PARAMETERREGISTRATION_HPP
32 
33 #include <sstream>
35 #include "Sacado_Traits.hpp"
37 
38 namespace Sacado {
39 
45  template <typename EvalType, typename EvalTypeTraits = DefaultEvalTypeTraits>
46  class ParameterRegistration :
47  public Sacado::ScalarParameterEntry<EvalType, EvalTypeTraits > {
48 
50  typedef typename EvalTypeTraits::template apply<EvalType>::type ScalarT;
51 
52 
53  public:
54 
56 
58  ParameterRegistration(const std::string &name_,
60  ParamLib& paramLib)
61  : access(access_), name(name_) {
62 
63  if (!paramLib.isParameter(name))
64  paramLib.addParameterFamily(name, true, false);
65  if (!paramLib.template isParameterForType<EvalType>(name))
66  paramLib.template addEntry<EvalType>(name, Teuchos::rcp(this,false));
67  }
68 
70  ParameterRegistration(const std::string &name_,
72  const Teuchos::RCP<ParamLib>& paramLib)
73  : access(access_), name(name_) {
74 
75  if (paramLib != Teuchos::null) {
76  if (!paramLib->isParameter(name))
77  paramLib->addParameterFamily(name, true, false);
78  if (!paramLib->template isParameterForType<EvalType>(name)) {
79  paramLib->template addEntry<EvalType>(name, Teuchos::rcp(this,false));
80  }
81  }
82  }
83 
86 
88  virtual void setRealValue(double value) {
89  setValue(ScalarT(value)); }
90 
92  virtual void setValue(const ScalarT& value) {
93  access->setValue(name, value);
94  }
95 
97  virtual const ScalarT& getValue() const {
98  return access->getValue(name);
99  }
100 
101  protected:
102 
105  const std::string name;
106 
107  };
108 
109 }
110 
111 #endif // SACADO_PARAMETERREGISTRATION_HPP
virtual const ScalarT & getValue() const
Get parameter value using ParameterAccessor.
ScalarParameterLibrary< EvalTypeTraits > ParamLib
EvalTypeTraits::template apply< EvalType >::type ScalarT
Scalar type.
ParameterAccessor< EvalType, EvalTypeTraits > * access
Pointer to source function.
bool addParameterFamily(const std::string &name, bool supports_ad, bool supports_analytic)
Create a new parameter family.
virtual void setValue(const ScalarT &value)
Set parameter values using ParameterAccessor.
ParameterRegistration(const std::string &name_, ParameterAccessor< EvalType, EvalTypeTraits > *access_, ParamLib &paramLib)
Constructor: Registers the parameter with the Parameter Library.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ParameterRegistration(const std::string &name_, ParameterAccessor< EvalType, EvalTypeTraits > *access_, const Teuchos::RCP< ParamLib > &paramLib)
Constructor: Registers the parameter with the Parameter Library.
A base class for scalar parameter values.
bool isParameter(const std::string &name) const
Determine if parameter of name name is in the library.
virtual void setRealValue(double value)
Set real parameter value.
Specialization of Sacado::ParameterLibraryBase for scalar parameters.
Abstract class that provides access to a parameter value in a code for the parameter library...