52 #ifndef SACADO_FAD_SFAD_MP_VECTOR_HPP
53 #define SACADO_FAD_SFAD_MP_VECTOR_HPP
55 #include "Sacado_Fad_SFad.hpp"
59 template <
typename Ord,
typename Val,
int Num,
typename Dev>
60 class StaticFixedStorage;
66 template <
typename S>
class Vector;
71 template <
typename Ord,
typename Val,
int VecNum,
typename Dev,
int Num>
72 struct ExprSpec< SFadExprTag< Sacado::
MP::Vector< Stokhos::StaticFixedStorage<Ord,Val,VecNum,Dev> >, Num > > {
75 template <
typename Ord,
typename Val,
int VecNum,
typename Dev,
int Num>
76 struct ExprSpec< SFad< Sacado::
MP::Vector< Stokhos::StaticFixedStorage<Ord,Val,VecNum,Dev> >, Num > > {
87 template <
typename Ord,
typename Val,
int VecNum,
typename Dev,
int Num>
111 KOKKOS_INLINE_FUNCTION
113 ss_array<T>::zero(dx_, Num); }
119 template <
typename S>
120 KOKKOS_INLINE_FUNCTION
121 Expr(
const S & x, SACADO_ENABLE_VALUE_CTOR_DECL) :
123 ss_array<T>::zero(dx_, Num);
130 KOKKOS_INLINE_FUNCTION
131 Expr(
const int sz,
const T & x,
const DerivInit zero_out = InitDerivArray) : val_(x) {
132 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
134 throw "SFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
136 if (zero_out == InitDerivArray)
137 ss_array<T>::zero(dx_, Num);
146 KOKKOS_INLINE_FUNCTION
147 Expr(
const int sz,
const int i,
const T & x) :
149 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
151 throw "SFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
153 throw "SFad::SFad() Error: Invalid derivative index.";
156 ss_array<T>::zero(dx_, Num);
161 KOKKOS_INLINE_FUNCTION
164 for (
int i=0; i<Num; i++)
169 template <
typename S>
170 KOKKOS_INLINE_FUNCTION
171 Expr(
const Expr<S>& x, SACADO_ENABLE_EXPR_CTOR_DECL) {
172 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
174 throw "SFad::SFad() Error: Attempt to assign with incompatible sizes";
177 for(
int i=0; i<Num; ++i) {
178 for (
int j=0;
j<VecNum; ++
j)
182 for (
int j=0;
j<VecNum; ++
j)
183 this->
val(
j) = x.val(
j);
187 KOKKOS_INLINE_FUNCTION
197 KOKKOS_INLINE_FUNCTION
198 void diff(
const int ith,
const int n) {
199 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
201 throw "SFad::diff() Error: Supplied derivative dimension does not match compile time length.";
204 ss_array<T>::zero(dx_, Num);
213 KOKKOS_INLINE_FUNCTION
215 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
217 throw "SFad::resize() Error: Cannot resize fixed derivative array dimension";
226 KOKKOS_INLINE_FUNCTION
230 KOKKOS_INLINE_FUNCTION
231 void zero() { ss_array<T>::zero(dx_, Num); }
234 KOKKOS_INLINE_FUNCTION
238 KOKKOS_INLINE_FUNCTION
242 template <
typename S>
243 KOKKOS_INLINE_FUNCTION
245 typedef IsEqual<value_type> IE;
246 if (x.size() != this->size())
return false;
247 bool eq = IE::eval(x.val(), this->
val());
248 for (
int i=0; i<this->size(); i++)
249 eq = eq && IE::eval(x.dx(i), this->
dx(i));
261 KOKKOS_INLINE_FUNCTION
262 const T&
val()
const {
return val_;}
265 KOKKOS_INLINE_FUNCTION
269 KOKKOS_INLINE_FUNCTION
273 KOKKOS_INLINE_FUNCTION
284 KOKKOS_INLINE_FUNCTION
285 int size()
const {
return Num;}
291 KOKKOS_INLINE_FUNCTION
295 KOKKOS_INLINE_FUNCTION
299 KOKKOS_INLINE_FUNCTION
303 KOKKOS_INLINE_FUNCTION
307 KOKKOS_INLINE_FUNCTION
308 const T*
dx()
const {
return &(dx_[0]);}
311 KOKKOS_INLINE_FUNCTION
312 const T&
dx(
int i)
const {
return dx_[i]; }
315 KOKKOS_INLINE_FUNCTION
319 KOKKOS_INLINE_FUNCTION
323 KOKKOS_INLINE_FUNCTION
324 const val_type&
dx(
int i,
int j)
const {
return dx_[i].fastAccessCoeff(j); }
327 KOKKOS_INLINE_FUNCTION
331 KOKKOS_INLINE_FUNCTION
342 template <
typename S>
343 KOKKOS_INLINE_FUNCTION
344 SACADO_ENABLE_VALUE_FUNC(Expr&) operator=(const S& v) {
346 ss_array<T>::zero(dx_, Num);
351 KOKKOS_INLINE_FUNCTION
352 Expr& operator=(
const Expr& x) {
358 for (
int i=0; i<Num; i++)
365 template <
typename S>
366 KOKKOS_INLINE_FUNCTION
367 SACADO_ENABLE_EXPR_FUNC(Expr&) operator=(const Expr<S>& x) {
368 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
370 throw "SFad::operator=() Error: Attempt to assign with incompatible sizes";
373 for(
int i=0; i<Num; ++i) {
374 for (
int j=0;
j<VecNum; ++
j)
378 for (
int j=0;
j<VecNum; ++
j)
379 this->
val(
j) = x.val(
j);
392 template <
typename S>
393 KOKKOS_INLINE_FUNCTION
394 SACADO_ENABLE_VALUE_FUNC(Expr&) operator += (const S& v) {
400 template <
typename S>
401 KOKKOS_INLINE_FUNCTION
402 SACADO_ENABLE_VALUE_FUNC(Expr&) operator -= (const S& v) {
408 template <
typename S>
409 KOKKOS_INLINE_FUNCTION
410 SACADO_ENABLE_VALUE_FUNC(Expr&) operator *= (const S& v) {
412 for (
int i=0; i<Num; ++i)
418 template <
typename S>
419 KOKKOS_INLINE_FUNCTION
420 SACADO_ENABLE_VALUE_FUNC(Expr&) operator /= (const S& v) {
422 for (
int i=0; i<Num; ++i)
428 template <
typename S>
429 KOKKOS_INLINE_FUNCTION
430 SACADO_ENABLE_EXPR_FUNC(Expr&) operator += (const Expr<S>& x) {
431 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
433 throw "SFad::operator+=() Error: Attempt to assign with incompatible sizes";
436 for(
int i=0; i<Num; ++i) {
437 for (
int j=0;
j<VecNum; ++
j)
441 for (
int j=0;
j<VecNum; ++
j)
442 this->
val(
j) += x.val(
j);
448 template <
typename S>
449 KOKKOS_INLINE_FUNCTION
450 SACADO_ENABLE_EXPR_FUNC(Expr&) operator -= (const Expr<S>& x) {
451 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
453 throw "SFad::operator-=() Error: Attempt to assign with incompatible sizes";
456 for(
int i=0; i<Num; ++i) {
457 for (
int j=0;
j<VecNum; ++
j)
461 for (
int j=0;
j<VecNum; ++
j)
462 this->
val(
j) -= x.val(
j);
468 template <
typename S>
469 KOKKOS_INLINE_FUNCTION
470 SACADO_ENABLE_EXPR_FUNC(Expr&) operator *= (const Expr<S>& x) {
472 for (
int j=0;
j<VecNum; ++
j)
473 xval.fastAccessCoeff(
j) = x.val(
j);
475 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
477 throw "SFad::operator*=() Error: Attempt to assign with incompatible sizes";
480 for(
int i=0; i<Num; ++i)
481 for (
int j=0;
j<VecNum; ++
j)
482 dx_[i].
fastAccessCoeff(
j) = val_.fastAccessCoeff(
j) * x.fastAccessDx(i,
j) + dx_[i] * xval.fastAccessCoeff(
j);
490 template <
typename S>
491 KOKKOS_INLINE_FUNCTION
492 SACADO_ENABLE_EXPR_FUNC(Expr&) operator /= (const Expr<S>& x) {
494 for (
int j=0;
j<VecNum; ++
j)
495 xval.fastAccessCoeff(
j) = x.val(
j);
498 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
500 throw "SFad::operator/=() Error: Attempt to assign with incompatible sizes";
503 for(
int i=0; i<Num; ++i)
504 for (
int j=0;
j<VecNum; ++
j)
505 dx_[i].
fastAccessCoeff(
j) = ( dx_[i].fastAccessCoeff(
j)*xval.fastAccessCoeff(
j) - val_.fastAccessCoeff(
j)*x.fastAccessDx(i,
j) )/ (xval2.fastAccessCoeff(
j));
530 #endif // SACADO_FAD_SFAD_MP_VECTOR_HPP
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
KOKKOS_INLINE_FUNCTION val_type & val(int j)
Returns value.
KOKKOS_INLINE_FUNCTION val_type & fastAccessDx(int i, int j)
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize derivative array to length sz.
RemoveConst< T >::type value_type
Typename of values.
KOKKOS_INLINE_FUNCTION bool hasFastAccess() const
Returns true if derivative array is not empty.
KOKKOS_INLINE_FUNCTION const val_type & fastAccessDx(int i, int j) const
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
KOKKOS_INLINE_FUNCTION Expr(const Expr< S > &x, SACADO_ENABLE_EXPR_CTOR_DECL)
Copy constructor from any Expression object.
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION Expr(const Expr &x)
Copy constructor.
KOKKOS_INLINE_FUNCTION int availableSize() const
Returns number of derivative components that can be stored without reallocation.
KOKKOS_INLINE_FUNCTION const T & dx(int i) const
Returns derivative component i with bounds checking.
ScalarType< value_type >::type scalar_type
Typename of scalar's (which may be different from T)
KOKKOS_INLINE_FUNCTION bool updateValue() const
Return whether this Fad object has an updated value.
value_type::value_type val_type
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()
Destructor.
SFad< value_type, Num > base_expr_type
Typename of base-expressions.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
KOKKOS_INLINE_FUNCTION const val_type & val(int j) const
Returns value.
KOKKOS_INLINE_FUNCTION Expr(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Constructor with supplied value x.
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
KOKKOS_INLINE_FUNCTION void diff(const int ith, const int n)
Set Fad object as the ith independent variable.
KOKKOS_INLINE_FUNCTION Expr(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz and value x.
Sacado::MP::Vector< Stokhos::StaticFixedStorage< Ord, Val, VecNum, Dev > > T
KOKKOS_INLINE_FUNCTION void setUpdateValue(bool update_val)
Set whether this Fad object should update values.
KOKKOS_INLINE_FUNCTION bool isPassive() const
Returns true if derivative array is empty.
KOKKOS_INLINE_FUNCTION void zero()
Zero out 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 val_type & dx(int i, int j) const
Returns derivative component i with bounds checking.
KOKKOS_INLINE_FUNCTION void setIsConstant(bool is_const)
Set whether variable is constant.
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.
KOKKOS_INLINE_FUNCTION Expr()
Default constructor.