Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_ELRCacheFad_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_ELRCACHEFAD_SFADTRAITS_HPP
34 #define SACADO_ELRCACHEFAD_SFADTRAITS_HPP
35 
36 #include "Sacado_Traits.hpp"
37 #include <sstream>
38 
39 // Forward declarations
40 namespace Sacado {
41  namespace ELRCacheFad {
42  template <typename T, int Num> class SFad;
43  }
44 }
45 
46 namespace Sacado {
47 
49  SACADO_SFAD_PROMOTE_SPEC( ELRCacheFad, SFad )
50 
51 
52  template <typename ValueT, int Num>
53  struct ScalarType< ELRCacheFad::SFad<ValueT,Num> > {
55  };
56 
58  template <typename ValueT, int Num>
59  struct ValueType< ELRCacheFad::SFad<ValueT,Num> > {
60  typedef ValueT type;
61  };
62 
64  template <typename ValueT, int Num>
65  struct IsADType< ELRCacheFad::SFad<ValueT,Num> > {
66  static const bool value = true;
67  };
68 
70  template <typename ValueT, int Num>
71  struct IsScalarType< ELRCacheFad::SFad<ValueT,Num> > {
72  static const bool value = false;
73  };
74 
76  template <typename ValueT, int Num>
77  struct Value< ELRCacheFad::SFad<ValueT,Num> > {
81  return x.val(); }
82  };
83 
85  template <typename ValueT, int Num>
86  struct ScalarValue< ELRCacheFad::SFad<ValueT,Num> > {
91  return ScalarValue<value_type>::eval(x.val()); }
92  };
93 
95  template <typename ValueT, int Num>
96  struct StringName< ELRCacheFad::SFad<ValueT,Num> > {
97  static std::string eval() {
98  std::stringstream ss;
99  ss << "Sacado::ELRCacheFad::SFad< "
100  << StringName<ValueT>::eval() << ", " << Num << " >";
101  return ss.str();
102  }
103  };
104 
106  template <typename ValueT, int Num>
107  struct IsEqual< ELRCacheFad::SFad<ValueT,Num> > {
111  return x.isEqualTo(y);
112  }
113  };
114 
116  template <typename ValueT, int Num>
117  struct IsStaticallySized< ELRCacheFad::SFad<ValueT,Num> > {
118  static const bool value = true;
119  };
120 
122  template <typename ValueT, int Num>
123  struct IsStaticallySized< const ELRCacheFad::SFad<ValueT,Num> > {
124  static const bool value = true;
125  };
126 
128  template <typename ValueT, int Num>
129  struct StaticSize< ELRCacheFad::SFad<ValueT,Num> > {
130  static const unsigned value = Num;
131  };
132 
134  template <typename ValueT, int Num>
135  struct StaticSize< const ELRCacheFad::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::ELRCacheFad::SFad<ValueT,Num>,
151  Sacado::ELRCacheFad::SFad<ValueT,Num> > {
154  promote;
155  };
156 
157  template <typename ValueT, int Num, typename R>
158  struct PromotionTraits< Sacado::ELRCacheFad::SFad<ValueT,Num>, R > {
160  promote;
161  };
162 
163  template <typename L, typename ValueT, int Num>
164  struct PromotionTraits< L, Sacado::ELRCacheFad::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::ELRCacheFad::SFad<ValueT,Num> > :
178  public Sacado::Fad::ScalarTraitsImp< Sacado::ELRCacheFad::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::ELRCacheFad::SFad<ValueT,Num> > :
189  public Sacado::Fad::SerializationTraitsImp< Ordinal,
190  Sacado::ELRCacheFad::SFad<ValueT,Num> >
191  {};
192 
193  template <typename Ordinal, typename ValueT, int Num>
194  struct ValueTypeSerializer<Ordinal, Sacado::ELRCacheFad::SFad<ValueT,Num> > :
195  public Sacado::Fad::SerializerImp< Ordinal,
196  Sacado::ELRCacheFad::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_ELRCACHEFAD_SFADTRAITS_HPP
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
static std::string eval()
ScalarType< ELRCacheFad::SFad< ValueT, Num > >::type scalar_type
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 const scalar_type & eval(const ELRCacheFad::SFad< ValueT, Num > &x)
ValueType< ELRCacheFad::SFad< ValueT, Num > >::type value_type
static SACADO_INLINE_FUNCTION const value_type & eval(const ELRCacheFad::SFad< ValueT, Num > &x)
static SACADO_INLINE_FUNCTION bool eval(const ELRCacheFad::SFad< ValueT, Num > &x, const ELRCacheFad::SFad< ValueT, Num > &y)
static const bool value
Base template specification for testing equivalence.
ValueType< ELRCacheFad::SFad< ValueT, Num > >::type value_type
int Ordinal
static const bool value
Base template specification for IsScalarType.
#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.