52 #ifndef SACADO_ELRFAD_SFAD_HPP 53 #define SACADO_ELRFAD_SFAD_HPP 66 template <
typename T,
int Num>
70 template <
typename T,
int Num>
class SFad;
79 template <
typename T,
int Num>
94 static const int num_args = 1;
97 static const bool is_linear =
true;
112 template <
typename S>
125 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 127 throw "SELRFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
141 Expr(
const int sz,
const int i,
const T & x) :
143 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 145 throw "SELRFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
147 throw "SELRFad::SFad() Error: Invalid derivative index.";
158 for (
int i=0; i<Num; i++)
163 template <
typename S>
166 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 168 throw "SELRFad::SFad() Error: Attempt to assign with incompatible sizes";
172 LocalAccumOp< Expr<S> > op(x);
175 for(
int i=0; i<Num; ++i) {
188 this->
val() = x.val();
203 void diff(
const int ith,
const int n) {
204 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 206 throw "SELRFad::diff() Error: Supplied derivative dimension does not match compile time length.";
220 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 222 throw "SELRFad::resize() Error: Cannot resize fixed derivative array dimension";
247 template <
typename S>
251 if (x.size() != this->size())
return false;
252 bool eq = IE::eval(x.val(), this->
val());
253 for (
int i=0; i<this->size(); i++)
254 eq = eq && IE::eval(x.dx(i), this->
dx(i));
267 const T&
val()
const {
return val_;}
282 int size()
const {
return Num;}
305 const T*
dx()
const {
return &(dx_[0]);}
309 const T&
dx(
int i)
const {
return dx_[i]; }
328 dots[0] = this->dx_[i];
353 template <
typename S>
363 Expr& operator=(
const Expr& x) {
370 for (
int i=0; i<Num; i++)
377 template <
typename S>
380 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 382 throw "SELRFad::operator=() Error: Attempt to assign with incompatible sizes";
386 LocalAccumOp< Expr<S> > op(x);
389 for(
int i=0; i<Num; ++i) {
415 template <
typename S>
423 template <
typename S>
431 template <
typename S>
435 for (
int i=0; i<Num; ++i)
441 template <
typename S>
445 for (
int i=0; i<Num; ++i)
451 template <
typename S>
454 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 456 throw "SELRFad::operator+=() Error: Attempt to assign with incompatible sizes";
460 LocalAccumOp< Expr<S> > op(x);
463 for(
int i=0; i<Num; ++i) {
482 template <
typename S>
485 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 487 throw "SELRFad::operator-=() Error: Attempt to assign with incompatible sizes";
491 LocalAccumOp< Expr<S> > op(x);
494 for(
int i=0; i<Num; ++i) {
513 template <
typename S>
518 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 520 throw "SELRFad::operator*=() Error: Attempt to assign with incompatible sizes";
524 LocalAccumOp< Expr<S> > op(x);
527 for(
int i=0; i<Num; ++i) {
536 dx_[i] = val_ * op.t + dx_[i] * xval;
546 template <
typename S>
551 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ ) 553 throw "SELRFad::operator/=() Error: Attempt to assign with incompatible sizes";
557 LocalAccumOp< Expr<S> > op(x);
562 for(
int i=0; i<Num; ++i) {
571 dx_[i] = (dx_[i] * xval - val_ * op.t) / xval2;
597 template <
typename ExprT>
598 struct LocalAccumOp {
600 static const int N = ExprT::num_args;
611 template <
typename ArgT>
613 void operator () (ArgT arg)
const {
614 const int Arg = ArgT::value;
615 if (x.template isActive<Arg>())
616 t += partials[Arg] * x.template getTangent<Arg>(i);
626 #define FAD_NS ELRFad 633 #endif // SACADO_ELRFAD_SFAD_HPP
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 const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
SFad< value_type, Num > base_expr_type
Typename of base-expressions.
KOKKOS_INLINE_FUNCTION const value_type * getDx(int j) const
Get dx array.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
#define SACADO_ENABLE_VALUE_CTOR_DECL
RemoveConst< T >::type value_type
Typename of values.
KOKKOS_INLINE_FUNCTION LocalAccumOp(const ExprT &x_)
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
#define SACADO_ENABLE_EXPR_CTOR_DECL
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
KOKKOS_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
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 Expr(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION Expr(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize derivative array to length sz.
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 computePartials(const T &bar, value_type partials[]) const
Return partials w.r.t. arguments.
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
KOKKOS_INLINE_FUNCTION const T & getTangent(int i) const
Return tangent component i of argument Arg.
KOKKOS_INLINE_FUNCTION const T & dx(int i) const
Returns derivative component i with bounds checking.
KOKKOS_INLINE_FUNCTION ~Expr()
Destructor.
KOKKOS_INLINE_FUNCTION void diff(const int ith, const int n)
Set Fad object as the ith independent variable.
KOKKOS_INLINE_FUNCTION void getTangents(int i, value_type dots[]) const
Return tangent component i of arguments.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
KOKKOS_INLINE_FUNCTION Expr(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
Wrapper for a generic expression template.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
KOKKOS_INLINE_FUNCTION Expr()
Default constructor.
KOKKOS_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
KOKKOS_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION void zero()
Zero out the derivative array.
KOKKOS_INLINE_FUNCTION void getTangents(int i_)
ExprT::value_type value_type
KOKKOS_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
KOKKOS_INLINE_FUNCTION bool isActive() const
Return whether argument is active.
KOKKOS_INLINE_FUNCTION Expr(const Expr &x)
Copy constructor.
A tag for specializing Expr for SFad expressions.