Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_DOF_Functors.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef __Panzer_DOF_Functors_hpp__
12#define __Panzer_DOF_Functors_hpp__
13
14#include "Phalanx_MDField.hpp"
15#include "Phalanx_KokkosDeviceTypes.hpp"
16
17namespace panzer {
18
19//**********************************************************************
20
48// This hides the EvaluateDOF functors outside of this file
49namespace dof_functors {
50
58template <typename ScalarT,typename Array,int spaceDim>
60 PHX::View<const ScalarT**> dof_basis; // <C,P>
61 PHX::View<ScalarT***> dof_ip; // <C,P,D>
62 Array basis;
63 const int numFields;
64 const int numPoints;
65 const int fadSize;
67
68public:
69 using scratch_view = Kokkos::View<ScalarT* ,typename PHX::DevLayout<ScalarT>::type,typename PHX::exec_space::scratch_memory_space,Kokkos::MemoryUnmanaged>;
70
78 EvaluateDOFWithSens_Vector(PHX::View<const ScalarT**> in_dof_basis,
79 PHX::View<ScalarT***> in_dof_ip,
80 Array in_basis,
81 bool in_use_shared_memory = false)
82 : dof_basis(in_dof_basis), dof_ip(in_dof_ip), basis(in_basis),
83 numFields(static_cast<int>(basis.extent(1))),
84 numPoints(static_cast<int>(basis.extent(2))),
85 fadSize(static_cast<int>(Kokkos::dimension_scalar(dof_basis))),
86 use_shared_memory(in_use_shared_memory)
87 {}
88
90 KOKKOS_INLINE_FUNCTION
91 void operator()(const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) const
92 {
93 const int cell = team.league_rank();
94
95 if (not use_shared_memory) {
96 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numPoints), [&] (const int& pt) {
97 for (int d=0; d<spaceDim; ++d) {
98 // first initialize to the right thing (prevents over writing with 0)
99 // then loop over one less basis function
100 dof_ip(cell,pt,d) = dof_basis(cell, 0) * basis(cell, 0, pt, d);
101 // The start index is one, not zero since we used the zero index for initialization above.
102 for (int bf=1; bf<numFields; ++bf) {
103 dof_ip(cell,pt,d) += dof_basis(cell, bf) * basis(cell, bf, pt, d);
104 }
105 }
106 });
107 }
108 else {
109
110 // Copy reused data into fast scratch space
111 scratch_view dof_values;
112 scratch_view point_values;
113 if (Sacado::IsADType<ScalarT>::value) {
114 dof_values = scratch_view(team.team_shmem(),numFields,fadSize);
115 point_values = scratch_view(team.team_shmem(),numPoints,fadSize);
116 }
117 else {
118 dof_values = scratch_view(team.team_shmem(),numFields);
119 point_values = scratch_view(team.team_shmem(),numPoints);
120 }
121
122 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numFields), [&] (const int& dof) {
123 dof_values(dof) = dof_basis(cell,dof);
124 });
125
126 team.team_barrier();
127
128 for (int dim=0; dim < spaceDim; ++dim) {
129
130 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numPoints), [&] (const int& pt) {
131 point_values(pt) = 0.0;
132 });
133
134 // Perform contraction
135 for (int dof=0; dof<numFields; ++dof) {
136 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numPoints), [&] (const int& pt) {
137 point_values(pt) += dof_values(dof) * basis(cell,dof,pt,dim);
138 });
139 }
140
141 // Copy to main memory
142 Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,numPoints), [&] (const int& pt) {
143 dof_ip(cell,pt,dim) = point_values(pt);
144 });
145
146 } // loop over dim
147 } // if (use_shared_memory) {
148 }
149
151 size_t team_shmem_size(int /* team_size */ ) const
152 {
153 if (not use_shared_memory)
154 return 0;
155
156 size_t bytes;
157 if (Sacado::IsADType<ScalarT>::value)
158 bytes = scratch_view::shmem_size(numFields,fadSize) + scratch_view::shmem_size(numPoints,fadSize);
159 else
160 bytes = scratch_view::shmem_size(numFields) + scratch_view::shmem_size(numPoints);
161 return bytes;
162 }
163
164};
165
172template <typename ScalarT, typename Array>
174 PHX::MDField<const ScalarT,Cell,Point> dof_basis;
175 PHX::MDField<ScalarT,Cell,Point> dof_ip;
176 Array basis;
177
180
181public:
182 typedef typename PHX::Device execution_space;
183
190 EvaluateDOFWithSens_Scalar(PHX::MDField<const ScalarT,Cell,Point> in_dof_basis,
191 PHX::MDField<ScalarT,Cell,Point> in_dof_ip,
192 Array in_basis)
193 : dof_basis(in_dof_basis), dof_ip(in_dof_ip), basis(in_basis)
194 {
195 numFields = basis.extent(1);
196 numPoints = basis.extent(2);
197 }
199 KOKKOS_INLINE_FUNCTION
200 void operator()(const unsigned int cell) const
201 {
202 for (int pt=0; pt<numPoints; pt++) {
203 // first initialize to the right thing (prevents over writing with 0)
204 // then loop over one less basis function
205 dof_ip(cell,pt) = dof_basis(cell, 0) * basis(cell, 0, pt);
206 for (int bf=1; bf<numFields; bf++) {
207 dof_ip(cell,pt) += dof_basis(cell, bf) * basis(cell, bf, pt);
208 }
209 }
210 }
211};
212
226template <typename ScalarT,typename Array,int spaceDim>
228 PHX::MDField<const ScalarT,Cell,Point> dof_basis;
229 PHX::MDField<ScalarT,Cell,Point,Dim> dof_ip;
230 PHX::View<const int*> offsets;
231 Array basis;
232
233 const int numFields;
234 const int numPoints;
235
236public:
237 typedef typename PHX::Device execution_space;
238
246 EvaluateDOFFastSens_Vector(PHX::MDField<const ScalarT,Cell,Point> in_dof_basis,
247 PHX::MDField<ScalarT,Cell,Point,Dim> in_dof_ip,
248 PHX::View<const int*> in_offsets,
249 Array in_basis)
250 : dof_basis(in_dof_basis), dof_ip(in_dof_ip), offsets(in_offsets), basis(in_basis),
251 numFields(in_basis.extent(1)),
252 numPoints(in_basis.extent(2))
253 {}
254
256 KOKKOS_INLINE_FUNCTION
257 void operator()(const unsigned int cell) const
258 {
259 for (int pt=0; pt<numPoints; pt++) {
260 for (int d=0; d<spaceDim; d++) {
261 // first initialize to the right thing (prevents over writing with 0)
262 // then loop over one less basis function
263
264 // This is a possible issue if you need sensitivity to coordinates (you will need to
265 // change basis and then use the product rule!)
266 dof_ip(cell,pt,d) = dof_basis(cell, 0).val() * basis(cell, 0, pt, d);
267 dof_ip(cell,pt,d).fastAccessDx(offsets(0)) = dof_basis(cell, 0).fastAccessDx(offsets(0)) * Sacado::scalarValue(basis(cell, 0, pt, d));
268
269 for (int bf=1; bf<numFields; bf++) {
270 dof_ip(cell,pt,d).val() += dof_basis(cell, bf).val() * Sacado::scalarValue(basis(cell, bf, pt, d));
271 dof_ip(cell,pt,d).fastAccessDx(offsets(bf)) += dof_basis(cell, bf).fastAccessDx(offsets(bf)) * Sacado::scalarValue(basis(cell, bf, pt, d));
272 }
273 }
274 }
275 }
276};
277
290template <typename ScalarT, typename Array>
292 PHX::MDField<const ScalarT,Cell,Point> dof_basis;
293 PHX::MDField<ScalarT,Cell,Point> dof_ip;
294 PHX::View<const int*> offsets;
295 Array basis;
296
299
300public:
301 typedef typename PHX::Device execution_space;
302
310 EvaluateDOFFastSens_Scalar(PHX::MDField<const ScalarT,Cell,Point> in_dof_basis,
311 PHX::MDField<ScalarT,Cell,Point> in_dof_ip,
312 PHX::View<const int*> in_offsets,
313 Array in_basis)
314 : dof_basis(in_dof_basis), dof_ip(in_dof_ip), offsets(in_offsets), basis(in_basis)
315 {
316 numFields = basis.extent(1);
317 numPoints = basis.extent(2);
318 }
320 KOKKOS_INLINE_FUNCTION
321 void operator()(const unsigned int cell) const
322 {
323 for (int pt=0; pt<numPoints; pt++) {
324 // first initialize to the right thing (prevents over writing with 0)
325 // then loop over one less basis function
326
327 // This is a possible issue if you need sensitivity to coordinates (you will need to
328 // change basis and then use the product rule!)
329 dof_ip(cell,pt) = dof_basis(cell, 0).val() * Sacado::scalarValue(basis(cell, 0, pt));
330 dof_ip(cell,pt).fastAccessDx(offsets(0)) = dof_basis(cell, 0).fastAccessDx(offsets(0)) * Sacado::scalarValue(basis(cell, 0, pt));
331
332 for (int bf=1; bf<numFields; bf++) {
333 dof_ip(cell,pt).val() += dof_basis(cell, bf).val() * Sacado::scalarValue(basis(cell, bf, pt));
334 dof_ip(cell,pt).fastAccessDx(offsets(bf)) += dof_basis(cell, bf).fastAccessDx(offsets(bf)) * Sacado::scalarValue(basis(cell, bf, pt));
335 }
336 }
337 }
338};
339
340}
341
342}
343
344#endif
Scalar-valued DOF interpolation functor using the fast-sensitivity optimization.
KOKKOS_INLINE_FUNCTION void operator()(const unsigned int cell) const
Computes dof_ip (value and its one nonzero sensitivity) for all points of one cell.
EvaluateDOFFastSens_Scalar(PHX::MDField< const ScalarT, Cell, Point > in_dof_basis, PHX::MDField< ScalarT, Cell, Point > in_dof_ip, PHX::View< const int * > in_offsets, Array in_basis)
Constructor.
PHX::MDField< const ScalarT, Cell, Point > dof_basis
Vector-valued DOF interpolation functor using the fast-sensitivity optimization.
EvaluateDOFFastSens_Vector(PHX::MDField< const ScalarT, Cell, Point > in_dof_basis, PHX::MDField< ScalarT, Cell, Point, Dim > in_dof_ip, PHX::View< const int * > in_offsets, Array in_basis)
Constructor.
PHX::MDField< ScalarT, Cell, Point, Dim > dof_ip
PHX::MDField< const ScalarT, Cell, Point > dof_basis
KOKKOS_INLINE_FUNCTION void operator()(const unsigned int cell) const
Computes dof_ip (value and its one nonzero sensitivity) for all points/dimensions of one cell.
Scalar-valued DOF interpolation functor with full derivative propagation.
EvaluateDOFWithSens_Scalar(PHX::MDField< const ScalarT, Cell, Point > in_dof_basis, PHX::MDField< ScalarT, Cell, Point > in_dof_ip, Array in_basis)
Constructor.
PHX::MDField< const ScalarT, Cell, Point > dof_basis
KOKKOS_INLINE_FUNCTION void operator()(const unsigned int cell) const
Computes dof_ip for all points of one cell.
Vector-valued DOF interpolation functor with full derivative propagation.
size_t team_shmem_size(int) const
Returns the team scratch memory size (in bytes) required by operator() when use_shared_memory is enab...
KOKKOS_INLINE_FUNCTION void operator()(const Kokkos::TeamPolicy< PHX::exec_space >::member_type &team) const
Computes dof_ip for one cell (team.league_rank()), optionally staging through team scratch memory.
Kokkos::View< ScalarT *,typename PHX::DevLayout< ScalarT >::type, typename PHX::exec_space::scratch_memory_space, Kokkos::MemoryUnmanaged > scratch_view
EvaluateDOFWithSens_Vector(PHX::View< const ScalarT ** > in_dof_basis, PHX::View< ScalarT *** > in_dof_ip, Array in_basis, bool in_use_shared_memory=false)
Constructor.