Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_DMFadTraits.hpp
Go to the documentation of this file.
1 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Sacado Package
7 // Copyright (2006) Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // This library is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as
14 // published by the Free Software Foundation; either version 2.1 of the
15 // License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 // USA
26 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27 // (etphipp@sandia.gov).
28 //
29 // ***********************************************************************
30 // @HEADER
31 
32 #ifndef SACADO_FAD_DMFADTRAITS_HPP
33 #define SACADO_FAD_DMFADTRAITS_HPP
34 
35 #include "Sacado_Traits.hpp"
36 
37 // Forward declarations
38 namespace Sacado {
39  namespace Fad {
40  template <typename T> class DMFad;
41  }
42 }
43 
44 namespace Sacado {
45 
47  SACADO_FAD_PROMOTE_SPEC( Fad, DMFad )
48 
49 
50  template <typename ValueT>
51  struct ScalarType< Fad::DMFad<ValueT> > {
53  };
54 
56  template <typename ValueT>
57  struct ValueType< Fad::DMFad<ValueT> > {
58  typedef ValueT type;
59  };
60 
62  template <typename ValueT>
63  struct IsADType< Fad::DMFad<ValueT> > {
64  static const bool value = true;
65  };
66 
68  template <typename ValueT>
69  struct IsScalarType< Fad::DMFad<ValueT> > {
70  static const bool value = false;
71  };
72 
74  template <typename ValueT>
75  struct Value< Fad::DMFad<ValueT> > {
76  typedef typename ValueType< Fad::DMFad<ValueT> >::type value_type;
77  static const value_type& eval(const Fad::DMFad<ValueT>& x) {
78  return x.val(); }
79  };
80 
82  template <typename ValueT>
83  struct ScalarValue< Fad::DMFad<ValueT> > {
84  typedef typename ValueType< Fad::DMFad<ValueT> >::type value_type;
85  typedef typename ScalarType< Fad::DMFad<ValueT> >::type scalar_type;
86  static const scalar_type& eval(const Fad::DMFad<ValueT>& x) {
87  return ScalarValue<value_type>::eval(x.val()); }
88  };
89 
91  template <typename ValueT>
92  struct StringName< Fad::DMFad<ValueT> > {
93  static std::string eval() {
94  return std::string("Sacado::Fad::DMFad< ") +
95  StringName<ValueT>::eval() + " >"; }
96  };
97 
99  template <typename ValueT>
100  struct IsEqual< Fad::DMFad<ValueT> > {
101  static bool eval(const Fad::DMFad<ValueT>& x, const Fad::DMFad<ValueT>& y) {
102  return x.isEqualTo(y);
103  }
104  };
105 
107  template <typename ValueT>
108  struct IsStaticallySized< Fad::DMFad<ValueT> > {
109  static const bool value = false;
110  };
111 
112  template <typename T>
113  struct IsFad< Fad::DMFad<T> > {
114  static const bool value = true;
115  };
116 
117 } // namespace Sacado
118 
119 // Define Teuchos traits classes
120 #ifdef HAVE_SACADO_TEUCHOS
122 #include "Teuchos_ScalarTraits.hpp"
124 
125 namespace Teuchos {
126 
128  template <typename ValueT>
129  struct PromotionTraits< Sacado::Fad::DMFad<ValueT>,
130  Sacado::Fad::DMFad<ValueT> > {
133  promote;
134  };
135 
137  template <typename ValueT, typename R>
138  struct PromotionTraits< Sacado::Fad::DMFad<ValueT>, R > {
139  typedef typename Sacado::Promote< Sacado::Fad::DMFad<ValueT>, R >::type
140  promote;
141  };
142 
144  template <typename L, typename ValueT>
145  struct PromotionTraits< L, Sacado::Fad::DMFad<ValueT> > {
146  public:
147  typedef typename Sacado::Promote< L, Sacado::Fad::DMFad<ValueT> >::type
148  promote;
149  };
150 
152  template <typename ValueT>
153  struct ScalarTraits< Sacado::Fad::DMFad<ValueT> > :
154  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::DMFad<ValueT> >
155  {};
156 
158  template <typename Ordinal, typename ValueT>
159  struct SerializationTraits<Ordinal, Sacado::Fad::DMFad<ValueT> > :
160  public Sacado::Fad::SerializationTraitsImp< Ordinal,
161  Sacado::Fad::DMFad<ValueT> >
162  {};
163 
165  template <typename Ordinal, typename ValueT>
166  struct ValueTypeSerializer<Ordinal, Sacado::Fad::DMFad<ValueT> > :
167  public Sacado::Fad::SerializerImp< Ordinal,
168  Sacado::Fad::DMFad<ValueT>,
169  ValueTypeSerializer<Ordinal,ValueT> >
170  {
172  typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
173  typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
174  ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
175  Ordinal sz = 0) :
176  Base(vs, sz) {}
177  };
178 }
179 #endif // HAVE_SACADO_TEUCHOS
180 
181 #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.
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.