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_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_FAD_SFADTRAITS_HPP
31 #define SACADO_FAD_SFADTRAITS_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 #include <sstream>
43 
44 // Forward declarations
45 namespace Sacado {
46  namespace Fad {
47  template <typename T, int Num> class SFad;
48  }
49 }
50 
51 namespace Sacado {
52 
55 
56 
57  template <typename ValueT, int Num>
58  struct ScalarType< Fad::SFad<ValueT,Num> > {
60  };
61 
63  template <typename ValueT, int Num>
64  struct ValueType< Fad::SFad<ValueT,Num> > {
65  typedef ValueT type;
66  };
67 
69  template <typename ValueT, int Num>
70  struct IsADType< Fad::SFad<ValueT,Num> > {
71  static const bool value = true;
72  };
73 
75  template <typename ValueT, int Num>
76  struct IsScalarType< Fad::SFad<ValueT,Num> > {
77  static const bool value = false;
78  };
79 
81  template <typename ValueT, int Num>
82  struct IsSimdType< Fad::SFad<ValueT,Num> > {
83  static const bool value = IsSimdType<ValueT>::value;
84  };
85 
87  template <typename ValueT, int Num>
88  struct Value< Fad::SFad<ValueT,Num> > {
89  typedef typename ValueType< Fad::SFad<ValueT,Num> >::type value_type;
91  static const value_type& eval(const Fad::SFad<ValueT,Num>& x) {
92  return x.val(); }
93  };
94 
96  template <typename ValueT, int Num>
97  struct ScalarValue< Fad::SFad<ValueT,Num> > {
98  typedef typename ValueType< Fad::SFad<ValueT,Num> >::type value_type;
101  static const scalar_type& eval(const Fad::SFad<ValueT,Num>& x) {
102  return ScalarValue<value_type>::eval(x.val()); }
103  };
104 
106  template <typename ValueT, int Num>
107  struct StringName< Fad::SFad<ValueT,Num> > {
108  static std::string eval() {
109  std::stringstream ss;
110  ss << "Sacado::Fad::SFad< "
111  << StringName<ValueT>::eval() << ", " << Num << " >";
112  return ss.str();
113  }
114  };
115 
117  template <typename ValueT, int Num>
118  struct IsEqual< Fad::SFad<ValueT,Num> > {
120  static bool eval(const Fad::SFad<ValueT,Num>& x,
121  const Fad::SFad<ValueT,Num>& y) {
122  return x.isEqualTo(y);
123  }
124  };
125 
127  template <typename ValueT, int Num>
128  struct IsStaticallySized< Fad::SFad<ValueT,Num> > {
129  static const bool value = true;
130  };
131 
133  template <typename ValueT, int Num>
134  struct IsStaticallySized< const Fad::SFad<ValueT,Num> > {
135  static const bool value = true;
136  };
137 
139  template <typename ValueT, int Num>
140  struct StaticSize< Fad::SFad<ValueT,Num> > {
141  static const unsigned value = Num;
142  };
143 
145  template <typename ValueT, int Num>
146  struct StaticSize< const Fad::SFad<ValueT,Num> > {
147  static const unsigned value = Num;
148  };
149 
150 } // namespace Sacado
151 
152 //
153 // Define Teuchos traits classes
154 //
155 
156 // Promotion traits
157 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
159 namespace Teuchos {
160  template <typename ValueT, int Num>
161  struct PromotionTraits< Sacado::Fad::SFad<ValueT,Num>,
162  Sacado::Fad::SFad<ValueT,Num> > {
165  promote;
166  };
167 
168  template <typename ValueT, int Num, typename R>
169  struct PromotionTraits< Sacado::Fad::SFad<ValueT,Num>, R > {
170  typedef typename Sacado::Promote< Sacado::Fad::SFad<ValueT,Num>, R >::type
171  promote;
172  };
173 
174  template <typename L, typename ValueT, int Num>
175  struct PromotionTraits< L, Sacado::Fad::SFad<ValueT,Num> > {
176  public:
178  promote;
179  };
180 }
181 #endif
182 
183 // Scalar traits
184 #ifdef HAVE_SACADO_TEUCHOSCORE
186 namespace Teuchos {
187  template <typename ValueT, int Num>
188  struct ScalarTraits< Sacado::Fad::SFad<ValueT,Num> > :
189  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::SFad<ValueT,Num> >
190  {};
191 }
192 #endif
193 
194 // Serialization traits
195 #ifdef HAVE_SACADO_TEUCHOSCOMM
197 namespace Teuchos {
198  template <typename Ordinal, typename ValueT, int Num>
199  struct SerializationTraits<Ordinal, Sacado::Fad::SFad<ValueT,Num> > :
200  public Sacado::Fad::SerializationTraitsImp< Ordinal,
201  Sacado::Fad::SFad<ValueT,Num> >
202  {};
203 
204  template <typename Ordinal, typename ValueT, int Num>
205  struct ValueTypeSerializer<Ordinal, Sacado::Fad::SFad<ValueT,Num> > :
206  public Sacado::Fad::SerializerImp< Ordinal,
207  Sacado::Fad::SFad<ValueT,Num>,
208  ValueTypeSerializer<Ordinal,ValueT> >
209  {
211  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
212  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
213  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
214  Ordinal sz = 0) :
215  Base(vs, sz) {}
216  };
217 }
218 #endif
219 
220 // KokkosComm
221 #if defined(HAVE_SACADO_KOKKOS) && defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
222 #include "KokkosExp_View_Fad.hpp"
223 #endif
224 
225 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
226 
227 #endif // SACADO_FAD_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.
ValueType< Fad::SFad< ValueT, Num > >::type value_type
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 Fad::SFad< ValueT, Num > &x, const Fad::SFad< ValueT, Num > &y)
Base template specification for IsSimdType.
static SACADO_INLINE_FUNCTION const scalar_type & eval(const Fad::SFad< ValueT, Num > &x)
static const bool value
ValueType< Fad::SFad< ValueT, Num > >::type value_type
Base template specification for testing equivalence.
static const bool value
ScalarType< Fad::SFad< ValueT, Num > >::type scalar_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
static SACADO_INLINE_FUNCTION const value_type & eval(const Fad::SFad< ValueT, Num > &x)
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.