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_DFadTraits.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_DFADTRAITS_HPP
31 #define SACADO_FAD_DFADTRAITS_HPP
32 
33 #include "Sacado_ConfigDefs.h"
34 
35 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
36 
38 
39 #else
40 
41 #include "Sacado_Traits.hpp"
42 
43 // Forward declarations
44 namespace Sacado {
45  namespace Fad {
46  template <typename T> class DFad;
47  }
48 }
49 
50 namespace Sacado {
51 
54 
55 
56  template <typename ValueT>
57  struct ScalarType< Fad::DFad<ValueT> > {
58  typedef typename Fad::DFad<ValueT>::ScalarT type;
59  };
60 
62  template <typename ValueT>
63  struct ValueType< Fad::DFad<ValueT> > {
64  typedef ValueT type;
65  };
66 
68  template <typename ValueT>
69  struct IsADType< Fad::DFad<ValueT> > {
70  static const bool value = true;
71  };
72 
74  template <typename ValueT>
75  struct IsScalarType< Fad::DFad<ValueT> > {
76  static const bool value = false;
77  };
78 
80  template <typename ValueT>
81  struct IsSimdType< Fad::DFad<ValueT> > {
82  static const bool value = IsSimdType<ValueT>::value;
83  };
84 
86  template <typename ValueT>
87  struct Value< Fad::DFad<ValueT> > {
88  typedef typename ValueType< Fad::DFad<ValueT> >::type value_type;
90  static const value_type& eval(const Fad::DFad<ValueT>& x) {
91  return x.val(); }
92  };
93 
95  template <typename ValueT>
96  struct ScalarValue< Fad::DFad<ValueT> > {
97  typedef typename ValueType< Fad::DFad<ValueT> >::type value_type;
98  typedef typename ScalarType< Fad::DFad<ValueT> >::type scalar_type;
100  static const scalar_type& eval(const Fad::DFad<ValueT>& x) {
101  return ScalarValue<value_type>::eval(x.val()); }
102  };
103 
105  template <typename ValueT>
106  struct StringName< Fad::DFad<ValueT> > {
107  static std::string eval() {
108  return std::string("Sacado::Fad::DFad< ") +
109  StringName<ValueT>::eval() + " >"; }
110  };
111 
113  template <typename ValueT>
114  struct IsEqual< Fad::DFad<ValueT> > {
116  static bool eval(const Fad::DFad<ValueT>& x, const Fad::DFad<ValueT>& y) {
117  return x.isEqualTo(y);
118  }
119  };
120 
122  template <typename ValueT>
123  struct IsStaticallySized< Fad::DFad<ValueT> > {
124  static const bool value = false;
125  };
126 
128  template <typename ValueT>
129  struct IsStaticallySized< const Fad::DFad<ValueT> > {
130  static const bool value = false;
131  };
132 
133 } // namespace Sacado
134 
135 //
136 // Define Teuchos traits classes
137 //
138 
139 // Promotion traits
140 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
142 namespace Teuchos {
143  template <typename ValueT>
144  struct PromotionTraits< Sacado::Fad::DFad<ValueT>,
145  Sacado::Fad::DFad<ValueT> > {
148  promote;
149  };
150 
151  template <typename ValueT, typename R>
152  struct PromotionTraits< Sacado::Fad::DFad<ValueT>, R > {
153  typedef typename Sacado::Promote< Sacado::Fad::DFad<ValueT>, R >::type
154  promote;
155  };
156 
157  template <typename L, typename ValueT>
158  struct PromotionTraits< L, Sacado::Fad::DFad<ValueT> > {
159  public:
160  typedef typename Sacado::Promote< L, Sacado::Fad::DFad<ValueT> >::type
161  promote;
162  };
163 }
164 #endif
165 
166 // Scalar traits
167 #ifdef HAVE_SACADO_TEUCHOSCORE
169 namespace Teuchos {
170  template <typename ValueT>
171  struct ScalarTraits< Sacado::Fad::DFad<ValueT> > :
172  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::DFad<ValueT> >
173  {};
174 }
175 #endif
176 
177 // Serialization traits
178 #ifdef HAVE_SACADO_TEUCHOSCOMM
180 namespace Teuchos {
181  template <typename Ordinal, typename ValueT>
182  struct SerializationTraits<Ordinal, Sacado::Fad::DFad<ValueT> > :
183  public Sacado::Fad::SerializationTraitsImp< Ordinal,
184  Sacado::Fad::DFad<ValueT> >
185  {};
186 
187  template <typename Ordinal, typename ValueT>
188  struct ValueTypeSerializer<Ordinal, Sacado::Fad::DFad<ValueT> > :
189  public Sacado::Fad::SerializerImp< Ordinal,
190  Sacado::Fad::DFad<ValueT>,
191  ValueTypeSerializer<Ordinal,ValueT> >
192  {
194  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
195  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
196  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
197  Ordinal sz = 0) :
198  Base(vs, sz) {}
199  };
200 }
201 #endif
202 
203 // KokkosComm
204 #if defined(HAVE_SACADO_KOKKOS) && defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
205 #include "KokkosExp_View_Fad.hpp"
206 #endif
207 
208 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
209 
210 #endif // SACADO_FAD_DFADTRAITS_HPP
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
static std::string eval()
Base template specification for ScalarValue.
Base template specification for ScalarType.
Base template specification for string names of types.
Base template specification for IsADType.
Sacado::Fad::DFad< double > FadType
static SACADO_INLINE_FUNCTION bool eval(const Fad::DFad< ValueT > &x, const Fad::DFad< ValueT > &y)
static SACADO_INLINE_FUNCTION const value_type & eval(const Fad::DFad< ValueT > &x)
Base template specification for Value.
Base template specification for IsSimdType.
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
static const bool value
GeneralFad< DynamicStorage< T > > DFad
Base template specification for testing equivalence.
static SACADO_INLINE_FUNCTION const scalar_type & eval(const Fad::DFad< ValueT > &x)
ScalarType< Fad::DFad< ValueT > >::type scalar_type
static const bool value
int Ordinal
ValueType< Fad::DFad< ValueT > >::type value_type
ValueType< Fad::DFad< ValueT > >::type value_type
static const bool value
Base template specification for IsScalarType.
#define SACADO_INLINE_FUNCTION
Base template specification for ValueType.
Base template specification for Promote.
const double y
Base template specification for testing whether type is statically sized.