48 #ifndef __INTREPID2_ORIENTATION_DEF_HPP__
49 #define __INTREPID2_ORIENTATION_DEF_HPP__
52 #if defined (__clang__) && !defined (__INTEL_COMPILER)
53 #pragma clang system_header
62 template<
typename cellVertViewType>
65 Orientation::getCellVertexMap(
typename cellVertViewType::non_const_value_type *subCellVerts,
66 ordinal_type &numVerts,
67 const shards::CellTopology cellTopo,
68 const cellVertViewType cellVertices,
69 const ordinal_type subCellDim,
70 const ordinal_type subCellOrd) {
71 static_assert(Kokkos::Impl::MemorySpaceAccess
72 <Kokkos::HostSpace,
typename cellVertViewType::device_type::memory_space>::accessible,
73 "host space cannot access cellVertViewType");
77 subCellVerts[0] = cellVertices(subCellOrd);
81 numVerts = cellTopo.getVertexCount(subCellDim, subCellOrd);
82 for (ordinal_type i=0;i<numVerts;++i)
83 subCellVerts[i] = cellVertices(cellTopo.getNodeMap(subCellDim, subCellOrd, i));
89 template<
typename subCellVertType>
92 Orientation::getOrientation(
const subCellVertType subCellVerts[],
93 const ordinal_type numVerts) {
96 #ifdef HAVE_INTREPID2_DEBUG
97 for(ordinal_type i=0;i<numVerts-1;++i)
98 for(ordinal_type j=i+1;j<numVerts;++j)
99 INTREPID2_TEST_FOR_ABORT( ( subCellVerts[i] == subCellVerts[j] ),
100 ">>> ERROR (Intrepid::Orientation::getOrientation): " \
101 "Invalid subCellVerts, some vertex ids are repeated");
104 ordinal_type rotation = 0;
105 for (ordinal_type i=1;i<numVerts;++i)
106 rotation = (subCellVerts[i] < subCellVerts[rotation]) ? i : rotation;
114 const ordinal_type axes[][2] = { {1,2}, {2,0}, {0,1} };
115 const ordinal_type flip = (subCellVerts[axes[rotation][0]] > subCellVerts[axes[rotation][1]]);
117 ort = flip*3 + rotation;
121 const ordinal_type axes[][2] = { {1,3}, {2,0}, {3,1}, {0,2} };
122 const ordinal_type flip = (subCellVerts[axes[rotation][0]] > subCellVerts[axes[rotation][1]]);
124 ort = flip*4 + rotation;
128 INTREPID2_TEST_FOR_ABORT(
true,
129 ">>> ERROR (Intrepid::Orientation::getOrientation): " \
130 "Invalid numVerts (2 (edge),3 (triangle) and 4 (quadrilateral) are allowed)");
137 template<
typename cellVertViewType>
140 Orientation::getOrientation(
const shards::CellTopology cellTopo,
141 const cellVertViewType cellVertices,
143 static_assert(Kokkos::Impl::MemorySpaceAccess
144 <Kokkos::HostSpace,
typename cellVertViewType::device_type::memory_space>::accessible,
145 "host space cannot access cellVertViewType");
148 auto dim = cellTopo.getDimension();
149 const ordinal_type nedge = (isSide && dim==1) ? 1 : cellTopo.getEdgeCount();
152 typename cellVertViewType::non_const_value_type vertsSubCell[2];
153 ordinal_type orts[12], nvertSubCell;
154 for (ordinal_type i=0;i<nedge;++i) {
155 Orientation::getCellVertexMap(vertsSubCell,
160 orts[i] = Orientation::getOrientation(vertsSubCell, nvertSubCell);
164 const ordinal_type nface = (isSide && dim==2) ? 1 : cellTopo.getFaceCount();
166 typename cellVertViewType::non_const_value_type vertsSubCell[4];
167 ordinal_type orts[6], nvertSubCell;
168 for (ordinal_type i=0;i<nface;++i) {
169 Orientation::getCellVertexMap(vertsSubCell,
174 orts[i] = Orientation::getOrientation(vertsSubCell, nvertSubCell);
184 const ordinal_type subcellOrd,
185 const shards::CellTopology cellTopo) {
186 ordinal_type r_val = -1;
188 const auto cellBaseKey = cellTopo.getBaseKey();
189 if (cellBaseKey == shards::Hexahedron<>::key) {
190 INTREPID2_TEST_FOR_EXCEPTION( !(subcellOrd < 6) &&
191 !(subsubcellOrd < 4),
193 "subcell and subsubcell information are not correct" );
194 const int quad_to_hex_edges[6][4] = { { 0, 9, 4, 8 },
200 r_val = quad_to_hex_edges[subcellOrd][subsubcellOrd];
201 }
else if (cellBaseKey == shards::Tetrahedron<>::key) {
202 INTREPID2_TEST_FOR_EXCEPTION( !(subcellOrd < 4) &&
203 !(subsubcellOrd < 3),
205 "subcell and subsubcell information are not correct" );
206 const ordinal_type tri_to_tet_edges[4][3] = { { 0, 4, 3 },
210 r_val = tri_to_tet_edges[subcellOrd][subsubcellOrd];
212 INTREPID2_TEST_FOR_EXCEPTION(
true, std::logic_error,
213 "cellTopo is not supported: try TET and HEX" );
218 KOKKOS_INLINE_FUNCTION
220 : _edgeOrt(0), _faceOrt(0) {}
222 KOKKOS_INLINE_FUNCTION
225 return (_edgeOrt == 0 && _faceOrt == 0);
228 KOKKOS_INLINE_FUNCTION
231 #ifdef HAVE_INTREPID2_DEBUG
232 INTREPID2_TEST_FOR_ABORT( !((numEdge == 1) || (3 <= numEdge && numEdge <= 12 )),
233 ">>> ERROR (Intrepid::Orientation::setEdgeOrientation): " \
237 for (ordinal_type i=0;i<numEdge;++i)
238 _edgeOrt |= (edgeOrt[i] & 1) << i;
241 KOKKOS_INLINE_FUNCTION
244 #ifdef HAVE_INTREPID2_DEBUG
245 INTREPID2_TEST_FOR_ABORT( !((numEdge == 1) || (3 <= numEdge && numEdge <= 12 )),
246 ">>> ERROR (Intrepid::Orientation::setEdgeOrientation): " \
249 for (ordinal_type i=0;i<numEdge;++i)
250 edgeOrt[i] = (_edgeOrt & (1 << i)) >> i;
253 KOKKOS_INLINE_FUNCTION
256 #ifdef HAVE_INTREPID2_DEBUG
257 INTREPID2_TEST_FOR_ABORT( !((numFace == 1) || (4 <= numFace && numFace <= 6 )),
258 ">>> ERROR (Intrepid::Orientation::setFaceOrientation): "
262 for (ordinal_type i=0;i<numFace;++i) {
263 const ordinal_type s = i*3;
264 _faceOrt |= (faceOrt[i] & 7) << s;
268 KOKKOS_INLINE_FUNCTION
271 #ifdef HAVE_INTREPID2_DEBUG
272 INTREPID2_TEST_FOR_ABORT( !((numFace == 1) || (4 <= numFace && numFace <= 6 )),
273 ">>> ERROR (Intrepid::Orientation::setEdgeOrientation): "
276 for (ordinal_type i=0;i<numFace;++i) {
277 const ordinal_type s = i*3;
278 faceOrt[i] = (_faceOrt & (7 << s)) >> s;
283 return "Orientation{ face: " + std::to_string(_faceOrt) +
"; edge: " + std::to_string(_edgeOrt) +
" }";
KOKKOS_INLINE_FUNCTION void getFaceOrientation(ordinal_type *faceOrt, const ordinal_type numFace) const
KOKKOS_INLINE_FUNCTION void setEdgeOrientation(const ordinal_type numEdge, const ordinal_type edgeOrt[])
Orientation encoding and decoding.
KOKKOS_INLINE_FUNCTION bool isAlignedToReference() const
KOKKOS_INLINE_FUNCTION void setFaceOrientation(const ordinal_type numFace, const ordinal_type faceOrt[])
std::string to_string() const
static ordinal_type getEdgeOrdinalOfFace(const ordinal_type subsubcellOrd, const ordinal_type subcellOrd, const shards::CellTopology cellTopo)
KOKKOS_INLINE_FUNCTION void getEdgeOrientation(ordinal_type *edgeOrt, const ordinal_type numEdge) const
KOKKOS_INLINE_FUNCTION Orientation()