69 typedef typename ScalarViewType::value_type value_type;
71 CoordsViewType dofCoords_;
72 CoeffsViewType dofCoeffs_;
73 const ortViewType orts_;
74 const t2oViewType tagToOrdinal_;
75 const subcellParamViewType edgeParam_, faceParam_;
76 const intViewType edgesInternalDofOrdinals_, facesInternalDofOrdinals_;
77 const ScalarViewType edgesInternalDofCoords_, edgeDofCoeffs_;
78 const ScalarViewType facesInternalDofCoords_, faceDofCoeffs_;
79 ScalarViewType edgeWorkView_, faceWorkView_;
80 const ordinal_type cellDim_, numEdges_, numFaces_;
81 const intViewType edgeTopoKey_, numEdgesInternalDofs_;
82 const intViewType faceTopoKey_, numFacesInternalDofs_;
83 const bool isBasisHCURL_, isBasisHDIV_;
86 CoeffsViewType dofCoeffs,
87 const ortViewType orts,
88 const t2oViewType tagToOrdinal,
89 const subcellParamViewType edgeParam,
90 const subcellParamViewType faceParam,
91 const intViewType edgesInternalDofOrdinals,
92 const intViewType facesInternalDofOrdinals,
93 const ScalarViewType edgesInternalDofCoords,
94 const ScalarViewType edgeDofCoeffs,
95 const ScalarViewType facesInternalDofCoords,
96 const ScalarViewType faceDofCoeffs,
97 const ordinal_type cellDim,
98 const ordinal_type numEdges,
99 const ordinal_type numFaces,
100 const intViewType edgeTopoKey,
101 const intViewType numEdgesInternalDofs,
102 const intViewType faceTopoKey,
103 const intViewType numFacesInternalDofs,
104 const bool isBasisHCURL,
105 const bool isBasisHDIV
107 : dofCoords_(dofCoords),
108 dofCoeffs_(dofCoeffs),
110 tagToOrdinal_(tagToOrdinal),
111 edgeParam_(edgeParam),
112 faceParam_(faceParam),
113 edgesInternalDofOrdinals_(edgesInternalDofOrdinals),
114 facesInternalDofOrdinals_(facesInternalDofOrdinals),
115 edgesInternalDofCoords_(edgesInternalDofCoords),
116 edgeDofCoeffs_(edgeDofCoeffs),
117 facesInternalDofCoords_(facesInternalDofCoords),
118 faceDofCoeffs_(faceDofCoeffs),
122 edgeTopoKey_(edgeTopoKey),
123 numEdgesInternalDofs_(numEdgesInternalDofs),
124 faceTopoKey_(faceTopoKey),
125 numFacesInternalDofs_(numFacesInternalDofs),
126 isBasisHCURL_(isBasisHCURL),
127 isBasisHDIV_(isBasisHDIV)
130 edgeWorkView_ = ScalarViewType(
"edgeWorkView", dofCoords.extent(0), edgesInternalDofCoords.extent(1), cellDim);
132 faceWorkView_ = ScalarViewType(
"faceWorkView", dofCoords.extent(0), facesInternalDofCoords.extent(1), cellDim);
135 KOKKOS_INLINE_FUNCTION
136 void operator()(
const ordinal_type cell)
const {
137 typedef Kokkos::pair<ordinal_type,ordinal_type> range_type;
142 ordinal_type eOrt[12];
143 orts_(cell).getEdgeOrientation(eOrt, numEdges_);
144 for (ordinal_type iedge=0; iedge < numEdges_; ++iedge) {
145 ordinal_type numInternalDofs = numEdgesInternalDofs_(iedge);
146 auto dofRange = range_type(0, numInternalDofs);
147 auto edgeInternalDofCoords = Kokkos::subview(edgesInternalDofCoords_, iedge, dofRange, Kokkos::ALL());
148 auto cellDofCoordsOriented = Kokkos::subview(edgeWorkView_,cell, dofRange, range_type(0,cellDim_));
153 for (ordinal_type j=0;j<numInternalDofs;++j) {
154 auto idof = tagToOrdinal_(1, iedge, j);
155 for (ordinal_type d=0;d<cellDim_;++d)
156 dofCoords_(cell,idof,d) = cellDofCoordsOriented(j,d);
163 ScalarViewType tangents(tmp,1,cellDim_);
164 for (ordinal_type iedge=0; iedge < numEdges_; ++iedge) {
166 for(ordinal_type j=0; j<numEdgesInternalDofs_(iedge); ++j) {
167 auto idof = tagToOrdinal_(1, iedge, j);
168 auto jdof = edgesInternalDofOrdinals_(iedge, j);
169 for(ordinal_type d=0; d <cellDim_; ++d) {
170 dofCoeffs_(cell,idof,d) = 0;
171 dofCoeffs_(cell,idof,d) += tangents(0,d)*edgeDofCoeffs_(iedge,jdof);
175 }
else if(isBasisHDIV_) {
177 ScalarViewType tangentsAndNormal(tmp,cellDim_,cellDim_);
178 for (ordinal_type iedge=0; iedge < numEdges_; ++iedge) {
180 for(ordinal_type j=0; j<numEdgesInternalDofs_(iedge); ++j) {
181 auto idof = tagToOrdinal_(1, iedge, j);
182 auto jdof = edgesInternalDofOrdinals_(iedge, j);
183 for(ordinal_type d=0; d <cellDim_; ++d)
184 dofCoeffs_(cell,idof,d) = tangentsAndNormal(cellDim_-1, d)*edgeDofCoeffs_(iedge,jdof);
188 for (ordinal_type iedge=0; iedge < numEdges_; ++iedge) {
189 for(ordinal_type j=0; j<numEdgesInternalDofs_(iedge); ++j) {
190 auto idof = tagToOrdinal_(1, iedge, j);
191 auto jdof = edgesInternalDofOrdinals_(iedge, j);
192 dofCoeffs_(cell,idof,0) = edgeDofCoeffs_(iedge,jdof);
201 ordinal_type fOrt[12];
202 orts_(cell).getFaceOrientation(fOrt, numFaces_);
204 for (ordinal_type iface=0; iface < numFaces_; ++iface) {
205 ordinal_type ort = fOrt[iface];
206 ordinal_type numInternalDofs = numFacesInternalDofs_(iface);
207 auto dofRange = range_type(0, numInternalDofs);
208 auto faceInternalDofCoords = Kokkos::subview(facesInternalDofCoords_, iface, dofRange, Kokkos::ALL());
209 auto cellDofCoordsOriented = Kokkos::subview(faceWorkView_,cell, dofRange, range_type(0,cellDim_));
212 for (ordinal_type j=0;j<numInternalDofs;++j) {
213 auto idof = tagToOrdinal_(2, iface, j);
214 for (ordinal_type d=0;d<cellDim_;++d)
215 dofCoords_(cell,idof,d) = cellDofCoordsOriented(j,d);
221 ScalarViewType tangents(tmp,2,cellDim_);
222 for (ordinal_type iface=0; iface < numFaces_; ++iface) {
224 for(ordinal_type j=0; j<numFacesInternalDofs_(iface); ++j) {
225 auto idof = tagToOrdinal_(2, iface, j);
226 auto jdof = facesInternalDofOrdinals_(iface, j);
227 for(ordinal_type d=0; d <cellDim_; ++d) {
228 dofCoeffs_(cell,idof,d) = 0;
229 for(ordinal_type k=0; k <2; ++k)
230 dofCoeffs_(cell,idof,d) += tangents(k,d)*faceDofCoeffs_(iface,jdof,k);
234 }
else if(isBasisHDIV_) {
236 ScalarViewType tangentsAndNormal(tmp,cellDim_,cellDim_);
237 for (ordinal_type iface=0; iface < numFaces_; ++iface) {
239 for(ordinal_type j=0; j<numFacesInternalDofs_(iface); ++j) {
240 auto idof = tagToOrdinal_(2, iface, j);
241 auto jdof = facesInternalDofOrdinals_(iface, j);
242 for(ordinal_type d=0; d <cellDim_; ++d)
243 dofCoeffs_(cell,idof,d) = tangentsAndNormal(cellDim_-1,d)*faceDofCoeffs_(iface,jdof);
248 for (ordinal_type iface=0; iface < numFaces_; ++iface) {
249 for(ordinal_type j=0; j<numFacesInternalDofs_(iface); ++j) {
250 auto idof = tagToOrdinal_(2, iface, j);
251 auto jdof = facesInternalDofOrdinals_(iface, j);
252 dofCoeffs_(cell,idof,0) = faceDofCoeffs_(iface,jdof);
266 Kokkos::DynRankView<typename BasisType::scalarType, coordsProperties...> dofCoords,
267 Kokkos::DynRankView<typename BasisType::scalarType, coeffsProperties...> dofCoeffs,
268 const BasisType* basis,
269 const Kokkos::DynRankView<ortValueType, ortProperties...> orts) {
271 using HostSpaceType = Kokkos::DefaultHostExecutionSpace;
272 using scalarType =
typename BasisType::scalarType;
273 using ScalarViewType = Kokkos::DynRankView<scalarType, DeviceType>;
274 using ScalarViewTypeHost = Kokkos::DynRankView<scalarType, HostSpaceType>;
275 using intViewType = Kokkos::DynRankView<ordinal_type, DeviceType>;
276 using range_type = Kokkos::pair<ordinal_type,ordinal_type>;
278 const auto topo = basis->getBaseCellTopology();
279 const std::string name(basis->getName());
281 bool isBasisHCURL = (basis->getFunctionSpace()==FUNCTION_SPACE_HCURL);
282 bool isBasisHDIV = (basis->getFunctionSpace()==FUNCTION_SPACE_HDIV);
284 ordinal_type numEdges = (basis->getDofCount(1, 0) > 0) ? topo.getEdgeCount() : 0;
285 ordinal_type numFaces = (basis->getDofCount(2, 0) > 0) ? topo.getFaceCount() : 0;
287 std::vector<Teuchos::RCP<Basis<DeviceType,scalarType,scalarType> > > edgeBases, faceBases;
289 for(
int i=0;i<numEdges;++i)
290 edgeBases.push_back(basis->getSubCellRefBasis(1,i));
291 for(
int i=0;i<numFaces;++i)
292 faceBases.push_back(basis->getSubCellRefBasis(2,i));
294 auto tagToOrdinal = Kokkos::create_mirror_view_and_copy(
typename DeviceType::memory_space(), basis->getAllDofOrdinal());
296 const ordinal_type dim = topo.getDimension();
298 const ordinal_type numCells = dofCoeffs.extent(0);
300 ScalarViewType refDofCoords(
"refDofCoords", dofCoords.extent(1), dofCoords.extent(2)), refDofCoeffs;
301 basis->getDofCoords(refDofCoords);
304 if(dofCoeffs.rank() == 3)
305 refDofCoeffs = ScalarViewType(
"refDofCoeffs", dofCoeffs.extent(1), dofCoeffs.extent(2));
307 refDofCoeffs = ScalarViewType(
"refDofCoeffs",dofCoeffs.extent(1));
308 basis->getDofCoeffs(refDofCoeffs);
311 if((numFaces == 0) && (numEdges == 0))
315 intViewType edgeTopoKey(
"edgeTopoKey",numEdges);
316 intViewType sOrt(
"eOrt", numEdges);
317 intViewType numEdgesInternalDofs(
"numEdgesInternalDofs", numEdges);
318 ScalarViewType edgesInternalDofCoords;
319 intViewType edgesInternalDofOrdinals;
320 ScalarViewType edgeDofCoeffs;
322 ordinal_type maxNumEdgesInternalDofs=0;
323 ordinal_type edgeBasisMaxCardinality=0;
325 auto hostNumEdgesInternalDofs = Kokkos::create_mirror_view(numEdgesInternalDofs);
326 for (ordinal_type iedge=0; iedge < numEdges; ++iedge) {
327 ordinal_type numInternalDofs = edgeBases[iedge]->getDofCount(1,0);
328 hostNumEdgesInternalDofs(iedge) = numInternalDofs;
329 maxNumEdgesInternalDofs = std::max(maxNumEdgesInternalDofs,numInternalDofs);
330 ordinal_type edgeBasisCardinality = edgeBases[iedge]->getCardinality();
331 edgeBasisMaxCardinality = std::max(edgeBasisMaxCardinality, edgeBasisCardinality);
333 Kokkos::deep_copy(numEdgesInternalDofs,hostNumEdgesInternalDofs);
335 edgeDofCoeffs = ScalarViewType(
"edgeDofCoeffs", numEdges, edgeBasisMaxCardinality);
336 edgesInternalDofCoords = ScalarViewType(
"edgeInternalDofCoords", numEdges, maxNumEdgesInternalDofs,1);
337 edgesInternalDofOrdinals = intViewType(
"edgeInternalDofCoords", numEdges, maxNumEdgesInternalDofs);
338 auto hostEdgesInternalDofCoords = Kokkos::create_mirror_view(edgesInternalDofCoords);
339 auto hostEdgesInternalDofOrdinals = Kokkos::create_mirror_view(edgesInternalDofOrdinals);
340 auto hostEdgeTopoKey = Kokkos::create_mirror_view(edgeTopoKey);
341 for (ordinal_type iedge=0; iedge < numEdges; ++iedge) {
342 auto hostEdgeBasisPtr = edgeBases[iedge]->getHostBasis();
343 hostEdgeTopoKey(iedge) = hostEdgeBasisPtr->getBaseCellTopology().getBaseKey();
344 ordinal_type edgeBasisCardinality = hostEdgeBasisPtr->getCardinality();
345 ScalarViewTypeHost edgeDofCoords(
"edgeDofCoords", edgeBasisCardinality, 1);
346 hostEdgeBasisPtr->getDofCoords(edgeDofCoords);
347 for(ordinal_type i=0; i<hostNumEdgesInternalDofs(iedge); ++i) {
348 hostEdgesInternalDofOrdinals(iedge, i) = hostEdgeBasisPtr->getDofOrdinal(1, 0, i);
349 hostEdgesInternalDofCoords(iedge, i,0) = edgeDofCoords(hostEdgesInternalDofOrdinals(iedge, i),0);
351 auto edgeBasisPtr = edgeBases[iedge];
352 auto dofRange = range_type(0, edgeBasisPtr->getCardinality());
353 edgeBasisPtr->getDofCoeffs(Kokkos::subview(edgeDofCoeffs, iedge, dofRange));
355 Kokkos::deep_copy(edgesInternalDofCoords,hostEdgesInternalDofCoords);
356 Kokkos::deep_copy(edgesInternalDofOrdinals,hostEdgesInternalDofOrdinals);
357 Kokkos::deep_copy(edgeTopoKey,hostEdgeTopoKey);
362 intViewType faceTopoKey(
"faceTopoKey",numFaces);
363 intViewType fOrt(
"fOrt", numFaces);
364 intViewType numFacesInternalDofs(
"numFacesInternalDofs", numFaces);
365 ScalarViewType facesInternalDofCoords;
366 intViewType facesInternalDofOrdinals;
367 ScalarViewType faceDofCoeffs;
369 ordinal_type maxNumFacesInternalDofs=0;
370 ordinal_type faceBasisMaxCardinality=0;
372 auto hostNumFacesInternalDofs = Kokkos::create_mirror_view(numFacesInternalDofs);
373 for (ordinal_type iface=0; iface < numFaces; ++iface) {
374 ordinal_type numInternalDofs = faceBases[iface]->getDofCount(2,0);
375 hostNumFacesInternalDofs(iface) = numInternalDofs;
376 maxNumFacesInternalDofs = std::max(maxNumFacesInternalDofs,numInternalDofs);
377 ordinal_type faceBasisCardinality = faceBases[iface]->getCardinality();
378 faceBasisMaxCardinality = std::max(faceBasisMaxCardinality, faceBasisCardinality);
380 Kokkos::deep_copy(numFacesInternalDofs,hostNumFacesInternalDofs);
382 facesInternalDofCoords = ScalarViewType(
"faceInternalDofCoords", numFaces, maxNumFacesInternalDofs, 2);
383 facesInternalDofOrdinals = intViewType(
"faceInternalDofCoords", numFaces, maxNumFacesInternalDofs);
386 faceDofCoeffs = ScalarViewType(
"faceDofCoeffs", numFaces, faceBasisMaxCardinality,2);
388 faceDofCoeffs = ScalarViewType(
"faceDofCoeffs", numFaces, faceBasisMaxCardinality);
390 auto hostFacesInternalDofCoords = Kokkos::create_mirror_view(facesInternalDofCoords);
391 auto hostFacesInternalDofOrdinals = Kokkos::create_mirror_view(facesInternalDofOrdinals);
392 auto hostFaceTopoKey = Kokkos::create_mirror_view(faceTopoKey);
393 for (ordinal_type iface=0; iface < numFaces; ++iface) {
394 auto hostFaceBasisPtr = faceBases[iface]->getHostBasis();
395 hostFaceTopoKey(iface) = hostFaceBasisPtr->getBaseCellTopology().getBaseKey();
396 ordinal_type faceBasisCardinality = hostFaceBasisPtr->getCardinality();
397 ScalarViewTypeHost faceDofCoords(
"faceDofCoords", faceBasisCardinality, 2);
398 hostFaceBasisPtr->getDofCoords(faceDofCoords);
399 for(ordinal_type i=0; i<hostNumFacesInternalDofs(iface); ++i) {
400 hostFacesInternalDofOrdinals(iface, i) = hostFaceBasisPtr->getDofOrdinal(2, 0, i);
401 for(ordinal_type d=0; d <2; ++d)
402 hostFacesInternalDofCoords(iface, i,d) = faceDofCoords(hostFacesInternalDofOrdinals(iface, i),d);
404 auto faceBasisPtr = faceBases[iface];
405 auto dofRange = range_type(0, faceBasisPtr->getCardinality());
406 faceBasisPtr->getDofCoeffs(Kokkos::subview(faceDofCoeffs, iface, dofRange, Kokkos::ALL()));
408 Kokkos::deep_copy(facesInternalDofCoords,hostFacesInternalDofCoords);
409 Kokkos::deep_copy(facesInternalDofOrdinals,hostFacesInternalDofOrdinals);
410 Kokkos::deep_copy(faceTopoKey,hostFaceTopoKey);
412 typename RefSubcellParametrization<DeviceType>::ConstViewType faceParam;
419 const Kokkos::RangePolicy<typename DeviceType::execution_space> policy(0, numCells);
421 <
decltype(dofCoords),
424 decltype(tagToOrdinal),
427 ScalarViewType> FunctorType;
428 Kokkos::parallel_for(policy,
429 FunctorType(dofCoords, dofCoeffs,
430 orts, tagToOrdinal, edgeParam, faceParam,
431 edgesInternalDofOrdinals, facesInternalDofOrdinals,
432 edgesInternalDofCoords, edgeDofCoeffs,
433 facesInternalDofCoords, faceDofCoeffs,
434 dim, numEdges, numFaces,
435 edgeTopoKey, numEdgesInternalDofs,
436 faceTopoKey, numFacesInternalDofs,
437 isBasisHCURL, isBasisHDIV));