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_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_ConfigDefs.h"
34 
35 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
36 
38 
39 namespace Sacado {
40  namespace Fad {
41 
42  template <typename T, unsigned static_length, unsigned static_stride,
43  typename U>
44  using ViewStorage = Exp::ViewStorage<T,static_length,static_stride,U>;
45 
46  }
47 }
48 
49 #else
50 
51 #include "Sacado_Traits.hpp"
54 
55 namespace Sacado {
56 
57  namespace Fad {
58 
64  template <typename T, unsigned static_length, unsigned static_stride, typename U>
65  class ViewStorage {
66 
67  private:
68 
69  // Enumerated flag so logic is evaluated at compile-time
70  enum { stride_one = 1 == static_stride };
71 
72  public:
73 
74  typedef T value_type;
75 
77  template <typename S>
80  sz_(0), stride_(0), val_(0), dx_(0) {}
81 
84  ViewStorage(const int sz, const T & x, const DerivInit zero_out = InitDerivArray) :
85  sz_(0), stride_(0), val_(0), dx_(0) {}
86 
89  ViewStorage(T* v, const int arg_size = 0, const int arg_stride = 0) :
90  sz_(arg_size), stride_(arg_stride), val_(v+sz_.value*stride_.value), dx_(v) {}
91 
94  ViewStorage(T* arg_dx, T* arg_val, const int arg_size = 0,
95  const int arg_stride = 0) :
96  sz_(arg_size), stride_(arg_stride), val_(arg_val), dx_(arg_dx) {}
97 
101  sz_(x.sz_), stride_(x.stride_), val_(x.val_), dx_(x.dx_) {}
102 
106 
110  if (this != &x) {
111  *val_ = *x.val_;
112  if (stride_one)
113  for (int i=0; i<sz_.value; ++i)
114  dx_[i] = x.dx_[i];
115  else
116  for (int i=0; i<sz_.value; ++i)
117  dx_[i*stride_.value] = x.dx_[i*x.stride_.value];
118  }
119  return *this;
120  }
121 
124  int size() const { return sz_.value;}
125 
128  int length() const { return sz_.value; }
129 
131 
137  void resize(int sz) {
139  }
140 
142 
148  void resizeAndZero(int /* sz */) {}
149 
152  void expand(int sz) {}
153 
156  void zero() {
158  }
159 
162  const T& val() const { return *val_; }
163 
166  T& val() { return *val_; }
167 
170  const T* dx() const { return dx_;}
171 
174  T dx(int i) const {
175  return unsigned(sz_.value) > 0 ? dx_[ unsigned(stride_one) == 1 ? i : i * stride_.value ] : T(0.);
176  }
177 
180  T& fastAccessDx(int i) {
181  return dx_[ unsigned(stride_one) == 1 ? i : i * stride_.value ];
182  }
183 
186  const T& fastAccessDx(int i) const {
187  return dx_[ unsigned(stride_one) == 1 ? i : i * stride_.value ];
188  }
189 
190  protected:
191 
194 
197 
199  T *val_;
200 
202  T *dx_;
203 
204  }; // class ViewStorage
205 
206  } // namespace Fad
207 
208 } // namespace Sacado
209 
210 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
211 
212 #endif // SACADO_FAD_VIEWSTORAGE_HPP
KOKKOS_INLINE_FUNCTION void resizeAndZero(int)
Resize the derivative array to sz.
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.
KOKKOS_INLINE_FUNCTION int length() const
Returns array length.
const mpl::integral_nonzero_constant< int, static_length > sz_
Derivative array size.
#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 ViewStorage(T *arg_dx, T *arg_val, const int arg_size=0, const int arg_stride=0)
Constructor.
KOKKOS_INLINE_FUNCTION void zero()
Zero out derivative array.
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 & val() const
Returns value.
KOKKOS_INLINE_FUNCTION ViewStorage(const ViewStorage &x)
Copy constructor.
Initialize the derivative array.
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 int size() const
Returns number of derivative components.
KOKKOS_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
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.