Intrepid2
Intrepid2_CellGeometryTestUtils.hpp
Go to the documentation of this file.
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#ifndef Intrepid2_CellGeometryTestUtils_h
16#define Intrepid2_CellGeometryTestUtils_h
17
19#include "Intrepid2_ScalarView.hpp"
20
22
23namespace Intrepid2
24{
30 template< typename PointScalar, int spaceDim, typename DeviceType >
31 inline
33 const bool &copyAffineness)
34 {
35 // copy the nodes from CellGeometry into a raw View
36 const int numCells = anyCellGeometry.extent_int(0);
37 const int numNodes = anyCellGeometry.extent_int(1);
38
39 using PointScalarView = ScalarView<PointScalar, DeviceType >;
40 using intView = ScalarView< int, DeviceType >;
41
42 auto cellToNodes = intView ("cell to nodes", numCells, numNodes); // this will be a one-to-one mapping
43 PointScalarView nodes = getView<PointScalar,DeviceType>("nodes", numCells * numNodes, spaceDim); // we store redundant copies of vertices for each cell
44
45 using ExecutionSpace = typename DeviceType::execution_space;
46 auto policy = Kokkos::MDRangePolicy<ExecutionSpace,Kokkos::Rank<2>>({0,0},{numCells,numNodes});
47
48 Kokkos::parallel_for("copy cell nodes from CellGeometry", policy,
49 KOKKOS_LAMBDA (const int &cellOrdinal, const int &nodeOrdinalInCell) {
50 const int globalNodeOrdinal = cellOrdinal * numNodes + nodeOrdinalInCell;
51 for (int d=0; d<spaceDim; d++)
52 {
53 nodes(globalNodeOrdinal,d) = anyCellGeometry(cellOrdinal,nodeOrdinalInCell,d);
54 }
55 cellToNodes(cellOrdinal,nodeOrdinalInCell) = globalNodeOrdinal;
56 });
57
58 ExecutionSpace().fence();
59
60 const bool claimAffine = copyAffineness && anyCellGeometry.affine();
61 const auto nodeOrdering = anyCellGeometry.nodeOrderingForHypercubes();
62
63 const auto cellTopology = anyCellGeometry.cellTopology();
64 CellGeometry<PointScalar, spaceDim, DeviceType> nodalCellGeometry(cellTopology,cellToNodes,nodes,claimAffine,nodeOrdering);
65
66 return nodalCellGeometry;
67 }
68
74 template<class PointScalar, int spaceDim, typename DeviceType>
75 inline CellGeometry<PointScalar,spaceDim,DeviceType> uniformCartesianMesh(const Kokkos::Array<PointScalar,spaceDim> &domainExtents,
76 const Kokkos::Array<int,spaceDim> &gridCellCounts)
77 {
78 Kokkos::Array<PointScalar,spaceDim> origin;
79 for (int d=0; d<spaceDim; d++)
80 {
81 origin[d] = 0.0;
82 }
83
85 const auto NO_SUBDIVISION = CellGeometry::NO_SUBDIVISION;
86 const auto HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS = CellGeometry::HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS;
87
88 return CellGeometry(origin, domainExtents, gridCellCounts, NO_SUBDIVISION, HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS);
89 }
90
96 template<class PointScalar, int spaceDim, typename DeviceType>
97 inline CellGeometry<PointScalar,spaceDim,DeviceType> uniformCartesianMesh(const PointScalar &domainExtent, const int &meshWidth)
98 {
99 Kokkos::Array<PointScalar,spaceDim> origin;
100 Kokkos::Array<PointScalar,spaceDim> domainExtents;
101 Kokkos::Array<int,spaceDim> gridCellCounts;
102 for (int d=0; d<spaceDim; d++)
103 {
104 origin[d] = 0.0;
105 domainExtents[d] = domainExtent;
106 gridCellCounts[d] = meshWidth;
107 }
108
110 const auto NO_SUBDIVISION = CellGeometry::NO_SUBDIVISION;
111 const auto HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS = CellGeometry::HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS;
112
113 return CellGeometry(origin, domainExtents, gridCellCounts, NO_SUBDIVISION, HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS);
114 }
115} // namespace Intrepid2
116
117#endif /* Intrepid2_CellGeometryTestUtils_h */
CellGeometry< PointScalar, spaceDim, DeviceType > uniformCartesianMesh(const Kokkos::Array< PointScalar, spaceDim > &domainExtents, const Kokkos::Array< int, spaceDim > &gridCellCounts)
Create a uniform Cartesian mesh, with origin at 0, and domain extents and mesh widths that can be dif...
CellGeometry< PointScalar, spaceDim, DeviceType > getNodalCellGeometry(CellGeometry< PointScalar, spaceDim, DeviceType > &anyCellGeometry, const bool &copyAffineness)
Use the cell nodes provided by one cell geometry object to create another CellGeometry that is node-b...
Allows definition of cell geometry information, including uniform and curvilinear mesh definition,...
Utility methods for Intrepid2 unit tests.
CellGeometry provides the nodes for a set of cells; has options that support efficient definition of ...
KOKKOS_INLINE_FUNCTION bool affine() const
Returns true if Jacobian is constant within each cell.
@ HYPERCUBE_NODE_ORDER_CLASSIC_SHARDS
classic shards ordering
KOKKOS_INLINE_FUNCTION HypercubeNodeOrdering nodeOrderingForHypercubes() const
Returns the node ordering used for hypercubes.
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 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...