Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Fad_DMFad.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_DMFAD_HPP
31 #define SACADO_FAD_DMFAD_HPP
32 
33 #include "Sacado_ConfigDefs.h"
34 
35 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
36 
37 #include "Sacado_Fad_MemPoolStorage.hpp" // For Fad::MemPoolStorage<> alias
38 #include "Sacado_Fad_Exp_DMFad.hpp"
39 
40 namespace Sacado {
41  namespace Fad {
42  template <typename T>
43  using DMFad = Exp::GeneralFad< Exp::MemPoolStorage<T> >;
44  }
45 }
46 
47 #else
48 
52 
53 namespace Sacado {
54 
55  namespace Fad {
56 
67  template <typename ValueT>
68  class DMFad : public Expr< GeneralFad<ValueT,MemPoolStorage<ValueT> > > {
69 
70  public:
71 
76 
78  typedef typename ExprType::value_type value_type;
79 
81  typedef typename ExprType::scalar_type scalar_type;
82 
85 
87  template <typename T>
88  struct apply {
89  typedef DMFad<T> type;
90  };
91 
96 
98 
101  DMFad() :
102  ExprType() {}
103 
105 
108  template <typename S>
110  ExprType(x) {}
111 
113 
116  DMFad(const int sz, const ValueT& x, const DerivInit zero_out = InitDerivArray) :
117  ExprType(sz,x,zero_out) {}
118 
120 
125  DMFad(const int sz, const int i, const ValueT & x) :
126  ExprType(sz,i,x) {}
127 
129  DMFad(const DMFad& x) :
130  ExprType(x) {}
131 
133  template <typename S>
135  ExprType(x) {}
136 
138 
140  ~DMFad() {}
141 
143  template <typename S>
144  SACADO_ENABLE_VALUE_FUNC(DMFad&) operator=(const S& v) {
145  GeneralFadType::operator=(v);
146  return *this;
147  }
148 
150  DMFad& operator=(const DMFad& x) {
151  GeneralFadType::operator=(static_cast<const GeneralFadType&>(x));
152  return *this;
153  }
154 
156  template <typename S>
157  SACADO_ENABLE_EXPR_FUNC(DMFad&) operator=(const Expr<S>& x)
158  {
159  GeneralFadType::operator=(x);
160  return *this;
161  }
162 
164  static void setDefaultPool(MemPool* pool) {
165  MemPoolStorage<ValueT>::defaultPool_ = pool;
166  }
167 
169  template <typename S>
171  SACADO_ENABLE_VALUE_FUNC(DMFad&) operator += (const S& x) {
172  GeneralFadType::operator+=(x);
173  return *this;
174  }
175 
177  template <typename S>
179  SACADO_ENABLE_VALUE_FUNC(DMFad&) operator -= (const S& x) {
180  GeneralFadType::operator-=(x);
181  return *this;
182  }
183 
185  template <typename S>
187  SACADO_ENABLE_VALUE_FUNC(DMFad&) operator *= (const S& x) {
188  GeneralFadType::operator*=(x);
189  return *this;
190  }
191 
193  template <typename S>
195  SACADO_ENABLE_VALUE_FUNC(DMFad&) operator /= (const S& x) {
196  GeneralFadType::operator/=(x);
197  return *this;
198  }
199 
201  DMFad& operator += (const DMFad& x) {
202  GeneralFadType::operator+=(static_cast<const GeneralFadType&>(x));
203  return *this;
204  }
205 
207  DMFad& operator -= (const DMFad& x) {
208  GeneralFadType::operator-=(static_cast<const GeneralFadType&>(x));
209  return *this;
210  }
211 
213  DMFad& operator *= (const DMFad& x) {
214  GeneralFadType::operator*=(static_cast<const GeneralFadType&>(x));
215  return *this;
216  }
217 
219  DMFad& operator /= (const DMFad& x) {
220  GeneralFadType::operator/=(static_cast<const GeneralFadType&>(x));
221  return *this;
222  }
223 
225  template <typename S>
227  SACADO_ENABLE_EXPR_FUNC(DMFad&) operator += (const Expr<S>& x) {
228  GeneralFadType::operator+=(x);
229  return *this;
230  }
231 
233  template <typename S>
235  SACADO_ENABLE_EXPR_FUNC(DMFad&) operator -= (const Expr<S>& x) {
236  GeneralFadType::operator-=(x);
237  return *this;
238  }
239 
241  template <typename S>
243  SACADO_ENABLE_EXPR_FUNC(DMFad&) operator *= (const Expr<S>& x) {
244  GeneralFadType::operator*=(x);
245  return *this;
246  }
247 
249  template <typename S>
251  SACADO_ENABLE_EXPR_FUNC(DMFad&) operator /= (const Expr<S>& x) {
252  GeneralFadType::operator/=(x);
253  return *this;
254  }
255 
256  }; // class DMFad<ValueT>
257 
258  template <typename T>
259  struct BaseExpr< GeneralFad<T,Fad::MemPoolStorage<T> > > {
261  };
262 
263  template <typename T>
264  struct ExprLevel< DMFad<T> > {
265  static const unsigned value =
267  };
268 
269  template <typename T>
270  struct IsFadExpr< DMFad<T> > {
271  static const bool value = true;
272  };
273 
274  } // namespace Fad
275 
276  template <typename T>
277  struct IsExpr< Fad::DMFad<T> > {
278  static const bool value = true;
279  };
280 
281  template <typename T>
282  struct BaseExprType< Fad::DMFad<T> > {
284  };
285 
287  template< class ValueType, unsigned length, unsigned stride >
288  struct ViewFadType< Sacado::Fad::DMFad< ValueType >, length, stride > {
290  };
291 
293  template< class ValueType, unsigned length, unsigned stride >
294  struct ViewFadType< const Sacado::Fad::DMFad< ValueType >, length, stride > {
296  };
297 
298 } // namespace Sacado
299 
300 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
301 
302 #endif // SACADO_FAD_DMFAD_HPP
Wrapper for a generic expression template.
ExprType::value_type value_type
Typename of values.
DMFad(const int sz, const int i, const ValueT &x)
Constructor with size sz, index i, and value x.
Turn DMFad into a meta-function class usable with mpl::apply.
Sacado::Fad::ViewFad< ValueType, length, stride, Sacado::Fad::DMFad< ValueType > > type
Expr< GeneralFadType > ExprType
#define SACADO_ENABLE_VALUE_CTOR_DECL
DMFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
GeneralFad< MemPoolStorage< T > > DMFad
static const bool value
#define SACADO_ENABLE_EXPR_CTOR_DECL
Is a type an expression.
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
Fad::DMFad< T >::base_expr_type type
MemPoolStorage< ValueT > StorageType
Base classes.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
Determine whether a given type is an expression.
DMFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x convertible to ValueT.
Meta-function for determining concrete base expression.
Derivative array storage class using dynamic memory allocation.
Get the base Fad type from a view/expression.
ExprType::scalar_type scalar_type
Typename of scalar&#39;s (which may be different from value_type)
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
Meta-function for determining nesting with an expression.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
Sacado::Fad::ViewFad< const ValueType, length, stride, Sacado::Fad::DMFad< const ValueType > > type
DMFad(const DMFad &x)
Copy constructor.
static const unsigned value
Initialize the derivative array.
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)
DMFad(const int sz, const ValueT &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
GeneralFad< ValueT, StorageType > GeneralFadType
DMFad< typename GeneralFad< T, Fad::MemPoolStorage< T > >::value_type > type
DMFad()
Default constructor.
Forward-mode AD class templated on the storage for the derivative array.
Get view type for any Fad type.