52 #ifndef SACADO_FAD_GENERALFAD_HPP
53 #define SACADO_FAD_GENERALFAD_HPP
62 #ifndef SACADO_FAD_DERIV_LOOP
63 #if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
64 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=threadIdx.x; I<SZ; I+=blockDim.x)
66 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=0; I<SZ; ++I)
70 #ifndef SACADO_FAD_THREAD_SINGLE
71 #if (defined(SACADO_VIEW_CUDA_HIERARCHICAL) || defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
72 #define SACADO_FAD_THREAD_SINGLE if (threadIdx.x == 0)
74 #define SACADO_FAD_THREAD_SINGLE
84 template <
typename T,
typename Storage>
108 template <
typename S>
119 Storage(sz, x, zero_out) {}
143 template <
typename S>
148 const int sz = x.size();
151 if (x.hasFastAccess())
159 this->
val() = x.val();
174 void diff(
const int ith,
const int n) {
175 if (this->size() != n)
195 template <
typename S>
199 if (x.size() != this->size())
return false;
200 bool eq = IE::eval(x.val(), this->
val());
201 const int sz = this->size();
203 eq = eq && IE::eval(x.dx(i), this->
dx(i));
232 if (is_const && this->size()!=0)
244 template <
typename S>
248 if (this->size()) this->resize(0);
257 Storage::operator=(x);
262 template <
typename S>
265 const int xsz = x.size();
267 if (xsz != this->size())
268 this->resizeAndZero(xsz);
270 const int sz = this->size();
278 if (x.hasFastAccess()) {
300 template <typename S>
308 template <
typename S>
316 template <
typename S>
319 const int sz = this->size();
327 template <typename S>
330 const int sz = this->size();
340 const int xsz = x.size(), sz = this->size();
342 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
343 if ((xsz != sz) && (xsz != 0) && (sz != 0))
344 throw "Fad Error: Attempt to assign with incompatible sizes";
353 this->resizeAndZero(xsz);
367 const int xsz = x.size(), sz = this->size();
369 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
370 if ((xsz != sz) && (xsz != 0) && (sz != 0))
371 throw "Fad Error: Attempt to assign with incompatible sizes";
380 this->resizeAndZero(xsz);
386 this->val() -= x.val();
395 const int xsz = x.size(), sz = this->size();
399 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
400 if ((xsz != sz) && (xsz != 0) && (sz != 0))
401 throw "Fad Error: Attempt to assign with incompatible sizes";
410 this->resizeAndZero(xsz);
430 const int xsz = x.size(), sz = this->size();
434 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
435 if ((xsz != sz) && (xsz != 0) && (sz != 0))
436 throw "Fad Error: Attempt to assign with incompatible sizes";
446 this->resizeAndZero(xsz);
464 template <typename S>
467 const int xsz = x.size(), sz = this->size();
469 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
470 if ((xsz != sz) && (xsz != 0) && (sz != 0))
471 throw "Fad Error: Attempt to assign with incompatible sizes";
476 if (x.hasFastAccess())
484 this->resizeAndZero(xsz);
485 if (x.hasFastAccess())
494 this->val() += x.val();
500 template <typename S>
503 const int xsz = x.size(), sz = this->size();
505 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
506 if ((xsz != sz) && (xsz != 0) && (sz != 0))
507 throw "Fad Error: Attempt to assign with incompatible sizes";
512 if (x.hasFastAccess())
520 this->resizeAndZero(xsz);
521 if (x.hasFastAccess())
530 this->val() -= x.val();
537 template <typename S>
540 const int xsz = x.size(), sz = this->size();
544 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
545 if ((xsz != sz) && (xsz != 0) && (sz != 0))
546 throw "Fad Error: Attempt to assign with incompatible sizes";
551 if (x.hasFastAccess())
559 this->resizeAndZero(xsz);
560 if (x.hasFastAccess())
581 template <typename S>
584 const int xsz = x.size(), sz = this->size();
588 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
589 if ((xsz != sz) && (xsz != 0) && (sz != 0))
590 throw "Fad Error: Attempt to assign with incompatible sizes";
595 if (x.hasFastAccess())
603 this->resizeAndZero(xsz);
604 if (x.hasFastAccess())
606 this->
fastAccessDx(i) = - v*x.fastAccessDx(i) / (xval*xval);
632 #endif // SACADO_FAD_GENERALFAD_HPP
Wrapper for a generic expression template.
KOKKOS_INLINE_FUNCTION ~GeneralFad()
Destructor.
KOKKOS_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
KOKKOS_INLINE_FUNCTION GeneralFad(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
#define SACADO_ENABLE_VALUE_CTOR_DECL
#define SACADO_FAD_DERIV_LOOP(I, SZ)
KOKKOS_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
RemoveConst< T >::type value_type
Typename of values.
#define SACADO_ENABLE_EXPR_CTOR_DECL
KOKKOS_INLINE_FUNCTION GeneralFad(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION GeneralFad()
Default constructor.
KOKKOS_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
KOKKOS_INLINE_FUNCTION void cache() const
Cache values.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
KOKKOS_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.
KOKKOS_INLINE_FUNCTION GeneralFad(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
KOKKOS_INLINE_FUNCTION SACADO_ENABLE_EXPR_FUNC(bool) isEqualTo(const Expr< S > &x) const
Returns whether two Fad objects have the same values.
KOKKOS_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
Do not initialize the derivative array.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
KOKKOS_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp
KOKKOS_INLINE_FUNCTION GeneralFad(const Storage &s)
Constructor with supplied storage s.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION GeneralFad(const GeneralFad &x)
Copy constructor.
KOKKOS_INLINE_FUNCTION void diff(const int ith, const int n)
Set GeneralFad object as the ith independent variable.
Forward-mode AD class templated on the storage for the derivative array.