33 #ifndef SACADO_CACHEFAD_SFAD_HPP
34 #define SACADO_CACHEFAD_SFAD_HPP
46 template <
typename T,
int Num>
50 template <
typename T,
int Num>
class SFad;
59 template <
typename T,
int Num>
99 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
101 throw "CacheFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
115 Expr(
const int sz,
const int i,
const T &
x) :
117 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
119 throw "CacheFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
121 throw "CacheFad::SFad() Error: Invalid derivative index.";
132 for (
int i=0;
i<Num;
i++)
137 template <
typename S>
140 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
142 throw "CacheFad::SFad() Error: Attempt to assign with incompatible sizes";
147 this->
val() = x.val();
149 for(
int i=0;
i<Num; ++
i)
150 dx_[
i] = x.fastAccessDx(
i);
165 void diff(
const int ith,
const int n) {
166 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
168 throw "CacheFad::diff() Error: Supplied derivative dimension does not match compile time length.";
182 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
184 throw "CacheFad::resize() Error: Cannot resize fixed derivative array dimension";
213 template <
typename S>
217 if (x.size() != this->size())
return false;
218 bool eq = IE::eval(x.val(), this->
val());
219 for (
int i=0;
i<this->size();
i++)
220 eq = eq && IE::eval(x.dx(
i), this->
dx(
i));
248 int size()
const {
return Num;}
271 const T*
dx()
const {
return &(dx_[0]);}
275 const T&
dx(
int i)
const {
return dx_[
i]; }
293 template <
typename S>
303 Expr& operator=(
const Expr&
x) {
309 for (
int i=0;
i<Num;
i++)
316 template <
typename S>
319 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
321 throw "CacheFad::operator=() Error: Attempt to assign with incompatible sizes";
326 for(
int i=0;
i<Num; ++
i)
327 dx_[
i] = x.fastAccessDx(
i);
342 template <
typename S>
350 template <
typename S>
358 template <
typename S>
362 for (
int i=0;
i<Num; ++
i)
368 template <
typename S>
372 for (
int i=0;
i<Num; ++
i)
378 template <
typename S>
381 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
383 throw "CacheFad::operator+=() Error: Attempt to assign with incompatible sizes";
388 for (
int i=0;
i<Num; ++
i)
389 dx_[
i] += x.fastAccessDx(
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>
423 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
425 throw "CacheFad::operator*=() Error: Attempt to assign with incompatible sizes";
428 for(
int i=0;
i<Num; ++
i)
429 dx_[
i] =
val_ * x.fastAccessDx(
i) + dx_[
i] * xval;
437 template <
typename S>
444 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
446 throw "CacheFad::operator/=() Error: Attempt to assign with incompatible sizes";
449 for(
int i=0;
i<Num; ++
i)
450 dx_[
i] = ( dx_[
i]*xval -
val_*x.fastAccessDx(
i) )/ (xval*xval);
473 #define FAD_NS CacheFad
480 #endif // SACADO_CACHEFAD_SFAD_HPP
A tag for specializing Expr for SFad expressions.
SACADO_INLINE_FUNCTION Expr(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
SACADO_INLINE_FUNCTION int size() const
Returns number of derivative components.
SACADO_INLINE_FUNCTION void resize(int sz)
Resize derivative array to length sz.
SACADO_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
SACADO_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
#define SACADO_ENABLE_VALUE_CTOR_DECL
SACADO_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
#define SACADO_ENABLE_EXPR_CTOR_DECL
RemoveConst< T >::type value_type
Typename of values.
SACADO_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
SACADO_INLINE_FUNCTION Expr(const int sz, const int i, const T &x)
Constructor with size sz, index i, and value x.
SACADO_INLINE_FUNCTION Expr(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
#define SACADO_ENABLE_VALUE_FUNC(RETURN_TYPE)
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
Base template specification for testing equivalence.
SACADO_INLINE_FUNCTION Expr(const Expr &x)
Copy constructor.
SACADO_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
SACADO_INLINE_FUNCTION const T & val() const
Returns value.
SACADO_INLINE_FUNCTION SACADO_ENABLE_EXPR_FUNC(bool) isEqualTo(const Expr< S > &x) const
Returns whether two Fad objects have the same values.
#define SACADO_ENABLE_EXPR_FUNC(RETURN_TYPE)
SACADO_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...
SACADO_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
SACADO_INLINE_FUNCTION ~Expr()
Destructor.
SACADO_INLINE_FUNCTION Expr()
Default constructor.
static SACADO_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
SACADO_INLINE_FUNCTION const T & dx(int i) const
Returns derivative component i with bounds checking.
SACADO_INLINE_FUNCTION void cache() const
Cache values.
SACADO_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
Initialize the derivative array.
SACADO_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
SACADO_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
SACADO_INLINE_FUNCTION Expr(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
#define SACADO_INLINE_FUNCTION
SACADO_INLINE_FUNCTION void diff(const int ith, const int n)
Set Fad object as the ith independent variable.
SFad< value_type, Num > base_expr_type
Typename of base-expressions.
Wrapper for a generic expression template.
SACADO_INLINE_FUNCTION void zero()
Zero out the derivative array.
SACADO_INLINE_FUNCTION T & val()
Returns value.