Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_DVFadTraits.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_FAD_DVFADTRAITS_HPP
50 #define SACADO_FAD_DVFADTRAITS_HPP
51 
52 #include "Sacado_ConfigDefs.h"
53 
54 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
55 
57 
58 #else
59 
60 #include "Sacado_Traits.hpp"
61 
62 // Forward declarations
63 namespace Sacado {
64  namespace Fad {
65  template <typename T> class DVFad;
66  }
67 }
68 
69 namespace Sacado {
70 
73 
74 
75  template <typename ValueT>
76  struct ScalarType< Fad::DVFad<ValueT> > {
78  };
79 
81  template <typename ValueT>
82  struct ValueType< Fad::DVFad<ValueT> > {
83  typedef ValueT type;
84  };
85 
87  template <typename ValueT>
88  struct IsADType< Fad::DVFad<ValueT> > {
89  static const bool value = true;
90  };
91 
93  template <typename ValueT>
94  struct IsScalarType< Fad::DVFad<ValueT> > {
95  static const bool value = false;
96  };
97 
99  template <typename ValueT>
100  struct Value< Fad::DVFad<ValueT> > {
101  typedef typename ValueType< Fad::DVFad<ValueT> >::type value_type;
102  static const value_type& eval(const Fad::DVFad<ValueT>& x) {
103  return x.val(); }
104  };
105 
107  template <typename ValueT>
108  struct ScalarValue< Fad::DVFad<ValueT> > {
109  typedef typename ValueType< Fad::DVFad<ValueT> >::type value_type;
110  typedef typename ScalarType< Fad::DVFad<ValueT> >::type scalar_type;
111  static const scalar_type& eval(const Fad::DVFad<ValueT>& x) {
112  return ScalarValue<value_type>::eval(x.val()); }
113  };
114 
116  template <typename ValueT>
117  struct StringName< Fad::DVFad<ValueT> > {
118  static std::string eval() {
119  return std::string("Sacado::Fad::DVFad< ") +
120  StringName<ValueT>::eval() + " >"; }
121  };
122 
124  template <typename ValueT>
125  struct IsEqual< Fad::DVFad<ValueT> > {
126  static bool eval(const Fad::DVFad<ValueT>& x, const Fad::DVFad<ValueT>& y) {
127  return x.isEqualTo(y);
128  }
129  };
130 
132  template <typename ValueT>
133  struct IsStaticallySized< Fad::DVFad<ValueT> > {
134  static const bool value = false;
135  };
136 
137  template <typename T>
138  struct IsFad< Fad::DVFad<T> > {
139  static const bool value = true;
140  };
141 
142 } // namespace Sacado
143 
144 // Define Teuchos traits classes
145 #ifdef HAVE_SACADO_TEUCHOS
146 #include "Teuchos_PromotionTraits.hpp"
147 #include "Teuchos_ScalarTraits.hpp"
149 
150 namespace Teuchos {
151 
153  template <typename ValueT>
154  struct PromotionTraits< Sacado::Fad::DVFad<ValueT>,
155  Sacado::Fad::DVFad<ValueT> > {
158  promote;
159  };
160 
162  template <typename ValueT, typename R>
163  struct PromotionTraits< Sacado::Fad::DVFad<ValueT>, R > {
164  typedef typename Sacado::Promote< Sacado::Fad::DVFad<ValueT>, R >::type
165  promote;
166  };
167 
169  template <typename L, typename ValueT>
170  struct PromotionTraits< L, Sacado::Fad::DVFad<ValueT> > {
171  public:
172  typedef typename Sacado::Promote< L, Sacado::Fad::DVFad<ValueT> >::type
173  promote;
174  };
175 
177  template <typename ValueT>
178  struct ScalarTraits< Sacado::Fad::DVFad<ValueT> > :
179  public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::DVFad<ValueT> >
180  {};
181 }
182 #endif // HAVE_SACADO_TEUCHOS
183 
184 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
185 
186 #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.
GeneralFad< VectorDynamicStorage< T > > DVFad
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.