Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_CacheFad_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_CACHEFAD_DFADTRAITS_HPP
31 #define SACADO_CACHEFAD_DFADTRAITS_HPP
32 
33 #include "Sacado_Traits.hpp"
34 
35 // Forward declarations
36 namespace Sacado {
37  namespace CacheFad {
38  template <typename T> class DFad;
39  }
40 }
41 
42 namespace Sacado {
43 
45  SACADO_FAD_PROMOTE_SPEC( CacheFad, DFad )
46 
47 
48  template <typename ValueT>
49  struct ScalarType< CacheFad::DFad<ValueT> > {
51  };
52 
54  template <typename ValueT>
55  struct ValueType< CacheFad::DFad<ValueT> > {
56  typedef ValueT type;
57  };
58 
60  template <typename ValueT>
61  struct IsADType< CacheFad::DFad<ValueT> > {
62  static const bool value = true;
63  };
64 
66  template <typename ValueT>
67  struct IsScalarType< CacheFad::DFad<ValueT> > {
68  static const bool value = false;
69  };
70 
72  template <typename ValueT>
73  struct Value< CacheFad::DFad<ValueT> > {
76  static const value_type& eval(const CacheFad::DFad<ValueT>& x) {
77  return x.val(); }
78  };
79 
81  template <typename ValueT>
82  struct ScalarValue< CacheFad::DFad<ValueT> > {
86  static const scalar_type& eval(const CacheFad::DFad<ValueT>& x) {
87  return ScalarValue<value_type>::eval(x.val()); }
88  };
89 
91  template <typename ValueT>
92  struct StringName< CacheFad::DFad<ValueT> > {
93  static std::string eval() {
94  return std::string("Sacado::CacheFad::DFad< ") +
95  StringName<ValueT>::eval() + " >"; }
96  };
97 
99  template <typename ValueT>
100  struct IsEqual< CacheFad::DFad<ValueT> > {
102  static bool eval(const CacheFad::DFad<ValueT>& x,
103  const CacheFad::DFad<ValueT>& y) {
104  return x.isEqualTo(y);
105  }
106  };
107 
109  template <typename ValueT>
110  struct IsStaticallySized< CacheFad::DFad<ValueT> > {
111  static const bool value = false;
112  };
113 
115  template <typename ValueT>
116  struct IsStaticallySized< const CacheFad::DFad<ValueT> > {
117  static const bool value = false;
118  };
119 
120 } // namespace Sacado
121 
122 //
123 // Define Teuchos traits classes
124 //
125 
126 // Promotion traits
127 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
129 namespace Teuchos {
130  template <typename ValueT>
131  struct PromotionTraits< Sacado::CacheFad::DFad<ValueT>,
132  Sacado::CacheFad::DFad<ValueT> > {
135  promote;
136  };
137 
138  template <typename ValueT, typename R>
139  struct PromotionTraits< Sacado::CacheFad::DFad<ValueT>, R > {
140  typedef typename Sacado::Promote< Sacado::CacheFad::DFad<ValueT>, R >::type
141  promote;
142  };
143 
144  template <typename L, typename ValueT>
145  struct PromotionTraits< L, Sacado::CacheFad::DFad<ValueT> > {
146  public:
148  promote;
149  };
150 }
151 #endif
152 
153 // Scalar traits
154 #ifdef HAVE_SACADO_TEUCHOSCORE
156 namespace Teuchos {
157  template <typename ValueT>
158  struct ScalarTraits< Sacado::CacheFad::DFad<ValueT> > :
159  public Sacado::Fad::ScalarTraitsImp< Sacado::CacheFad::DFad<ValueT> >
160  {};
161 }
162 #endif
163 
164 // Serialization traits
165 #ifdef HAVE_SACADO_TEUCHOSCOMM
167 namespace Teuchos {
168  template <typename Ordinal, typename ValueT>
169  struct SerializationTraits<Ordinal, Sacado::CacheFad::DFad<ValueT> > :
170  public Sacado::Fad::SerializationTraitsImp< Ordinal,
171  Sacado::CacheFad::DFad<ValueT> >
172  {};
173 
174  template <typename Ordinal, typename ValueT>
175  struct ValueTypeSerializer<Ordinal, Sacado::CacheFad::DFad<ValueT> > :
176  public Sacado::Fad::SerializerImp< Ordinal,
177  Sacado::CacheFad::DFad<ValueT>,
178  ValueTypeSerializer<Ordinal,ValueT> >
179  {
181  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
182  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
183  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
184  Ordinal sz = 0) :
185  Base(vs, sz) {}
186  };
187 }
188 #endif
189 
190 // KokkosComm
191 #if defined(HAVE_SACADO_KOKKOS) && defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
192 #include "KokkosExp_View_Fad.hpp"
193 #endif
194 
195 #endif // SACADO_FAD_DFADTRAITS_HPP
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
static SACADO_INLINE_FUNCTION const value_type & eval(const CacheFad::DFad< ValueT > &x)
static std::string eval()
Base template specification for ScalarValue.
Base template specification for ScalarType.
ScalarType< CacheFad::DFad< ValueT > >::type scalar_type
Base template specification for string names of types.
Base template specification for IsADType.
Sacado::Fad::DFad< double > FadType
ValueType< CacheFad::DFad< ValueT > >::type value_type
Base template specification for Value.
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
static const bool value
ValueType< CacheFad::DFad< ValueT > >::type value_type
GeneralFad< DynamicStorage< T > > DFad
Base template specification for testing equivalence.
int Ordinal
static const bool value
static SACADO_INLINE_FUNCTION const scalar_type & eval(const CacheFad::DFad< ValueT > &x)
Base template specification for IsScalarType.
#define SACADO_INLINE_FUNCTION
static SACADO_INLINE_FUNCTION bool eval(const CacheFad::DFad< ValueT > &x, const CacheFad::DFad< ValueT > &y)
Base template specification for ValueType.
Base template specification for Promote.
const double y
Base template specification for testing whether type is statically sized.