Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_SLFad_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 
34  // Forward declaration
35  template <typename T, int Num>
37 
51  template <typename ValueT, int Num>
52  class SLFad :
53  public Expr< GeneralFad<ValueT,Fad::StaticStorage<ValueT,Num> > > {
54 
55  public:
56 
59  typedef GeneralFad<ValueT,StorageType> GeneralFadType;
60  typedef Expr<GeneralFadType> ExprType;
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 SLFad<T,Num> type;
75  };
76 
81 
83 
87  SLFad() :
88  ExprType() {}
89 
91 
94  template <typename S>
97  ExprType(x) {}
98 
100 
104  SLFad(const int sz, const ValueT & x, const DerivInit zero_out = InitDerivArray) :
105  ExprType(sz,x,zero_out) {}
106 
108 
114  SLFad(const int sz, const int i, const ValueT & x) :
115  ExprType(sz,i,x) {}
116 
119  SLFad(const SLFad& x) :
120  ExprType(x) {}
121 
123  template <typename S>
125  SLFad(const Expr<S>& x, SACADO_ENABLE_EXPR_CTOR_DECL) :
126  ExprType(x) {}
127 
129 
132  ~SLFad() {}
133 
135  template <typename S>
137  SACADO_ENABLE_VALUE_FUNC(SLFad&) operator=(const S& v) {
138  GeneralFadType::operator=(v);
139  return *this;
140  }
141 
144  SLFad& operator=(const SLFad& x) {
145  GeneralFadType::operator=(static_cast<const GeneralFadType&>(x));
146  return *this;
147  }
148 
150  template <typename S>
152  SACADO_ENABLE_EXPR_FUNC(SLFad&) operator=(const Expr<S>& x)
153  {
154  GeneralFadType::operator=(x);
155  return *this;
156  }
157 
159  template <typename S>
161  SACADO_ENABLE_VALUE_FUNC(SLFad&) operator += (const S& x) {
162  GeneralFadType::operator+=(x);
163  return *this;
164  }
165 
167  template <typename S>
169  SACADO_ENABLE_VALUE_FUNC(SLFad&) operator -= (const S& x) {
170  GeneralFadType::operator-=(x);
171  return *this;
172  }
173 
175  template <typename S>
177  SACADO_ENABLE_VALUE_FUNC(SLFad&) operator *= (const S& x) {
178  GeneralFadType::operator*=(x);
179  return *this;
180  }
181 
183  template <typename S>
185  SACADO_ENABLE_VALUE_FUNC(SLFad&) operator /= (const S& x) {
186  GeneralFadType::operator/=(x);
187  return *this;
188  }
189 
192  SLFad& operator += (const SLFad& x) {
193  GeneralFadType::operator+=(static_cast<const GeneralFadType&>(x));
194  return *this;
195  }
196 
199  SLFad& operator -= (const SLFad& x) {
200  GeneralFadType::operator-=(static_cast<const GeneralFadType&>(x));
201  return *this;
202  }
203 
206  SLFad& operator *= (const SLFad& x) {
207  GeneralFadType::operator*=(static_cast<const GeneralFadType&>(x));
208  return *this;
209  }
210 
213  SLFad& operator /= (const SLFad& x) {
214  GeneralFadType::operator/=(static_cast<const GeneralFadType&>(x));
215  return *this;
216  }
217 
219  template <typename S>
221  SACADO_ENABLE_EXPR_FUNC(SLFad&) operator += (const Expr<S>& x) {
222  GeneralFadType::operator+=(x);
223  //*this = *this + x;
224  return *this;
225  }
226 
228  template <typename S>
230  SACADO_ENABLE_EXPR_FUNC(SLFad&) operator -= (const Expr<S>& x) {
231  GeneralFadType::operator-=(x);
232  return *this;
233  }
234 
236  template <typename S>
238  SACADO_ENABLE_EXPR_FUNC(SLFad&) operator *= (const Expr<S>& x) {
239  GeneralFadType::operator*=(x);
240  return *this;
241  }
242 
244  template <typename S>
246  SACADO_ENABLE_EXPR_FUNC(SLFad&) operator /= (const Expr<S>& x) {
247  GeneralFadType::operator/=(x);
248  return *this;
249  }
250 
251  }; // class SLFad<ValueT,Num>
252 
253  template <typename T, int N>
254  struct BaseExpr< GeneralFad<T,Fad::StaticStorage<T,N> > > {
256  };
257 
258  template <typename T, int N>
259  struct ExprLevel< SLFad<T,N> > {
260  static const unsigned value =
261  ExprLevel< typename SLFad<T,N>::value_type >::value + 1;
262  };
263 
264  template <typename T, int N>
265  struct IsFadExpr< SLFad<T,N> > {
266  static const bool value = true;
267  };
268 
269  } // namespace Fad
270 
271  template <typename T, int N>
272  struct IsFad< FAD_NS::SLFad<T,N> > {
273  static const bool value = true;
274  };
275 
276  template <typename T, int N>
277  struct IsExpr< FAD_NS::SLFad<T,N> > {
278  static const bool value = true;
279  };
280 
281  template <typename T, int N>
282  struct BaseExprType< FAD_NS::SLFad<T,N> > {
284  };
285 
286  template <typename T,unsigned,unsigned> struct ViewFadType;
287  namespace FAD_NS {
288  template <typename,unsigned,unsigned,typename> class ViewFad;
289  }
290 
292  template< class ValueType, int N, unsigned length, unsigned stride >
293  struct ViewFadType< Sacado::FAD_NS::SLFad< ValueType, N >, length, stride > {
295  };
296 
298 
301  template< class ValueType, int N, unsigned length, unsigned stride >
302  struct ViewFadType< const Sacado::FAD_NS::SLFad< ValueType, N >, length, stride > {
304  };
305 
306 } // namespace Sacado
Turn SLFad into a meta-function class usable with mpl::apply.
KOKKOS_INLINE_FUNCTION SLFad(const int sz, const ValueT &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
Derivative array storage class using static memory allocation.
#define SACADO_ENABLE_VALUE_CTOR_DECL
Base template specification for whether a type is a Fad type.
KOKKOS_INLINE_FUNCTION SLFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
KOKKOS_INLINE_FUNCTION SLFad(const int sz, const int i, const ValueT &x)
Constructor with size sz, index i, and value x.
Forward-mode AD class using dynamic memory allocation and expression templates.
KOKKOS_INLINE_FUNCTION SLFad(const SLFad &x)
Copy constructor.
static const bool value
#define SACADO_ENABLE_EXPR_CTOR_DECL
KOKKOS_INLINE_FUNCTION SLFad()
Default constructor.
KOKKOS_INLINE_FUNCTION ~SLFad()
Destructor.
Is a type an expression.
Sacado::FAD_NS::ViewFad< const ValueType, length, stride, Sacado::FAD_NS::SLFad< ValueType, N > > type
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
ExprType::value_type value_type
Typename of values.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
FAD_NS::SLFad< T, N >::base_expr_type type
Fad::StaticStorage< ValueT, Num > StorageType
Base classes.
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)
Expr< GeneralFadType > ExprType
Sacado::FAD_NS::ViewFad< ValueType, length, stride, Sacado::FAD_NS::SLFad< ValueType, N > > type
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
GeneralFad< ValueT, StorageType > GeneralFadType
Forward-mode AD class using static memory allocation with long arrays and expression templates...
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION SLFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x convertible to ValueT.
static const bool value
#define FAD_NS
SLFad< typename GeneralFad< T, Fad::StaticStorage< T, N > >::value_type, N > type
Get view type for any Fad type.