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_SFadTraits.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 // A short implementation ( not all operators and
26 // functions are overloaded ) of 1st order Automatic
27 // Differentiation in forward mode (FAD) using
28 // EXPRESSION TEMPLATES.
29 //
30 //********************************************************
31 // @HEADER
32 
33 #ifndef SACADO_CACHEFAD_SFADTRAITS_HPP
34 #define SACADO_CACHEFAD_SFADTRAITS_HPP
35 
36 #include "Sacado_Traits.hpp"
37 #include <sstream>
38 
39 // Forward declarations
40 namespace Sacado {
41  namespace CacheFad {
42  template <typename T, int Num> class SFad;
43  }
44 }
45 
46 namespace Sacado {
47 
49  SACADO_SFAD_PROMOTE_SPEC( CacheFad, SFad )
50 
51 
52  template <typename ValueT, int Num>
53  struct ScalarType< CacheFad::SFad<ValueT,Num> > {
55  };
56 
58  template <typename ValueT, int Num>
59  struct ValueType< CacheFad::SFad<ValueT,Num> > {
60  typedef ValueT type;
61  };
62 
64  template <typename ValueT, int Num>
65  struct IsADType< CacheFad::SFad<ValueT,Num> > {
66  static const bool value = true;
67  };
68 
70  template <typename ValueT, int Num>
71  struct IsScalarType< CacheFad::SFad<ValueT,Num> > {
72  static const bool value = false;
73  };
74 
76  template <typename ValueT, int Num>
77  struct Value< CacheFad::SFad<ValueT,Num> > {
80  static const value_type& eval(const CacheFad::SFad<ValueT,Num>& x) {
81  return x.val(); }
82  };
83 
85  template <typename ValueT, int Num>
86  struct ScalarValue< CacheFad::SFad<ValueT,Num> > {
90  static const scalar_type& eval(const CacheFad::SFad<ValueT,Num>& x) {
91  return ScalarValue<value_type>::eval(x.val()); }
92  };
93 
95  template <typename ValueT, int Num>
96  struct StringName< CacheFad::SFad<ValueT,Num> > {
97  static std::string eval() {
98  std::stringstream ss;
99  ss << "Sacado::CacheFad::SFad< "
100  << StringName<ValueT>::eval() << ", " << Num << " >";
101  return ss.str();
102  }
103  };
104 
106  template <typename ValueT, int Num>
107  struct IsEqual< CacheFad::SFad<ValueT,Num> > {
109  static bool eval(const CacheFad::SFad<ValueT,Num>& x,
110  const CacheFad::SFad<ValueT,Num>& y) {
111  return x.isEqualTo(y);
112  }
113  };
114 
116  template <typename ValueT, int Num>
117  struct IsStaticallySized< CacheFad::SFad<ValueT,Num> > {
118  static const bool value = true;
119  };
120 
122  template <typename ValueT, int Num>
123  struct IsStaticallySized< const CacheFad::SFad<ValueT,Num> > {
124  static const bool value = true;
125  };
126 
128  template <typename ValueT, int Num>
129  struct StaticSize< CacheFad::SFad<ValueT,Num> > {
130  static const unsigned value = Num;
131  };
132 
134  template <typename ValueT, int Num>
135  struct StaticSize< const CacheFad::SFad<ValueT,Num> > {
136  static const unsigned value = Num;
137  };
138 
139 } // namespace Sacado
140 
141 //
142 // Define Teuchos traits classes
143 //
144 
145 // Promotion traits
146 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
148 namespace Teuchos {
149  template <typename ValueT, int Num>
150  struct PromotionTraits< Sacado::CacheFad::SFad<ValueT,Num>,
151  Sacado::CacheFad::SFad<ValueT,Num> > {
154  promote;
155  };
156 
157  template <typename ValueT, int Num, typename R>
158  struct PromotionTraits< Sacado::CacheFad::SFad<ValueT,Num>, R > {
160  promote;
161  };
162 
163  template <typename L, typename ValueT, int Num>
164  struct PromotionTraits< L, Sacado::CacheFad::SFad<ValueT,Num> > {
165  public:
167  promote;
168  };
169 }
170 #endif
171 
172 // Scalar traits
173 #ifdef HAVE_SACADO_TEUCHOSCORE
175 namespace Teuchos {
176  template <typename ValueT, int Num>
177  struct ScalarTraits< Sacado::CacheFad::SFad<ValueT,Num> > :
178  public Sacado::Fad::ScalarTraitsImp< Sacado::CacheFad::SFad<ValueT,Num> >
179  {};
180 }
181 #endif
182 
183 // Serialization traits
184 #ifdef HAVE_SACADO_TEUCHOSCOMM
186 namespace Teuchos {
187  template <typename Ordinal, typename ValueT, int Num>
188  struct SerializationTraits<Ordinal, Sacado::CacheFad::SFad<ValueT,Num> > :
189  public Sacado::Fad::SerializationTraitsImp< Ordinal,
190  Sacado::CacheFad::SFad<ValueT,Num> >
191  {};
192 
193  template <typename Ordinal, typename ValueT, int Num>
194  struct ValueTypeSerializer<Ordinal, Sacado::CacheFad::SFad<ValueT,Num> > :
195  public Sacado::Fad::SerializerImp< Ordinal,
196  Sacado::CacheFad::SFad<ValueT,Num>,
197  ValueTypeSerializer<Ordinal,ValueT> >
198  {
200  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
201  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
202  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
203  Ordinal sz = 0) :
204  Base(vs, sz) {}
205  };
206 }
207 #endif
208 
209 // KokkosComm
210 #if defined(HAVE_SACADO_KOKKOS) && defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
211 #include "KokkosExp_View_Fad.hpp"
212 #endif
213 
214 #endif // SACADO_CACHEFAD_SFADTRAITS_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
Base template specification for static size.
Base template specification for Value.
static SACADO_INLINE_FUNCTION bool eval(const CacheFad::SFad< ValueT, Num > &x, const CacheFad::SFad< ValueT, Num > &y)
ScalarType< CacheFad::SFad< ValueT, Num > >::type scalar_type
static const bool value
ValueType< CacheFad::SFad< ValueT, Num > >::type value_type
Base template specification for testing equivalence.
static SACADO_INLINE_FUNCTION const value_type & eval(const CacheFad::SFad< ValueT, Num > &x)
int Ordinal
static const bool value
ValueType< CacheFad::SFad< ValueT, Num > >::type value_type
Base template specification for IsScalarType.
static SACADO_INLINE_FUNCTION const scalar_type & eval(const CacheFad::SFad< ValueT, Num > &x)
#define SACADO_SFAD_PROMOTE_SPEC(NS, FAD)
#define SACADO_INLINE_FUNCTION
static const unsigned value
GeneralFad< StaticFixedStorage< T, Num > > SFad
Base template specification for ValueType.
Base template specification for Promote.
const double y
Base template specification for testing whether type is statically sized.