33 #ifndef SACADO_FAD_GENERALFAD_HPP
34 #define SACADO_FAD_GENERALFAD_HPP
43 #ifndef SACADO_FAD_DERIV_LOOP
44 #if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
45 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=threadIdx.x; I<SZ; I+=blockDim.x)
47 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=0; I<SZ; ++I)
51 #ifndef SACADO_FAD_THREAD_SINGLE
52 #if (defined(SACADO_VIEW_CUDA_HIERARCHICAL) || defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
53 #define SACADO_FAD_THREAD_SINGLE if (threadIdx.x == 0)
55 #define SACADO_FAD_THREAD_SINGLE
65 template <
typename T,
typename Storage>
100 Storage(sz, x, zero_out) {}
124 template <
typename S>
129 const int sz = x.size();
132 if (x.hasFastAccess())
140 this->
val() = x.val();
155 void diff(
const int ith,
const int n) {
156 if (this->size() != n)
176 template <
typename S>
180 if (x.size() != this->size())
return false;
181 bool eq = IE::eval(x.val(), this->
val());
182 const int sz = this->size();
184 eq = eq && IE::eval(x.dx(
i), this->
dx(
i));
213 if (is_const && this->size()!=0)
225 template <
typename S>
229 if (this->size()) this->resize(0);
238 Storage::operator=(x);
243 template <
typename S>
246 const int xsz = x.size();
248 if (xsz != this->size())
249 this->resizeAndZero(xsz);
251 const int sz = this->size();
259 if (x.hasFastAccess()) {
281 template <typename S>
289 template <
typename S>
297 template <
typename S>
300 const int sz = this->size();
308 template <typename S>
311 const int sz = this->size();
321 const int xsz = x.size(), sz = this->size();
323 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
324 if ((xsz != sz) && (xsz != 0) && (sz != 0))
325 throw "Fad Error: Attempt to assign with incompatible sizes";
334 this->resizeAndZero(xsz);
348 const int xsz = x.size(), sz = this->size();
350 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
351 if ((xsz != sz) && (xsz != 0) && (sz != 0))
352 throw "Fad Error: Attempt to assign with incompatible sizes";
361 this->resizeAndZero(xsz);
367 this->val() -= x.val();
376 const int xsz = x.size(), sz = this->size();
380 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
381 if ((xsz != sz) && (xsz != 0) && (sz != 0))
382 throw "Fad Error: Attempt to assign with incompatible sizes";
391 this->resizeAndZero(xsz);
411 const int xsz = x.size(), sz = this->size();
415 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
416 if ((xsz != sz) && (xsz != 0) && (sz != 0))
417 throw "Fad Error: Attempt to assign with incompatible sizes";
427 this->resizeAndZero(xsz);
445 template <typename S>
448 const int xsz = x.size(), sz = this->size();
450 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
451 if ((xsz != sz) && (xsz != 0) && (sz != 0))
452 throw "Fad Error: Attempt to assign with incompatible sizes";
457 if (x.hasFastAccess())
465 this->resizeAndZero(xsz);
466 if (x.hasFastAccess())
475 this->val() += x.val();
481 template <typename S>
484 const int xsz = x.size(), sz = this->size();
486 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
487 if ((xsz != sz) && (xsz != 0) && (sz != 0))
488 throw "Fad Error: Attempt to assign with incompatible sizes";
493 if (x.hasFastAccess())
501 this->resizeAndZero(xsz);
502 if (x.hasFastAccess())
511 this->val() -= x.val();
518 template <typename S>
521 const int xsz = x.size(), sz = this->size();
525 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
526 if ((xsz != sz) && (xsz != 0) && (sz != 0))
527 throw "Fad Error: Attempt to assign with incompatible sizes";
532 if (x.hasFastAccess())
540 this->resizeAndZero(xsz);
541 if (x.hasFastAccess())
562 template <typename S>
565 const int xsz = x.size(), sz = this->size();
569 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
570 if ((xsz != sz) && (xsz != 0) && (sz != 0))
571 throw "Fad Error: Attempt to assign with incompatible sizes";
576 if (x.hasFastAccess())
584 this->resizeAndZero(xsz);
585 if (x.hasFastAccess())
587 this->
fastAccessDx(i) = - v*x.fastAccessDx(i) / (xval*xval);
613 #endif // SACADO_FAD_GENERALFAD_HPP
Wrapper for a generic expression template.
SACADO_INLINE_FUNCTION GeneralFad(const GeneralFad &x)
Copy constructor.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
#define SACADO_ENABLE_VALUE_CTOR_DECL
SACADO_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
#define SACADO_FAD_DERIV_LOOP(I, SZ)
SACADO_INLINE_FUNCTION void diff(const int ith, const int n)
Set GeneralFad object as the ith independent variable.
RemoveConst< T >::type value_type
Typename of values.
#define SACADO_ENABLE_EXPR_CTOR_DECL
SACADO_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
SACADO_INLINE_FUNCTION GeneralFad(const Storage &s)
Constructor with supplied storage s.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
SACADO_INLINE_FUNCTION GeneralFad(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
Base template specification for testing equivalence.
SACADO_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
Do not initialize the derivative array.
SACADO_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
SACADO_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
SACADO_INLINE_FUNCTION GeneralFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
SACADO_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
SACADO_INLINE_FUNCTION GeneralFad(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
Initialize the derivative array.
SACADO_INLINE_FUNCTION SACADO_ENABLE_EXPR_FUNC(bool) isEqualTo(const Expr< S > &x) const
Returns whether two Fad objects have the same values.
SACADO_INLINE_FUNCTION void cache() const
Cache values.
SACADO_INLINE_FUNCTION ~GeneralFad()
Destructor.
#define SACADO_INLINE_FUNCTION
SACADO_INLINE_FUNCTION GeneralFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
SACADO_INLINE_FUNCTION GeneralFad()
Default constructor.
Forward-mode AD class templated on the storage for the derivative array.