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 Value< Fad::SFad<ValueT,Num> > {
104  static const value_type& eval(const Fad::SFad<ValueT,Num>& x) {
105  return x.val(); }
106  };
107 
109  template <typename ValueT, int Num>
110  struct ScalarValue< Fad::SFad<ValueT,Num> > {
114  static const scalar_type& eval(const Fad::SFad<ValueT,Num>& x) {
115  return ScalarValue<value_type>::eval(x.val()); }
116  };
117 
119  template <typename ValueT, int Num>
120  struct StringName< Fad::SFad<ValueT,Num> > {
121  static std::string eval() {
122  std::stringstream ss;
123  ss << "Sacado::Fad::SFad< "
124  << StringName<ValueT>::eval() << ", " << Num << " >";
125  return ss.str();
126  }
127  };
128 
130  template <typename ValueT, int Num>
131  struct IsEqual< Fad::SFad<ValueT,Num> > {
133  static bool eval(const Fad::SFad<ValueT,Num>& x,
134  const Fad::SFad<ValueT,Num>& y) {
135  return x.isEqualTo(y);
136  }
137  };
138 
140  template <typename ValueT, int Num>
141  struct IsStaticallySized< Fad::SFad<ValueT,Num> > {
142  static const bool value = true;
143  };
144 
146  template <typename ValueT, int Num>
147  struct IsStaticallySized< const Fad::SFad<ValueT,Num> > {
148  static const bool value = true;
149  };
150 
152  template <typename ValueT, int Num>
153  struct StaticSize< Fad::SFad<ValueT,Num> > {
154  static const unsigned value = Num;
155  };
156 
158  template <typename ValueT, int Num>
159  struct StaticSize< const Fad::SFad<ValueT,Num> > {
160  static const unsigned value = Num;
161  };
162 
163 } // namespace Sacado
164 
165 // Define Teuchos traits classes
166 #ifdef HAVE_SACADO_TEUCHOS
168 #include "Teuchos_ScalarTraits.hpp"
170 
171 namespace Teuchos {
172 
174  template <typename ValueT, int Num>
175  struct PromotionTraits< Sacado::Fad::SFad<ValueT,Num>,
176  Sacado::Fad::SFad<ValueT,Num> > {
179  promote;
180  };
181 
183  template <typename ValueT, int Num, typename R>
184  struct PromotionTraits< Sacado::Fad::SFad<ValueT,Num>, R > {
185  typedef typename Sacado::Promote< Sacado::Fad::SFad<ValueT,Num>, R >::type
186  promote;
187  };
188 
190  template <typename L, typename ValueT, int Num>
191  struct PromotionTraits< L, Sacado::Fad::SFad<ValueT,Num> > {
192  public:
194  promote;
195  };
196 
198  template <typename ValueT, int Num>
199  struct ScalarTraits< Sacado::Fad::SFad<ValueT,Num> > :
200  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::SFad<ValueT,Num> >
201  {};
202 
204  template <typename Ordinal, typename ValueT, int Num>
205  struct SerializationTraits<Ordinal, Sacado::Fad::SFad<ValueT,Num> > :
206  public Sacado::Fad::StaticSerializationTraitsImp< Ordinal,
207  Sacado::Fad::SFad<ValueT,Num> >
208  {};
209 
211  template <typename Ordinal, typename ValueT, int Num>
212  struct ValueTypeSerializer<Ordinal, Sacado::Fad::SFad<ValueT,Num> > :
213  public Sacado::Fad::SerializerImp< Ordinal,
214  Sacado::Fad::SFad<ValueT,Num>,
215  ValueTypeSerializer<Ordinal,ValueT> >
216  {
218  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
219  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
220  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
221  Ordinal sz = 0) :
222  Base(vs, sz) {}
223  };
224 }
225 #endif // HAVE_SACADO_TEUCHOS
226 
227 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
228 
229 #endif // SACADO_FAD_SFADTRAITS_HPP
static std::string eval()
Base template specification for ScalarValue.
Base template specification for ScalarType.
static KOKKOS_INLINE_FUNCTION bool eval(const Fad::SFad< ValueT, Num > &x, const Fad::SFad< ValueT, Num > &y)
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.
#define KOKKOS_INLINE_FUNCTION
static const bool value
ValueType< Fad::SFad< ValueT, Num > >::type value_type
Base template specification for testing equivalence.
static KOKKOS_INLINE_FUNCTION const value_type & eval(const Fad::SFad< ValueT, Num > &x)
static KOKKOS_INLINE_FUNCTION const scalar_type & eval(const Fad::SFad< ValueT, Num > &x)
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)
static const unsigned value
GeneralFad< StaticFixedStorage< T, Num > > SFad
Base template specification for ValueType.
Base template specification for Promote.
static KOKKOS_INLINE_FUNCTION const T & eval(const T &x)
Base template specification for testing whether type is statically sized.