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 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_FAD_STATICSTORAGE_HPP
11 #define SACADO_FAD_STATICSTORAGE_HPP
12 
13 #include "Sacado_ConfigDefs.h"
14 
15 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
16 
18 
19 namespace Sacado {
20  namespace Fad {
21 
22  template <typename T, int N>
23  using StaticStorage = Exp::StaticStorage<T,N>;
24 
25  }
26 }
27 
28 #else
29 
30 #include "Sacado_ConfigDefs.h"
32 
33 namespace Sacado {
34 
35  namespace Fad {
36 
38 
42  template <typename T, int Num>
43  class StaticStorage {
44 
45  public:
46 
47  typedef T value_type;
48 
50  template <typename S>
53  val_(x), sz_(0) {}
54 
56 
60  StaticStorage(const int sz, const T & x, const DerivInit zero_out = InitDerivArray) :
61  val_(x), sz_(sz) {
62 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
63  if (sz > Num)
64  throw "StaticStorage::StaticStorage() Error: Supplied derivative dimension exceeds maximum length.";
65 #endif
66  if (zero_out == InitDerivArray)
68  }
69 
73  val_(x.val_), sz_(x.sz_) {
74  //ss_array<T>::copy(x.dx_, dx_, sz_);
75  for (int i=0; i<sz_; i++)
76  dx_[i] = x.dx_[i];
77  }
78 
82 
86  if (this != &x) {
87  val_ = x.val_;
88  sz_ = x.sz_;
89  //ss_array<T>::copy(x.dx_, dx_, sz_);
90  for (int i=0; i<sz_; i++)
91  dx_[i] = x.dx_[i];
92  }
93  return *this;
94  }
95 
98  int size() const { return sz_;}
99 
102  int length() const { return Num; }
103 
106  void resize(int sz) {
107 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
108  if (sz > Num)
109  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
110 #endif
111  sz_ = sz;
112  }
113 
115 
120  void resizeAndZero(int sz) {
121 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
122  if (sz > Num)
123  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
124 #endif
125  if (sz > sz_)
127  sz_ = sz;
128  }
129 
131 
136  void expand(int sz) {
137 #if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
138  if (sz > Num)
139  throw "StaticStorage::resize() Error: Supplied derivative dimension exceeds maximum length.";
140 #endif
141  if (sz > sz_)
143  sz_ = sz;
144  }
145 
146 
150 
153  const T& val() const { return val_; }
154 
157  T& val() { return val_; }
158 
161  const T* dx() const { return dx_;}
162 
165  T dx(int i) const { return sz_ ? dx_[i] : T(0.); }
166 
169  T& fastAccessDx(int i) { return dx_[i];}
170 
173  const T& fastAccessDx(int i) const { return dx_[i];}
174 
175  protected:
176 
179 
181  T dx_[Num];
182 
184  int sz_;
185 
186  }; // class StaticStorage
187 
188  } // namespace Fad
189 
190 } // namespace Sacado
191 
192 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
193 
194 #endif // SACADO_FAD_STATICSTORAGE_HPP
Derivative array storage class using static memory allocation.
#define SACADO_ENABLE_VALUE_CTOR_DECL
SACADO_INLINE_FUNCTION void resizeAndZero(int sz)
Resize the derivative array to sz.
SACADO_INLINE_FUNCTION T dx(int i) const
Returns derivative component i with bounds checking.
SACADO_INLINE_FUNCTION int size() const
Returns number of derivative components.
SACADO_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
SACADO_INLINE_FUNCTION const T & val() const
Returns value.
SACADO_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
#define T
Definition: Sacado_rad.hpp:553
SACADO_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
SACADO_INLINE_FUNCTION int length() const
Returns array length.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
int sz_
Size of derivative array.
SACADO_INLINE_FUNCTION ~StaticStorage()
Destructor.
SACADO_INLINE_FUNCTION StaticStorage(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz.
static SACADO_INLINE_FUNCTION void zero(T *dest, int sz)
Zero out array dest of length sz.
SACADO_INLINE_FUNCTION StaticStorage(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Default constructor.
Initialize the derivative array.
SACADO_INLINE_FUNCTION StaticStorage & operator=(const StaticStorage &x)
Assignment.
SACADO_INLINE_FUNCTION T & val()
Returns value.
#define SACADO_INLINE_FUNCTION
SACADO_INLINE_FUNCTION void zero()
Zero out derivative array.
SACADO_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
SACADO_INLINE_FUNCTION const T * dx() const
Returns derivative array.
SACADO_INLINE_FUNCTION StaticStorage(const StaticStorage &x)
Copy constructor.