52 #ifndef SACADO_FAD_SFAD_HPP
53 #define SACADO_FAD_SFAD_HPP
57 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
63 template <
typename T,
int Num>
64 using SFad = Exp::GeneralFad< Exp::StaticFixedStorage<T,Num> >;
79 #ifndef SACADO_FAD_DERIV_LOOP
80 #if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
81 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=threadIdx.x; I<SZ; I+=blockDim.x)
83 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=0; I<SZ; ++I)
87 #ifndef SACADO_FAD_THREAD_SINGLE
88 #if (defined(SACADO_VIEW_CUDA_HIERARCHICAL) || defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD)) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
89 #define SACADO_FAD_THREAD_SINGLE if (threadIdx.x == 0)
91 #define SACADO_FAD_THREAD_SINGLE
96 template <
typename T,
int Num>
100 template <
typename T,
int Num>
class SFad;
109 template <
typename T,
int Num>
137 template <
typename S>
150 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
152 throw "SFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
165 Expr(
const int sz,
const int i,
const T & x) :
167 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
169 throw "SFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
171 throw "SFad::SFad() Error: Invalid derivative index.";
182 for (
int i=0; i<Num; i++)
187 template <
typename S>
190 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
192 throw "SFad::SFad() Error: Attempt to assign with incompatible sizes";
195 for(
int i=0; i<Num; ++i)
196 dx_[i] = x.fastAccessDx(i);
198 this->
val() = x.val();
213 void diff(
const int ith,
const int n) {
214 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
216 throw "SFad::diff() Error: Supplied derivative dimension does not match compile time length.";
230 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
232 throw "SFad::resize() Error: Cannot resize fixed derivative array dimension";
261 template <
typename S>
265 if (x.size() != this->size())
return false;
266 bool eq = IE::eval(x.val(), this->
val());
267 for (
int i=0; i<this->size(); i++)
268 eq = eq && IE::eval(x.dx(i), this->
dx(i));
281 const T&
val()
const {
return val_;}
296 int size()
const {
return Num;}
319 const T*
dx()
const {
return &(dx_[0]);}
323 const T&
dx(
int i)
const {
return dx_[i]; }
341 template <
typename S>
351 Expr& operator=(
const Expr& x) {
357 for (
int i=0; i<Num; i++)
364 template <
typename S>
367 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
369 throw "SFad::operator=() Error: Attempt to assign with incompatible sizes";
372 for(
int i=0; i<Num; ++i)
373 dx_[i] = x.fastAccessDx(i);
388 template <
typename S>
396 template <
typename S>
404 template <
typename S>
408 for (
int i=0; i<Num; ++i)
414 template <
typename S>
418 for (
int i=0; i<Num; ++i)
424 template <
typename S>
427 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
429 throw "SFad::operator+=() Error: Attempt to assign with incompatible sizes";
432 for (
int i=0; i<Num; ++i)
433 dx_[i] += x.fastAccessDx(i);
441 template <
typename S>
444 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
446 throw "SFad::operator-=() Error: Attempt to assign with incompatible sizes";
449 for(
int i=0; i<Num; ++i)
450 dx_[i] -= x.fastAccessDx(i);
458 template <
typename S>
463 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
465 throw "SFad::operator*=() Error: Attempt to assign with incompatible sizes";
468 for(
int i=0; i<Num; ++i)
469 dx_[i] = val_ * x.fastAccessDx(i) + dx_[i] * xval;
477 template <
typename S>
482 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
484 throw "SFad::operator/=() Error: Attempt to assign with incompatible sizes";
487 for(
int i=0; i<Num; ++i)
488 dx_[i] = ( dx_[i]*xval - val_*x.fastAccessDx(i) )/ (xval*xval);
517 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
521 #endif // SACADO_FAD_SFAD_HPP
Wrapper for a generic expression template.
KOKKOS_INLINE_FUNCTION ~Expr()
Destructor.
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 const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
#define SACADO_ENABLE_VALUE_CTOR_DECL
KOKKOS_INLINE_FUNCTION void zero()
Zero out the derivative array.
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
KOKKOS_INLINE_FUNCTION Expr()
Default constructor.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
RemoveConst< T >::type value_type
Typename of values.
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.
#define SACADO_ENABLE_EXPR_CTOR_DECL
KOKKOS_INLINE_FUNCTION Expr(const Expr &x)
Copy constructor.
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
KOKKOS_INLINE_FUNCTION void diff(const int ith, const int n)
Set Fad object as the ith independent variable.
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
KOKKOS_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION Expr(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
Base template specification for testing equivalence.
KOKKOS_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
KOKKOS_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
KOKKOS_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize derivative array to length sz.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
KOKKOS_INLINE_FUNCTION Expr(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
KOKKOS_INLINE_FUNCTION Expr(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION Expr(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
KOKKOS_INLINE_FUNCTION const T & dx(int i) const
Returns derivative component i with bounds checking.
KOKKOS_INLINE_FUNCTION void cache() const
Cache values.
A tag for specializing Expr for SFad expressions.
SFad< value_type, Num > base_expr_type
Typename of base-expressions.
GeneralFad< StaticFixedStorage< T, Num > > SFad