Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Fad_DMFadTraits.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 // @HEADER
29 
30 #ifndef SACADO_FAD_DMFADTRAITS_HPP
31 #define SACADO_FAD_DMFADTRAITS_HPP
32 
33 #include "Sacado_ConfigDefs.h"
34 
35 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
36 
38 
39 #else
40 
41 #include "Sacado_Traits.hpp"
42 
43 // Forward declarations
44 namespace Sacado {
45  namespace Fad {
46  template <typename T> class DMFad;
47  }
48 }
49 
50 namespace Sacado {
51 
54 
55 
56  template <typename ValueT>
57  struct ScalarType< Fad::DMFad<ValueT> > {
59  };
60 
62  template <typename ValueT>
63  struct ValueType< Fad::DMFad<ValueT> > {
64  typedef ValueT type;
65  };
66 
68  template <typename ValueT>
69  struct IsADType< Fad::DMFad<ValueT> > {
70  static const bool value = true;
71  };
72 
74  template <typename ValueT>
75  struct IsScalarType< Fad::DMFad<ValueT> > {
76  static const bool value = false;
77  };
78 
80  template <typename ValueT>
81  struct IsSimdType< Fad::DMFad<ValueT> > {
82  static const bool value = IsSimdType<ValueT>::value;
83  };
84 
86  template <typename ValueT>
87  struct Value< Fad::DMFad<ValueT> > {
88  typedef typename ValueType< Fad::DMFad<ValueT> >::type value_type;
89  static const value_type& eval(const Fad::DMFad<ValueT>& x) {
90  return x.val(); }
91  };
92 
94  template <typename ValueT>
95  struct ScalarValue< Fad::DMFad<ValueT> > {
96  typedef typename ValueType< Fad::DMFad<ValueT> >::type value_type;
97  typedef typename ScalarType< Fad::DMFad<ValueT> >::type scalar_type;
98  static const scalar_type& eval(const Fad::DMFad<ValueT>& x) {
99  return ScalarValue<value_type>::eval(x.val()); }
100  };
101 
103  template <typename ValueT>
104  struct StringName< Fad::DMFad<ValueT> > {
105  static std::string eval() {
106  return std::string("Sacado::Fad::DMFad< ") +
107  StringName<ValueT>::eval() + " >"; }
108  };
109 
111  template <typename ValueT>
112  struct IsEqual< Fad::DMFad<ValueT> > {
113  static bool eval(const Fad::DMFad<ValueT>& x, const Fad::DMFad<ValueT>& y) {
114  return x.isEqualTo(y);
115  }
116  };
117 
119  template <typename ValueT>
120  struct IsStaticallySized< Fad::DMFad<ValueT> > {
121  static const bool value = false;
122  };
123 
124  template <typename T>
125  struct IsFad< Fad::DMFad<T> > {
126  static const bool value = true;
127  };
128 
129 } // namespace Sacado
130 
131 //
132 // Define Teuchos traits classes
133 //
134 
135 // Promotion traits
136 #ifdef HAVE_SACADO_TEUCHOSNUMERICS
138 namespace Teuchos {
139  template <typename ValueT>
140  struct PromotionTraits< Sacado::Fad::DMFad<ValueT>,
141  Sacado::Fad::DMFad<ValueT> > {
144  promote;
145  };
146 
147  template <typename ValueT, typename R>
148  struct PromotionTraits< Sacado::Fad::DMFad<ValueT>, R > {
149  typedef typename Sacado::Promote< Sacado::Fad::DMFad<ValueT>, R >::type
150  promote;
151  };
152 
153  template <typename L, typename ValueT>
154  struct PromotionTraits< L, Sacado::Fad::DMFad<ValueT> > {
155  public:
156  typedef typename Sacado::Promote< L, Sacado::Fad::DMFad<ValueT> >::type
157  promote;
158  };
159 }
160 #endif
161 
162 // Scalar traits
163 #ifdef HAVE_SACADO_TEUCHOSCORE
165 namespace Teuchos {
166  template <typename ValueT>
167  struct ScalarTraits< Sacado::Fad::DMFad<ValueT> > :
168  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::DMFad<ValueT> >
169  {};
170 }
171 #endif
172 
173 // Serialization traits
174 #ifdef HAVE_SACADO_TEUCHOSCOMM
176 namespace Teuchos {
177  template <typename Ordinal, typename ValueT>
178  struct SerializationTraits<Ordinal, Sacado::Fad::DMFad<ValueT> > :
179  public Sacado::Fad::SerializationTraitsImp< Ordinal,
180  Sacado::Fad::DMFad<ValueT> >
181  {};
182 
183  template <typename Ordinal, typename ValueT>
184  struct ValueTypeSerializer<Ordinal, Sacado::Fad::DMFad<ValueT> > :
185  public Sacado::Fad::SerializerImp< Ordinal,
186  Sacado::Fad::DMFad<ValueT>,
187  ValueTypeSerializer<Ordinal,ValueT> >
188  {
190  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
191  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
192  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
193  Ordinal sz = 0) :
194  Base(vs, sz) {}
195  };
196 }
197 #endif
198 
199 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
200 
201 #endif // SACADO_FAD_DMFADTRAITS_HPP
static std::string eval()
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.
GeneralFad< MemPoolStorage< T > > DMFad
Base template specification for IsADType.
Sacado::Fad::DFad< double > FadType
ScalarType< Fad::DMFad< ValueT > >::type scalar_type
Base template specification for Value.
ValueType< Fad::DMFad< ValueT > >::type value_type
ValueType< Fad::DMFad< ValueT > >::type value_type
Base template specification for IsSimdType.
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
static const bool value
Base template specification for testing equivalence.
static const scalar_type & eval(const Fad::DMFad< ValueT > &x)
static const bool value
int Ordinal
static const bool value
Base template specification for IsScalarType.
Forward-mode AD class using dynamic memory allocation and expression templates.
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
static const value_type & eval(const Fad::DMFad< ValueT > &x)
static const bool value
static bool eval(const Fad::DMFad< ValueT > &x, const Fad::DMFad< ValueT > &y)
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.