52 #ifndef SACADO_CACHEFAD_SFAD_HPP 53 #define SACADO_CACHEFAD_SFAD_HPP 65 template <
typename T,
int Num>
69 template <
typename T,
int Num>
class SFad;
78 template <
typename T,
int Num>
105 template <
typename S>
118 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 120 throw "CacheFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
134 Expr(
const int sz,
const int i,
const T & x) :
136 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 138 throw "CacheFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
140 throw "CacheFad::SFad() Error: Invalid derivative index.";
151 for (
int i=0; i<Num; i++)
156 template <
typename S>
159 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 161 throw "CacheFad::SFad() Error: Attempt to assign with incompatible sizes";
166 this->
val() = x.val();
168 for(
int i=0; i<Num; ++i)
169 dx_[i] = x.fastAccessDx(i);
184 void diff(
const int ith,
const int n) {
185 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 187 throw "CacheFad::diff() Error: Supplied derivative dimension does not match compile time length.";
201 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 203 throw "CacheFad::resize() Error: Cannot resize fixed derivative array dimension";
232 template <
typename S>
236 if (x.size() != this->size())
return false;
237 bool eq = IE::eval(x.val(), this->
val());
238 for (
int i=0; i<this->size(); i++)
239 eq = eq && IE::eval(x.dx(i), this->
dx(i));
252 const T&
val()
const {
return val_;}
267 int size()
const {
return Num;}
290 const T*
dx()
const {
return &(dx_[0]);}
294 const T&
dx(
int i)
const {
return dx_[i]; }
312 template <
typename S>
322 Expr& operator=(
const Expr& x) {
328 for (
int i=0; i<Num; i++)
335 template <
typename S>
338 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 340 throw "CacheFad::operator=() Error: Attempt to assign with incompatible sizes";
345 for(
int i=0; i<Num; ++i)
346 dx_[i] = x.fastAccessDx(i);
361 template <
typename S>
369 template <
typename S>
377 template <
typename S>
381 for (
int i=0; i<Num; ++i)
387 template <
typename S>
391 for (
int i=0; i<Num; ++i)
397 template <
typename S>
400 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 402 throw "CacheFad::operator+=() Error: Attempt to assign with incompatible sizes";
407 for (
int i=0; i<Num; ++i)
408 dx_[i] += x.fastAccessDx(i);
416 template <
typename S>
419 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 421 throw "CacheFad::operator-=() Error: Attempt to assign with incompatible sizes";
426 for(
int i=0; i<Num; ++i)
427 dx_[i] -= x.fastAccessDx(i);
435 template <
typename S>
442 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 444 throw "CacheFad::operator*=() Error: Attempt to assign with incompatible sizes";
447 for(
int i=0; i<Num; ++i)
448 dx_[i] = val_ * x.fastAccessDx(i) + dx_[i] * xval;
456 template <
typename S>
463 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 465 throw "CacheFad::operator/=() Error: Attempt to assign with incompatible sizes";
468 for(
int i=0; i<Num; ++i)
469 dx_[i] = ( dx_[i]*xval - val_*x.fastAccessDx(i) )/ (xval*xval);
492 #define FAD_NS CacheFad 499 #endif // SACADO_CACHEFAD_SFAD_HPP
A tag for specializing Expr for SFad expressions.
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
#define SACADO_ENABLE_VALUE_CTOR_DECL
KOKKOS_INLINE_FUNCTION Expr(const Expr &x)
Copy constructor.
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
#define SACADO_ENABLE_EXPR_CTOR_DECL
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize derivative array to length sz.
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
RemoveConst< T >::type value_type
Typename of values.
KOKKOS_INLINE_FUNCTION void zero()
Zero out the derivative array.
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
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 void cache() const
Cache values.
KOKKOS_INLINE_FUNCTION ~Expr()
Destructor.
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 & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
KOKKOS_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
KOKKOS_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
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 const T * dx() const
Returns derivative array.
KOKKOS_INLINE_FUNCTION Expr()
Default constructor.
KOKKOS_INLINE_FUNCTION const T & dx(int i) const
Returns derivative component i with bounds checking.
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 bool hasFastAccess() const
Returns true if derivative array is not empty.
SFad< value_type, Num > base_expr_type
Typename of base-expressions.
Wrapper for a generic expression template.
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 void diff(const int ith, const int n)
Set Fad object as the ith independent variable.
KOKKOS_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.