Intrepid2
Intrepid2_CellGeometryDef.hpp
1// @HEADER
2// *****************************************************************************
3// Intrepid2 Package
4//
5// Copyright 2007 NTESS and the Intrepid2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
15
16#ifndef Intrepid2_CellGeometryDef_h
17#define Intrepid2_CellGeometryDef_h
18
19namespace Intrepid2
20{
21
22 namespace Impl
23 {
26 template<class PointScalar, int spaceDim, typename DeviceType>
28 {
29 using BasisPtr = Teuchos::RCP<Intrepid2::Basis<DeviceType,PointScalar,PointScalar> >;
30 using CellGeometryType = CellGeometry<PointScalar,spaceDim,DeviceType>;
31 public:
32 // conceptually, these should be private members, but for the definition of these, we need them to be externally accessible.
33 static std::map<const CellGeometryType *, shards::CellTopology> cellTopology_;
34 static std::map<const CellGeometryType *, BasisPtr> basisForNodes_;
35
36 public:
37 static void constructorCalled(const CellGeometryType *cellGeometry, const shards::CellTopology &cellTopo, BasisPtr basisForNodes)
38 {
39 cellTopology_[cellGeometry] = cellTopo;
40 basisForNodes_[cellGeometry] = basisForNodes;
41 }
42
43 static void destructorCalled(const CellGeometryType *cellGeometry)
44 {
45 cellTopology_.erase(cellGeometry);
46 basisForNodes_.erase(cellGeometry);
47 }
48
49 static BasisPtr getBasis(const CellGeometryType *cellGeometry)
50 {
51 return basisForNodes_[cellGeometry];
52 }
53
54 static const shards::CellTopology & getCellTopology(const CellGeometryType *cellGeometry)
55 {
56 return cellTopology_[cellGeometry];
57 }
58 };
59
60 // member lookup map definitions for CellGeometryHostMembers:
61 template< class PointScalar, int spaceDim, typename DeviceType > typename std::map<const CellGeometry<PointScalar,spaceDim,DeviceType> *, shards::CellTopology> CellGeometryHostMembers< PointScalar,spaceDim,DeviceType>::cellTopology_;
62
63 template< class PointScalar, int spaceDim, typename DeviceType > typename std::map<const CellGeometry<PointScalar,spaceDim,DeviceType> *, Teuchos::RCP<Intrepid2::Basis<DeviceType,PointScalar,PointScalar> >> CellGeometryHostMembers< PointScalar,spaceDim,DeviceType>::basisForNodes_;
64
67 template<class PointScalar, int spaceDim, typename DeviceType>
68 class CellMeasureFunctor
69 {
70 Kokkos::View<PointScalar**, DeviceType> cellMeasures_; // (C,P)
71 Kokkos::View<PointScalar**, DeviceType> detData_; // (C,P)
72 TensorData<PointScalar,DeviceType> cubatureWeights_; // (P)
73 public:
74 CellMeasureFunctor(Kokkos::View<PointScalar**, DeviceType> cellMeasures,
75 Kokkos::View<PointScalar**, DeviceType> detData, TensorData<PointScalar,DeviceType> cubatureWeights)
76 :
77 cellMeasures_(cellMeasures),
78 detData_(detData),
79 cubatureWeights_(cubatureWeights)
80 {}
81
82 KOKKOS_INLINE_FUNCTION void
83 operator () (const ordinal_type cellOrdinal, const ordinal_type pointOrdinal) const
84 {
85 cellMeasures_(cellOrdinal,pointOrdinal) = detData_(cellOrdinal,pointOrdinal) * cubatureWeights_(pointOrdinal);
86 }
87 };
88 }
89
90 template<class PointScalar, int spaceDim, typename DeviceType>
91 KOKKOS_INLINE_FUNCTION
93:
94 nodeOrdering_(cellGeometry.nodeOrdering_),
95 cellGeometryType_(cellGeometry.cellGeometryType_),
96 subdivisionStrategy_(cellGeometry.subdivisionStrategy_),
97 affine_(cellGeometry.affine_),
98 orientations_(cellGeometry.orientations_),
99 origin_(cellGeometry.origin_),
100 domainExtents_(cellGeometry.domainExtents_),
101 gridCellCounts_(cellGeometry.gridCellCounts_),
102 tensorVertices_(cellGeometry.tensorVertices_),
103 cellToNodes_(cellGeometry.cellToNodes_),
104 nodes_(cellGeometry.nodes_),
105 numCells_(cellGeometry.numCells_),
106 numNodesPerCell_(cellGeometry.numNodesPerCell_)
107 {
108 // host-only registration with HostMemberLookup:
109#ifndef INTREPID2_COMPILE_DEVICE_CODE
110 shards::CellTopology cellTopo = cellGeometry.cellTopology();
111 BasisPtr basisForNodes = cellGeometry.basisForNodes();
113 HostMemberLookup::constructorCalled(this, cellTopo, basisForNodes);
114#endif
115 }
116
117 template<class PointScalar, int spaceDim, typename DeviceType>
118 KOKKOS_INLINE_FUNCTION
120 {
121 // host-only deregistration with HostMemberLookup:
122#ifndef INTREPID2_COMPILE_DEVICE_CODE
124 HostMemberLookup::destructorCalled(this);
125#endif
126 }
127
128 template<class PointScalar, int spaceDim, typename DeviceType>
129 KOKKOS_INLINE_FUNCTION
131 {
132 switch (subdivisionStrategy) {
133 case NO_SUBDIVISION:
134 return 1;
137 return 2;
138 case FOUR_TRIANGLES:
139 return 4;
140 case FIVE_TETRAHEDRA:
141 return 5;
142 case SIX_PYRAMIDS:
143 case SIX_TETRAHEDRA:
144 return 6;
145 }
146 return -1;
147 }
148
149 template<class PointScalar, int spaceDim, typename DeviceType>
151 CellGeometry<PointScalar,spaceDim,DeviceType>::allocateJacobianDataPrivate(const ScalarView<PointScalar,DeviceType> &pointComponentView, const int &pointsPerCell, const int startCell, const int endCell) const
152 {
153 ScalarView<PointScalar,DeviceType> data;
154 const int rank = 4; // C,P,D,D
155 const int CELL_DIM = 0;
156 const int POINT_DIM = 1;
157 const int D1_DIM = 2;
158 const int D2_DIM = 3;
159
160 const int numCellsWorkset = (endCell == -1) ? (numCells_ - startCell) : (endCell - startCell);
161
162 Kokkos::Array<int,7> extents { numCellsWorkset, pointsPerCell, spaceDim, spaceDim, 1, 1, 1 };
163 Kokkos::Array<DataVariationType,7> variationType { CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT };
164
165 int blockPlusDiagonalLastNonDiagonal = -1;
166
167 if (cellGeometryType_ == UNIFORM_GRID)
168 {
169 if (uniformJacobianModulus() != 1)
170 {
171 variationType[CELL_DIM] = MODULAR;
172 variationType[POINT_DIM] = CONSTANT;
173 variationType[D1_DIM] = GENERAL;
174 variationType[D2_DIM] = GENERAL;
175
176 int cellTypeModulus = uniformJacobianModulus();
177
178 data = Impl::createMatchingDynRankView(pointComponentView, "CellGeometryProvider: Jacobian data", cellTypeModulus, spaceDim, spaceDim);
179 }
180 else
181 {
182 // diagonal Jacobian
183 variationType[D1_DIM] = BLOCK_PLUS_DIAGONAL;
184 variationType[D2_DIM] = BLOCK_PLUS_DIAGONAL;
185 blockPlusDiagonalLastNonDiagonal = -1;
186
187 data = Impl::createMatchingDynRankView(pointComponentView, "CellGeometryProvider: Jacobian data", spaceDim);
188 }
189 }
190 else if (cellGeometryType_ == TENSOR_GRID)
191 {
192 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "tensor grid support not yet implemented");
193 }
194 else if (cellGeometryType_ == FIRST_ORDER)
195 {
196 const bool simplex = (spaceDim + 1 == cellToNodes_.extent_int(1));
197 if (simplex)
198 {
199 variationType[CELL_DIM] = GENERAL;
200 variationType[POINT_DIM] = CONSTANT; // affine: no point variation
201 variationType[D1_DIM] = GENERAL;
202 variationType[D2_DIM] = GENERAL;
203
204 data = Impl::createMatchingDynRankView(data, "CellGeometryProvider: Jacobian data", numCells_, spaceDim, spaceDim);
205 }
206 else
207 {
208 variationType[CELL_DIM] = GENERAL;
209 variationType[D1_DIM] = GENERAL;
210 variationType[D2_DIM] = GENERAL;
211 if (affine_)
212 {
213 // no point variation
214 variationType[POINT_DIM] = CONSTANT;
215 data = Impl::createMatchingDynRankView(data, "CellGeometryProvider: Jacobian data", numCellsWorkset, spaceDim, spaceDim);
216 }
217 else
218 {
219 variationType[POINT_DIM] = GENERAL;
220 data = Impl::createMatchingDynRankView(data, "CellGeometryProvider: Jacobian data", numCellsWorkset, pointsPerCell, spaceDim, spaceDim);
221 }
222 }
223 }
224 else if (cellGeometryType_ == HIGHER_ORDER)
225 {
226 // most general case: varies in all 4 dimensions
227 variationType[CELL_DIM] = GENERAL;
228 variationType[POINT_DIM] = GENERAL;
229 variationType[D1_DIM] = GENERAL;
230 variationType[D2_DIM] = GENERAL;
231 data = Impl::createMatchingDynRankView(data, "CellGeometryProvider: Jacobian data", numCellsWorkset, pointsPerCell, spaceDim, spaceDim);
232 }
233 else
234 {
235 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "support for this CellGeometryType is not yet implemented");
236 }
237
238 Data<PointScalar,DeviceType> jacobianData(data,rank,extents,variationType,blockPlusDiagonalLastNonDiagonal);
239 return jacobianData;
240 }
241
242 template<class PointScalar, int spaceDim, typename DeviceType>
244 const int &pointsPerCell, const Data<PointScalar,DeviceType> &refData,
245 const int startCell, const int endCell) const
246 {
247 const int numCellsWorkset = (endCell == -1) ? (numCells_ - startCell) : (endCell - startCell);
248
249 if (cellGeometryType_ == UNIFORM_GRID)
250 {
251 if (uniformJacobianModulus() != 1)
252 {
253 int cellTypeModulus = uniformJacobianModulus();
254
255 auto dataView3 = jacobianData.getUnderlyingView3(); // (cellTypeModulus, spaceDim, spaceDim) allocated in allocateJacobianDataPrivate()
256 auto dataHost = Kokkos::create_mirror_view(dataView3);
257
258 const int startCellType = startCell % cellTypeModulus;
259 const int endCellType = (numCellsWorkset >= cellTypeModulus) ? startCellType + cellTypeModulus : startCellType + numCellsWorkset;
260 const int gridCellOrdinal = 0; // sample cell
261 for (int cellType=startCellType; cellType<endCellType; cellType++)
262 {
263 const int subdivisionOrdinal = cellType % cellTypeModulus;
264 const int nodeZero = 0;
265 // simplex Jacobian formula is J_00 = x1 - x0, J_01 = x2 - x0, etc.
266 for (int i=0; i<spaceDim; i++)
267 {
268 for (int j=0; j<spaceDim; j++)
269 {
270 const int node = j+1; // this is the only node other than the 0 node that has non-zero derivative in the j direction -- and this has unit derivative
271 // nodeZero has derivative -1 in every dimension.
272 const auto J_ij = subdivisionCoordinate(gridCellOrdinal, subdivisionOrdinal, node, i) - subdivisionCoordinate(gridCellOrdinal, subdivisionOrdinal, nodeZero, i);
273 dataHost(cellType,i,j) = J_ij;
274 }
275 }
276 }
277
278 Kokkos::deep_copy(dataView3,dataHost);
279 }
280 else
281 {
282 // diagonal Jacobian
283 auto dataView1 = jacobianData.getUnderlyingView1(); // (spaceDim) allocated in allocateJacobianDataPrivate()
284 const auto domainExtents = domainExtents_;
285 const auto gridCellCounts = gridCellCounts_;
286
287 using ExecutionSpace = typename DeviceType::execution_space;
288 auto policy = Kokkos::RangePolicy<>(ExecutionSpace(),0,spaceDim);
289 Kokkos::parallel_for("fill jacobian", policy, KOKKOS_LAMBDA(const int d1)
290 {
291 // diagonal jacobian
292 const double REF_SPACE_EXTENT = 2.0;
293 dataView1(d1) = (domainExtents[d1] / REF_SPACE_EXTENT) / gridCellCounts[d1];
294 });
295 ExecutionSpace().fence();
296 }
297 }
298 else if (cellGeometryType_ == TENSOR_GRID)
299 {
300 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "tensor grid support not yet implemented");
301 }
302 else if ((cellGeometryType_ == FIRST_ORDER) || (cellGeometryType_ == HIGHER_ORDER))
303 {
304 const bool simplex = (spaceDim + 1 == cellToNodes_.extent_int(1));
305 if (simplex)
306 {
307 auto dataView3 = jacobianData.getUnderlyingView3(); // (numCells_, spaceDim, spaceDim) allocated in allocateJacobianDataPrivate()
308
309 // get local (shallow) copies to avoid implicit references to this
310 auto cellToNodes = cellToNodes_;
311 auto nodes = nodes_;
312
313 using ExecutionSpace = typename DeviceType::execution_space;
314 auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<3>>({startCell,0,0},{numCellsWorkset,spaceDim,spaceDim});
315
316 Kokkos::parallel_for("compute first-order simplex Jacobians", policy,
317 KOKKOS_LAMBDA (const int &cellOrdinal, const int &d1, const int &d2) {
318 const int nodeZero = 0; // nodeZero has derivative -1 in every dimension.
319 const int node = d2+1; // this is the only node other than the 0 node that has non-zero derivative in the d2 direction -- and this has unit derivative (except in 1D, where each derivative is ±0.5)
320 const auto & nodeCoord = nodes(cellToNodes(cellOrdinal,node), d1);
321 const auto & nodeZeroCoord = nodes(cellToNodes(cellOrdinal,nodeZero), d1);
322 const PointScalar J_ij = nodeCoord - nodeZeroCoord;
323 dataView3(cellOrdinal,d1,d2) = (spaceDim != 1) ? J_ij : J_ij * 0.5;
324 });
325 }
326 else
327 {
329 auto basisForNodes = this->basisForNodes();
330
331 if (affine_)
332 {
333 // no point variation
334 auto dataView3 = jacobianData.getUnderlyingView3(); // (numCellsWorkset, spaceDim, spaceDim) allocated in allocateJacobianDataPrivate()
335
336 // TODO: find an allocation-free way to do this… (consider modifying CellTools::setJacobian() to support affine case.)
337 const int onePoint = 1;
338 auto testPointView = Impl::createMatchingDynRankView(dataView3, "CellGeometryProvider: test point", onePoint, spaceDim);
339 auto tempData = Impl::createMatchingDynRankView(dataView3, "CellGeometryProvider: temporary Jacobian data", numCellsWorkset, onePoint, spaceDim, spaceDim);
340
341 Kokkos::deep_copy(testPointView, 0.0);
342
343 CellTools::setJacobian(tempData, testPointView, *this, basisForNodes, startCell, endCell);
344
345 auto tempDataSubview = Kokkos::subview(tempData, Kokkos::ALL(), 0, Kokkos::ALL(), Kokkos::ALL());
346 Kokkos::deep_copy(dataView3, tempDataSubview);
347 }
348 else
349 {
350 auto dataView = jacobianData.getUnderlyingView(); // (numCellsWorkset, pointsPerCell, spaceDim, spaceDim) allocated in allocateJacobianDataPrivate()
351 TEUCHOS_TEST_FOR_EXCEPTION(basisForNodes == Teuchos::null, std::invalid_argument, "basisForNodes must not be null");
352 TEUCHOS_TEST_FOR_EXCEPTION(dataView.size() == 0, std::invalid_argument, "underlying view is not valid");
353
354 // refData should contain the basis gradients; shape is (F,P,D) or (C,F,P,D)
355 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(!refData.isValid(), std::invalid_argument, "refData should be a valid container for cases with non-affine geometry");
356 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE((refData.rank() != 3) && (refData.rank() != 4), std::invalid_argument, "refData should have shape (F,P,D) or (C,F,P,D)");
357 if (refData.rank() == 3)
358 {
359 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(refData.extent_int(0) != basisForNodes->getCardinality(), std::invalid_argument, "refData should have shape (F,P,D) or (C,F,P,D)");
360 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(refData.extent_int(1) != pointsPerCell, std::invalid_argument, "refData should have shape (F,P,D) or (C,F,P,D)");
361 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(refData.extent_int(2) != spaceDim, std::invalid_argument, "refData should have shape (F,P,D) or (C,F,P,D)");
362 }
363 else
364 {
365 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(refData.extent_int(0) != numCellsWorkset, std::invalid_argument, "refData should have shape (F,P,D) or (C,F,P,D)");
366 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(refData.extent_int(1) != basisForNodes->getCardinality(), std::invalid_argument, "refData should have shape (F,P,D) or (C,F,P,D)");
367 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(refData.extent_int(2) != pointsPerCell, std::invalid_argument, "refData should have shape (F,P,D) or (C,F,P,D)");
368 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(refData.extent_int(3) != spaceDim, std::invalid_argument, "refData should have shape (F,P,D) or (C,F,P,D)");
369 }
370
371 CellTools::setJacobian(dataView, *this, refData, startCell, endCell);
372 }
373 }
374 }
375 else
376 {
377 // TODO: handle the other cases
378 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "support for this CellGeometryType is not yet implemented");
379 }
380 }
381
382 // Uniform grid constructor, with optional subdivision into simplices
383 template<class PointScalar, int spaceDim, typename DeviceType>
384 CellGeometry<PointScalar,spaceDim,DeviceType>::CellGeometry(const Kokkos::Array<PointScalar,spaceDim> &origin,
385 const Kokkos::Array<PointScalar,spaceDim> &domainExtents,
386 const Kokkos::Array<int,spaceDim> &gridCellCounts,
387 SubdivisionStrategy subdivisionStrategy,
388 HypercubeNodeOrdering nodeOrdering)
389 :
390 nodeOrdering_(nodeOrdering),
391 cellGeometryType_(UNIFORM_GRID),
392 subdivisionStrategy_(subdivisionStrategy),
393 affine_(true),
394 origin_(origin),
395 domainExtents_(domainExtents),
396 gridCellCounts_(gridCellCounts)
397 {
398 numCells_ = 1;
399 for (int d=0; d<spaceDim; d++)
400 {
401 numCells_ *= gridCellCounts_[d];
402 }
403 numCells_ *= numCellsPerGridCell(subdivisionStrategy_);
404
405 shards::CellTopology cellTopo; // will register with HostMemberLookup below
406 using BasisFamily = DerivedNodalBasisFamily<DeviceType,PointScalar,PointScalar>;
407 const int linearPolyOrder = 1;
408 BasisPtr basisForNodes;
409 if (subdivisionStrategy_ == NO_SUBDIVISION)
410 {
411 // hypercube
412 numNodesPerCell_ = 1 << spaceDim; // 2^D vertices in a D-dimensional hypercube
413
414 if (spaceDim == 1)
415 {
416 cellTopo = shards::CellTopology(shards::getCellTopologyData<shards::Line<> >());
417 basisForNodes = getBasis<BasisFamily>(cellTopo, FUNCTION_SPACE_HGRAD, linearPolyOrder);
418 }
419 else if (spaceDim == 2)
420 {
421 cellTopo = shards::CellTopology(shards::getCellTopologyData<shards::Quadrilateral<> >());
422 basisForNodes = getBasis<BasisFamily>(cellTopo, FUNCTION_SPACE_HGRAD, linearPolyOrder);
423 }
424 else if (spaceDim == 3)
425 {
426 cellTopo = shards::CellTopology(shards::getCellTopologyData<shards::Hexahedron<> >());
427 basisForNodes = getBasis<BasisFamily>(cellTopo, FUNCTION_SPACE_HGRAD, linearPolyOrder);
428 }
429 else
430 {
431 INTREPID2_TEST_FOR_EXCEPTION(nodeOrdering_ == HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS, std::invalid_argument,
432 "Classic Shards node ordering is only defined for hypercubes through space dimension 3");
433 // Shards does not provide topologies above 3D, so cellTopology() is left invalid (a default-constructed
434 // shards::CellTopology), and operations that require it (e.g., orientations) fail. The uniform-grid path is
435 // affine, and still supplies coordinates and Jacobians for higher-dimensional tensor-product cells; the node
436 // basis is a tensor product of linear H(grad) line bases.
437 basisForNodes = getHypercubeBasis_HGRAD<BasisFamily>(linearPolyOrder, spaceDim);
438 }
439 }
440 else
441 {
442 // simplex
443 numNodesPerCell_ = spaceDim + 1; // D+1 vertices in a D-dimensional simplex
444 if (spaceDim == 2)
445 {
446 cellTopo = shards::CellTopology(shards::getCellTopologyData<shards::Triangle<> >());
447 basisForNodes = getBasis<BasisFamily>(cellTopo, FUNCTION_SPACE_HGRAD, linearPolyOrder);
448 }
449 else if (spaceDim == 3)
450 {
451 cellTopo = shards::CellTopology(shards::getCellTopologyData<shards::Tetrahedron<> >());
452 basisForNodes = getBasis<BasisFamily>(cellTopo, FUNCTION_SPACE_HGRAD, linearPolyOrder);
453 }
454 else
455 {
456 INTREPID2_TEST_FOR_EXCEPTION(true, std::invalid_argument,
457 "Uniform-grid simplex subdivision is only supported in space dimensions 2 and 3");
458 }
459 }
460
461 if (nodeOrdering_ == HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS)
462 {
463 // override basisForNodes for quad, hexahedron. Apparently the lowest-order bases below are *not* in the same order as their
464 // arbitrary-polynomial-order counterparts; the latter do not match the order of the shards::CellTopology nodes.
465 if (cellTopo.getKey() == shards::Quadrilateral<>::key)
466 {
468 }
469 else if (cellTopo.getKey() == shards::Hexahedron<>::key)
470 {
472 }
473 }
474
476 HostMemberLookup::constructorCalled(this, cellTopo, basisForNodes);
477 }
478
479 // Node-based constructor for straight-edged cell geometry.
480 // If claimAffine is true, we assume (without checking) that the mapping from reference space is affine.
481 // (If claimAffine is false, we check whether the topology is simplicial; if so, we conclude that the mapping must be affine.)
482 template<class PointScalar, int spaceDim, typename DeviceType>
484 ScalarView<int,DeviceType> cellToNodes,
485 ScalarView<PointScalar,DeviceType> nodes,
486 const bool claimAffine,
487 const HypercubeNodeOrdering nodeOrdering)
488 :
489 nodeOrdering_(nodeOrdering),
490 cellGeometryType_(FIRST_ORDER),
491 cellToNodes_(cellToNodes),
492 nodes_(nodes)
493 {
494 if(cellToNodes.is_allocated())
495 {
496 numCells_ = cellToNodes.extent_int(0);
497 numNodesPerCell_ = cellToNodes.extent_int(1);
498 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(numNodesPerCell_ != cellTopo.getNodeCount(), std::invalid_argument, "cellToNodes.extent(1) does not match the cell topology node count");
499 }
500 else
501 {
502 numCells_ = nodes.extent_int(0);
503 numNodesPerCell_ = nodes.extent_int(1);
504 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(numNodesPerCell_ != cellTopo.getNodeCount(), std::invalid_argument, "nodes.extent(1) does not match the cell topology node count");
505 }
506
507
508 if (!claimAffine)
509 {
510 // if cellTopo is simplicial, then since the geometry is straight-edged, it is also affine
511 const bool simplicialTopo = (cellTopo.getNodeCount() == cellTopo.getDimension() + 1);
512 affine_ = simplicialTopo;
513 }
514 else
515 {
516 affine_ = true;
517 }
518
519 using BasisFamily = DerivedNodalBasisFamily<DeviceType,PointScalar,PointScalar>;
520 const int linearPolyOrder = 1;
521 BasisPtr basisForNodes = getBasis<BasisFamily>(cellTopo, FUNCTION_SPACE_HGRAD, linearPolyOrder);
522
523 if (nodeOrdering_ == HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS)
524 {
525 // override basisForNodes for quad, hexahedron. Apparently the lowest-order bases below are *not* in the same order as their
526 // arbitrary-polynomial-order counterparts; the latter do not match the order of the shards::CellTopology nodes.
527 if (cellTopo.getKey() == shards::Quadrilateral<>::key)
528 {
530 }
531 else if (cellTopo.getKey() == shards::Hexahedron<>::key)
532 {
534 }
535 }
536
538 HostMemberLookup::constructorCalled(this, cellTopo, basisForNodes);
539 }
540
541 // Constructor for higher-order geometry
542 template<class PointScalar, int spaceDim, typename DeviceType>
544 ScalarView<PointScalar,DeviceType> cellNodes)
545 :
546 nodeOrdering_(HYPERCUBE_NODE_ORDER_TENSOR),
547 cellGeometryType_(HIGHER_ORDER),
548 nodes_(cellNodes)
549 {
550 numCells_ = cellNodes.extent_int(0);
551 numNodesPerCell_ = cellNodes.extent_int(1);
552
553 // if basis degree is 1, mark as first-order geometry
554 const bool firstOrderGeometry = (basisForNodes->getDegree() == 1);
555 cellGeometryType_ = firstOrderGeometry ? FIRST_ORDER : HIGHER_ORDER;
556
557 shards::CellTopology cellTopo = basisForNodes->getBaseCellTopology();
558
559 if (firstOrderGeometry && (cellTopo.getNodeCount() == spaceDim + 1)) // lowest-order and simplicial
560 {
561 affine_ = true;
562 }
563 else
564 {
565 affine_ = false;
566 }
568 HostMemberLookup::constructorCalled(this, cellTopo, basisForNodes);
569 }
570
571 template<class PointScalar, int spaceDim, typename DeviceType>
572 KOKKOS_INLINE_FUNCTION
574 {
575 return affine_;
576 }
577
578 template<class PointScalar, int spaceDim, typename DeviceType>
581 const TensorData<PointScalar,DeviceType> & cubatureWeights ) const
582 {
583 // Output possibilities for a cubatureWeights with N components:
584 // 1. For AFFINE elements (jacobianDet cell-wise constant), returns a container with N+1 tensorial components; the first component corresponds to cells
585 // 2. Otherwise, returns a container with 1 tensorial component
586
587 INTREPID2_TEST_FOR_EXCEPTION(cubatureWeights.rank() != 1, std::invalid_argument, "cubatureWeights container must have shape (P)");
588
589 const int numTensorComponents = affine_ ? cubatureWeights.numTensorComponents() + 1 : 1;
590 std::vector< Data<PointScalar,DeviceType> > tensorComponents(numTensorComponents);
591
592 if (affine_)
593 {
594 const int cellExtent = jacobianDet.extent_int(0);
595 Kokkos::Array<DataVariationType,7> cellVariationTypes {jacobianDet.getVariationTypes()[0], CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT};
596 const int cellDataDim = jacobianDet.getDataExtent(0);
597 Kokkos::Array<int,7> cellExtents{cellExtent,1,1,1,1,1,1};
598
599 ScalarView<PointScalar,DeviceType> detDataView ("cell relative volumes", cellDataDim);
600 tensorComponents[0] = Data<PointScalar,DeviceType>(detDataView,1,cellExtents,cellVariationTypes);
601
602 for (int cubTensorComponent=0; cubTensorComponent<numTensorComponents-1; cubTensorComponent++)
603 {
604 auto cubatureComponent = cubatureWeights.getTensorComponent(cubTensorComponent);
605 const auto cubatureExtents = cubatureComponent.getExtents();
606 const auto cubatureVariationTypes = cubatureComponent.getVariationTypes();
607 const int numPoints = cubatureComponent.getDataExtent(0);
608 ScalarView<PointScalar,DeviceType> cubatureWeightView ("cubature component weights", numPoints);
609 const int pointComponentRank = 1;
610 tensorComponents[cubTensorComponent+1] = Data<PointScalar,DeviceType>(cubatureWeightView,pointComponentRank,cubatureExtents,cubatureVariationTypes);
611 }
612 }
613 else
614 {
615 const int cellExtent = jacobianDet.extent_int(0);
616 Kokkos::Array<DataVariationType,7> variationTypes {jacobianDet.getVariationTypes()[0], GENERAL, CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT};
617 const int cellDataDim = jacobianDet.getDataExtent(0);
618
619 const int numPoints = cubatureWeights.extent_int(0);
620 Kokkos::Array<int,7> extents{cellExtent,numPoints,1,1,1,1,1};
621
622 ScalarView<PointScalar,DeviceType> cubatureWeightView;
623 if (variationTypes[0] != CONSTANT)
624 {
625 cubatureWeightView = ScalarView<PointScalar,DeviceType>("cell measure", cellDataDim, numPoints);
626 }
627 else
628 {
629 cubatureWeightView = ScalarView<PointScalar,DeviceType>("cell measure", numPoints);
630 }
631 const int cellMeasureRank = 2;
632 tensorComponents[0] = Data<PointScalar,DeviceType>(cubatureWeightView,cellMeasureRank,extents,variationTypes);
633 }
634 const bool separateFirstComponent = (numTensorComponents > 1);
635 return TensorData<PointScalar,DeviceType>(tensorComponents, separateFirstComponent);
636 }
637
638 template<class PointScalar, int spaceDim, typename DeviceType>
640 const Data<PointScalar,DeviceType> & jacobianDet,
641 const TensorData<PointScalar,DeviceType> & cubatureWeights ) const
642 {
643 // Output possibilities for a cubatureWeights with N components:
644 // 1. For AFFINE elements (jacobianDet constant on each cell), returns a container with N+1 tensorial components; the first component corresponds to cells
645 // 2. Otherwise, returns a container with 1 tensorial component
646
647 INTREPID2_TEST_FOR_EXCEPTION((cellMeasure.numTensorComponents() != cubatureWeights.numTensorComponents() + 1) && (cellMeasure.numTensorComponents() != 1), std::invalid_argument,
648 "cellMeasure must either have a tensor component count of 1 or a tensor component count that is one higher than that of cubatureWeights");
649
650 INTREPID2_TEST_FOR_EXCEPTION(cubatureWeights.rank() != 1, std::invalid_argument, "cubatureWeights container must have shape (P)");
651
652 if (cellMeasure.numTensorComponents() == cubatureWeights.numTensorComponents() + 1)
653 {
654 // affine case; the first component should contain the cell volume divided by ref cell volume; this should be stored in jacobianDet
655 Kokkos::deep_copy(cellMeasure.getTensorComponent(0).getUnderlyingView1(), jacobianDet.getUnderlyingView1()); // copy point-invariant data from jacobianDet to the first tensor component of cell measure container
656 const int numTensorDimensions = cubatureWeights.numTensorComponents();
657 for (int i=1; i<numTensorDimensions+1; i++)
658 {
659 Kokkos::deep_copy(cellMeasure.getTensorComponent(i).getUnderlyingView1(), cubatureWeights.getTensorComponent(i-1).getUnderlyingView1());
660 }
661 }
662 else
663 {
664 auto detVaries = jacobianDet.getVariationTypes();
665
666 const bool detCellVaries = detVaries[0] != CONSTANT;
667 const bool detPointVaries = detVaries[1] != CONSTANT;
668
669 if (detCellVaries && detPointVaries)
670 {
671 auto cellMeasureData = cellMeasure.getTensorComponent(0).getUnderlyingView2();
672 auto detData = jacobianDet.getUnderlyingView2();
673 const int numCells = detData.extent_int(0);
674 const int numPoints = detData.extent_int(1);
675 INTREPID2_TEST_FOR_EXCEPTION(numCells != cellMeasureData.extent_int(0), std::invalid_argument, "cellMeasureData doesn't match jacobianDet in cell dimension");
676 INTREPID2_TEST_FOR_EXCEPTION(numPoints != cellMeasureData.extent_int(1), std::invalid_argument, "cellMeasureData doesn't match jacobianDet in point dimension");
677
678 // We implement this case as a functor (rather than a lambda) to work around an apparent CUDA 10.1.243 compiler bug
679 Impl::CellMeasureFunctor<PointScalar,spaceDim,DeviceType> cellMeasureFunctor(cellMeasureData, detData, cubatureWeights);
680
681 using ExecutionSpace = typename DeviceType::execution_space;
682 Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<2>> rangePolicy({0,0},{numCells,numPoints});
683 Kokkos::parallel_for(rangePolicy, cellMeasureFunctor);
684 }
685 else if (detCellVaries && !detPointVaries)
686 {
687 auto cellMeasureData = cellMeasure.getTensorComponent(0).getUnderlyingView2();
688 auto detData = jacobianDet.getUnderlyingView1();
689 using ExecutionSpace = typename DeviceType::execution_space;
690 Kokkos::parallel_for(
691 Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<2>>({0,0},{detData.extent_int(0),cubatureWeights.extent_int(0)}),
692 KOKKOS_LAMBDA (int cellOrdinal, int pointOrdinal) {
693 cellMeasureData(cellOrdinal,pointOrdinal) = detData(cellOrdinal) * cubatureWeights(pointOrdinal);
694 });
695 }
696 else
697 {
698 // constant jacobian det case
699 // cell measure data has shape (P)
700 auto cellMeasureData = cellMeasure.getTensorComponent(0).getUnderlyingView1();
701 auto detData = jacobianDet.getUnderlyingView1();
702 using ExecutionSpace = typename DeviceType::execution_space;
703 Kokkos::parallel_for(Kokkos::RangePolicy<ExecutionSpace>(0,cellMeasureData.extent_int(0)),
704 KOKKOS_LAMBDA (const int &pointOrdinal) {
705 cellMeasureData(pointOrdinal) = detData(0) * cubatureWeights(pointOrdinal);
706 });
707 }
708 }
709 }
710
711 template<class PointScalar, int spaceDim, typename DeviceType>
712 typename CellGeometry<PointScalar,spaceDim,DeviceType>::BasisPtr
714 {
716 return HostMemberLookup::getBasis(this);
717 }
718
719 template<class PointScalar, int spaceDim, typename DeviceType>
721 {
723 return HostMemberLookup::getCellTopology(this);
724 }
725
726 template<class PointScalar, int spaceDim, typename DeviceType>
727 KOKKOS_INLINE_FUNCTION
728 ordinal_type CellGeometry<PointScalar,spaceDim,DeviceType>::cellToNode(ordinal_type cell, ordinal_type node) const
729 {
730 if (cellToNodes_.is_allocated())
731 {
732 return cellToNodes_(cell,node);
733 }
734 else if (cellGeometryType_ == UNIFORM_GRID)
735 {
736 const ordinal_type numSubdivisions = numCellsPerGridCell(subdivisionStrategy_);
737 const ordinal_type gridCell = cell / numSubdivisions;
738 const ordinal_type subdivisionOrdinal = cell % numSubdivisions;
739
740 Kokkos::Array<ordinal_type,spaceDim> gridCellCoords;
741 ordinal_type gridCellDivided = gridCell;
742 ordinal_type numGridNodes = 1;
743 ordinal_type numGridCells = 1;
744 for (int d=0; d<spaceDim; d++)
745 {
746 gridCellCoords[d] = gridCellDivided % gridCellCounts_[d];
747 gridCellDivided = gridCellDivided / gridCellCounts_[d];
748 numGridCells *= gridCellCounts_[d];
749 numGridNodes *= (gridCellCounts_[d] + 1);
750 }
751
752 const ordinal_type gridCellNode = gridCellNodeForSubdivisionNode(gridCell, subdivisionOrdinal, node);
753
754 // most subdivision strategies don't add internal node(s), but a couple do. If so, the gridCellNode
755 // will be equal to the number of vertices in the grid cell.
756 const ordinal_type numInteriorNodes = ((subdivisionStrategy_ == FOUR_TRIANGLES) || (subdivisionStrategy_ == SIX_PYRAMIDS)) ? 1 : 0;
757
758 // the global nodes list the grid-cell-interior nodes first.
759 const ordinal_type gridNodeNumberingOffset = numInteriorNodes * numGridCells;
760
761 const ordinal_type numNodesPerGridCell = 1 << spaceDim;
762 if (gridCellNode >= numNodesPerGridCell)
763 {
764 const ordinal_type interiorGridNodeOffset = gridCellNode - numNodesPerGridCell;
765 return numNodesPerGridCell * gridCell + interiorGridNodeOffset;
766 }
767 else
768 {
769 // use gridCellCoords, plus hypercubeComponentNodeNumber(gridCellNode, d), to set up a Cartesian vertex numbering of the grid as a whole. Then, add gridNodeNumberingOffset to account for interior nodes.
770 // let x be the fastest-moving index
771 ordinal_type d_index_stride = 1; // number of node indices we move by moving 1 node in dimension d
772 ordinal_type cartesianNodeNumber = 0;
773 for (int d=0; d<spaceDim; d++)
774 {
775 const ordinal_type d_index = gridCellCoords[d] + hypercubeComponentNodeNumber(gridCellNode,d);
776 cartesianNodeNumber += d_index * d_index_stride;
777 d_index_stride *= (gridCellCounts_[d] + 1);
778 }
779 return cartesianNodeNumber + gridNodeNumberingOffset;
780 }
781 }
782 else
783 {
784 // cellToNode() not supported
785 return -1;
786 }
787 }
788
789 template<class PointScalar, int spaceDim, typename DeviceType>
790 KOKKOS_INLINE_FUNCTION
792 {
793 if (cellGeometryType_ == UNIFORM_GRID)
794 {
795 const int numSubdivisions = numCellsPerGridCell(subdivisionStrategy_);
796 if (numSubdivisions == 1)
797 {
798 return CONSTANT;
799 }
800 else
801 {
802 return MODULAR;
803 }
804 }
805 else return GENERAL;
806 }
807
808 template<class PointScalar, int spaceDim, typename DeviceType>
810 {
811 Data<PointScalar,DeviceType> emptyRefData;
812 if (cellGeometryType_ == UNIFORM_GRID)
813 {
814 // no need for basis computations
815 return emptyRefData;
816 }
817 else if (cellGeometryType_ == TENSOR_GRID)
818 {
819 // no need for basis values
820 return emptyRefData;
821 }
822 else if ((cellGeometryType_ == FIRST_ORDER) || (cellGeometryType_ == HIGHER_ORDER))
823 {
824 const bool simplex = (spaceDim + 1 == cellToNodes_.extent_int(1));
825 if (simplex)
826 {
827 // no need for precomputed basis values
828 return emptyRefData;
829 }
830 else
831 {
832 auto basisForNodes = this->basisForNodes();
833
834 if (affine_)
835 {
836 // no need for precomputed basis values
837 return emptyRefData;
838 }
839 else
840 {
841 // 2 use cases: (P,D) and (C,P,D).
842 // if (P,D), call the TensorPoints variant
843 if (points.rank() == 2)
844 {
845 TensorPoints<PointScalar,DeviceType> tensorPoints(points);
846 return getJacobianRefData(tensorPoints);
847 }
848 else
849 {
850 const int numCells = points.extent_int(0);
851 const int numPoints = points.extent_int(1);
852 const int numFields = basisForNodes->getCardinality();
853
854 auto cellBasisGradientsView = Impl::createMatchingDynRankView(points, "CellGeometryProvider: cellBasisGradients", numCells, numFields, numPoints, spaceDim);
855 auto basisGradientsView = Impl::createMatchingDynRankView(points, "CellGeometryProvider: basisGradients", numFields, numPoints, spaceDim);
856
857 for (int cellOrdinal=0; cellOrdinal<numCells; cellOrdinal++)
858 {
859 auto refPointsForCell = Kokkos::subview(points, cellOrdinal, Kokkos::ALL(), Kokkos::ALL());
860 basisForNodes->getValues(basisGradientsView, refPointsForCell, OPERATOR_GRAD);
861
862 // At some (likely relatively small) memory cost, we copy the BasisGradients into an explicit (F,P,D) container.
863 // Given that we expect to reuse this for a non-trivial number of cell in the common use case, the extra memory
864 // cost is likely worth the increased flop count, etc. (One might want to revisit this in cases of high spaceDim
865 // and/or very high polynomial order.)
866
867 using ExecutionSpace = typename DeviceType::execution_space;
868 auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<3>>({0,0,0},{numFields,numPoints,spaceDim});
869
870 Kokkos::parallel_for("copy basis gradients", policy,
871 KOKKOS_LAMBDA (const int &fieldOrdinal, const int &pointOrdinal, const int &d) {
872 cellBasisGradientsView(cellOrdinal,fieldOrdinal,pointOrdinal,d) = basisGradientsView(fieldOrdinal,pointOrdinal,d);
873 });
874 ExecutionSpace().fence();
875 }
876 Data<PointScalar,DeviceType> basisRefData(cellBasisGradientsView);
877 return basisRefData;
878 }
879 }
880 }
881 }
882 else
883 {
884 // TODO: handle the other cases
885 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "support for this CellGeometryType is not yet implemented");
886 }
887 return emptyRefData;
888
889
890 }
891
892 template<class PointScalar, int spaceDim, typename DeviceType>
894 {
895 Data<PointScalar,DeviceType> emptyRefData;
896 if (cellGeometryType_ == UNIFORM_GRID)
897 {
898 // no need for basis computations
899 return emptyRefData;
900 }
901 else if (cellGeometryType_ == TENSOR_GRID)
902 {
903 // no need for basis values
904 return emptyRefData;
905 }
906 else if ((cellGeometryType_ == FIRST_ORDER) || (cellGeometryType_ == HIGHER_ORDER))
907 {
908 const bool simplex = (spaceDim + 1 == cellToNodes_.extent_int(1));
909 if (simplex)
910 {
911 // no need for precomputed basis values
912 return emptyRefData;
913 }
914 else
915 {
916 auto basisForNodes = this->basisForNodes();
917
918 if (affine_)
919 {
920 // no need for precomputed basis values
921 return emptyRefData;
922 }
923 else
924 {
925 auto basisGradients = basisForNodes->allocateBasisValues(points, OPERATOR_GRAD);
926 basisForNodes->getValues(basisGradients, points, OPERATOR_GRAD);
927
928 int numPoints = points.extent_int(0);
929 int numFields = basisForNodes->getCardinality();
930
931 // At some (likely relatively small) memory cost, we copy the BasisGradients into an explicit (F,P,D) container.
932 // Given that we expect to reuse this for a non-trivial number of cell in the common use case, the extra memory
933 // cost is likely worth the increased flop count, etc. (One might want to revisit this in cases of high spaceDim
934 // and/or very high polynomial order.)
935
936 auto firstPointComponentView = points.getTensorComponent(0); // (P,D0)
937 auto basisGradientsView = Impl::createMatchingDynRankView(firstPointComponentView, "CellGeometryProvider: temporary basisGradients", numFields, numPoints, spaceDim);
938
939 using ExecutionSpace = typename DeviceType::execution_space;
940 auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<3>>({0,0,0},{numFields,numPoints,spaceDim});
941
942 Kokkos::parallel_for("copy basis gradients", policy,
943 KOKKOS_LAMBDA (const int &fieldOrdinal, const int &pointOrdinal, const int &d) {
944 basisGradientsView(fieldOrdinal,pointOrdinal,d) = basisGradients(fieldOrdinal,pointOrdinal,d);
945 });
946 ExecutionSpace().fence();
947
948 Data<PointScalar,DeviceType> basisRefData(basisGradientsView);
949 return basisRefData;
950 }
951 }
952 }
953 else
954 {
955 // TODO: handle the other cases
956 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "support for this CellGeometryType is not yet implemented");
957 }
958 return emptyRefData;
959 }
960
961 template<class PointScalar, int spaceDim, typename DeviceType>
962 KOKKOS_INLINE_FUNCTION
964 {
965 if (nodeOrdering_ == HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS)
966 {
967 // note that Shards numbers nodes for quad counter-clockwise
968 // cube is tensor-product of the (x,y) quad with a z line segment
969 if (d==0)
970 {
971 if ((hypercubeNodeNumber % 4 == 1) || (hypercubeNodeNumber % 4 == 2))
972 return 1;
973 else
974 return 0;
975 }
976 else if (d==1)
977 {
978 if ((hypercubeNodeNumber % 4 == 2) || (hypercubeNodeNumber % 4 == 3))
979 return 1;
980 else
981 return 0;
982 }
983 }
984 // tensor formula coincides with shards formula for d ≥ 2
985 const int nodesForPriorDimensions = 1 << d;
986 if ((hypercubeNodeNumber / nodesForPriorDimensions) % 2 == 1)
987 return 1;
988 else
989 return 0;
990 }
991
992 template<class PointScalar, int spaceDim, typename DeviceType>
994 {
995 using HostExecSpace = Kokkos::DefaultHostExecutionSpace;
996 INTREPID2_TEST_FOR_EXCEPTION(this->cellTopology().getCellTopologyData() == nullptr, std::invalid_argument,
997 "CellGeometry: orientations require a cell topology, which is not defined for space dimensions above 3");
998
999 const bool isGridType = (cellGeometryType_ == TENSOR_GRID) || (cellGeometryType_ == UNIFORM_GRID);
1000 const int numOrientations = isGridType ? numCellsPerGridCell(subdivisionStrategy_) : numCells();
1001
1002 const int nodesPerCell = numNodesPerCell();
1003
1004 ScalarView<Orientation, DeviceType> orientationsView("orientations", numOrientations);
1005 auto orientationsHost = Kokkos::create_mirror_view(typename HostExecSpace::memory_space(), orientationsView);
1006
1008
1009 if (isGridType)
1010 {
1011 // then there are as many distinct orientations possible as there are there are cells per grid cell
1012 // fill cellNodesHost with sample nodes from grid cell 0
1013 const int numSubdivisions = numCellsPerGridCell(subdivisionStrategy_); // can be up to 6
1014 ScalarView<PointScalar, HostExecSpace> cellNodesHost("cellNodesHost",numOrientations,nodesPerCell); // (C,N) -- where C = numOrientations
1015
1016#if defined(INTREPID2_COMPILE_DEVICE_CODE)
1018#else
1019 const int gridCellOrdinal = 0;
1020 auto hostPolicy = Kokkos::MDRangePolicy<HostExecSpace,Kokkos::Rank<2>>({0,0},{numSubdivisions,nodesPerCell});
1021 Kokkos::parallel_for("fill cellNodesHost", hostPolicy,
1022 [this,gridCellOrdinal,cellNodesHost] (const int &subdivisionOrdinal, const int &nodeInCell) {
1023 auto node = this->gridCellNodeForSubdivisionNode(gridCellOrdinal, subdivisionOrdinal, nodeInCell);
1024 cellNodesHost(subdivisionOrdinal,nodeInCell) = node;
1025 });
1026#endif
1027 cellVariationType = (numSubdivisions == 1) ? CONSTANT : MODULAR;
1028 OrientationTools<HostExecSpace>::getOrientation(orientationsHost,cellNodesHost,this->cellTopology());
1029 }
1030 else
1031 {
1033 auto cellNodesHost = Kokkos::create_mirror_view_and_copy(typename HostExecSpace::memory_space(), cellToNodes_);
1034 OrientationTools<HostExecSpace>::getOrientation(orientationsHost,cellNodesHost,this->cellTopology());
1035 }
1036 Kokkos::deep_copy(orientationsView,orientationsHost);
1037
1038 const int orientationsRank = 1; // shape (C)
1039 const Kokkos::Array<int,7> orientationExtents {static_cast<int>(numCells_),1,1,1,1,1,1};
1040 const Kokkos::Array<DataVariationType,7> orientationVariationTypes { cellVariationType, CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT, CONSTANT};
1041 orientations_ = Data<Orientation,DeviceType>(orientationsView, orientationsRank, orientationExtents, orientationVariationTypes);
1042 }
1043
1044 template<class PointScalar, int spaceDim, typename DeviceType>
1045 KOKKOS_INLINE_FUNCTION
1047 if (r == 0)
1048 {
1049 return numCells_;
1050 }
1051 else if (r == 1)
1052 {
1053 return numNodesPerCell_;
1054 }
1055 else if (r == 2)
1056 {
1057 return spaceDim;
1058 }
1059 else
1060 {
1061 return 1;
1062 }
1063 }
1064
1065 template<class PointScalar, int spaceDim, typename DeviceType>
1066 template <typename iType>
1067 KOKKOS_INLINE_FUNCTION
1068 typename std::enable_if<std::is_integral<iType>::value, int>::type
1070 {
1071 return static_cast<int>(extent(r));
1072 }
1073
1074 template<class PointScalar, int spaceDim, typename DeviceType>
1075 KOKKOS_INLINE_FUNCTION
1081
1082 template<class PointScalar, int spaceDim, typename DeviceType>
1083 KOKKOS_INLINE_FUNCTION
1085 {
1086 return numCells_;
1087 }
1088
1089 template<class PointScalar, int spaceDim, typename DeviceType>
1090 KOKKOS_INLINE_FUNCTION
1092 {
1093 if (cellGeometryType_ == UNIFORM_GRID)
1094 {
1095 return gridCellCounts_[dim];
1096 }
1097 else if (cellGeometryType_ == TENSOR_GRID)
1098 {
1099 return tensorVertices_.extent_int(dim);
1100 }
1101 else
1102 {
1103 return -1; // not valid for this cell geometry type
1104 }
1105 }
1106
1107 template<class PointScalar, int spaceDim, typename DeviceType>
1108 KOKKOS_INLINE_FUNCTION
1110 {
1111 return numNodesPerCell_;
1112 }
1113
1114 template<class PointScalar, int spaceDim, typename DeviceType>
1115 KOKKOS_INLINE_FUNCTION
1117 {
1118 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(!orientations_.isValid(), std::invalid_argument, "orientations_ not initialized; call initializeOrientations() first");
1119 return orientations_(cellNumber);
1120 }
1121
1122 template<class PointScalar, int spaceDim, typename DeviceType>
1124 {
1125 if (!orientations_.isValid())
1126 {
1128 }
1129 return orientations_;
1130 }
1131
1132 template<class PointScalar, int spaceDim, typename DeviceType>
1133 KOKKOS_INLINE_FUNCTION
1134 PointScalar CellGeometry<PointScalar,spaceDim,DeviceType>::gridCellCoordinate(const int &gridCellOrdinal, const int &localNodeNumber, const int &dim) const
1135 {
1136 const int componentNode = hypercubeComponentNodeNumber(localNodeNumber, dim);
1137 int cellCountForPriorDimensions = 1;
1138 for (int d=0; d<dim; d++)
1139 {
1140 cellCountForPriorDimensions *= numCellsInDimension(d);
1141 }
1142 const int componentGridCellOrdinal = (gridCellOrdinal / cellCountForPriorDimensions) % numCellsInDimension(dim);
1143 const int vertexOrdinal = componentGridCellOrdinal + componentNode;
1144 if (cellGeometryType_ == UNIFORM_GRID)
1145 {
1146 return origin_[dim] + (vertexOrdinal * domainExtents_[dim]) / gridCellCounts_[dim];
1147 }
1148 else if (cellGeometryType_ == TENSOR_GRID)
1149 {
1150 Kokkos::Array<int,spaceDim> pointOrdinalComponents;
1151 for (int d=0; d<spaceDim; d++)
1152 {
1153 pointOrdinalComponents[d] = 0;
1154 }
1155 pointOrdinalComponents[dim] = vertexOrdinal;
1156 return tensorVertices_(pointOrdinalComponents,dim);
1157 }
1158 else
1159 {
1160 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "Unsupported geometry type");
1161 return 0; // unreachable; here to avoid compiler warnings
1162 }
1163 }
1164
1165 template<class PointScalar, int spaceDim, typename DeviceType>
1166 KOKKOS_INLINE_FUNCTION
1168 {
1169 return 3; // (C,N,D)
1170 }
1171
1172 template<class PointScalar, int spaceDim, typename DeviceType>
1173 KOKKOS_INLINE_FUNCTION
1174 int CellGeometry<PointScalar,spaceDim,DeviceType>::gridCellNodeForSubdivisionNode(const int &gridCellOrdinal, const int &subdivisionOrdinal,
1175 const int &subdivisionNodeNumber) const
1176 {
1177 // TODO: do something to reuse the nodeLookup containers
1178 switch (subdivisionStrategy_)
1179 {
1180 case NO_SUBDIVISION:
1181 return subdivisionNodeNumber;
1183 case TWO_TRIANGLES_LEFT:
1184 case FOUR_TRIANGLES:
1185 {
1186 Kokkos::Array<int,3> nodeLookup;
1187 if (subdivisionStrategy_ == TWO_TRIANGLES_RIGHT)
1188 {
1189 if (subdivisionOrdinal == 0)
1190 {
1191 // bottom-right cell: node numbers coincide with quad node numbers
1192 nodeLookup = {0,1,2};
1193 }
1194 else if (subdivisionOrdinal == 1)
1195 {
1196 // node 0 --> node 2
1197 // node 1 --> node 3
1198 // node 2 --> node 0
1199 nodeLookup = {2,3,0};
1200 }
1201 else
1202 {
1203 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "Unsupported subdivision ordinal");
1204 }
1205 }
1206 else if (subdivisionStrategy_ == TWO_TRIANGLES_LEFT)
1207 {
1208 if (subdivisionOrdinal == 0)
1209 {
1210 // bottom-left cell:
1211 // node 0 --> node 3
1212 // node 1 --> node 0
1213 // node 2 --> node 1
1214 nodeLookup = {3,0,1};
1215 }
1216 else if (subdivisionOrdinal == 1)
1217 {
1218 // node 0 --> node 2
1219 // node 1 --> node 3
1220 // node 2 --> node 0
1221 nodeLookup = {2,3,0};
1222 }
1223 else
1224 {
1225 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "Unsupported subdivision ordinal");
1226 }
1227 }
1228 else // FOUR_TRIANGLES
1229 {
1230 // counter-clockwise, bottom triangle first
1231 // bottom triangle goes:
1232 // 0 --> 1
1233 // 1 --> center
1234 // 2 --> 0
1235 // and similarly for the other triangles, proceeding counter-clockwise
1236 // node 1 always being the center, we special-case that
1237 if (subdivisionNodeNumber == 1)
1238 {
1239 // center coordinate: we call this node 4 in the quadrilateral
1240 return 4;
1241 }
1242 else
1243 {
1244 nodeLookup = {(subdivisionOrdinal + 1) % 4, -1, subdivisionOrdinal};
1245 }
1246 }
1247 const int gridCellNodeNumber = nodeLookup[subdivisionNodeNumber];
1248 return gridCellNodeNumber;
1249 }
1250 case FIVE_TETRAHEDRA:
1251 case SIX_TETRAHEDRA:
1252 {
1253 Kokkos::Array<int,4> nodeLookup;
1254 if (subdivisionStrategy_ == FIVE_TETRAHEDRA)
1255 {
1256 /*
1257 // to discretize a unit cube into 5 tetrahedra, we can take the four vertices
1258 // (1,1,1)
1259 // (0,0,1)
1260 // (0,1,0)
1261 // (1,0,0)
1262 // as an interior tetrahedron. Call this cell 0. The remaining 4 cells can be determined
1263 // by selecting three of the above points (there are exactly 4 such combinations) and then selecting
1264 // from the remaining four vertices of the cube the one nearest the plane defined by those three points.
1265 // The remaining four vertices are:
1266 // (0,0,0)
1267 // (1,1,0)
1268 // (1,0,1)
1269 // (0,1,1)
1270 // For each of these four, we pick one, and then take the three nearest vertices from cell 0 to form a new tetrahedron.
1271 // We enumerate as follows:
1272 // cell 0: (1,1,1), (0,0,1), (0,1,0), (1,0,0)
1273 // cell 1: (0,0,0), (1,0,0), (0,1,0), (0,0,1)
1274 // cell 2: (1,1,0), (1,1,1), (0,1,0), (1,0,0)
1275 // cell 3: (1,0,1), (1,1,1), (0,0,1), (1,0,0)
1276 // cell 4: (0,1,1), (1,1,1), (0,0,1), (0,1,0)
1277 */
1278 // tetrahedra are as follows:
1279 // 0: {1,3,4,6}
1280 // 1: {0,1,3,4}
1281 // 2: {1,2,3,6}
1282 // 3: {1,4,5,6}
1283 // 4: {3,4,6,7}
1284 switch (subdivisionOrdinal) {
1285 case 0:
1286 nodeLookup = {1,3,4,6};
1287 break;
1288 case 1:
1289 nodeLookup = {0,1,3,4};
1290 break;
1291 case 2:
1292 nodeLookup = {1,2,3,6};
1293 break;
1294 case 3:
1295 nodeLookup = {1,4,5,6};
1296 break;
1297 case 4:
1298 nodeLookup = {3,4,6,7};
1299 break;
1300 default:
1301 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "invalid subdivisionOrdinal");
1302 break;
1303 }
1304 }
1305 else if (subdivisionStrategy_ == SIX_TETRAHEDRA)
1306 {
1307 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "support for SIX_TETRAHEDRA not yet implemented");
1308 }
1309 const int gridCellNodeNumber = nodeLookup[subdivisionNodeNumber];
1310 return gridCellNodeNumber;
1311 }
1312 case SIX_PYRAMIDS:
1313 {
1314 Kokkos::Array<int,5> nodeLookup; // nodeLookup[4] = 8; // center
1315 // we order the subcell divisions as bottom, top, left, right, front, back
1316 if (nodeOrdering_ == HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS)
1317 {
1318 switch (subdivisionOrdinal)
1319 {
1320 case 0: // bottom (min z)
1321 nodeLookup = {0,1,2,3,8};
1322 break;
1323 case 1: // top (max z)
1324 nodeLookup = {4,5,6,7,8};
1325 break;
1326 case 2: // left (min y)
1327 nodeLookup = {0,1,5,4,8};
1328 break;
1329 case 3: // right (max y)
1330 nodeLookup = {3,2,6,7,8};
1331 break;
1332 case 4: // front (max x)
1333 nodeLookup = {1,2,6,5,8};
1334 break;
1335 case 5: // back (min x)
1336 nodeLookup = {0,3,7,4,8};
1337 break;
1338 default:
1339 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "Invalid subdivisionOrdinal!");
1340 }
1341 }
1342 else // tensor ordering
1343 {
1344 switch (subdivisionOrdinal)
1345 {
1346 case 0: // bottom (min z)
1347 nodeLookup = {0,1,3,2,8};
1348 break;
1349 case 1: // top (max z)
1350 nodeLookup = {4,5,7,6,8};
1351 break;
1352 case 2: // left (min y)
1353 nodeLookup = {0,1,5,4,8};
1354 break;
1355 case 3: // right (max y)
1356 nodeLookup = {2,3,7,6,8};
1357 break;
1358 case 4: // front (max x)
1359 nodeLookup = {1,3,7,5,8};
1360 break;
1361 case 5: // back (min x)
1362 nodeLookup = {0,2,6,4,8};
1363 break;
1364 default:
1365 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "Invalid subdivisionOrdinal!");
1366 }
1367 }
1368 const int gridCellNodeNumber = nodeLookup[subdivisionNodeNumber];
1369 return gridCellNodeNumber;
1370 }
1371 default:
1372 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(true, std::invalid_argument, "Subdivision strategy not yet implemented!");
1373 // some compilers complain about missing return
1374 return 0; // statement should be unreachable...
1375 }
1376 }
1377
1378 template<class PointScalar, int spaceDim, typename DeviceType>
1379 KOKKOS_INLINE_FUNCTION
1380 PointScalar CellGeometry<PointScalar,spaceDim,DeviceType>::subdivisionCoordinate(const int &gridCellOrdinal, const int &subdivisionOrdinal,
1381 const int &subdivisionNodeNumber, const int &d) const
1382 {
1383 int gridCellNode = gridCellNodeForSubdivisionNode(gridCellOrdinal, subdivisionOrdinal, subdivisionNodeNumber);
1384
1385 if (subdivisionStrategy_ == FOUR_TRIANGLES)
1386 {
1387 // this is a case in which the gridCellNode may not actually be a node in the grid cell
1388 if (gridCellNode == 4) // center vertex
1389 {
1390 // d == 0 means quad vertices 0 and 1 suffice;
1391 // d == 1 means quad vertices 0 and 3 suffice
1392 const int gridVertex0 = 0;
1393 const int gridVertex1 = (d == 0) ? 1 : 3;
1394 return 0.5 * (gridCellCoordinate(gridCellOrdinal, gridVertex0, d) + gridCellCoordinate(gridCellOrdinal, gridVertex1, d));
1395 }
1396 }
1397 else if (subdivisionStrategy_ == SIX_PYRAMIDS)
1398 {
1399 // this is a case in which the gridCellNode may not actually be a node in the grid cell
1400 if (gridCellNode == 8) // center vertex
1401 {
1402 // can compute the center vertex coord in dim d by averaging diagonally opposite vertices'
1403 // coords in dimension d.
1404 const int gridVertex0 = 0; // 0 is diagonally opposite to 6 or 7, depending on nodeOrdering_
1405 const int gridVertex1 = (nodeOrdering_ == HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS) ? 6 : 7;
1406 return 0.5 * (gridCellCoordinate(gridCellOrdinal, gridVertex0, d) + gridCellCoordinate(gridCellOrdinal, gridVertex1, d));
1407 }
1408 }
1409 return gridCellCoordinate(gridCellOrdinal, gridCellNode, d);
1410 }
1411
1412 template<class PointScalar, int spaceDim, typename DeviceType>
1413 KOKKOS_INLINE_FUNCTION
1414 PointScalar
1415 CellGeometry<PointScalar,spaceDim,DeviceType>::operator()(const int& cell, const int& node, const int& dim) const {
1416 if ((cellGeometryType_ == UNIFORM_GRID) || (cellGeometryType_ == TENSOR_GRID))
1417 {
1418 const int numSubdivisions = numCellsPerGridCell(subdivisionStrategy_);
1419 if (numSubdivisions == 1)
1420 {
1421 // hypercube
1422 return gridCellCoordinate(cell, node, dim);
1423 }
1424 else
1425 {
1426 const int subdivisionOrdinal = cell % numSubdivisions;
1427 const int gridCellOrdinal = cell / numSubdivisions;
1428 return subdivisionCoordinate(gridCellOrdinal, subdivisionOrdinal, node, dim);
1429 }
1430 }
1431 else
1432 {
1433#ifdef HAVE_INTREPID2_DEBUG
1434 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE((cell < 0), std::invalid_argument, "cell out of bounds");
1435 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(static_cast<unsigned>(cell) > numCells_, std::invalid_argument, "cell out of bounds");
1436 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE((node < 0), std::invalid_argument, "node out of bounds");
1437 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(static_cast<unsigned>(node) > numNodesPerCell_, std::invalid_argument, "node out of bounds");
1438 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE((dim < 0), std::invalid_argument, "dim out of bounds" );
1439 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(dim > spaceDim, std::invalid_argument, "dim out of bounds" );
1440#endif
1441 if (cellToNodes_.is_allocated())
1442 {
1443 const int nodeNumber = cellToNodes_(cell,node);
1444 return nodes_(nodeNumber,dim);
1445 }
1446 else
1447 {
1448 return nodes_(cell,node,dim);
1449 }
1450 }
1451 }
1452
1453 template<class PointScalar, int spaceDim, typename DeviceType>
1454 void CellGeometry<PointScalar,spaceDim,DeviceType>::orientations(ScalarView<Orientation,DeviceType> orientationsView, const int &startCell, const int &endCell)
1455 {
1456 auto orientationsData = getOrientations();
1457 const int numCellsWorkset = (endCell == -1) ? (numCells_ - startCell) : (endCell - startCell);
1458
1459 using ExecutionSpace = typename DeviceType::execution_space;
1460 auto policy = Kokkos::RangePolicy<ExecutionSpace>(ExecutionSpace(),0,numCellsWorkset);
1461 Kokkos::parallel_for("copy orientations", policy, KOKKOS_LAMBDA(const int cellOrdinal)
1462 {
1463 orientationsView(cellOrdinal) = orientationsData(cellOrdinal);
1464 });
1465 ExecutionSpace().fence();
1466 }
1467
1468 template<class PointScalar, int spaceDim, typename DeviceType>
1469 KOKKOS_INLINE_FUNCTION
1471 {
1472 if (cellGeometryType_ == UNIFORM_GRID)
1473 {
1474 return numCellsPerGridCell(subdivisionStrategy_);
1475 }
1476 else
1477 {
1478 return numCells_;
1479 }
1480 }
1481
1482 template<class PointScalar, int spaceDim, typename DeviceType>
1484 {
1485 const int pointsPerCell = points.extent_int(0);
1486 return allocateJacobianDataPrivate(points.getTensorComponent(0),pointsPerCell,startCell,endCell);
1487 }
1488
1489 template<class PointScalar, int spaceDim, typename DeviceType>
1490 Data<PointScalar,DeviceType> CellGeometry<PointScalar,spaceDim,DeviceType>::allocateJacobianData(const ScalarView<PointScalar,DeviceType> &points, const int startCell, const int endCell) const
1491 {
1492 // if points is rank 3, it has shape (C,P,D). If it's rank 2, (P,D).
1493 const int pointDimension = (points.rank() == 3) ? 1 : 0;
1494 const int pointsPerCell = points.extent_int(pointDimension);
1495 return allocateJacobianDataPrivate(points,pointsPerCell,startCell,endCell);
1496 }
1497
1498 template<class PointScalar, int spaceDim, typename DeviceType>
1499 Data<PointScalar,DeviceType> CellGeometry<PointScalar,spaceDim,DeviceType>::allocateJacobianData(const int &numPoints, const int startCell, const int endCell) const
1500 {
1501 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(!affine_, std::invalid_argument, "this version of allocateJacobianData() is only supported for affine CellGeometry");
1502
1503 ScalarView<PointScalar,DeviceType> emptyPoints;
1504 return allocateJacobianDataPrivate(emptyPoints,numPoints,startCell,endCell);
1505 }
1506
1507 template<class PointScalar, int spaceDim, typename DeviceType>
1509 const Data<PointScalar,DeviceType> &refData, const int startCell, const int endCell) const
1510 {
1511 const int pointsPerCell = points.extent_int(0);
1512 setJacobianDataPrivate(jacobianData,pointsPerCell,refData,startCell,endCell);
1513 }
1514
1515 template<class PointScalar, int spaceDim, typename DeviceType>
1516 void CellGeometry<PointScalar,spaceDim,DeviceType>::setJacobian(Data<PointScalar,DeviceType> &jacobianData, const ScalarView<PointScalar,DeviceType> &points,
1517 const Data<PointScalar,DeviceType> &refData, const int startCell, const int endCell) const
1518 {
1519 // if points is rank 3, it has shape (C,P,D). If it's rank 2, (P,D).
1520 const int pointDimension = (points.rank() == 3) ? 1 : 0;
1521 const int pointsPerCell = points.extent_int(pointDimension);
1522 setJacobianDataPrivate(jacobianData,pointsPerCell,refData,startCell,endCell);
1523 }
1524
1525 template<class PointScalar, int spaceDim, typename DeviceType>
1526 void CellGeometry<PointScalar,spaceDim,DeviceType>::setJacobian(Data<PointScalar,DeviceType> &jacobianData, const int &numPoints, const int startCell, const int endCell) const
1527 {
1528 INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(!affine_, std::invalid_argument, "this version of setJacobian() is only supported for affine CellGeometry");
1529
1530 Data<PointScalar,DeviceType> emptyRefData;
1531 setJacobianDataPrivate(jacobianData,numPoints,emptyRefData,startCell,endCell);
1532 }
1533} // namespace Intrepid2
1534
1535#endif /* Intrepid2_CellGeometryDef_h */
@ GENERAL
arbitrary variation
@ BLOCK_PLUS_DIAGONAL
one of two dimensions in a matrix; bottom-right part of matrix is diagonal
@ MODULAR
varies according to modulus of the index
static BasisFamily::BasisPtr getHypercubeBasis_HGRAD(int polyOrder, int spaceDim, const EPointType pointType=POINTTYPE_DEFAULT)
Factory method for isotropic HGRAD bases on a hypercube for the given family. Note that this will ret...
static BasisFamily::BasisPtr getBasis(const shards::CellTopology &cellTopo, Intrepid2::EFunctionSpace fs, int polyOrder, const EPointType pointType=POINTTYPE_DEFAULT)
Factory method for isotropic bases in the given family on the specified cell topology.
DeduceDynRankView< InViewType >::type createMatchingDynRankView(const InViewType &view, const CtorProp &prop, const Dims... dims)
Creates and returns a view that matches the value_type of the provided view The output view type is d...
#define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg)
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Hexahedron cell.
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Quadrilateral cell.
An abstract base class that defines interface for concrete basis implementations for Finite Element (...
CellGeometry provides the nodes for a set of cells; has options that support efficient definition of ...
void computeCellMeasure(TensorData< PointScalar, DeviceType > &cellMeasure, const Data< PointScalar, DeviceType > &jacobianDet, const TensorData< PointScalar, DeviceType > &cubatureWeights) const
Compute cell measures that correspond to provided Jacobian determinants and.
void setJacobianDataPrivate(Data< PointScalar, DeviceType > &jacobianData, const int &pointsPerCell, const Data< PointScalar, DeviceType > &refData, const int startCell, const int endCell) const
Notionally-private method that provides a common interface for multiple public-facing setJacobianData...
BasisPtr basisForNodes() const
H^1 Basis used in the reference-to-physical transformation. Linear for straight-edged geometry; highe...
KOKKOS_INLINE_FUNCTION int numCellsPerGridCell(SubdivisionStrategy subdivisionStrategy) const
Helper method that returns the number of cells into which each grid cell will be subdivided based on ...
KOKKOS_INLINE_FUNCTION size_t extent(const int &r) const
Returns the logical extent of the container in the specified dimension; the shape of CellGeometry is ...
void setJacobian(Data< PointScalar, DeviceType > &jacobianData, const TensorPoints< PointScalar, DeviceType > &points, const Data< PointScalar, DeviceType > &refData, const int startCell=0, const int endCell=-1) const
Compute Jacobian values for the reference-to-physical transformation, and place them in the provided ...
TensorData< PointScalar, DeviceType > allocateCellMeasure(const Data< PointScalar, DeviceType > &jacobianDet, const TensorData< PointScalar, DeviceType > &cubatureWeights) const
Allocate a TensorData object appropriate for passing to computeCellMeasure().
KOKKOS_INLINE_FUNCTION int numCells() const
Returns the number of cells.
KOKKOS_INLINE_FUNCTION int numNodesPerCell() const
Returns the number of nodes per cell; may be more than the number of vertices in the corresponding Ce...
Data< PointScalar, DeviceType > getJacobianRefData(const ScalarView< PointScalar, DeviceType > &points) const
Computes reference-space data for the specified points, to be used in setJacobian().
KOKKOS_INLINE_FUNCTION int numCellsInDimension(const int &dim) const
For uniform grid and tensor grid CellGeometry, returns the number of cells in the specified component...
KOKKOS_INLINE_FUNCTION Orientation getOrientation(int &cellNumber) const
Returns the orientation for the specified cell. Requires that initializeOrientations() has been calle...
KOKKOS_INLINE_FUNCTION PointScalar gridCellCoordinate(const int &gridCellOrdinal, const int &localNodeNumber, const int &dim) const
returns coordinate in dimension dim of the indicated node in the indicated grid cell
CellGeometry(const Kokkos::Array< PointScalar, spaceDim > &origin, const Kokkos::Array< PointScalar, spaceDim > &domainExtents, const Kokkos::Array< int, spaceDim > &gridCellCounts, SubdivisionStrategy subdivisionStrategy=NO_SUBDIVISION, HypercubeNodeOrdering nodeOrdering=HYPERCUBE_NODE_ORDER_TENSOR)
Uniform grid constructor, with optional subdivision into simplices.
void initializeOrientations()
Initialize the internal orientations_ member with the orientations of each member cell....
Data< PointScalar, DeviceType > allocateJacobianDataPrivate(const ScalarView< PointScalar, DeviceType > &pointComponentView, const int &pointsPerCell, const int startCell, const int endCell) const
Notionally-private method that provides a common interface for multiple public-facing allocateJacobia...
KOKKOS_INLINE_FUNCTION DataVariationType cellVariationType() const
KOKKOS_INLINE_FUNCTION int hypercubeComponentNodeNumber(int hypercubeNodeNumber, int d) const
For hypercube vertex number hypercubeNodeNumber, returns the component node number in specified dimen...
KOKKOS_INLINE_FUNCTION PointScalar subdivisionCoordinate(const int &gridCellOrdinal, const int &subdivisionOrdinal, const int &subdivisionNodeNumber, const int &d) const
returns coordinate in dimension d for the indicated subdivision of the indicated grid cell
@ TWO_TRIANGLES_RIGHT
square --> two triangles, with a hypotenuse of slope 1
@ SIX_PYRAMIDS
cube --> six pyramids
@ SIX_TETRAHEDRA
cube --> six tetrahedra
@ FIVE_TETRAHEDRA
cube --> five tetrahedra
@ TWO_TRIANGLES_LEFT
square --> two triangles, with a hypotenuse of slope -1
@ FOUR_TRIANGLES
square --> four triangles, with a new vertex at center
KOKKOS_INLINE_FUNCTION unsigned rank() const
Returns the logical rank of this container. This is always 3.
@ UNIFORM_GRID
each grid division has the same dimensions
@ FIRST_ORDER
geometry expressible in terms of vertices of the cell
@ HIGHER_ORDER
geometry expressible in terms of a higher-order basis (must be specified)
@ TENSOR_GRID
grid expressed as a Cartesian product of 1D grids (could be a Shishkin mesh, e.g.)
KOKKOS_INLINE_FUNCTION bool affine() const
Returns true if Jacobian is constant within each cell.
void orientations(ScalarView< Orientation, DeviceType > orientationsView, const int &startCell=0, const int &endCell=-1)
Fills the provided container with the orientations for the specified cell range. Calls getOrientation...
Data< PointScalar, DeviceType > allocateJacobianData(const TensorPoints< PointScalar, DeviceType > &points, const int startCell=0, const int endCell=-1) const
Allocate a container into which Jacobians of the reference-to-physical mapping can be placed.
@ HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS
classic shards ordering
@ HYPERCUBE_NODE_ORDER_TENSOR
a more natural tensor ordering
KOKKOS_INLINE_FUNCTION ~CellGeometry()
Destructor.
KOKKOS_INLINE_FUNCTION HypercubeNodeOrdering nodeOrderingForHypercubes() const
Returns the node ordering used for hypercubes.
Data< Orientation, DeviceType > getOrientations()
Returns the orientations for all cells. Calls initializeOrientations() if it has not previously been ...
KOKKOS_INLINE_FUNCTION int uniformJacobianModulus() const
Returns an integer indicating the number of distinct cell types vis-a-vis Jacobians.
KOKKOS_INLINE_FUNCTION int gridCellNodeForSubdivisionNode(const int &gridCellOrdinal, const int &subdivisionOrdinal, const int &subdivisionNodeNumber) const
returns coordinate in dimension d for the indicated subdivision of the indicated grid cell
const shards::CellTopology & cellTopology() const
The shards CellTopology for each cell within the CellGeometry object. Note that this is always a lowe...
KOKKOS_INLINE_FUNCTION PointScalar operator()(const int &cell, const int &node, const int &dim) const
Return the coordinate (weight) of the specified node. For straight-edged geometry,...
KOKKOS_INLINE_FUNCTION ordinal_type cellToNode(ordinal_type cellIndex, ordinal_type cellNodeNumber) const
Returns a global node number corresponding to the specified (cell, node) combination....
KOKKOS_INLINE_FUNCTION std::enable_if< std::is_integral< iType >::value, int >::type extent_int(const iType &r) const
Returns the logical extent of the container in the specified dimension as an int; the shape of CellGe...
A stateless class for operations on cell data. Provides methods for:
static void setJacobian(JacobianViewType jacobian, const PointViewType points, const WorksetType worksetCell, const Teuchos::RCP< HGradBasisType > basis, const int startCell=0, const int endCell=-1)
Computes the Jacobian matrix DF of the reference-to-physical frame map F.
Wrapper around a Kokkos::View that allows data that is constant or repeating in various logical dimen...
KOKKOS_INLINE_FUNCTION enable_if_t< rank==1, const Kokkos::View< typename RankExpander< DataScalar, rank >::value_type, DeviceType > & > getUnderlyingView() const
Returns the underlying view. Throws an exception if the underlying view is not rank 1.
KOKKOS_INLINE_FUNCTION int extent_int(const int &r) const
Returns the logical extent in the specified dimension.
KOKKOS_INLINE_FUNCTION const Kokkos::View< DataScalar **, DeviceType > & getUnderlyingView2() const
returns the View that stores the unique data. For rank-2 underlying containers.
KOKKOS_INLINE_FUNCTION constexpr bool isValid() const
returns true for containers that have data; false for those that don't (namely, those that have been ...
KOKKOS_INLINE_FUNCTION const Kokkos::View< DataScalar ***, DeviceType > & getUnderlyingView3() const
returns the View that stores the unique data. For rank-3 underlying containers.
KOKKOS_INLINE_FUNCTION const Kokkos::Array< DataVariationType, 7 > & getVariationTypes() const
Returns an array with the variation types in each logical dimension.
KOKKOS_INLINE_FUNCTION const Kokkos::View< DataScalar *, DeviceType > & getUnderlyingView1() const
returns the View that stores the unique data. For rank-1 underlying containers.
KOKKOS_INLINE_FUNCTION int getDataExtent(const ordinal_type &d) const
returns the true extent of the data corresponding to the logical dimension provided; if the data does...
KOKKOS_INLINE_FUNCTION Kokkos::Array< int, 7 > getExtents() const
Returns an array containing the logical extents in each dimension.
KOKKOS_INLINE_FUNCTION unsigned rank() const
Returns the logical rank of the Data container.
Store host-only "members" of CellGeometry using a static map indexed on the CellGeometry pointer....
Functor for full (C,P) Jacobian determinant container. CUDA compiler issues led us to avoid lambdas f...
Orientation encoding and decoding.
static void getOrientation(Kokkos::DynRankView< elemOrtValueType, elemOrtProperties... > elemOrts, const Kokkos::DynRankView< elemNodeValueType, elemNodeProperties... > elemNodes, const shards::CellTopology cellTopo, bool isSide=false)
Compute orientations of cells in a workset.
View-like interface to tensor data; tensor components are stored separately and multiplied together a...
KOKKOS_INLINE_FUNCTION const Data< Scalar, DeviceType > & getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.
KOKKOS_INLINE_FUNCTION ordinal_type rank() const
Returns the rank of the container.
KOKKOS_INLINE_FUNCTION std::enable_if< std::is_integral< iType >::value, ordinal_type >::type extent_int(const iType &d) const
Returns the logical extent in the requested dimension.
KOKKOS_INLINE_FUNCTION ordinal_type numTensorComponents() const
Return the number of tensorial components.
View-like interface to tensor points; point components are stored separately; the appropriate coordin...
KOKKOS_INLINE_FUNCTION ScalarView< PointScalar, DeviceType > getTensorComponent(const ordinal_type &r) const
Returns the requested tensor component.
KOKKOS_INLINE_FUNCTION std::enable_if< std::is_integral< iType >::value, int >::type extent_int(const iType &r) const
Returns the logical extent in the requested dimension.