Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_Exp_StaticStorage.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #ifndef SACADO_FAD_EXP_STATICSTORAGE_HPP
31 #define SACADO_FAD_EXP_STATICSTORAGE_HPP
32 
33 #include <type_traits>
34 
35 #include "Sacado_ConfigDefs.h"
37 
38 namespace Sacado {
39 
40  namespace Fad {
41  namespace Exp {
42 
44 
48  template <typename T, int Num>
49  class StaticStorage {
50 
51  public:
52 
53  typedef typename std::remove_cv<T>::type value_type;
54  static constexpr bool is_statically_sized = false;
55  static constexpr int static_size = 0;
56 
58  template <typename TT>
59  struct apply {
61  };
62 
64  template <int N>
65  struct apply_N {
67  };
68 
72  val_(), sz_(0) {}
73 
76  StaticStorage(const T & x) :
77  val_(x), sz_(0) {}
78 
80 
84  StaticStorage(const int sz, const T & x, const DerivInit zero_out) :
85  val_(x), sz_(sz) {
86 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
87  if (sz > Num)
88  throw "StaticStorage::StaticStorage() Error: Supplied derivative dimension exceeds maximum length.";
89 #endif
90  if (zero_out == InitDerivArray)
92  }
93 
97  val_(x.val_), sz_(x.sz_) {
98  //ss_array<T>::copy(x.dx_, dx_, sz_);
99  for (int i=0; i<sz_; i++)
100  dx_[i] = x.dx_[i];
101  }
102 
106 
110  if (this != &x) {
111  val_ = x.val_;
112  sz_ = x.sz_;
113  //ss_array<T>::copy(x.dx_, dx_, sz_);
114  for (int i=0; i<sz_; i++)
115  dx_[i] = x.dx_[i];
116  }
117  return *this;
118  }
119 
122  int size() const { return sz_;}
123 
126  int length() const { return Num; }
127 
130  void resize(int sz) {
131 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
132  if (sz > Num)
133  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
134 #endif
135  sz_ = sz;
136  }
137 
139 
144  void resizeAndZero(int sz) {
145 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
146  if (sz > Num)
147  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
148 #endif
149  if (sz > sz_)
151  sz_ = sz;
152  }
153 
155 
160  void expand(int sz) {
161 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
162  if (sz > Num)
163  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
164 #endif
165  if (sz > sz_)
167  sz_ = sz;
168  }
169 
170 
174 
177  const T& val() const { return val_; }
178 
181  T& val() { return val_; }
182 
185  const T* dx() const { return dx_;}
186 
189  T dx(int i) const { return sz_ ? dx_[i] : T(0.); }
190 
193  T& fastAccessDx(int i) { return dx_[i];}
194 
197  const T& fastAccessDx(int i) const { return dx_[i];}
198 
199  protected:
200 
203 
205  T dx_[Num];
206 
208  int sz_;
209 
210  }; // class StaticStorage
211 
212  } // namespace Exp
213  } // namespace Fad
214 
215 } // namespace Sacado
216 
217 #endif // SACADO_FAD_EXP_STATICSTORAGE_HPP
Sacado::Fad::Exp::StaticStorage::zero
KOKKOS_INLINE_FUNCTION void zero()
Zero out derivative array.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:173
Sacado::Fad::Exp::StaticStorage::apply_N::type
StaticStorage< T, Num > type
Definition: Sacado_Fad_Exp_StaticStorage.hpp:66
KOKKOS_INLINE_FUNCTION
#define KOKKOS_INLINE_FUNCTION
Definition: Sacado_ConfigDefs.h:90
Sacado::Fad::Exp::StaticStorage::val
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:181
Sacado::Fad::Exp::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage(const int sz, const T &x, const DerivInit zero_out)
Constructor with size sz.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:84
Sacado::Fad::Exp::StaticStorage::dx
const KOKKOS_INLINE_FUNCTION T * dx() const
Returns derivative array.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:185
Sacado::Fad::Exp::StaticStorage::resizeAndZero
KOKKOS_INLINE_FUNCTION void resizeAndZero(int sz)
Resize the derivative array to sz.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:144
Sacado::Fad::Exp::StaticStorage::resize
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:130
Sacado::Fad::Exp::StaticStorage
Derivative array storage class using static memory allocation.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:49
Sacado::Fad::Exp::StaticStorage::is_statically_sized
static constexpr bool is_statically_sized
Definition: Sacado_Fad_Exp_StaticStorage.hpp:54
Sacado_StaticArrayTraits.hpp
Sacado::Fad::Exp::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage()
Default constructor.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:71
Sacado::Fad::Exp::StaticStorage::apply_N
Replace static derivative length (interpreted as a fixed length)
Definition: Sacado_Fad_Exp_StaticStorage.hpp:65
T
#define T
Definition: Sacado_rad.hpp:573
Sacado::Fad::Exp::StaticStorage::apply::type
StaticStorage< TT, Num > type
Definition: Sacado_Fad_Exp_StaticStorage.hpp:60
Sacado::Fad::Exp::StaticStorage::fastAccessDx
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:193
Sacado::Fad::Exp::StaticStorage::expand
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:160
Sacado::Fad::Exp::StaticStorage::apply
Turn StaticStorage into a meta-function class usable with mpl::apply.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:59
Sacado::Fad::Exp::StaticStorage::~StaticStorage
KOKKOS_INLINE_FUNCTION ~StaticStorage()
Destructor.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:105
Sacado::Fad::Exp::StaticStorage::value_type
std::remove_cv< T >::type value_type
Definition: Sacado_Fad_Exp_StaticStorage.hpp:53
Sacado::Fad::Exp::StaticStorage::val_
T val_
Value.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:202
Sacado::Fad::Exp::StaticStorage::operator=
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const StaticStorage &x)
Assignment.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:109
Sacado::Fad::Exp::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage(const StaticStorage &x)
Copy constructor.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:96
Sacado::Fad::Exp::StaticStorage::fastAccessDx
const KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:197
Sacado
Definition: Sacado_mpl_apply.hpp:39
Sacado::Fad::Exp::StaticStorage::size
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:122
Sacado::Fad::Exp::StaticStorage::StaticStorage
KOKKOS_INLINE_FUNCTION StaticStorage(const T &x)
Constructor with value.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:76
Sacado::Fad::Exp::StaticStorage::length
KOKKOS_INLINE_FUNCTION int length() const
Returns array length.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:126
Sacado::Fad::Exp::StaticStorage::dx
KOKKOS_INLINE_FUNCTION T dx(int i) const
Returns derivative component i with bounds checking.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:189
Sacado_ConfigDefs.h
Sacado::Fad::Exp::StaticStorage::sz_
int sz_
Size of derivative array.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:208
Sacado::Fad::Exp::StaticStorage::val
const KOKKOS_INLINE_FUNCTION T & val() const
Returns value.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:177
Sacado::Fad::Exp::StaticStorage::static_size
static constexpr int static_size
Definition: Sacado_Fad_Exp_StaticStorage.hpp:55
Sacado::ss_array::zero
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
Definition: Sacado_StaticArrayTraits.hpp:54
Sacado::DerivInit
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors.
Definition: Sacado_Traits.hpp:70
Sacado::InitDerivArray
Initialize the derivative array.
Definition: Sacado_Traits.hpp:72
Sacado::Fad::Exp::StaticStorage::dx_
T dx_[Num]
Derivative array.
Definition: Sacado_Fad_Exp_StaticStorage.hpp:205