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_Exp_GeneralFad.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_FAD_EXP_GENERALFAD_HPP
11 #define SACADO_FAD_EXP_GENERALFAD_HPP
12 
17 
18 namespace Sacado {
19 
21  namespace Fad {
22  namespace Exp {
23 
25 
29  template <typename Storage>
30  class GeneralFad :
31  public Expr< GeneralFad<Storage> >, // Brings in expression interface
32  public Extender<Storage> // Brings in interface extensions & storage
33  {
34  public:
35 
37  typedef Storage StorageType;
38 
41 
44 
46  using typename StorageType::value_type;
47 
50 
52  static constexpr bool is_view = Storage::is_view;
53 
55  template <typename T>
56  struct apply {
57  typedef typename Storage::template apply<T>::type S;
59  };
60 
62  template <int N>
63  struct apply_N {
64  typedef typename Storage::template apply_N<N>::type S;
66  };
67 
72 
74  using ExtenderType::ExtenderType;
75 
78  GeneralFad() = default;
79 
82  GeneralFad(const GeneralFad& x) = default;
83 
86  GeneralFad(GeneralFad&& x) = default;
87 
89  template <typename S>
92  ExtenderType(x) {}
93 
95  template <typename S>
98  ExtenderType(x.derived().size(), value_type(0.), NoInitDerivArray)
99  {
101  }
102 
105  ~GeneralFad() = default;
106 
108 
115  void diff(const int ith, const int n) {
116  if (this->size() != n)
117  this->resize(n);
118 
119  this->zero();
120  this->fastAccessDx(ith) = value_type(1.);
121  }
122 
124 
127  void setUpdateValue(bool update_val) {}
128 
130 
133  bool updateValue() const { return true; }
134 
136 
139  void cache() const {}
140 
142  template <typename S>
144  SACADO_EXP_ENABLE_EXPR_FUNC(bool) isEqualTo(const Expr<S>& xx) const {
145  typedef typename Expr<S>::derived_type expr_type;
146  const expr_type& x = xx.derived();
147 
148  typedef IsEqual<value_type> IE;
149  if (x.size() != this->size()) return false;
150  bool eq = IE::eval(x.val(), this->val());
151  const int sz = this->size();
153  eq = eq && IE::eval(x.dx(i), this->dx(i));
154  return eq;
155  }
156 
158 
163 
169  int availableSize() const { return this->length(); }
170 
173  bool hasFastAccess() const { return this->size()!=0; }
174 
177  void setIsConstant(bool is_const) {
178  if (is_const && this->size()!=0)
179  this->resize(0);
180  }
181 
183 
188 
190  template <typename S>
192  SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator=(const S& v) {
193  this->val() = v;
194  if (this->size()) this->resize(0);
195  return *this;
196  }
197 
200  GeneralFad&
201  operator=(const GeneralFad& x) = default;
202 
205  GeneralFad&
206  operator=(GeneralFad&& x) = default;
207 
209  template <typename S>
211  SACADO_EXP_ENABLE_EXPR_FUNC(GeneralFad&) operator=(const Expr<S>& x) {
212  ExprAssign<GeneralFad>::assign_equal(*this, x.derived());
213  return *this;
214  }
215 
217 
222 
224  template <typename S>
226  SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator += (const S& v) {
227  this->val() += v;
228  return *this;
229  }
230 
232  template <typename S>
234  SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator -= (const S& v) {
235  this->val() -= v;
236  return *this;
237  }
238 
240  template <typename S>
242  SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator *= (const S& v) {
243  const int sz = this->size();
244  this->val() *= v;
246  this->fastAccessDx(i) *= v;
247  return *this;
248  }
249 
251  template <typename S>
253  SACADO_ENABLE_VALUE_FUNC(GeneralFad&) operator /= (const S& v) {
254  const int sz = this->size();
255  this->val() /= v;
257  this->fastAccessDx(i) /= v;
258  return *this;
259  }
260 
263  GeneralFad& operator += (const GeneralFad& x) {
265  return *this;
266  }
267 
270  GeneralFad& operator -= (const GeneralFad& x) {
272  return *this;
273  }
274 
277  GeneralFad& operator *= (const GeneralFad& x) {
279  return *this;
280  }
281 
284  GeneralFad& operator /= (const GeneralFad& x) {
286  return *this;
287  }
288 
290  template <typename S>
292  SACADO_EXP_ENABLE_EXPR_FUNC(GeneralFad&) operator += (const Expr<S>& x) {
293  ExprAssign<GeneralFad>::assign_plus_equal(*this, x.derived());
294  return *this;
295  }
296 
298  template <typename S>
300  SACADO_EXP_ENABLE_EXPR_FUNC(GeneralFad&) operator -= (const Expr<S>& x) {
301  ExprAssign<GeneralFad>::assign_minus_equal(*this, x.derived());
302  return *this;
303  }
304 
306  template <typename S>
308  SACADO_EXP_ENABLE_EXPR_FUNC(GeneralFad&) operator *= (const Expr<S>& x) {
309  ExprAssign<GeneralFad>::assign_times_equal(*this, x.derived());
310  return *this;
311  }
312 
314  template <typename S>
316  SACADO_EXP_ENABLE_EXPR_FUNC(GeneralFad&) operator /= (const Expr<S>& x) {
318  return *this;
319  }
320 
322 
323  }; // class GeneralFad
324 
325  template <typename S>
326  struct ExprLevel< GeneralFad<S> > {
327  static constexpr unsigned value =
329  };
330 
331  template <typename S>
332  struct IsFadExpr< GeneralFad<S> > {
333  static constexpr bool value = true;
334  };
335 
336  } // namespace Exp
337  } // namespace Fad
338 
339  template <typename S>
340  struct IsView< Fad::Exp::GeneralFad<S> > {
341  static constexpr bool value = Fad::Exp::GeneralFad<S>::is_view;
342  };
343 
344  template <typename S>
345  struct IsFad< Fad::Exp::GeneralFad<S> > {
346  static constexpr bool value = true;
347  };
348 
349  template <typename S>
350  struct IsExpr< Fad::Exp::GeneralFad<S> > {
351  static constexpr bool value = true;
352  };
353 
354  template <typename S>
355  struct BaseExprType< Fad::Exp::GeneralFad<S> > {
357  };
358 
359 } // namespace Sacado
360 
361 #include "Sacado_Fad_Exp_Ops.hpp"
362 
363 #endif // SACADO_FAD_EXP_GENERALFAD_HPP
Wrapper for a generic expression template.
static SACADO_INLINE_FUNCTION void assign_divide_equal(DstType &dst, const SrcType &x)
Implementation of dst /= x.
expr expr dx(i)
SACADO_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
static SACADO_INLINE_FUNCTION void assign_times_equal(DstType &dst, const SrcType &x)
Implementation of dst *= x.
SACADO_INLINE_FUNCTION GeneralFad(const Expr< S > &x, SACADO_EXP_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object (disabled for ViewFad)
Base template specification for whether a type is a Fad type.
#define SACADO_DEFAULTED_FUNCTION
SACADO_INLINE_FUNCTION SACADO_EXP_ENABLE_EXPR_FUNC(bool) isEqualTo(const Expr< S > &xx) const
Returns whether two Fad objects have the same values.
SACADO_INLINE_FUNCTION GeneralFad(const S &x, SACADO_EXP_ENABLE_VALUE_CTOR_DECL)
Constructor with value (disabled for ViewFad)
static SACADO_INLINE_FUNCTION void assign_equal(DstType &dst, const SrcType &x)
Implementation of dst = x.
Turn GeneralFad into a meta-function class usable with mpl::apply.
#define SACADO_EXP_ENABLE_EXPR_CTOR_DECL
Determine whether a given type is an expression.
Wrapper for a generic expression template.
Replace static derivative length.
SACADO_INLINE_FUNCTION void cache() const
Cache values.
Is a type an expression.
SACADO_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
expr val()
Storage::template apply_N< N >::type S
SACADO_INLINE_FUNCTION const derived_type & derived() const
Return derived object.
SACADO_INLINE_FUNCTION void diff(const int ith, const int n)
Set GeneralFad object as the ith independent variable.
Determine whether a given type is a view.
Base template specification for testing equivalence.
Forward-mode AD class templated on the storage for the derivative array.
#define SACADO_FAD_DERIV_LOOP(I, SZ)
Get the base Fad type from a view/expression.
Extender< Storage > ExtenderType
Extender type.
#define SACADO_EXP_ENABLE_VALUE_CTOR_DECL
T derived_type
Typename of derived object, returned by derived()
SACADO_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
Do not initialize the derivative array.
Storage::template apply< T >::type S
ScalarType< value_type >::type scalar_type
Typename of scalar&#39;s (which may be different from T)
static constexpr bool is_view
Whether we are a view.
Meta-function for determining nesting with an expression.
Expr< GeneralFad< Storage > > ExprType
Expression type.
int value
SACADO_INLINE_FUNCTION SACADO_ENABLE_VALUE_FUNC(GeneralFad &) operator
Assignment operator with constant right-hand-side.
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
SACADO_DEFAULTED_FUNCTION GeneralFad()=default
Default constructor.
static SACADO_INLINE_FUNCTION void assign_minus_equal(DstType &dst, const SrcType &x)
Implementation of dst -= x.
SACADO_DEFAULTED_FUNCTION ~GeneralFad()=default
Destructor.
SACADO_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
#define SACADO_INLINE_FUNCTION
SACADO_DEFAULTED_FUNCTION GeneralFad & operator=(GeneralFad &&x)=default
Move assignment with GeneralFad right-hand-side.
SACADO_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
static SACADO_INLINE_FUNCTION void assign_plus_equal(DstType &dst, const SrcType &x)
Implementation of dst += x.
Forward-mode AD class templated on the storage for the derivative array.
Extension class for extending interface of its argument.