Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_Fad_ViewStorage.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_VIEWSTORAGE_HPP
31 #define SACADO_FAD_VIEWSTORAGE_HPP
32 
33 #include "Sacado_Traits.hpp"
36 
37 namespace Sacado {
38 
39  namespace Fad {
40 
46  template <typename T, unsigned static_length, unsigned static_stride, typename U>
47  class ViewStorage {
48 
49  private:
50 
51  // Enumerated flag so logic is evaluated at compile-time
52  enum { stride_one = 1 == static_stride };
53 
54  public:
55 
56  typedef T value_type;
57 
59  template <typename S>
62  sz_(0), stride_(0), val_(0), dx_(0) {}
63 
66  ViewStorage(const int sz, const T & x, const DerivInit zero_out = InitDerivArray) :
67  sz_(0), stride_(0), val_(0), dx_(0) {}
68 
71  ViewStorage(T* v, const int arg_size = 0, const int arg_stride = 0) :
72  sz_(arg_size), stride_(arg_stride), val_(v+sz_.value*stride_.value), dx_(v) {}
73 
77  sz_(x.sz_), stride_(x.stride_), val_(x.val_), dx_(x.dx_) {}
78 
82 
86  if (this != &x) {
87  *val_ = *x.val_;
88  if (stride_one)
89  for (int i=0; i<sz_.value; ++i)
90  dx_[i] = x.dx_[i];
91  else
92  for (int i=0; i<sz_.value; ++i)
93  dx_[i*stride_.value] = x.dx_[i*x.stride_.value];
94  }
95  return *this;
96  }
97 
100  int size() const { return sz_.value;}
101 
104  int length() const { return sz_.value; }
105 
107 
113  void resize(int sz) {
115  }
116 
118 
124  void resizeAndZero(int sz) {}
125 
128  void expand(int sz) {}
129 
132  void zero() {
134  }
135 
138  const T& val() const { return *val_; }
139 
142  T& val() { return *val_; }
143 
146  const T* dx() const { return dx_;}
147 
150  T dx(int i) const {
151  return sz_.value ? dx_[ stride_one ? i : i * stride_.value ] : T(0.);
152  }
153 
156  T& fastAccessDx(int i) {
157  return dx_[ stride_one ? i : i * stride_.value ];
158  }
159 
162  const T& fastAccessDx(int i) const {
163  return dx_[ stride_one ? i : i * stride_.value ];
164  }
165 
166  protected:
167 
170 
173 
175  T *val_;
176 
178  T *dx_;
179 
180  }; // class ViewStorage
181 
182  } // namespace Fad
183 
184 } // namespace Sacado
185 
186 #endif // SACADO_FAD_VIEWSTORAGE_HPP
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
const mpl::integral_nonzero_constant< int, static_length > sz_
Derivative array size.
KOKKOS_INLINE_FUNCTION T dx(int i) const
Returns derivative component i with bounds checking.
#define SACADO_ENABLE_VALUE_CTOR_DECL
static KOKKOS_INLINE_FUNCTION void strided_zero(T *dest, int stride, int sz)
Zero out array dest of length sz.
KOKKOS_INLINE_FUNCTION void zero()
Zero out derivative array.
KOKKOS_INLINE_FUNCTION void resizeAndZero(int sz)
Resize the derivative array to sz.
KOKKOS_INLINE_FUNCTION ViewStorage(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Default constructor (needed to satisfy interface)
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.
KOKKOS_INLINE_FUNCTION ViewStorage(T *v, const int arg_size=0, const int arg_stride=0)
Constructor.
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION ~ViewStorage()
Destructor.
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
const mpl::integral_nonzero_constant< int, static_stride > stride_
Derivative array stride.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
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.
KOKKOS_INLINE_FUNCTION ViewStorage(const ViewStorage &x)
Copy constructor.
Initialize the derivative array.
KOKKOS_INLINE_FUNCTION int length() const
Returns array length.
Derivative array storage class that is a view into a contiguous memory allocation. It does not provide proper value semantics and thus should not be used in a general-purpose scalar type.
KOKKOS_INLINE_FUNCTION ViewStorage(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz (needed to satisfy interface)
KOKKOS_INLINE_FUNCTION ViewStorage & operator=(const ViewStorage &x)
Assignment.
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.