Sacado Package Browser (Single Doxygen Collection)  Version of the Day
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 Value< Fad::DMFad<ValueT> > {
82  typedef typename ValueType< Fad::DMFad<ValueT> >::type value_type;
83  static const value_type& eval(const Fad::DMFad<ValueT>& x) {
84  return x.val(); }
85  };
86 
88  template <typename ValueT>
89  struct ScalarValue< Fad::DMFad<ValueT> > {
90  typedef typename ValueType< Fad::DMFad<ValueT> >::type value_type;
91  typedef typename ScalarType< Fad::DMFad<ValueT> >::type scalar_type;
92  static const scalar_type& eval(const Fad::DMFad<ValueT>& x) {
93  return ScalarValue<value_type>::eval(x.val()); }
94  };
95 
97  template <typename ValueT>
98  struct StringName< Fad::DMFad<ValueT> > {
99  static std::string eval() {
100  return std::string("Sacado::Fad::DMFad< ") +
101  StringName<ValueT>::eval() + " >"; }
102  };
103 
105  template <typename ValueT>
106  struct IsEqual< Fad::DMFad<ValueT> > {
107  static bool eval(const Fad::DMFad<ValueT>& x, const Fad::DMFad<ValueT>& y) {
108  return x.isEqualTo(y);
109  }
110  };
111 
113  template <typename ValueT>
114  struct IsStaticallySized< Fad::DMFad<ValueT> > {
115  static const bool value = false;
116  };
117 
118  template <typename T>
119  struct IsFad< Fad::DMFad<T> > {
120  static const bool value = true;
121  };
122 
123 } // namespace Sacado
124 
125 // Define Teuchos traits classes
126 #ifdef HAVE_SACADO_TEUCHOS
127 #include "Teuchos_PromotionTraits.hpp"
128 #include "Teuchos_ScalarTraits.hpp"
130 
131 namespace Teuchos {
132 
134  template <typename ValueT>
135  struct PromotionTraits< Sacado::Fad::DMFad<ValueT>,
136  Sacado::Fad::DMFad<ValueT> > {
139  promote;
140  };
141 
143  template <typename ValueT, typename R>
144  struct PromotionTraits< Sacado::Fad::DMFad<ValueT>, R > {
145  typedef typename Sacado::Promote< Sacado::Fad::DMFad<ValueT>, R >::type
146  promote;
147  };
148 
150  template <typename L, typename ValueT>
151  struct PromotionTraits< L, Sacado::Fad::DMFad<ValueT> > {
152  public:
153  typedef typename Sacado::Promote< L, Sacado::Fad::DMFad<ValueT> >::type
154  promote;
155  };
156 
158  template <typename ValueT>
159  struct ScalarTraits< Sacado::Fad::DMFad<ValueT> > :
160  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::DMFad<ValueT> >
161  {};
162 
164  template <typename Ordinal, typename ValueT>
165  struct SerializationTraits<Ordinal, Sacado::Fad::DMFad<ValueT> > :
166  public Sacado::Fad::SerializationTraitsImp< Ordinal,
167  Sacado::Fad::DMFad<ValueT> >
168  {};
169 
171  template <typename Ordinal, typename ValueT>
172  struct ValueTypeSerializer<Ordinal, Sacado::Fad::DMFad<ValueT> > :
173  public Sacado::Fad::SerializerImp< Ordinal,
174  Sacado::Fad::DMFad<ValueT>,
175  ValueTypeSerializer<Ordinal,ValueT> >
176  {
178  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
179  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
180  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
181  Ordinal sz = 0) :
182  Base(vs, sz) {}
183  };
184 }
185 #endif // HAVE_SACADO_TEUCHOS
186 
187 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
188 
189 #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
#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)
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.