Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_DFad_tmpl.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 namespace Sacado {
31 
32  namespace FAD_NS {
33 
44  template <typename ValueT>
45  class DFad :
46  public Expr< GeneralFad<ValueT,Fad::DynamicStorage<ValueT> > > {
47 
48  public:
49 
52  typedef GeneralFad<ValueT,StorageType> GeneralFadType;
53  typedef Expr<GeneralFadType> ExprType;
54 
56  typedef typename ExprType::value_type value_type;
57 
59  typedef typename ExprType::scalar_type scalar_type;
60 
63 
65  template <typename T>
66  struct apply {
67  typedef DFad<T> type;
68  };
69 
74 
76 
80  DFad() :
81  ExprType() {}
82 
84 
87  template <typename S>
90  ExprType(x) {}
91 
93 
97  DFad(const int sz, const ValueT& x, const DerivInit zero_out = InitDerivArray) :
98  ExprType(sz,x,zero_out) {}
99 
101 
107  DFad(const int sz, const int i, const ValueT & x) :
108  ExprType(sz,i,x) {}
109 
112  DFad(const DFad& x) :
113  ExprType(x) {}
114 
116  template <typename S>
118  DFad(const Expr<S>& x, SACADO_ENABLE_EXPR_CTOR_DECL) :
119  ExprType(x) {}
120 
122 
125  ~DFad() {}
126 
128  template <typename S>
130  SACADO_ENABLE_VALUE_FUNC(DFad&) operator=(const S& v) {
131  GeneralFadType::operator=(v);
132  return *this;
133  }
134 
137  DFad& operator=(const DFad& x) {
138  GeneralFadType::operator=(static_cast<const GeneralFadType&>(x));
139  return *this;
140  }
141 
143  template <typename S>
145  SACADO_ENABLE_EXPR_FUNC(DFad&) operator=(const Expr<S>& x)
146  {
147  GeneralFadType::operator=(x);
148  return *this;
149  }
150 
152  template <typename S>
154  SACADO_ENABLE_VALUE_FUNC(DFad&) operator += (const S& x) {
155  GeneralFadType::operator+=(x);
156  return *this;
157  }
158 
160  template <typename S>
162  SACADO_ENABLE_VALUE_FUNC(DFad&) operator -= (const S& x) {
163  GeneralFadType::operator-=(x);
164  return *this;
165  }
166 
168  template <typename S>
170  SACADO_ENABLE_VALUE_FUNC(DFad&) operator *= (const S& x) {
171  GeneralFadType::operator*=(x);
172  return *this;
173  }
174 
176  template <typename S>
178  SACADO_ENABLE_VALUE_FUNC(DFad&) operator /= (const S& x) {
179  GeneralFadType::operator/=(x);
180  return *this;
181  }
182 
185  DFad& operator += (const DFad& x) {
186  GeneralFadType::operator+=(static_cast<const GeneralFadType&>(x));
187  return *this;
188  }
189 
192  DFad& operator -= (const DFad& x) {
193  GeneralFadType::operator-=(static_cast<const GeneralFadType&>(x));
194  return *this;
195  }
196 
199  DFad& operator *= (const DFad& x) {
200  GeneralFadType::operator*=(static_cast<const GeneralFadType&>(x));
201  return *this;
202  }
203 
206  DFad& operator /= (const DFad& x) {
207  GeneralFadType::operator/=(static_cast<const GeneralFadType&>(x));
208  return *this;
209  }
210 
212  template <typename S>
214  SACADO_ENABLE_EXPR_FUNC(DFad&) operator += (const Expr<S>& x) {
215  GeneralFadType::operator+=(x);
216  return *this;
217  }
218 
220  template <typename S>
222  SACADO_ENABLE_EXPR_FUNC(DFad&) operator -= (const Expr<S>& x) {
223  GeneralFadType::operator-=(x);
224  return *this;
225  }
226 
228  template <typename S>
230  SACADO_ENABLE_EXPR_FUNC(DFad&) operator *= (const Expr<S>& x) {
231  GeneralFadType::operator*=(x);
232  return *this;
233  }
234 
236  template <typename S>
238  SACADO_ENABLE_EXPR_FUNC(DFad&) operator /= (const Expr<S>& x) {
239  GeneralFadType::operator/=(x);
240  return *this;
241  }
242 
243  }; // class DFad<ValueT>
244 
245  template <typename T>
246  struct BaseExpr< GeneralFad<T,Fad::DynamicStorage<T> > > {
248  };
249 
250  template <typename T>
251  struct ExprLevel< DFad<T> > {
252  static const unsigned value =
253  ExprLevel< typename DFad<T>::value_type >::value + 1;
254  };
255 
256  template <typename T>
257  struct IsFadExpr< DFad<T> > {
258  static const bool value = true;
259  };
260 
261  } // namespace Fad
262 
263  template <typename T>
264  struct IsFad< FAD_NS::DFad<T> > {
265  static const bool value = true;
266  };
267 
268  template <typename T>
269  struct IsExpr< FAD_NS::DFad<T> > {
270  static const bool value = true;
271  };
272 
273  template <typename T>
274  struct BaseExprType< FAD_NS::DFad<T> > {
276  };
277 
278  template <typename,unsigned,unsigned> struct ViewFadType;
279  namespace FAD_NS {
280  template <typename,unsigned,unsigned,typename> class ViewFad;
281  }
282 
284  template< class ValueType, unsigned length, unsigned stride >
285  struct ViewFadType< Sacado::FAD_NS::DFad< ValueType >, length, stride > {
287  };
288 
290 
293  template< class ValueType, unsigned length, unsigned stride >
294  struct ViewFadType< const Sacado::FAD_NS::DFad< ValueType >, length, stride > {
296  };
297 
298 } // namespace Sacado
Sacado::FAD_NS::ViewFad< const ValueType, length, stride, Sacado::FAD_NS::DFad< ValueType > > type
KOKKOS_INLINE_FUNCTION DFad(const int sz, const ValueT &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
#define SACADO_ENABLE_VALUE_CTOR_DECL
Base template specification for whether a type is a Fad type.
Forward-mode AD class using dynamic memory allocation and expression templates.
KOKKOS_INLINE_FUNCTION DFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
static const bool value
#define SACADO_ENABLE_EXPR_CTOR_DECL
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
KOKKOS_INLINE_FUNCTION DFad()
Default constructor.
Is a type an expression.
KOKKOS_INLINE_FUNCTION DFad(const DFad &x)
Copy constructor.
KOKKOS_INLINE_FUNCTION DFad(const int sz, const int i, const ValueT &x)
Constructor with size sz, index i, and value x.
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
FAD_NS::DFad< T >::base_expr_type type
ExprType::scalar_type scalar_type
Typename of scalar&#39;s (which may be different from value_type)
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
DFad< typename GeneralFad< T, Fad::DynamicStorage< T > >::value_type > type
Get the base Fad type from a view/expression.
Forward-mode AD class using dynamic memory allocation and expression templates.
Fad::DynamicStorage< ValueT > StorageType
Base classes.
ExprType::value_type value_type
Typename of values.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
Expr< GeneralFadType > ExprType
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION ~DFad()
Destructor.
KOKKOS_INLINE_FUNCTION DFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x convertible to ValueT.
static const bool value
Sacado::FAD_NS::ViewFad< ValueType, length, stride, Sacado::FAD_NS::DFad< ValueType > > type
Turn DFad into a meta-function class usable with mpl::apply.
GeneralFad< ValueT, StorageType > GeneralFadType
#define FAD_NS
Get view type for any Fad type.