Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Tay_TaylorTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
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_TAY_TAYLORTRAITS_HPP
31 #define SACADO_TAY_TAYLORTRAITS_HPP
32 
33 #include "Sacado_Traits.hpp"
34 
35 // Forward declarations
36 namespace Sacado {
37  namespace Tay {
38  template <typename T> class Taylor;
39  }
40 }
41 
42 namespace Sacado {
43 
45  SACADO_AD_PROMOTE_SPEC( Tay, Taylor )
46 
47 
48  template <typename T>
49  struct ScalarType< Tay::Taylor<T> > {
50  typedef typename ScalarType<T>::type type;
51  };
52 
54  template <typename T>
55  struct ValueType< Tay::Taylor<T> > {
56  typedef T type;
57  };
58 
60  template <typename T>
61  struct IsADType< Tay::Taylor<T> > {
62  static const bool value = true;
63  };
64 
66  template <typename T>
67  struct IsScalarType< Tay::Taylor<T> > {
68  static const bool value = false;
69  };
70 
72  template <typename T>
73  struct Value< Tay::Taylor<T> > {
74  typedef typename ValueType< Tay::Taylor<T> >::type value_type;
75  static const value_type& eval(const Tay::Taylor<T>& x) {
76  return x.val(); }
77  };
78 
80  template <typename T>
81  struct ScalarValue< Tay::Taylor<T> > {
82  typedef typename ValueType< Tay::Taylor<T> >::type value_type;
83  typedef typename ScalarType< Tay::Taylor<T> >::type scalar_type;
84  static const scalar_type& eval(const Tay::Taylor<T>& x) {
85  return ScalarValue<value_type>::eval(x.val()); }
86  };
87 
89  template <typename T>
90  struct StringName< Tay::Taylor<T> > {
91  static std::string eval() {
92  return std::string("Sacado::Tay::Taylor< ") +
93  StringName<T>::eval() + " >"; }
94  };
95 
97  template <typename T>
98  struct IsEqual< Tay::Taylor<T> > {
99  static bool eval(const Tay::Taylor<T>& x, const Tay::Taylor<T>& y) {
100  return x.isEqualTo(y);
101  }
102  };
103 
105  template <typename T>
106  struct IsStaticallySized< Tay::Taylor<T> > {
107  static const bool value = false;
108  };
109 
110 } // namespace Sacado
111 
112 //
113 // Define Teuchos traits classes
114 //
115 
116 // Promotion traits
117 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
119 namespace Teuchos {
120  template <typename ValueT>
121  struct PromotionTraits< Sacado::Tay::Taylor<ValueT>,
122  Sacado::Tay::Taylor<ValueT> > {
125  promote;
126  };
127 
129  template <typename ValueT, typename R>
130  struct PromotionTraits< Sacado::Tay::Taylor<ValueT>, R > {
131  typedef typename Sacado::Promote< Sacado::Tay::Taylor<ValueT>, R >::type
132  promote;
133  };
134 
136  template <typename L, typename ValueT>
137  struct PromotionTraits< L, Sacado::Tay::Taylor<ValueT> > {
138  public:
139  typedef typename Sacado::Promote< L, Sacado::Tay::Taylor<ValueT> >::type
140  promote;
141  };
142 }
143 #endif
144 
145 // Scalar traits
146 #ifdef HAVE_SACADO_TEUCHOSCORE
148 namespace Teuchos {
149  template <typename ValueT>
150  struct ScalarTraits< Sacado::Tay::Taylor<ValueT> > :
151  public Sacado::Tay::ScalarTraitsImp< Sacado::Tay::Taylor<ValueT> >
152  {};
153 }
154 #endif
155 
156 // Serialization traits
157 #ifdef HAVE_SACADO_TEUCHOSCOMM
159 namespace Teuchos {
160  template <typename Ordinal, typename ValueT>
161  struct SerializationTraits<Ordinal, Sacado::Tay::Taylor<ValueT> > :
162  public Sacado::Tay::SerializationTraitsImp< Ordinal,
163  Sacado::Tay::Taylor<ValueT> >
164  {};
165 
166  template <typename Ordinal, typename ValueT>
167  struct ValueTypeSerializer<Ordinal, Sacado::Tay::Taylor<ValueT> > :
168  public Sacado::Tay::SerializerImp< Ordinal,
169  Sacado::Tay::Taylor<ValueT>,
170  ValueTypeSerializer<Ordinal,ValueT> >
171  {
172  typedef Sacado::Tay::Taylor<ValueT> TayType;
173  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
174  typedef Sacado::Tay::SerializerImp< Ordinal,TayType,ValueSerializer> Base;
175  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
176  Ordinal sz = 0) :
177  Base(vs, sz) {}
178  };
179 }
180 #endif
181 
182 #endif // SACADO_TAYLOR_SIMPLETAYLORTRAITS_HPP
static std::string eval()
static const scalar_type & eval(const Tay::Taylor< T > &x)
Base template specification for ScalarValue.
Base template specification for ScalarType.
Base template specification for string names of types.
static const value_type & eval(const Tay::Taylor< T > &x)
Base template specification for IsADType.
static bool eval(const Tay::Taylor< T > &x, const Tay::Taylor< T > &y)
Base template specification for Value.
ValueType< Tay::Taylor< T > >::type value_type
#define SACADO_AD_PROMOTE_SPEC(NS, AD)
ValueType< Tay::Taylor< T > >::type value_type
#define T
Definition: Sacado_rad.hpp:573
static const bool value
Base template specification for testing equivalence.
bool isEqualTo(const Taylor &x) const
Returns whether two Taylor objects have the same values.
const T & val() const
Returns value.
int Ordinal
ScalarType< Tay::Taylor< T > >::type scalar_type
Taylor polynomial class.
static const bool value
Base template specification for IsScalarType.
Base template specification for ValueType.
Base template specification for Promote.
static KOKKOS_INLINE_FUNCTION const T & eval(const T &x)
Base template specification for testing whether type is statically sized.