Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Fad_SimpleFadTraits.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 // ***********************************************************************
9 //
10 // The forward-mode AD classes in Sacado are a derivative work of the
11 // expression template classes in the Fad package by Nicolas Di Cesare.
12 // The following banner is included in the original Fad source code:
13 //
14 // ************ DO NOT REMOVE THIS BANNER ****************
15 //
16 // Nicolas Di Cesare <Nicolas.Dicesare@ann.jussieu.fr>
17 // http://www.ann.jussieu.fr/~dicesare
18 //
19 // CEMRACS 98 : C++ courses,
20 // templates : new C++ techniques
21 // for scientific computing
22 //
23 //********************************************************
24 //
25 // NumericalTraits class to illustrate TRAITS
26 //
27 //********************************************************
28 // @HEADER
29 
30 #ifndef SACADO_FAD_SIMPLEFADTRAITS_HPP
31 #define SACADO_FAD_SIMPLEFADTRAITS_HPP
32 
33 #include "Sacado_Traits.hpp"
34 
35 // Forward declarations
36 namespace Sacado {
37  namespace Fad {
38  template <typename T> class SimpleFad;
39  }
40 }
41 
42 namespace Sacado {
43 
45  SACADO_FAD_PROMOTE_SPEC( Fad, SimpleFad )
46 
47 
48  template <typename ValueT>
49  struct ScalarType< Fad::SimpleFad<ValueT> > {
51  };
52 
54  template <typename ValueT>
55  struct ValueType< Fad::SimpleFad<ValueT> > {
56  typedef ValueT type;
57  };
58 
60  template <typename ValueT>
61  struct IsADType< Fad::SimpleFad<ValueT> > {
62  static const bool value = true;
63  };
64 
66  template <typename ValueT>
67  struct IsScalarType< Fad::SimpleFad<ValueT> > {
68  static const bool value = false;
69  };
70 
72  template <typename ValueT>
73  struct IsSimdType< Fad::SimpleFad<ValueT> > {
74  static const bool value = IsSimdType<ValueT>::value;
75  };
76 
78  template <typename ValueT>
79  struct Value< Fad::SimpleFad<ValueT> > {
81  static const value_type& eval(const Fad::SimpleFad<ValueT>& x) {
82  return x.val(); }
83  };
84 
86  template <typename ValueT>
87  struct ScalarValue< Fad::SimpleFad<ValueT> > {
90  static const scalar_type& eval(const Fad::SimpleFad<ValueT>& x) {
91  return ScalarValue<value_type>::eval(x.val()); }
92  };
93 
95  template <typename ValueT>
96  struct StringName< Fad::SimpleFad<ValueT> > {
97  static std::string eval() {
98  return std::string("Sacado::Fad::SimpleFad< ") +
99  StringName<ValueT>::eval() + " >"; }
100  };
101 
103  template <typename ValueT>
104  struct IsEqual< Fad::SimpleFad<ValueT> > {
105  static bool eval(const Fad::SimpleFad<ValueT>& x,
106  const Fad::SimpleFad<ValueT>& y) {
107  return x.isEqualTo(y);
108  }
109  };
110 
112  template <typename ValueT>
113  struct IsStaticallySized< Fad::SimpleFad<ValueT> > {
114  static const bool value = false;
115  };
116 
118  template <typename ValueT>
119  struct IsFad< Fad::SimpleFad<ValueT> > {
120  static const bool value = true;
121  };
122 
123 } // namespace Sacado
124 
125 //
126 // Define Teuchos traits classes
127 //
128 
129 // Promotion traits
130 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
132 namespace Teuchos {
133  template <typename ValueT>
134  struct PromotionTraits< Sacado::Fad::SimpleFad<ValueT>,
135  Sacado::Fad::SimpleFad<ValueT> > {
138  promote;
139  };
140 
141  template <typename ValueT, typename R>
142  struct PromotionTraits< Sacado::Fad::SimpleFad<ValueT>, R > {
143  typedef typename Sacado::Promote< Sacado::Fad::SimpleFad<ValueT>, R >::type
144  promote;
145  };
146 
147  template <typename L, typename ValueT>
148  struct PromotionTraits< L, Sacado::Fad::SimpleFad<ValueT> > {
149  public:
151  promote;
152  };
153 }
154 #endif
155 
156 // Scalar traits
157 #ifdef HAVE_SACADO_TEUCHOSCORE
159 namespace Teuchos {
160  template <typename ValueT>
161  struct ScalarTraits< Sacado::Fad::SimpleFad<ValueT> > :
162  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::SimpleFad<ValueT> >
163  {};
164 }
165 #endif
166 
167 // Serialization traits
168 #ifdef HAVE_SACADO_TEUCHOSCOMM
170 namespace Teuchos {
171  template <typename Ordinal, typename ValueT>
172  struct SerializationTraits<Ordinal, Sacado::Fad::SimpleFad<ValueT> > :
173  public Sacado::Fad::SerializationTraitsImp< Ordinal,
174  Sacado::Fad::SimpleFad<ValueT> >
175  {};
176 
177  template <typename Ordinal, typename ValueT>
178  struct ValueTypeSerializer<Ordinal, Sacado::Fad::SimpleFad<ValueT> > :
179  public Sacado::Fad::SerializerImp< Ordinal,
180  Sacado::Fad::SimpleFad<ValueT>,
181  ValueTypeSerializer<Ordinal,ValueT> >
182  {
184  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
185  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
186  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
187  Ordinal sz = 0) :
188  Base(vs, sz) {}
189  };
190 }
191 #endif
192 
193 #endif // SACADO_FAD_SIMPLEFADTRAITS_HPP
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
static bool eval(const Fad::SimpleFad< ValueT > &x, const Fad::SimpleFad< ValueT > &y)
static std::string eval()
ValueType< Fad::SimpleFad< ValueT > >::type value_type
Base template specification for ScalarValue.
Base template specification for ScalarType.
Base template specification for whether a type is a Fad type.
Base template specification for string names of types.
Base template specification for IsADType.
static const scalar_type & eval(const Fad::SimpleFad< ValueT > &x)
Sacado::Fad::DFad< double > FadType
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
Base template specification for Value.
Forward-mode AD class using dynamic memory allocation but no expression templates.
Base template specification for IsSimdType.
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
static const bool value
Base template specification for testing equivalence.
bool isEqualTo(const SimpleFad &x) const
Returns whether two Fad objects have the same values.
SACADO_INLINE_FUNCTION const ValueT & val() const
Returns value.
ScalarType< Fad::SimpleFad< ValueT > >::type scalar_type
static const bool value
int Ordinal
static const bool value
Base template specification for IsScalarType.
static const value_type & eval(const Fad::SimpleFad< ValueT > &x)
static const bool value
Base template specification for ValueType.
Base template specification for Promote.
ValueType< Fad::SimpleFad< ValueT > >::type value_type
const double y
Base template specification for testing whether type is statically sized.