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_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"
34 
35 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
36 
38 
39 namespace Sacado {
40  namespace Fad {
41 
42  template <typename T, int N>
43  using StaticStorage = Exp::StaticStorage<T,N>;
44 
45  }
46 }
47 
48 #else
49 
50 #include "Sacado_ConfigDefs.h"
52 
53 namespace Sacado {
54 
55  namespace Fad {
56 
58 
62  template <typename T, int Num>
63  class StaticStorage {
64 
65  public:
66 
67  typedef T value_type;
68 
70  template <typename S>
73  val_(x), sz_(0) {}
74 
76 
80  StaticStorage(const int sz, const T & x, const DerivInit zero_out = InitDerivArray) :
81  val_(x), sz_(sz) {
82 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
83  if (sz > Num)
84  throw "StaticStorage::StaticStorage() Error: Supplied derivative dimension exceeds maximum length.";
85 #endif
86  if (zero_out == InitDerivArray)
88  }
89 
93  val_(x.val_), sz_(x.sz_) {
94  //ss_array<T>::copy(x.dx_, dx_, sz_);
95  for (int i=0; i<sz_; i++)
96  dx_[i] = x.dx_[i];
97  }
98 
102 
106  if (this != &x) {
107  val_ = x.val_;
108  sz_ = x.sz_;
109  //ss_array<T>::copy(x.dx_, dx_, sz_);
110  for (int i=0; i<sz_; i++)
111  dx_[i] = x.dx_[i];
112  }
113  return *this;
114  }
115 
118  int size() const { return sz_;}
119 
122  int length() const { return Num; }
123 
126  void resize(int sz) {
127 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
128  if (sz > Num)
129  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
130 #endif
131  sz_ = sz;
132  }
133 
135 
140  void resizeAndZero(int sz) {
141 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
142  if (sz > Num)
143  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
144 #endif
145  if (sz > sz_)
147  sz_ = sz;
148  }
149 
151 
156  void expand(int sz) {
157 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
158  if (sz > Num)
159  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
160 #endif
161  if (sz > sz_)
163  sz_ = sz;
164  }
165 
166 
170 
173  const T& val() const { return val_; }
174 
177  T& val() { return val_; }
178 
181  const T* dx() const { return dx_;}
182 
185  T dx(int i) const { return sz_ ? dx_[i] : T(0.); }
186 
189  T& fastAccessDx(int i) { return dx_[i];}
190 
193  const T& fastAccessDx(int i) const { return dx_[i];}
194 
195  protected:
196 
199 
201  T dx_[Num];
202 
204  int sz_;
205 
206  }; // class StaticStorage
207 
208  } // namespace Fad
209 
210 } // namespace Sacado
211 
212 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
213 
214 #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 length() const
Returns array length.
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 void resize(int sz)
Resize the derivative array to sz.
KOKKOS_INLINE_FUNCTION T dx(int i) const
Returns derivative component i with bounds checking.
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 int size() const
Returns number of derivative components.
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.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION StaticStorage(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.
KOKKOS_INLINE_FUNCTION const T & val() const
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.