Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_SFad_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 
35 
41  template <typename ValueT, int Num>
42  class SFad :
43  public Expr< SFadExprTag<ValueT,Num > > {
44 
45  public:
46 
48  typedef Expr< SFadExprTag<ValueT,Num > > ExprType;
49 
51  typedef typename ExprType::value_type value_type;
52 
54  typedef typename ExprType::scalar_type scalar_type;
55 
58 
60  template <typename T>
61  struct apply {
62  typedef SFad<T,Num> type;
63  };
64 
69 
71 
75  SFad() :
76  ExprType() {}
77 
79 
82  template <typename S>
85  ExprType(x) {}
86 
88 
92  SFad(const int sz, const ValueT & x, const DerivInit zero_out = InitDerivArray) :
93  ExprType(sz,x,zero_out) {}
94 
96 
102  SFad(const int sz, const int i, const ValueT & x) :
103  ExprType(sz,i,x) {}
104 
107  SFad(const SFad& x) :
108  ExprType(static_cast<const ExprType&>(x)) {}
109 
111  template <typename S>
113  SFad(const Expr<S>& x, SACADO_ENABLE_EXPR_CTOR_DECL) :
114  ExprType(x) {}
115 
117 
120  ~SFad() {}
121 
123  template <typename S>
125  SACADO_ENABLE_VALUE_FUNC(SFad&) operator=(const S& v) {
126  ExprType::operator=(v);
127  return *this;
128  }
129 
132  SFad& operator=(const SFad& x) {
133  ExprType::operator=(static_cast<const ExprType&>(x));
134  return *this;
135  }
136 
138  template <typename S>
140  SACADO_ENABLE_EXPR_FUNC(SFad&) operator=(const Expr<S>& x)
141  {
142  ExprType::operator=(x);
143  return *this;
144  }
145 
147  template <typename S>
149  SACADO_ENABLE_VALUE_FUNC(SFad&) operator += (const S& x) {
150  ExprType::operator+=(x);
151  return *this;
152  }
153 
155  template <typename S>
157  SACADO_ENABLE_VALUE_FUNC(SFad&) operator -= (const S& x) {
158  ExprType::operator-=(x);
159  return *this;
160  }
161 
163  template <typename S>
165  SACADO_ENABLE_VALUE_FUNC(SFad&) operator *= (const S& x) {
166  ExprType::operator*=(x);
167  return *this;
168  }
169 
171  template <typename S>
173  SACADO_ENABLE_VALUE_FUNC(SFad&) operator /= (const S& x) {
174  ExprType::operator/=(x);
175  return *this;
176  }
177 
180  SFad& operator += (const SFad& x) {
181  ExprType::operator+=(static_cast<const ExprType&>(x));
182  return *this;
183  }
184 
187  SFad& operator -= (const SFad& x) {
188  ExprType::operator-=(static_cast<const ExprType&>(x));
189  return *this;
190  }
191 
194  SFad& operator *= (const SFad& x) {
195  ExprType::operator*=(static_cast<const ExprType&>(x));
196  return *this;
197  }
198 
201  SFad& operator /= (const SFad& x) {
202  ExprType::operator/=(static_cast<const ExprType&>(x));
203  return *this;
204  }
205 
207  template <typename S>
209  SACADO_ENABLE_EXPR_FUNC(SFad&) operator += (const Expr<S>& x) {
210  ExprType::operator+=(x);
211  return *this;
212  }
213 
215  template <typename S>
217  SACADO_ENABLE_EXPR_FUNC(SFad&) operator -= (const Expr<S>& x) {
218  ExprType::operator-=(x);
219  return *this;
220  }
221 
223  template <typename S>
225  SACADO_ENABLE_EXPR_FUNC(SFad&) operator *= (const Expr<S>& x) {
226  ExprType::operator*=(x);
227  return *this;
228  }
229 
231  template <typename S>
233  SACADO_ENABLE_EXPR_FUNC(SFad&) operator /= (const Expr<S>& x) {
234  ExprType::operator/=(x);
235  return *this;
236  }
237 
238  }; // class SFad<ValueT,Num>
239 
240  template <typename T, int Num>
241  std::ostream& operator << (std::ostream& os,
242  const Expr< SFadExprTag<T,Num> >& x) {
243  os << x.val() << " [";
244 
245  for (int i=0; i< x.size(); i++) {
246  os << " " << x.dx(i);
247  }
248 
249  os << " ]";
250  return os;
251  }
252 
253  template <typename T, int N>
254  struct ExprLevel< SFad<T,N> > {
255  static const unsigned value =
256  ExprLevel< typename SFad<T,N>::value_type >::value + 1;
257  };
258 
259  template <typename T, int N>
260  struct IsFadExpr< SFad<T,N> > {
261  static const bool value = true;
262  };
263 
264  } // namespace Fad
265 
266  template <typename T, int N>
267  struct IsFad< FAD_NS::SFad<T,N> > {
268  static const bool value = true;
269  };
270 
271  template <typename T, int N>
272  struct IsExpr< FAD_NS::SFad<T,N> > {
273  static const bool value = true;
274  };
275 
276  template <typename T, int N>
277  struct BaseExprType< FAD_NS::SFad<T,N> > {
279  };
280 
281  template <typename T,unsigned,unsigned> struct ViewFadType;
282  namespace FAD_NS {
283  template <typename,unsigned,unsigned,typename> class ViewFad;
284  }
285 
287  template< class ValueType, int N, unsigned length, unsigned stride >
288  struct ViewFadType< Sacado::FAD_NS::SFad< ValueType, N >, length, stride > {
290 };
291 
293 
296  template< class ValueType, int N, unsigned length, unsigned stride >
297  struct ViewFadType< const Sacado::FAD_NS::SFad< ValueType, N >, length, stride > {
299  };
300 
301 } // namespace Sacado
ExprType::scalar_type scalar_type
Typename of scalar&#39;s (which may be different from value_type)
KOKKOS_INLINE_FUNCTION SFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x convertible to ValueT.
KOKKOS_INLINE_FUNCTION SFad(const int sz, const ValueT &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
KOKKOS_INLINE_FUNCTION ~SFad()
Destructor.
#define SACADO_ENABLE_VALUE_CTOR_DECL
Base template specification for whether a type is a Fad type.
Sacado::FAD_NS::ViewFad< ValueType, length, stride, Sacado::FAD_NS::SFad< ValueType, N > > type
Forward-mode AD class using dynamic memory allocation and expression templates.
Turn SFad into a meta-function class usable with mpl::apply.
ScalarType< ValueT >::type ScalarT
Typename of scalar&#39;s (which may be different from ValueT)
static const bool value
#define SACADO_ENABLE_EXPR_CTOR_DECL
std::ostream & operator<<(std::ostream &os, const Expr< SFadExprTag< T, Num > > &x)
FAD_NS::SFad< T, N >::base_expr_type type
Is a type an expression.
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
Get the base Fad type from a view/expression.
KOKKOS_INLINE_FUNCTION SFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
Expr< SFadExprTag< ValueT, Num > > ExprType
Base classes.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
ExprType::value_type value_type
Typename of values.
KOKKOS_INLINE_FUNCTION SFad(const int sz, const int i, const ValueT &x)
Constructor with size sz, index i, and value x.
Forward-mode AD class using static memory allocation.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION SFad(const SFad &x)
Copy constructor.
Sacado::FAD_NS::ViewFad< const ValueType, length, stride, Sacado::FAD_NS::SFad< ValueType, N > > type
static const bool value
KOKKOS_INLINE_FUNCTION SFad()
Default constructor.
#define FAD_NS
Get view type for any Fad type.