Panzer  Version of the Day
Panzer_DOF_Functors.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef __Panzer_DOF_Functors_hpp__
44 #define __Panzer_DOF_Functors_hpp__
45 
46 #include "Phalanx_MDField.hpp"
47 #include "Phalanx_KokkosDeviceTypes.hpp"
48 
49 namespace panzer {
50 
51 //**********************************************************************
52 
53 // This hides the EvaluateDOF functors outside of this file
54 namespace dof_functors {
55 
56 template <typename ScalarT,typename Array,int spaceDim>
58  PHX::MDField<const ScalarT,Cell,Point> dof_basis;
59  PHX::MDField<ScalarT,Cell,Point,Dim> dof_ip;
61 
62  int numFields;
63  int numPoints;
64 
65 public:
66  typedef typename PHX::Device execution_space;
67 
68  EvaluateDOFWithSens_Vector(PHX::MDField<const ScalarT,Cell,Point> in_dof_basis,
69  PHX::MDField<ScalarT,Cell,Point,Dim> in_dof_ip,
70  Array in_basis)
71  : dof_basis(in_dof_basis), dof_ip(in_dof_ip), basis(in_basis)
72  {
73  numFields = basis.extent(1);
74  numPoints = basis.extent(2);
75  }
76  KOKKOS_INLINE_FUNCTION
77  void operator()(const unsigned int cell) const
78  {
79  for (int pt=0; pt<numPoints; pt++) {
80  for (int d=0; d<spaceDim; d++) {
81  // first initialize to the right thing (prevents over writing with 0)
82  // then loop over one less basis function
83  dof_ip(cell,pt,d) = dof_basis(cell, 0) * basis(cell, 0, pt, d);
84  for (int bf=1; bf<numFields; bf++)
85  dof_ip(cell,pt,d) += dof_basis(cell, bf) * basis(cell, bf, pt, d);
86  }
87  }
88  }
89 };
90 
91 template <typename ScalarT, typename Array>
93  PHX::MDField<const ScalarT,Cell,Point> dof_basis;
94  PHX::MDField<ScalarT,Cell,Point> dof_ip;
96 
97  int numFields;
98  int numPoints;
99 
100 public:
101  typedef typename PHX::Device execution_space;
102 
103  EvaluateDOFWithSens_Scalar(PHX::MDField<const ScalarT,Cell,Point> in_dof_basis,
104  PHX::MDField<ScalarT,Cell,Point> in_dof_ip,
105  Array in_basis)
106  : dof_basis(in_dof_basis), dof_ip(in_dof_ip), basis(in_basis)
107  {
108  numFields = basis.extent(1);
109  numPoints = basis.extent(2);
110  }
111  KOKKOS_INLINE_FUNCTION
112  void operator()(const unsigned int cell) const
113  {
114  for (int pt=0; pt<numPoints; pt++) {
115  // first initialize to the right thing (prevents over writing with 0)
116  // then loop over one less basis function
117  dof_ip(cell,pt) = dof_basis(cell, 0) * basis(cell, 0, pt);
118  for (int bf=1; bf<numFields; bf++) {
119  dof_ip(cell,pt) += dof_basis(cell, bf) * basis(cell, bf, pt);
120  }
121  }
122  }
123 };
124 
125 template <typename ScalarT,typename Array,int spaceDim>
127  PHX::MDField<const ScalarT,Cell,Point> dof_basis;
128  PHX::MDField<ScalarT,Cell,Point,Dim> dof_ip;
129  Kokkos::View<const int*,PHX::Device> offsets;
131 
134 
135 public:
136  typedef typename PHX::Device execution_space;
137 
138  EvaluateDOFFastSens_Vector(PHX::MDField<const ScalarT,Cell,Point> in_dof_basis,
139  PHX::MDField<ScalarT,Cell,Point,Dim> in_dof_ip,
140  Kokkos::View<const int*,PHX::Device> in_offsets,
141  Array in_basis)
142  : dof_basis(in_dof_basis), dof_ip(in_dof_ip), offsets(in_offsets), basis(in_basis)
143  {
144  numFields = basis.extent(1);
145  numPoints = basis.extent(2);
146  }
147  KOKKOS_INLINE_FUNCTION
148  void operator()(const unsigned int cell) const
149  {
150  typedef Sacado::ScalarValue<ScalarT> Value;
151 
152  for (int pt=0; pt<numPoints; pt++) {
153  for (int d=0; d<spaceDim; d++) {
154  // first initialize to the right thing (prevents over writing with 0)
155  // then loop over one less basis function
156 
157  // This is a possible issue if you need sensitivity to coordinates (you will need to
158  // change basis and then use the product rule!)
159  dof_ip(cell,pt,d) = dof_basis(cell, 0).val() * basis(cell, 0, pt, d);
160  dof_ip(cell,pt,d).fastAccessDx(offsets(0)) = dof_basis(cell, 0).fastAccessDx(offsets(0)) * Value::eval(basis(cell, 0, pt, d));
161 
162  for (int bf=1; bf<numFields; bf++) {
163  dof_ip(cell,pt,d).val() += dof_basis(cell, bf).val() * Value::eval(basis(cell, bf, pt, d));
164  dof_ip(cell,pt,d).fastAccessDx(offsets(bf)) += dof_basis(cell, bf).fastAccessDx(offsets(bf)) * Value::eval(basis(cell, bf, pt, d));
165  }
166  }
167  }
168  }
169 };
170 
171 template <typename ScalarT, typename Array>
173  PHX::MDField<const ScalarT,Cell,Point> dof_basis;
174  PHX::MDField<ScalarT,Cell,Point> dof_ip;
175  Kokkos::View<const int*,PHX::Device> offsets;
177 
180 
181 public:
182  typedef typename PHX::Device execution_space;
183 
184  EvaluateDOFFastSens_Scalar(PHX::MDField<const ScalarT,Cell,Point> in_dof_basis,
185  PHX::MDField<ScalarT,Cell,Point> in_dof_ip,
186  Kokkos::View<const int*,PHX::Device> in_offsets,
187  Array in_basis)
188  : dof_basis(in_dof_basis), dof_ip(in_dof_ip), offsets(in_offsets), basis(in_basis)
189  {
190  numFields = basis.extent(1);
191  numPoints = basis.extent(2);
192  }
193  KOKKOS_INLINE_FUNCTION
194  void operator()(const unsigned int cell) const
195  {
196  typedef Sacado::ScalarValue<ScalarT> Value;
197 
198  for (int pt=0; pt<numPoints; pt++) {
199  // first initialize to the right thing (prevents over writing with 0)
200  // then loop over one less basis function
201 
202  // This is a possible issue if you need sensitivity to coordinates (you will need to
203  // change basis and then use the product rule!)
204  dof_ip(cell,pt) = dof_basis(cell, 0).val() * Value::eval(basis(cell, 0, pt));
205  dof_ip(cell,pt).fastAccessDx(offsets(0)) = dof_basis(cell, 0).fastAccessDx(offsets(0)) * Value::eval(basis(cell, 0, pt));
206 
207  for (int bf=1; bf<numFields; bf++) {
208  dof_ip(cell,pt).val() += dof_basis(cell, bf).val() * Value::eval(basis(cell, bf, pt));
209  dof_ip(cell,pt).fastAccessDx(offsets(bf)) += dof_basis(cell, bf).fastAccessDx(offsets(bf)) * Value::eval(basis(cell, bf, pt));
210  }
211  }
212  }
213 };
214 
215 }
216 
217 }
218 
219 #endif
KOKKOS_INLINE_FUNCTION void operator()(const unsigned int cell) const
EvaluateDOFFastSens_Vector(PHX::MDField< const ScalarT, Cell, Point > in_dof_basis, PHX::MDField< ScalarT, Cell, Point, Dim > in_dof_ip, Kokkos::View< const int *, PHX::Device > in_offsets, Array in_basis)
PHX::MDField< const ScalarT, Cell, Point > dof_basis
Kokkos::View< const int *, PHX::Device > offsets
KOKKOS_INLINE_FUNCTION void operator()(const unsigned int cell) const
PHX::MDField< const ScalarT, Cell, Point > dof_basis
PHX::MDField< ScalarT, Cell, Point > dof_ip
KOKKOS_INLINE_FUNCTION void operator()(const unsigned int cell) const
PHX::MDField< ScalarT, Cell, Point, Dim > dof_ip
PHX::MDField< const ScalarT, Cell, Point > dof_basis
EvaluateDOFWithSens_Vector(PHX::MDField< const ScalarT, Cell, Point > in_dof_basis, PHX::MDField< ScalarT, Cell, Point, Dim > in_dof_ip, Array in_basis)
PHX::MDField< ScalarT, Cell, Point, Dim > dof_ip
EvaluateDOFFastSens_Scalar(PHX::MDField< const ScalarT, Cell, Point > in_dof_basis, PHX::MDField< ScalarT, Cell, Point > in_dof_ip, Kokkos::View< const int *, PHX::Device > in_offsets, Array in_basis)
EvaluateDOFWithSens_Scalar(PHX::MDField< const ScalarT, Cell, Point > in_dof_basis, PHX::MDField< ScalarT, Cell, Point > in_dof_ip, Array in_basis)
PHX::MDField< const ScalarT, Cell, Point > dof_basis
Kokkos::View< const int *, PHX::Device > offsets
KOKKOS_INLINE_FUNCTION void operator()(const unsigned int cell) const