Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_DVFadTraits.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 //
31 // The forward-mode AD classes in Sacado are a derivative work of the
32 // expression template classes in the Fad package by Nicolas Di Cesare.
33 // The following banner is included in the original Fad source code:
34 //
35 // ************ DO NOT REMOVE THIS BANNER ****************
36 //
37 // Nicolas Di Cesare <Nicolas.Dicesare@ann.jussieu.fr>
38 // http://www.ann.jussieu.fr/~dicesare
39 //
40 // CEMRACS 98 : C++ courses,
41 // templates : new C++ techniques
42 // for scientific computing
43 //
44 //********************************************************
45 //
46 // NumericalTraits class to illustrate TRAITS
47 //
48 //********************************************************
49 // @HEADER
50 
51 #ifndef SACADO_FAD_DVFADTRAITS_HPP
52 #define SACADO_FAD_DVFADTRAITS_HPP
53 
54 #include "Sacado_Traits.hpp"
55 
56 // Forward declarations
57 namespace Sacado {
58  namespace Fad {
59  template <typename T> class DVFad;
60  }
61 }
62 
63 namespace Sacado {
64 
66  SACADO_FAD_PROMOTE_SPEC( Fad, DVFad )
67 
68 
69  template <typename ValueT>
70  struct ScalarType< Fad::DVFad<ValueT> > {
72  };
73 
75  template <typename ValueT>
76  struct ValueType< Fad::DVFad<ValueT> > {
77  typedef ValueT type;
78  };
79 
81  template <typename ValueT>
82  struct IsADType< Fad::DVFad<ValueT> > {
83  static const bool value = true;
84  };
85 
87  template <typename ValueT>
88  struct IsScalarType< Fad::DVFad<ValueT> > {
89  static const bool value = false;
90  };
91 
93  template <typename ValueT>
94  struct Value< Fad::DVFad<ValueT> > {
95  typedef typename ValueType< Fad::DVFad<ValueT> >::type value_type;
96  static const value_type& eval(const Fad::DVFad<ValueT>& x) {
97  return x.val(); }
98  };
99 
101  template <typename ValueT>
102  struct ScalarValue< Fad::DVFad<ValueT> > {
103  typedef typename ValueType< Fad::DVFad<ValueT> >::type value_type;
104  typedef typename ScalarType< Fad::DVFad<ValueT> >::type scalar_type;
105  static const scalar_type& eval(const Fad::DVFad<ValueT>& x) {
106  return ScalarValue<value_type>::eval(x.val()); }
107  };
108 
110  template <typename ValueT>
111  struct StringName< Fad::DVFad<ValueT> > {
112  static std::string eval() {
113  return std::string("Sacado::Fad::DVFad< ") +
114  StringName<ValueT>::eval() + " >"; }
115  };
116 
118  template <typename ValueT>
119  struct IsEqual< Fad::DVFad<ValueT> > {
120  static bool eval(const Fad::DVFad<ValueT>& x, const Fad::DVFad<ValueT>& y) {
121  return x.isEqualTo(y);
122  }
123  };
124 
126  template <typename ValueT>
127  struct IsStaticallySized< Fad::DVFad<ValueT> > {
128  static const bool value = false;
129  };
130 
131  template <typename T>
132  struct IsFad< Fad::DVFad<T> > {
133  static const bool value = true;
134  };
135 
136 } // namespace Sacado
137 
138 // Define Teuchos traits classes
139 #ifdef HAVE_SACADO_TEUCHOS
140 #include "Teuchos_PromotionTraits.hpp"
141 #include "Teuchos_ScalarTraits.hpp"
143 
144 namespace Teuchos {
145 
147  template <typename ValueT>
148  struct PromotionTraits< Sacado::Fad::DVFad<ValueT>,
149  Sacado::Fad::DVFad<ValueT> > {
152  promote;
153  };
154 
156  template <typename ValueT, typename R>
157  struct PromotionTraits< Sacado::Fad::DVFad<ValueT>, R > {
158  typedef typename Sacado::Promote< Sacado::Fad::DVFad<ValueT>, R >::type
159  promote;
160  };
161 
163  template <typename L, typename ValueT>
164  struct PromotionTraits< L, Sacado::Fad::DVFad<ValueT> > {
165  public:
166  typedef typename Sacado::Promote< L, Sacado::Fad::DVFad<ValueT> >::type
167  promote;
168  };
169 
171  template <typename ValueT>
172  struct ScalarTraits< Sacado::Fad::DVFad<ValueT> > :
173  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::DVFad<ValueT> >
174  {};
175 }
176 #endif // HAVE_SACADO_TEUCHOS
177 
178 #endif // SACADO_FAD_DVFADTRAITS_HPP
ValueType< Fad::DVFad< ValueT > >::type value_type
ScalarType< Fad::DVFad< ValueT > >::type scalar_type
static std::string eval()
static bool eval(const Fad::DVFad< ValueT > &x, const Fad::DVFad< ValueT > &y)
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.
Base template specification for Value.
static const scalar_type & eval(const Fad::DVFad< ValueT > &x)
#define SACADO_FAD_PROMOTE_SPEC(NS, FAD)
static const bool value
Base template specification for testing equivalence.
Forward-mode AD class using dynamic memory allocation and expression templates.
ValueType< Fad::DVFad< ValueT > >::type value_type
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
static const bool value
static const value_type & eval(const Fad::DVFad< ValueT > &x)
Base template specification for IsScalarType.
static const bool value
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.