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 Value< Fad::SimpleFad<ValueT> > {
94  static const value_type& eval(const Fad::SimpleFad<ValueT>& x) {
95  return x.val(); }
96  };
97 
99  template <typename ValueT>
100  struct ScalarValue< Fad::SimpleFad<ValueT> > {
103  static const scalar_type& eval(const Fad::SimpleFad<ValueT>& x) {
104  return ScalarValue<value_type>::eval(x.val()); }
105  };
106 
108  template <typename ValueT>
109  struct StringName< Fad::SimpleFad<ValueT> > {
110  static std::string eval() {
111  return std::string("Sacado::Fad::SimpleFad< ") +
112  StringName<ValueT>::eval() + " >"; }
113  };
114 
116  template <typename ValueT>
117  struct IsEqual< Fad::SimpleFad<ValueT> > {
118  static bool eval(const Fad::SimpleFad<ValueT>& x,
119  const Fad::SimpleFad<ValueT>& y) {
120  return x.isEqualTo(y);
121  }
122  };
123 
125  template <typename ValueT>
126  struct IsStaticallySized< Fad::SimpleFad<ValueT> > {
127  static const bool value = false;
128  };
129 
131  template <typename ValueT>
132  struct IsFad< Fad::SimpleFad<ValueT> > {
133  static const bool value = true;
134  };
135 
136 } // namespace Sacado
137 
138 // Define Teuchos traits classes
139 #ifdef HAVE_SACADO_TEUCHOS
141 #include "Teuchos_ScalarTraits.hpp"
143 
144 namespace Teuchos {
145 
147  template <typename ValueT>
148  struct PromotionTraits< Sacado::Fad::SimpleFad<ValueT>,
149  Sacado::Fad::SimpleFad<ValueT> > {
152  promote;
153  };
154 
156  template <typename ValueT, typename R>
157  struct PromotionTraits< Sacado::Fad::SimpleFad<ValueT>, R > {
158  typedef typename Sacado::Promote< Sacado::Fad::SimpleFad<ValueT>, R >::type
159  promote;
160  };
161 
163  template <typename L, typename ValueT>
164  struct PromotionTraits< L, Sacado::Fad::SimpleFad<ValueT> > {
165  public:
167  promote;
168  };
169 
171  template <typename ValueT>
172  struct ScalarTraits< Sacado::Fad::SimpleFad<ValueT> > :
173  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::SimpleFad<ValueT> >
174  {};
175 
177  template <typename Ordinal, typename ValueT>
178  struct SerializationTraits<Ordinal, Sacado::Fad::SimpleFad<ValueT> > :
179  public Sacado::Fad::SerializationTraitsImp< Ordinal,
180  Sacado::Fad::SimpleFad<ValueT> >
181  {};
182 
184  template <typename Ordinal, typename ValueT>
185  struct ValueTypeSerializer<Ordinal, Sacado::Fad::SimpleFad<ValueT> > :
186  public Sacado::Fad::SerializerImp< Ordinal,
187  Sacado::Fad::SimpleFad<ValueT>,
188  ValueTypeSerializer<Ordinal,ValueT> >
189  {
191  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
192  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
193  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
194  Ordinal sz = 0) :
195  Base(vs, sz) {}
196  };
197 }
198 #endif // HAVE_SACADO_TEUCHOS
199 
200 #endif // SACADO_FAD_SIMPLEFADTRAITS_HPP
static bool eval(const Fad::SimpleFad< ValueT > &x, const Fad::SimpleFad< ValueT > &y)
static std::string eval()
ValueType< Fad::SimpleFad< ValueT > >::type value_type
Base template specification for ScalarValue.
Base template specification for ScalarType.
Base template specification for whether a type is a Fad type.
Base template specification for string names of types.
Base template specification for IsADType.
static const scalar_type & eval(const Fad::SimpleFad< ValueT > &x)
Sacado::Fad::DFad< double > FadType
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
KOKKOS_INLINE_FUNCTION const ValueT & val() const
Returns value.
Base template specification for Value.
Forward-mode AD class using dynamic memory allocation but no expression templates.
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
static const bool value
Base template specification for testing equivalence.
ScalarType< Fad::SimpleFad< ValueT > >::type scalar_type
bool isEqualTo(const SimpleFad &x) const
Returns whether two Fad objects have the same values.
int Ordinal
static const bool value
Base template specification for IsScalarType.
static const value_type & eval(const Fad::SimpleFad< ValueT > &x)
static const bool value
Base template specification for ValueType.
Base template specification for Promote.
static KOKKOS_INLINE_FUNCTION const T & eval(const T &x)
ValueType< Fad::SimpleFad< ValueT > >::type value_type
Base template specification for testing whether type is statically sized.