Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_SimpleFadTraits.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_SIMPLEFADTRAITS_HPP
50 #define SACADO_FAD_SIMPLEFADTRAITS_HPP
51 
52 #include "Sacado_Traits.hpp"
53 
54 // Forward declarations
55 namespace Sacado {
56  namespace Fad {
57  template <typename T> class SimpleFad;
58  }
59 }
60 
61 namespace Sacado {
62 
64  SACADO_FAD_PROMOTE_SPEC( Fad, SimpleFad )
65 
66 
67  template <typename ValueT>
68  struct ScalarType< Fad::SimpleFad<ValueT> > {
70  };
71 
73  template <typename ValueT>
74  struct ValueType< Fad::SimpleFad<ValueT> > {
75  typedef ValueT type;
76  };
77 
79  template <typename ValueT>
80  struct IsADType< Fad::SimpleFad<ValueT> > {
81  static const bool value = true;
82  };
83 
85  template <typename ValueT>
86  struct IsScalarType< Fad::SimpleFad<ValueT> > {
87  static const bool value = false;
88  };
89 
91  template <typename ValueT>
92  struct IsSimdType< Fad::SimpleFad<ValueT> > {
93  static const bool value = IsSimdType<ValueT>::value;
94  };
95 
97  template <typename ValueT>
98  struct Value< Fad::SimpleFad<ValueT> > {
100  static const value_type& eval(const Fad::SimpleFad<ValueT>& x) {
101  return x.val(); }
102  };
103 
105  template <typename ValueT>
106  struct ScalarValue< Fad::SimpleFad<ValueT> > {
109  static const scalar_type& eval(const Fad::SimpleFad<ValueT>& x) {
110  return ScalarValue<value_type>::eval(x.val()); }
111  };
112 
114  template <typename ValueT>
115  struct StringName< Fad::SimpleFad<ValueT> > {
116  static std::string eval() {
117  return std::string("Sacado::Fad::SimpleFad< ") +
118  StringName<ValueT>::eval() + " >"; }
119  };
120 
122  template <typename ValueT>
123  struct IsEqual< Fad::SimpleFad<ValueT> > {
124  static bool eval(const Fad::SimpleFad<ValueT>& x,
125  const Fad::SimpleFad<ValueT>& y) {
126  return x.isEqualTo(y);
127  }
128  };
129 
131  template <typename ValueT>
132  struct IsStaticallySized< Fad::SimpleFad<ValueT> > {
133  static const bool value = false;
134  };
135 
137  template <typename ValueT>
138  struct IsFad< Fad::SimpleFad<ValueT> > {
139  static const bool value = true;
140  };
141 
142 } // namespace Sacado
143 
144 //
145 // Define Teuchos traits classes
146 //
147 
148 // Promotion traits
149 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
150 #include "Teuchos_PromotionTraits.hpp"
151 namespace Teuchos {
152  template <typename ValueT>
153  struct PromotionTraits< Sacado::Fad::SimpleFad<ValueT>,
154  Sacado::Fad::SimpleFad<ValueT> > {
157  promote;
158  };
159 
160  template <typename ValueT, typename R>
161  struct PromotionTraits< Sacado::Fad::SimpleFad<ValueT>, R > {
162  typedef typename Sacado::Promote< Sacado::Fad::SimpleFad<ValueT>, R >::type
163  promote;
164  };
165 
166  template <typename L, typename ValueT>
167  struct PromotionTraits< L, Sacado::Fad::SimpleFad<ValueT> > {
168  public:
170  promote;
171  };
172 }
173 #endif
174 
175 // Scalar traits
176 #ifdef HAVE_SACADO_TEUCHOSCORE
178 namespace Teuchos {
179  template <typename ValueT>
180  struct ScalarTraits< Sacado::Fad::SimpleFad<ValueT> > :
181  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::SimpleFad<ValueT> >
182  {};
183 }
184 #endif
185 
186 // Serialization traits
187 #ifdef HAVE_SACADO_TEUCHOSCOMM
189 namespace Teuchos {
190  template <typename Ordinal, typename ValueT>
191  struct SerializationTraits<Ordinal, Sacado::Fad::SimpleFad<ValueT> > :
192  public Sacado::Fad::SerializationTraitsImp< Ordinal,
193  Sacado::Fad::SimpleFad<ValueT> >
194  {};
195 
196  template <typename Ordinal, typename ValueT>
197  struct ValueTypeSerializer<Ordinal, Sacado::Fad::SimpleFad<ValueT> > :
198  public Sacado::Fad::SerializerImp< Ordinal,
199  Sacado::Fad::SimpleFad<ValueT>,
200  ValueTypeSerializer<Ordinal,ValueT> >
201  {
203  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
204  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
205  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
206  Ordinal sz = 0) :
207  Base(vs, sz) {}
208  };
209 }
210 #endif
211 
212 #endif // SACADO_FAD_SIMPLEFADTRAITS_HPP
int Ordinal
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
Sacado::Fad::DFad< double > FadType
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
Forward-mode AD class using dynamic memory allocation but no expression templates.
ScalarType< ValueT >::type ScalarT
Typename of scalar's (which may be different from ValueT)
bool isEqualTo(const SimpleFad &x) const
Returns whether two Fad objects have the same values.
Base template specification for IsADType.
static const bool value
static bool eval(const Fad::SimpleFad< ValueT > &x, const Fad::SimpleFad< ValueT > &y)
Base template specification for testing equivalence.
Base template specification for whether a type is a Fad type.
static const bool value
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.
ValueType< Fad::SimpleFad< ValueT > >::type value_type
static const scalar_type & eval(const Fad::SimpleFad< ValueT > &x)
ScalarType< Fad::SimpleFad< ValueT > >::type scalar_type
Base template specification for ScalarValue.
static KOKKOS_INLINE_FUNCTION const T & eval(const T &x)
Base template specification for string names of types.
static std::string eval()
Base template specification for ValueType.
ValueType< Fad::SimpleFad< ValueT > >::type value_type
static const value_type & eval(const Fad::SimpleFad< ValueT > &x)
Base template specification for Value.