Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
KOKKOS_INLINE_FUNCTION T dx(int i) const
Returns derivative component i with bounds checking.
Turn StaticStorage into a meta-function class usable with mpl::apply.
KOKKOS_INLINE_FUNCTION StaticStorage()
Default constructor.
KOKKOS_INLINE_FUNCTION void resizeAndZero(int sz)
Resize the derivative array to sz.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
KOKKOS_INLINE_FUNCTION void zero()
Zero out derivative array.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
KOKKOS_INLINE_FUNCTION StaticStorage(const T &x)
Constructor with value.
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
KOKKOS_INLINE_FUNCTION ~StaticStorage()
Destructor.
KOKKOS_INLINE_FUNCTION StaticStorage(const int sz, const T &x, const DerivInit zero_out)
Constructor with size sz.
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
KOKKOS_INLINE_FUNCTION StaticStorage(const StaticStorage &x)
Copy constructor.
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const StaticStorage &x)
Assignment.
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
KOKKOS_INLINE_FUNCTION int length() const
Returns array length.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
KOKKOS_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
Initialize the derivative array.
Derivative array storage class using static memory allocation.
Replace static derivative length (interpreted as a fixed length)
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.