32 #ifndef SACADO_FAD_SFAD_MP_VECTOR_HPP
33 #define SACADO_FAD_SFAD_MP_VECTOR_HPP
35 #include "Sacado_Fad_SFad.hpp"
39 template <
typename Ord,
typename Val,
int Num,
typename Dev>
40 class StaticFixedStorage;
46 template <
typename S>
class Vector;
51 template <
typename Ord,
typename Val,
int VecNum,
typename Dev,
int Num>
52 struct ExprSpec< SFadExprTag< Sacado::
MP::Vector< Stokhos::StaticFixedStorage<Ord,Val,VecNum,Dev> >, Num > > {
55 template <
typename Ord,
typename Val,
int VecNum,
typename Dev,
int Num>
56 struct ExprSpec< SFad< Sacado::
MP::Vector< Stokhos::StaticFixedStorage<Ord,Val,VecNum,Dev> >, Num > > {
67 template <
typename Ord,
typename Val,
int VecNum,
typename Dev,
int Num>
91 KOKKOS_INLINE_FUNCTION
93 ss_array<T>::zero(dx_, Num); }
100 KOKKOS_INLINE_FUNCTION
101 Expr(
const S & x, SACADO_ENABLE_VALUE_CTOR_DECL) :
103 ss_array<T>::zero(dx_, Num);
110 KOKKOS_INLINE_FUNCTION
111 Expr(
const int sz,
const T & x,
const DerivInit zero_out = InitDerivArray) : val_(x) {
112 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
114 throw "SFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
116 if (zero_out == InitDerivArray)
117 ss_array<T>::zero(dx_, Num);
126 KOKKOS_INLINE_FUNCTION
127 Expr(
const int sz,
const int i,
const T & x) :
129 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
131 throw "SFad::SFad() Error: Supplied derivative dimension does not match compile time length.";
133 throw "SFad::SFad() Error: Invalid derivative index.";
136 ss_array<T>::zero(dx_, Num);
141 KOKKOS_INLINE_FUNCTION
144 for (
int i=0; i<Num; i++)
149 template <
typename S>
150 KOKKOS_INLINE_FUNCTION
151 Expr(
const Expr<S>& x, SACADO_ENABLE_EXPR_CTOR_DECL) {
152 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
154 throw "SFad::SFad() Error: Attempt to assign with incompatible sizes";
157 for(
int i=0; i<Num; ++i) {
158 for (
int j=0;
j<VecNum; ++
j)
162 for (
int j=0;
j<VecNum; ++
j)
163 this->
val(
j) = x.val(
j);
167 KOKKOS_INLINE_FUNCTION
177 KOKKOS_INLINE_FUNCTION
178 void diff(
const int ith,
const int n) {
179 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
181 throw "SFad::diff() Error: Supplied derivative dimension does not match compile time length.";
184 ss_array<T>::zero(dx_, Num);
193 KOKKOS_INLINE_FUNCTION
195 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
197 throw "SFad::resize() Error: Cannot resize fixed derivative array dimension";
206 KOKKOS_INLINE_FUNCTION
210 KOKKOS_INLINE_FUNCTION
211 void zero() { ss_array<T>::zero(dx_, Num); }
214 KOKKOS_INLINE_FUNCTION
218 KOKKOS_INLINE_FUNCTION
222 template <
typename S>
223 KOKKOS_INLINE_FUNCTION
225 typedef IsEqual<value_type> IE;
226 if (x.size() != this->size())
return false;
227 bool eq = IE::eval(x.val(), this->
val());
228 for (
int i=0; i<this->size(); i++)
229 eq = eq && IE::eval(x.dx(i), this->
dx(i));
241 KOKKOS_INLINE_FUNCTION
242 const T&
val()
const {
return val_;}
245 KOKKOS_INLINE_FUNCTION
249 KOKKOS_INLINE_FUNCTION
253 KOKKOS_INLINE_FUNCTION
264 KOKKOS_INLINE_FUNCTION
265 int size()
const {
return Num;}
271 KOKKOS_INLINE_FUNCTION
275 KOKKOS_INLINE_FUNCTION
279 KOKKOS_INLINE_FUNCTION
283 KOKKOS_INLINE_FUNCTION
287 KOKKOS_INLINE_FUNCTION
288 const T*
dx()
const {
return &(dx_[0]);}
291 KOKKOS_INLINE_FUNCTION
292 const T&
dx(
int i)
const {
return dx_[i]; }
295 KOKKOS_INLINE_FUNCTION
299 KOKKOS_INLINE_FUNCTION
303 KOKKOS_INLINE_FUNCTION
304 const val_type&
dx(
int i,
int j)
const {
return dx_[i].fastAccessCoeff(j); }
307 KOKKOS_INLINE_FUNCTION
311 KOKKOS_INLINE_FUNCTION
322 template <
typename S>
323 KOKKOS_INLINE_FUNCTION
324 SACADO_ENABLE_VALUE_FUNC(Expr&) operator=(const S& v) {
326 ss_array<T>::zero(dx_, Num);
331 KOKKOS_INLINE_FUNCTION
332 Expr& operator=(
const Expr& x) {
338 for (
int i=0; i<Num; i++)
345 template <
typename S>
346 KOKKOS_INLINE_FUNCTION
347 SACADO_ENABLE_EXPR_FUNC(Expr&) operator=(const Expr<S>& x) {
348 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
350 throw "SFad::operator=() Error: Attempt to assign with incompatible sizes";
353 for(
int i=0; i<Num; ++i) {
354 for (
int j=0;
j<VecNum; ++
j)
358 for (
int j=0;
j<VecNum; ++
j)
359 this->
val(
j) = x.val(
j);
372 template <
typename S>
373 KOKKOS_INLINE_FUNCTION
374 SACADO_ENABLE_VALUE_FUNC(Expr&) operator += (const S& v) {
380 template <
typename S>
381 KOKKOS_INLINE_FUNCTION
382 SACADO_ENABLE_VALUE_FUNC(Expr&) operator -= (const S& v) {
388 template <
typename S>
389 KOKKOS_INLINE_FUNCTION
390 SACADO_ENABLE_VALUE_FUNC(Expr&) operator *= (const S& v) {
392 for (
int i=0; i<Num; ++i)
398 template <
typename S>
399 KOKKOS_INLINE_FUNCTION
400 SACADO_ENABLE_VALUE_FUNC(Expr&) operator /= (const S& v) {
402 for (
int i=0; i<Num; ++i)
408 template <
typename S>
409 KOKKOS_INLINE_FUNCTION
410 SACADO_ENABLE_EXPR_FUNC(Expr&) operator += (const Expr<S>& x) {
411 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
413 throw "SFad::operator+=() Error: Attempt to assign with incompatible sizes";
416 for(
int i=0; i<Num; ++i) {
417 for (
int j=0;
j<VecNum; ++
j)
421 for (
int j=0;
j<VecNum; ++
j)
422 this->
val(
j) += x.val(
j);
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) {
452 for (
int j=0;
j<VecNum; ++
j)
453 xval.fastAccessCoeff(
j) = x.val(
j);
455 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
457 throw "SFad::operator*=() Error: Attempt to assign with incompatible sizes";
460 for(
int i=0; i<Num; ++i)
461 for (
int j=0;
j<VecNum; ++
j)
462 dx_[i].
fastAccessCoeff(
j) = val_.fastAccessCoeff(
j) * x.fastAccessDx(i,
j) + dx_[i] * xval.fastAccessCoeff(
j);
470 template <
typename S>
471 KOKKOS_INLINE_FUNCTION
472 SACADO_ENABLE_EXPR_FUNC(Expr&) operator /= (const Expr<S>& x) {
474 for (
int j=0;
j<VecNum; ++
j)
475 xval.fastAccessCoeff(
j) = x.val(
j);
478 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
480 throw "SFad::operator/=() Error: Attempt to assign with incompatible sizes";
483 for(
int i=0; i<Num; ++i)
484 for (
int j=0;
j<VecNum; ++
j)
485 dx_[i].
fastAccessCoeff(
j) = ( dx_[i].fastAccessCoeff(
j)*xval.fastAccessCoeff(
j) - val_.fastAccessCoeff(
j)*x.fastAccessDx(i,
j) )/ (xval2.fastAccessCoeff(
j));
510 #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.