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 //
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_ELRFAD_SFADTRAITS_HPP
50 #define SACADO_ELRFAD_SFADTRAITS_HPP
51 
52 #include "Sacado_Traits.hpp"
53 #include <sstream>
54 
55 // Forward declarations
56 namespace Sacado {
57  namespace ELRFad {
58  template <typename T, int Num> class SFad;
59  }
60 }
61 
62 namespace Sacado {
63 
66 
67 
68  template <typename ValueT, int Num>
69  struct ScalarType< ELRFad::SFad<ValueT,Num> > {
71  };
72 
74  template <typename ValueT, int Num>
75  struct ValueType< ELRFad::SFad<ValueT,Num> > {
76  typedef ValueT type;
77  };
78 
80  template <typename ValueT, int Num>
81  struct IsADType< ELRFad::SFad<ValueT,Num> > {
82  static const bool value = true;
83  };
84 
86  template <typename ValueT, int Num>
87  struct IsScalarType< ELRFad::SFad<ValueT,Num> > {
88  static const bool value = false;
89  };
90 
92  template <typename ValueT, int Num>
93  struct Value< ELRFad::SFad<ValueT,Num> > {
96  static const value_type& eval(const ELRFad::SFad<ValueT,Num>& x) {
97  return x.val(); }
98  };
99 
101  template <typename ValueT, int Num>
102  struct ScalarValue< ELRFad::SFad<ValueT,Num> > {
106  static const scalar_type& eval(const ELRFad::SFad<ValueT,Num>& x) {
107  return ScalarValue<value_type>::eval(x.val()); }
108  };
109 
111  template <typename ValueT, int Num>
112  struct StringName< ELRFad::SFad<ValueT,Num> > {
113  static std::string eval() {
114  std::stringstream ss;
115  ss << "Sacado::ELRFad::SFad< "
116  << StringName<ValueT>::eval() << ", " << Num << " >";
117  return ss.str();
118  }
119  };
120 
122  template <typename ValueT, int Num>
123  struct IsEqual< ELRFad::SFad<ValueT,Num> > {
125  static bool eval(const ELRFad::SFad<ValueT,Num>& x,
126  const ELRFad::SFad<ValueT,Num>& y) {
127  return x.isEqualTo(y);
128  }
129  };
130 
132  template <typename ValueT, int Num>
133  struct IsStaticallySized< ELRFad::SFad<ValueT,Num> > {
134  static const bool value = true;
135  };
136 
138  template <typename ValueT, int Num>
139  struct IsStaticallySized< const ELRFad::SFad<ValueT,Num> > {
140  static const bool value = true;
141  };
142 
144  template <typename ValueT, int Num>
145  struct StaticSize< ELRFad::SFad<ValueT,Num> > {
146  static const unsigned value = Num;
147  };
148 
150  template <typename ValueT, int Num>
151  struct StaticSize< const ELRFad::SFad<ValueT,Num> > {
152  static const unsigned value = Num;
153  };
154 
155 } // namespace Sacado
156 
157 //
158 // Define Teuchos traits classes
159 //
160 
161 // Promotion traits
162 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
164 namespace Teuchos {
165  template <typename ValueT, int Num>
166  struct PromotionTraits< Sacado::ELRFad::SFad<ValueT,Num>,
167  Sacado::ELRFad::SFad<ValueT,Num> > {
170  promote;
171  };
172 
173  template <typename ValueT, int Num, typename R>
174  struct PromotionTraits< Sacado::ELRFad::SFad<ValueT,Num>, R > {
175  typedef typename Sacado::Promote< Sacado::ELRFad::SFad<ValueT,Num>, R >::type
176  promote;
177  };
178 
179  template <typename L, typename ValueT, int Num>
180  struct PromotionTraits< L, Sacado::ELRFad::SFad<ValueT,Num> > {
181  public:
183  promote;
184  };
185 }
186 #endif
187 
188 // Scalar traits
189 #ifdef HAVE_SACADO_TEUCHOSCORE
191 namespace Teuchos {
192  template <typename ValueT, int Num>
193  struct ScalarTraits< Sacado::ELRFad::SFad<ValueT,Num> > :
194  public Sacado::Fad::ScalarTraitsImp< Sacado::ELRFad::SFad<ValueT,Num> >
195  {};
196 }
197 #endif
198 
199 // Serialization traits
200 #ifdef HAVE_SACADO_TEUCHOSCOMM
202 namespace Teuchos {
203  template <typename Ordinal, typename ValueT, int Num>
204  struct SerializationTraits<Ordinal, Sacado::ELRFad::SFad<ValueT,Num> > :
205  public Sacado::Fad::SerializationTraitsImp< Ordinal,
206  Sacado::ELRFad::SFad<ValueT,Num> >
207  {};
208 
209  template <typename Ordinal, typename ValueT, int Num>
210  struct ValueTypeSerializer<Ordinal, Sacado::ELRFad::SFad<ValueT,Num> > :
211  public Sacado::Fad::SerializerImp< Ordinal,
212  Sacado::ELRFad::SFad<ValueT,Num>,
213  ValueTypeSerializer<Ordinal,ValueT> >
214  {
216  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
217  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
218  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
219  Ordinal sz = 0) :
220  Base(vs, sz) {}
221  };
222 }
223 #endif
224 
225 // KokkosComm
226 #if defined(HAVE_SACADO_KOKKOS) && defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
227 #include "KokkosExp_View_Fad.hpp"
228 #endif
229 
230 #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.