Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_CacheFad_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_CACHEFAD_DFADTRAITS_HPP
50 #define SACADO_CACHEFAD_DFADTRAITS_HPP
51 
52 #include "Sacado_Traits.hpp"
53 
54 // Forward declarations
55 namespace Sacado {
56  namespace CacheFad {
57  template <typename T> class DFad;
58  }
59 }
60 
61 namespace Sacado {
62 
64  SACADO_FAD_PROMOTE_SPEC( CacheFad, DFad )
65 
66 
67  template <typename ValueT>
68  struct ScalarType< CacheFad::DFad<ValueT> > {
70  };
71 
73  template <typename ValueT>
74  struct ValueType< CacheFad::DFad<ValueT> > {
75  typedef ValueT type;
76  };
77 
79  template <typename ValueT>
80  struct IsADType< CacheFad::DFad<ValueT> > {
81  static const bool value = true;
82  };
83 
85  template <typename ValueT>
86  struct IsScalarType< CacheFad::DFad<ValueT> > {
87  static const bool value = false;
88  };
89 
91  template <typename ValueT>
92  struct Value< CacheFad::DFad<ValueT> > {
95  static const value_type& eval(const CacheFad::DFad<ValueT>& x) {
96  return x.val(); }
97  };
98 
100  template <typename ValueT>
101  struct ScalarValue< CacheFad::DFad<ValueT> > {
105  static const scalar_type& eval(const CacheFad::DFad<ValueT>& x) {
106  return ScalarValue<value_type>::eval(x.val()); }
107  };
108 
110  template <typename ValueT>
111  struct StringName< CacheFad::DFad<ValueT> > {
112  static std::string eval() {
113  return std::string("Sacado::CacheFad::DFad< ") +
114  StringName<ValueT>::eval() + " >"; }
115  };
116 
118  template <typename ValueT>
119  struct IsEqual< CacheFad::DFad<ValueT> > {
121  static bool eval(const CacheFad::DFad<ValueT>& x,
122  const CacheFad::DFad<ValueT>& y) {
123  return x.isEqualTo(y);
124  }
125  };
126 
128  template <typename ValueT>
129  struct IsStaticallySized< CacheFad::DFad<ValueT> > {
130  static const bool value = false;
131  };
132 
134  template <typename ValueT>
135  struct IsStaticallySized< const CacheFad::DFad<ValueT> > {
136  static const bool value = false;
137  };
138 
139 } // namespace Sacado
140 
141 //
142 // Define Teuchos traits classes
143 //
144 
145 // Promotion traits
146 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
148 namespace Teuchos {
149  template <typename ValueT>
150  struct PromotionTraits< Sacado::CacheFad::DFad<ValueT>,
151  Sacado::CacheFad::DFad<ValueT> > {
154  promote;
155  };
156 
157  template <typename ValueT, typename R>
158  struct PromotionTraits< Sacado::CacheFad::DFad<ValueT>, R > {
159  typedef typename Sacado::Promote< Sacado::CacheFad::DFad<ValueT>, R >::type
160  promote;
161  };
162 
163  template <typename L, typename ValueT>
164  struct PromotionTraits< L, Sacado::CacheFad::DFad<ValueT> > {
165  public:
167  promote;
168  };
169 }
170 #endif
171 
172 // Scalar traits
173 #ifdef HAVE_SACADO_TEUCHOSCORE
175 namespace Teuchos {
176  template <typename ValueT>
177  struct ScalarTraits< Sacado::CacheFad::DFad<ValueT> > :
178  public Sacado::Fad::ScalarTraitsImp< Sacado::CacheFad::DFad<ValueT> >
179  {};
180 }
181 #endif
182 
183 // Serialization traits
184 #ifdef HAVE_SACADO_TEUCHOSCOMM
186 namespace Teuchos {
187  template <typename Ordinal, typename ValueT>
188  struct SerializationTraits<Ordinal, Sacado::CacheFad::DFad<ValueT> > :
189  public Sacado::Fad::SerializationTraitsImp< Ordinal,
190  Sacado::CacheFad::DFad<ValueT> >
191  {};
192 
193  template <typename Ordinal, typename ValueT>
194  struct ValueTypeSerializer<Ordinal, Sacado::CacheFad::DFad<ValueT> > :
195  public Sacado::Fad::SerializerImp< Ordinal,
196  Sacado::CacheFad::DFad<ValueT>,
197  ValueTypeSerializer<Ordinal,ValueT> >
198  {
200  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
201  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
202  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
203  Ordinal sz = 0) :
204  Base(vs, sz) {}
205  };
206 }
207 #endif
208 
209 // KokkosComm
210 #if defined(HAVE_SACADO_KOKKOS) && defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
211 #include "KokkosExp_View_Fad.hpp"
212 #endif
213 
214 #endif // SACADO_FAD_DFADTRAITS_HPP
static SACADO_INLINE_FUNCTION const T & eval(const T &x)
static SACADO_INLINE_FUNCTION const value_type & eval(const CacheFad::DFad< ValueT > &x)
static std::string eval()
Base template specification for ScalarValue.
Base template specification for ScalarType.
ScalarType< CacheFad::DFad< ValueT > >::type scalar_type
Base template specification for string names of types.
Base template specification for IsADType.
Sacado::Fad::DFad< double > FadType
ValueType< CacheFad::DFad< ValueT > >::type value_type
Base template specification for Value.
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
static const bool value
ValueType< CacheFad::DFad< ValueT > >::type value_type
GeneralFad< DynamicStorage< T > > DFad
Base template specification for testing equivalence.
int Ordinal
static const bool value
static SACADO_INLINE_FUNCTION const scalar_type & eval(const CacheFad::DFad< ValueT > &x)
Base template specification for IsScalarType.
#define SACADO_INLINE_FUNCTION
static SACADO_INLINE_FUNCTION bool eval(const CacheFad::DFad< ValueT > &x, const CacheFad::DFad< ValueT > &y)
Base template specification for ValueType.
Base template specification for Promote.
const double y
Base template specification for testing whether type is statically sized.