Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_DFadTraits.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_DFADTRAITS_HPP
50 #define SACADO_FAD_DFADTRAITS_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 
62 // Forward declarations
63 namespace Sacado {
64  namespace Fad {
65  template <typename T> class DFad;
66  }
67 }
68 
69 namespace Sacado {
70 
73 
74 
75  template <typename ValueT>
76  struct ScalarType< Fad::DFad<ValueT> > {
77  typedef typename Fad::DFad<ValueT>::ScalarT type;
78  };
79 
81  template <typename ValueT>
82  struct ValueType< Fad::DFad<ValueT> > {
83  typedef ValueT type;
84  };
85 
87  template <typename ValueT>
88  struct IsADType< Fad::DFad<ValueT> > {
89  static const bool value = true;
90  };
91 
93  template <typename ValueT>
94  struct IsScalarType< Fad::DFad<ValueT> > {
95  static const bool value = false;
96  };
97 
99  template <typename ValueT>
100  struct Value< Fad::DFad<ValueT> > {
101  typedef typename ValueType< Fad::DFad<ValueT> >::type value_type;
103  static const value_type& eval(const Fad::DFad<ValueT>& x) {
104  return x.val(); }
105  };
106 
108  template <typename ValueT>
109  struct ScalarValue< Fad::DFad<ValueT> > {
110  typedef typename ValueType< Fad::DFad<ValueT> >::type value_type;
111  typedef typename ScalarType< Fad::DFad<ValueT> >::type scalar_type;
113  static const scalar_type& eval(const Fad::DFad<ValueT>& x) {
114  return ScalarValue<value_type>::eval(x.val()); }
115  };
116 
118  template <typename ValueT>
119  struct StringName< Fad::DFad<ValueT> > {
120  static std::string eval() {
121  return std::string("Sacado::Fad::DFad< ") +
122  StringName<ValueT>::eval() + " >"; }
123  };
124 
126  template <typename ValueT>
127  struct IsEqual< Fad::DFad<ValueT> > {
129  static bool eval(const Fad::DFad<ValueT>& x, const Fad::DFad<ValueT>& y) {
130  return x.isEqualTo(y);
131  }
132  };
133 
135  template <typename ValueT>
136  struct IsStaticallySized< Fad::DFad<ValueT> > {
137  static const bool value = false;
138  };
139 
141  template <typename ValueT>
142  struct IsStaticallySized< const Fad::DFad<ValueT> > {
143  static const bool value = false;
144  };
145 
146 } // namespace Sacado
147 
148 // Define Teuchos traits classes
149 #ifdef HAVE_SACADO_TEUCHOS
151 #include "Teuchos_ScalarTraits.hpp"
154 
155 namespace Teuchos {
156 
158  template <typename ValueT>
159  struct PromotionTraits< Sacado::Fad::DFad<ValueT>,
160  Sacado::Fad::DFad<ValueT> > {
163  promote;
164  };
165 
167  template <typename ValueT, typename R>
168  struct PromotionTraits< Sacado::Fad::DFad<ValueT>, R > {
169  typedef typename Sacado::Promote< Sacado::Fad::DFad<ValueT>, R >::type
170  promote;
171  };
172 
174  template <typename L, typename ValueT>
175  struct PromotionTraits< L, Sacado::Fad::DFad<ValueT> > {
176  public:
177  typedef typename Sacado::Promote< L, Sacado::Fad::DFad<ValueT> >::type
178  promote;
179  };
180 
182  template <typename ValueT>
183  struct ScalarTraits< Sacado::Fad::DFad<ValueT> > :
184  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::DFad<ValueT> >
185  {};
186 
188  template <typename Ordinal, typename ValueT>
189  struct SerializationTraits<Ordinal, Sacado::Fad::DFad<ValueT> > :
190  public Sacado::Fad::SerializationTraitsImp< Ordinal,
191  Sacado::Fad::DFad<ValueT> >
192  {};
193 
195  template <typename Ordinal, typename ValueT>
196  struct ValueTypeSerializer<Ordinal, Sacado::Fad::DFad<ValueT> > :
197  public Sacado::Fad::SerializerImp< Ordinal,
198  Sacado::Fad::DFad<ValueT>,
199  ValueTypeSerializer<Ordinal,ValueT> >
200  {
202  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
203  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
204  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
205  Ordinal sz = 0) :
206  Base(vs, sz) {}
207  };
208 }
209 #endif // HAVE_SACADO_TEUCHOS
210 
211 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
212 
213 #endif // SACADO_FAD_DFADTRAITS_HPP
static std::string eval()
static KOKKOS_INLINE_FUNCTION const scalar_type & eval(const Fad::DFad< ValueT > &x)
Base template specification for ScalarValue.
Base template specification for ScalarType.
Base template specification for string names of types.
Base template specification for IsADType.
Sacado::Fad::DFad< double > FadType
Base template specification for Value.
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
#define KOKKOS_INLINE_FUNCTION
static const bool value
GeneralFad< DynamicStorage< T > > DFad
Base template specification for testing equivalence.
static KOKKOS_INLINE_FUNCTION bool eval(const Fad::DFad< ValueT > &x, const Fad::DFad< ValueT > &y)
ScalarType< Fad::DFad< ValueT > >::type scalar_type
int Ordinal
ValueType< Fad::DFad< ValueT > >::type value_type
ValueType< Fad::DFad< ValueT > >::type value_type
static const bool value
static KOKKOS_INLINE_FUNCTION const value_type & eval(const Fad::DFad< ValueT > &x)
Base template specification for IsScalarType.
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.