Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_ELRFad_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 // NumericalTraits class to illustrate TRAITS
26 //
27 //********************************************************
28 // @HEADER
29 
30 #ifndef SACADO_ELRFAD_SFADTRAITS_HPP
31 #define SACADO_ELRFAD_SFADTRAITS_HPP
32 
33 #include "Sacado_Traits.hpp"
34 #include <sstream>
35 
36 // Forward declarations
37 namespace Sacado {
38  namespace ELRFad {
39  template <typename T, int Num> class SFad;
40  }
41 }
42 
43 namespace Sacado {
44 
47 
48 
49  template <typename ValueT, int Num>
50  struct ScalarType< ELRFad::SFad<ValueT,Num> > {
52  };
53 
55  template <typename ValueT, int Num>
56  struct ValueType< ELRFad::SFad<ValueT,Num> > {
57  typedef ValueT type;
58  };
59 
61  template <typename ValueT, int Num>
62  struct IsADType< ELRFad::SFad<ValueT,Num> > {
63  static const bool value = true;
64  };
65 
67  template <typename ValueT, int Num>
68  struct IsScalarType< ELRFad::SFad<ValueT,Num> > {
69  static const bool value = false;
70  };
71 
73  template <typename ValueT, int Num>
74  struct Value< ELRFad::SFad<ValueT,Num> > {
77  static const value_type& eval(const ELRFad::SFad<ValueT,Num>& x) {
78  return x.val(); }
79  };
80 
82  template <typename ValueT, int Num>
83  struct ScalarValue< ELRFad::SFad<ValueT,Num> > {
87  static const scalar_type& eval(const ELRFad::SFad<ValueT,Num>& x) {
88  return ScalarValue<value_type>::eval(x.val()); }
89  };
90 
92  template <typename ValueT, int Num>
93  struct StringName< ELRFad::SFad<ValueT,Num> > {
94  static std::string eval() {
95  std::stringstream ss;
96  ss << "Sacado::ELRFad::SFad< "
97  << StringName<ValueT>::eval() << ", " << Num << " >";
98  return ss.str();
99  }
100  };
101 
103  template <typename ValueT, int Num>
104  struct IsEqual< ELRFad::SFad<ValueT,Num> > {
106  static bool eval(const ELRFad::SFad<ValueT,Num>& x,
107  const ELRFad::SFad<ValueT,Num>& y) {
108  return x.isEqualTo(y);
109  }
110  };
111 
113  template <typename ValueT, int Num>
114  struct IsStaticallySized< ELRFad::SFad<ValueT,Num> > {
115  static const bool value = true;
116  };
117 
119  template <typename ValueT, int Num>
120  struct IsStaticallySized< const ELRFad::SFad<ValueT,Num> > {
121  static const bool value = true;
122  };
123 
125  template <typename ValueT, int Num>
126  struct StaticSize< ELRFad::SFad<ValueT,Num> > {
127  static const unsigned value = Num;
128  };
129 
131  template <typename ValueT, int Num>
132  struct StaticSize< const ELRFad::SFad<ValueT,Num> > {
133  static const unsigned value = Num;
134  };
135 
136 } // namespace Sacado
137 
138 //
139 // Define Teuchos traits classes
140 //
141 
142 // Promotion traits
143 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
145 namespace Teuchos {
146  template <typename ValueT, int Num>
147  struct PromotionTraits< Sacado::ELRFad::SFad<ValueT,Num>,
148  Sacado::ELRFad::SFad<ValueT,Num> > {
151  promote;
152  };
153 
154  template <typename ValueT, int Num, typename R>
155  struct PromotionTraits< Sacado::ELRFad::SFad<ValueT,Num>, R > {
156  typedef typename Sacado::Promote< Sacado::ELRFad::SFad<ValueT,Num>, R >::type
157  promote;
158  };
159 
160  template <typename L, typename ValueT, int Num>
161  struct PromotionTraits< L, Sacado::ELRFad::SFad<ValueT,Num> > {
162  public:
164  promote;
165  };
166 }
167 #endif
168 
169 // Scalar traits
170 #ifdef HAVE_SACADO_TEUCHOSCORE
172 namespace Teuchos {
173  template <typename ValueT, int Num>
174  struct ScalarTraits< Sacado::ELRFad::SFad<ValueT,Num> > :
175  public Sacado::Fad::ScalarTraitsImp< Sacado::ELRFad::SFad<ValueT,Num> >
176  {};
177 }
178 #endif
179 
180 // Serialization traits
181 #ifdef HAVE_SACADO_TEUCHOSCOMM
183 namespace Teuchos {
184  template <typename Ordinal, typename ValueT, int Num>
185  struct SerializationTraits<Ordinal, Sacado::ELRFad::SFad<ValueT,Num> > :
186  public Sacado::Fad::SerializationTraitsImp< Ordinal,
187  Sacado::ELRFad::SFad<ValueT,Num> >
188  {};
189 
190  template <typename Ordinal, typename ValueT, int Num>
191  struct ValueTypeSerializer<Ordinal, Sacado::ELRFad::SFad<ValueT,Num> > :
192  public Sacado::Fad::SerializerImp< Ordinal,
193  Sacado::ELRFad::SFad<ValueT,Num>,
194  ValueTypeSerializer<Ordinal,ValueT> >
195  {
197  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
198  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
199  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
200  Ordinal sz = 0) :
201  Base(vs, sz) {}
202  };
203 }
204 #endif
205 
206 // KokkosComm
207 #if defined(HAVE_SACADO_KOKKOS) && defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
208 #include "KokkosExp_View_Fad.hpp"
209 #endif
210 
211 #endif // SACADO_ELRFAD_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.
ScalarType< ELRFad::SFad< ValueT, Num > >::type scalar_type
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 value_type & eval(const ELRFad::SFad< ValueT, Num > &x)
static const bool value
static SACADO_INLINE_FUNCTION const scalar_type & eval(const ELRFad::SFad< ValueT, Num > &x)
Base template specification for testing equivalence.
ValueType< ELRFad::SFad< ValueT, Num > >::type value_type
int Ordinal
static SACADO_INLINE_FUNCTION bool eval(const ELRFad::SFad< ValueT, Num > &x, const ELRFad::SFad< ValueT, Num > &y)
ValueType< ELRFad::SFad< ValueT, Num > >::type value_type
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.