Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_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_STATICSTORAGE_HPP
31 #define SACADO_FAD_STATICSTORAGE_HPP
32 
33 #include "Sacado_ConfigDefs.h"
35 
36 namespace Sacado {
37 
38  namespace Fad {
39 
41 
45  template <typename T, int Num>
46  class StaticStorage {
47 
48  public:
49 
50  typedef T value_type;
51 
53  template <typename S>
56  val_(x), sz_(0) {}
57 
59 
63  StaticStorage(const int sz, const T & x, const DerivInit zero_out = InitDerivArray) :
64  val_(x), sz_(sz) {
65 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
66  if (sz > Num)
67  throw "StaticStorage::StaticStorage() Error: Supplied derivative dimension exceeds maximum length.";
68 #endif
69  if (zero_out == InitDerivArray)
71  }
72 
76  val_(x.val_), sz_(x.sz_) {
77  //ss_array<T>::copy(x.dx_, dx_, sz_);
78  for (int i=0; i<sz_; i++)
79  dx_[i] = x.dx_[i];
80  }
81 
85 
89  if (this != &x) {
90  val_ = x.val_;
91  sz_ = x.sz_;
92  //ss_array<T>::copy(x.dx_, dx_, sz_);
93  for (int i=0; i<sz_; i++)
94  dx_[i] = x.dx_[i];
95  }
96  return *this;
97  }
98 
101  int size() const { return sz_;}
102 
105  int length() const { return Num; }
106 
109  void resize(int sz) {
110 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
111  if (sz > Num)
112  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
113 #endif
114  sz_ = sz;
115  }
116 
118 
123  void resizeAndZero(int sz) {
124 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
125  if (sz > Num)
126  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
127 #endif
128  if (sz > sz_)
130  sz_ = sz;
131  }
132 
134 
139  void expand(int sz) {
140 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
141  if (sz > Num)
142  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
143 #endif
144  if (sz > sz_)
146  sz_ = sz;
147  }
148 
149 
153 
156  const T& val() const { return val_; }
157 
160  T& val() { return val_; }
161 
164  const T* dx() const { return dx_;}
165 
168  T dx(int i) const { return sz_ ? dx_[i] : T(0.); }
169 
172  T& fastAccessDx(int i) { return dx_[i];}
173 
176  const T& fastAccessDx(int i) const { return dx_[i];}
177 
178  protected:
179 
182 
184  T dx_[Num];
185 
187  int sz_;
188 
189  }; // class StaticStorage
190 
191  } // namespace Fad
192 
193 } // namespace Sacado
194 
195 #endif // SACADO_FAD_STATICSTORAGE_HPP
Derivative array storage class using static memory allocation.
#define SACADO_ENABLE_VALUE_CTOR_DECL
KOKKOS_INLINE_FUNCTION ~StaticStorage()
Destructor.
KOKKOS_INLINE_FUNCTION void zero()
Zero out derivative array.
KOKKOS_INLINE_FUNCTION StaticStorage(const StaticStorage &x)
Copy constructor.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
KOKKOS_INLINE_FUNCTION T dx(int i) const
Returns derivative component i with bounds checking.
static KOKKOS_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const StaticStorage &x)
Assignment.
KOKKOS_INLINE_FUNCTION StaticStorage(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Default constructor.
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
int sz_
Size of derivative array.
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION int length() const
Returns array length.
KOKKOS_INLINE_FUNCTION StaticStorage(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz.
KOKKOS_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
KOKKOS_INLINE_FUNCTION void resizeAndZero(int sz)
Resize the derivative array to sz.