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_VectorImp.hpp
Go to the documentation of this file.
1 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Sacado Package
7 // Copyright (2006) Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // This library is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as
14 // published by the Free Software Foundation; either version 2.1 of the
15 // License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 // USA
26 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27 // (etphipp@sandia.gov).
28 //
29 // ***********************************************************************
30 // @HEADER
31 
33 
34 template <typename OrdinalType, typename ValueType>
36 Vector(OrdinalType vec_size, OrdinalType deriv_sz,
37  VectorDerivOrientation orient) :
38  deriv_size_(deriv_sz), orient_(orient), stride_(1), vec_(vec_size)
39 {
40  ValueType* x = NULL;
41  ValueType* dx_ = NULL;
42  if (vec_size > 0) {
44  if (deriv_size_ > 0)
46  }
47  if (orient_ == Row) {
48  stride_ = vec_size;
49  for (OrdinalType i=0; i<vec_size; i++)
50  vec_[i].setMemory(deriv_size_, x+i, dx_+i, stride_);
51  }
52  else {
53  stride_ = 1;
54  for (OrdinalType i=0; i<vec_size; i++)
55  vec_[i].setMemory(deriv_size_, x+i, dx_+i*deriv_size_, stride_);
56  }
57 }
58 
59 template <typename OrdinalType, typename ValueType>
61 Vector(const Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >& fv) :
62  deriv_size_(fv.deriv_size_), orient_(fv.orient_), stride_(fv.stride_),
63  vec_(fv.size())
64 {
65  OrdinalType vec_size = fv.size();
66  ValueType* x = NULL;
67  ValueType* dx_ = NULL;
68  if (vec_size > 0) {
70  if (deriv_size_ > 0)
72  }
73  if (orient_ == Row) {
74  for (OrdinalType i=0; i<vec_size; i++) {
75  vec_[i].setMemory(deriv_size_, x+i, dx_+i, stride_);
76  vec_[i] = fv.vec_[i];
77  }
78  }
79  else {
80  for (OrdinalType i=0; i<vec_size; i++) {
81  vec_[i].setMemory(deriv_size_, x+i, dx_+i*deriv_size_, stride_);
82  vec_[i] = fv.vec_[i];
83  }
84  }
85 }
86 
87 template <typename OrdinalType, typename ValueType>
89 ~Vector()
90 {
91  // Here we must destroy the value and derivative arrays
92  if (vec_.size() > 0) {
93  ValueType *v = vals();
95  if (deriv_size_ > 0) {
96  v = dx();
97  ds_array<ValueType>::destroy_and_release(v, vec_.size()*deriv_size_);
98  }
99  }
100 }
101 
102 template <typename OrdinalType, typename ValueType>
106 {
107  vec_ = fv.vec_;
108  return *this;
109 }
110 
111 template <typename OrdinalType, typename ValueType>
112 ValueType*
114 vals()
115 {
116  if (vec_.size() == 0)
117  return NULL;
118  return &(vec_[0].val());
119 }
120 
121 template <typename OrdinalType, typename ValueType>
122 const ValueType*
124 vals() const
125 {
126  if (vec_.size() == 0)
127  return NULL;
128  return &(vec_[0].val());
129 }
130 
131 template <typename OrdinalType, typename ValueType>
132 ValueType*
134 dx()
135 {
136  if (vec_.size() == 0 || deriv_size_ == 0)
137  return NULL;
138  return &(vec_[0].fastAccessDx(0));
139 }
140 
141 template <typename OrdinalType, typename ValueType>
142 const ValueType*
144 dx() const
145 {
146  if (vec_.size() == 0 || deriv_size_ == 0)
147  return NULL;
148  return &(vec_[0].fastAccessDx(0));
149 }
expr expr dx(i)
static KOKKOS_INLINE_FUNCTION void destroy_and_release(T *m, int sz)
Destroy array elements and release memory.
A class for storing a contiguously allocated array of Fad objects. This is a general definition that ...
static KOKKOS_INLINE_FUNCTION T * get_and_fill(int sz)
Get memory for new array of length sz and fill with zeros.
Forward-mode AD class using dynamic memory allocation and expression templates.
std::vector< FadType > vec_
Vector of Fad&#39;s.
OrdinalType deriv_size_
Size of derivative array.
Base template specification for ValueType.