Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_DVFad.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_DVFAD_HPP
31 #define SACADO_FAD_DVFAD_HPP
32 
36 
37 namespace Sacado {
38 
39  namespace Fad {
40 
51  template <typename ValueT>
52  class DVFad :
53  public Expr< GeneralFad<ValueT,VectorDynamicStorage<ValueT> > > {
54 
55  public:
56 
61 
63  typedef typename ExprType::value_type value_type;
64 
66  typedef typename ExprType::scalar_type scalar_type;
67 
70 
72  template <typename T>
73  struct apply {
74  typedef DVFad<T> type;
75  };
76 
81 
83 
86  DVFad() :
87  ExprType() {}
88 
90 
93  template <typename S>
95  ExprType(x) {}
96 
98 
101  DVFad(const int sz, const ValueT& x, const DerivInit zero_out = InitDerivArray) :
102  ExprType(sz,x,zero_out) {}
103 
105 
110  DVFad(const int sz, const int i, const ValueT & x) :
111  ExprType(sz,i,x) {}
112 
114 
118  DVFad(const int sz, ValueT* x, ValueT* dx, bool zero_out = false) :
119  ExprType(sz,x,dx,zero_out) {}
120 
122 
127  DVFad(const int sz, const int i, ValueT* x, ValueT* dx) :
128  ExprType(sz,i,x,dx) {}
129 
131  DVFad(const DVFad& x) :
132  ExprType(x) {}
133 
135  template <typename S>
137  ExprType(x) {}
138 
140 
142  ~DVFad() {}
143 
145  template <typename S>
146  SACADO_ENABLE_VALUE_FUNC(DVFad&) operator=(const S& v) {
147  GeneralFadType::operator=(v);
148  return *this;
149  }
150 
152  DVFad& operator=(const DVFad& x) {
153  GeneralFadType::operator=(static_cast<const GeneralFadType&>(x));
154  return *this;
155  }
156 
158  template <typename S>
159  SACADO_ENABLE_EXPR_FUNC(DVFad&) operator=(const Expr<S>& x)
160  {
161  GeneralFadType::operator=(x);
162  return *this;
163  }
164 
166  template <typename S>
168  SACADO_ENABLE_VALUE_FUNC(DVFad&) operator += (const S& x) {
169  GeneralFadType::operator+=(x);
170  return *this;
171  }
172 
174  template <typename S>
176  SACADO_ENABLE_VALUE_FUNC(DVFad&) operator -= (const S& x) {
177  GeneralFadType::operator-=(x);
178  return *this;
179  }
180 
182  template <typename S>
184  SACADO_ENABLE_VALUE_FUNC(DVFad&) operator *= (const S& x) {
185  GeneralFadType::operator*=(x);
186  return *this;
187  }
188 
190  template <typename S>
192  SACADO_ENABLE_VALUE_FUNC(DVFad&) operator /= (const S& x) {
193  GeneralFadType::operator/=(x);
194  return *this;
195  }
196 
198  DVFad& operator += (const DVFad& x) {
199  GeneralFadType::operator+=(static_cast<const GeneralFadType&>(x));
200  return *this;
201  }
202 
204  DVFad& operator -= (const DVFad& x) {
205  GeneralFadType::operator-=(static_cast<const GeneralFadType&>(x));
206  return *this;
207  }
208 
210  DVFad& operator *= (const DVFad& x) {
211  GeneralFadType::operator*=(static_cast<const GeneralFadType&>(x));
212  return *this;
213  }
214 
216  DVFad& operator /= (const DVFad& x) {
217  GeneralFadType::operator/=(static_cast<const GeneralFadType&>(x));
218  return *this;
219  }
220 
222  template <typename S>
224  SACADO_ENABLE_EXPR_FUNC(DVFad&) operator += (const Expr<S>& x) {
225  GeneralFadType::operator+=(x);
226  return *this;
227  }
228 
230  template <typename S>
232  SACADO_ENABLE_EXPR_FUNC(DVFad&) operator -= (const Expr<S>& x) {
233  GeneralFadType::operator-=(x);
234  return *this;
235  }
236 
238  template <typename S>
240  SACADO_ENABLE_EXPR_FUNC(DVFad&) operator *= (const Expr<S>& x) {
241  GeneralFadType::operator*=(x);
242  return *this;
243  }
244 
246  template <typename S>
248  SACADO_ENABLE_EXPR_FUNC(DVFad&) operator /= (const Expr<S>& x) {
249  GeneralFadType::operator/=(x);
250  return *this;
251  }
252 
253  }; // class DVFad<ValueT>
254 
255  template <typename T>
258  };
259 
260  template <typename T>
261  struct ExprLevel< DVFad<T> > {
262  static const unsigned value =
264  };
265 
266  template <typename T>
267  struct IsFadExpr< DVFad<T> > {
268  static const bool value = true;
269  };
270 
271  } // namespace Fad
272 
273  template <typename T>
274  struct IsExpr< Fad::DVFad<T> > {
275  static const bool value = true;
276  };
277 
278  template <typename T>
279  struct BaseExprType< Fad::DVFad<T> > {
281  };
282 
284  template< class ValueType, unsigned length, unsigned stride >
285  struct ViewFadType< Sacado::Fad::DVFad< ValueType >, length, stride > {
287  };
288 
290  template< class ValueType, unsigned length, unsigned stride >
291  struct ViewFadType< const Sacado::Fad::DVFad< ValueType >, length, stride > {
293  };
294 
295 } // namespace Sacado
296 
297 #endif // SACADO_FAD_DFAD_HPP
Wrapper for a generic expression template.
DVFad< typename GeneralFad< T, Fad::VectorDynamicStorage< T > >::value_type > type
#define SACADO_ENABLE_VALUE_CTOR_DECL
ExprType::value_type value_type
Typename of values.
GeneralFad< ValueT, StorageType > GeneralFadType
Sacado::Fad::ViewFad< const ValueType, length, stride, Sacado::Fad::DVFad< const ValueType > > type
static const bool value
#define SACADO_ENABLE_EXPR_CTOR_DECL
DVFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
Is a type an expression.
DVFad(const int sz, const int i, ValueT *x, ValueT *dx)
Constructor with supplied memory and index i.
ExprType::scalar_type scalar_type
Typename of scalar&#39;s (which may be different from T)
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
Determine whether a given type is an expression.
Sacado::Fad::ViewFad< ValueType, length, stride, Sacado::Fad::DVFad< ValueType > > type
Meta-function for determining concrete base expression.
Fad::DVFad< T >::base_expr_type type
Get the base Fad type from a view/expression.
VectorDynamicStorage< ValueT > StorageType
Base classes.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
Forward-mode AD class using dynamic memory allocation and expression templates.
Meta-function for determining nesting with an expression.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
DVFad()
Default constructor.
DVFad(const DVFad &x)
Copy constructor.
Turn DVFad into a meta-function class usable with mpl::apply.
DVFad(const int sz, const ValueT &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
Derivative array storage class using dynamic memory allocation.
static const unsigned value
DVFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x convertible to ValueT.
DVFad(const int sz, ValueT *x, ValueT *dx, bool zero_out=false)
Constructor with supplied memory.
Initialize the derivative array.
expr expr dx(i)
Expr< GeneralFadType > ExprType
DVFad(const int sz, const int i, const ValueT &x)
Constructor with size sz, index i, and value x.
Forward-mode AD class templated on the storage for the derivative array.
Get view type for any Fad type.