Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_SFadTraits.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 //
29 // The forward-mode AD classes in Sacado are a derivative work of the
30 // expression template classes in the Fad package by Nicolas Di Cesare.
31 // The following banner is included in the original Fad source code:
32 //
33 // ************ DO NOT REMOVE THIS BANNER ****************
34 //
35 // Nicolas Di Cesare <Nicolas.Dicesare@ann.jussieu.fr>
36 // http://www.ann.jussieu.fr/~dicesare
37 //
38 // CEMRACS 98 : C++ courses,
39 // templates : new C++ techniques
40 // for scientific computing
41 //
42 //********************************************************
43 //
44 // NumericalTraits class to illustrate TRAITS
45 //
46 //********************************************************
47 // @HEADER
48 
49 #ifndef SACADO_FAD_SFADTRAITS_HPP
50 #define SACADO_FAD_SFADTRAITS_HPP
51 
52 #include "Sacado_ConfigDefs.h"
53 
54 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
55 
57 
58 #else
59 
60 #include "Sacado_Traits.hpp"
61 #include <sstream>
62 
63 // Forward declarations
64 namespace Sacado {
65  namespace Fad {
66  template <typename T, int Num> class SFad;
67  }
68 }
69 
70 namespace Sacado {
71 
74 
75 
76  template <typename ValueT, int Num>
77  struct ScalarType< Fad::SFad<ValueT,Num> > {
79  };
80 
82  template <typename ValueT, int Num>
83  struct ValueType< Fad::SFad<ValueT,Num> > {
84  typedef ValueT type;
85  };
86 
88  template <typename ValueT, int Num>
89  struct IsADType< Fad::SFad<ValueT,Num> > {
90  static const bool value = true;
91  };
92 
94  template <typename ValueT, int Num>
95  struct IsScalarType< Fad::SFad<ValueT,Num> > {
96  static const bool value = false;
97  };
98 
100  template <typename ValueT, int Num>
101  struct IsSimdType< Fad::SFad<ValueT,Num> > {
102  static const bool value = IsSimdType<ValueT>::value;
103  };
104 
106  template <typename ValueT, int Num>
107  struct Value< Fad::SFad<ValueT,Num> > {
110  static const value_type& eval(const Fad::SFad<ValueT,Num>& x) {
111  return x.val(); }
112  };
113 
115  template <typename ValueT, int Num>
116  struct ScalarValue< Fad::SFad<ValueT,Num> > {
120  static const scalar_type& eval(const Fad::SFad<ValueT,Num>& x) {
121  return ScalarValue<value_type>::eval(x.val()); }
122  };
123 
125  template <typename ValueT, int Num>
126  struct StringName< Fad::SFad<ValueT,Num> > {
127  static std::string eval() {
128  std::stringstream ss;
129  ss << "Sacado::Fad::SFad< "
130  << StringName<ValueT>::eval() << ", " << Num << " >";
131  return ss.str();
132  }
133  };
134 
136  template <typename ValueT, int Num>
137  struct IsEqual< Fad::SFad<ValueT,Num> > {
139  static bool eval(const Fad::SFad<ValueT,Num>& x,
140  const Fad::SFad<ValueT,Num>& y) {
141  return x.isEqualTo(y);
142  }
143  };
144 
146  template <typename ValueT, int Num>
147  struct IsStaticallySized< Fad::SFad<ValueT,Num> > {
148  static const bool value = true;
149  };
150 
152  template <typename ValueT, int Num>
153  struct IsStaticallySized< const Fad::SFad<ValueT,Num> > {
154  static const bool value = true;
155  };
156 
158  template <typename ValueT, int Num>
159  struct StaticSize< Fad::SFad<ValueT,Num> > {
160  static const unsigned value = Num;
161  };
162 
164  template <typename ValueT, int Num>
165  struct StaticSize< const Fad::SFad<ValueT,Num> > {
166  static const unsigned value = Num;
167  };
168 
169 } // namespace Sacado
170 
171 //
172 // Define Teuchos traits classes
173 //
174 
175 // Promotion traits
176 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
177 #include "Teuchos_PromotionTraits.hpp"
178 namespace Teuchos {
179  template <typename ValueT, int Num>
180  struct PromotionTraits< Sacado::Fad::SFad<ValueT,Num>,
181  Sacado::Fad::SFad<ValueT,Num> > {
184  promote;
185  };
186 
187  template <typename ValueT, int Num, typename R>
188  struct PromotionTraits< Sacado::Fad::SFad<ValueT,Num>, R > {
189  typedef typename Sacado::Promote< Sacado::Fad::SFad<ValueT,Num>, R >::type
190  promote;
191  };
192 
193  template <typename L, typename ValueT, int Num>
194  struct PromotionTraits< L, Sacado::Fad::SFad<ValueT,Num> > {
195  public:
197  promote;
198  };
199 }
200 #endif
201 
202 // Scalar traits
203 #ifdef HAVE_SACADO_TEUCHOSCORE
205 namespace Teuchos {
206  template <typename ValueT, int Num>
207  struct ScalarTraits< Sacado::Fad::SFad<ValueT,Num> > :
208  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::SFad<ValueT,Num> >
209  {};
210 }
211 #endif
212 
213 // Serialization traits
214 #ifdef HAVE_SACADO_TEUCHOSCOMM
216 namespace Teuchos {
217  template <typename Ordinal, typename ValueT, int Num>
218  struct SerializationTraits<Ordinal, Sacado::Fad::SFad<ValueT,Num> > :
219  public Sacado::Fad::SerializationTraitsImp< Ordinal,
220  Sacado::Fad::SFad<ValueT,Num> >
221  {};
222 
223  template <typename Ordinal, typename ValueT, int Num>
224  struct ValueTypeSerializer<Ordinal, Sacado::Fad::SFad<ValueT,Num> > :
225  public Sacado::Fad::SerializerImp< Ordinal,
226  Sacado::Fad::SFad<ValueT,Num>,
227  ValueTypeSerializer<Ordinal,ValueT> >
228  {
230  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
231  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
232  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
233  Ordinal sz = 0) :
234  Base(vs, sz) {}
235  };
236 }
237 #endif
238 
239 // KokkosComm
240 #if defined(HAVE_SACADO_KOKKOSCORE) && defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
241 #include "KokkosExp_View_Fad.hpp"
242 #endif
243 
244 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
245 
246 #endif // SACADO_FAD_SFADTRAITS_HPP
int Ordinal
#define KOKKOS_INLINE_FUNCTION
#define SACADO_SFAD_PROMOTE_SPEC(NS, FAD)
Sacado::Fad::DFad< double > FadType
GeneralFad< StaticFixedStorage< T, Num > > SFad
Base template specification for IsADType.
static const bool value
static KOKKOS_INLINE_FUNCTION bool eval(const Fad::SFad< ValueT, Num > &x, const Fad::SFad< ValueT, Num > &y)
Base template specification for testing equivalence.
Base template specification for IsScalarType.
static const bool value
Base template specification for IsSimdType.
static const bool value
Base template specification for testing whether type is statically sized.
Base template specification for Promote.
Base template specification for ScalarType.
ScalarType< Fad::SFad< ValueT, Num > >::type scalar_type
ValueType< Fad::SFad< ValueT, Num > >::type value_type
static KOKKOS_INLINE_FUNCTION const scalar_type & eval(const Fad::SFad< ValueT, Num > &x)
Base template specification for ScalarValue.
static KOKKOS_INLINE_FUNCTION const T & eval(const T &x)
Base template specification for static size.
static const unsigned value
Base template specification for string names of types.
static std::string eval()
Base template specification for ValueType.
ValueType< Fad::SFad< ValueT, Num > >::type value_type
static KOKKOS_INLINE_FUNCTION const value_type & eval(const Fad::SFad< ValueT, Num > &x)
Base template specification for Value.