15 #ifndef __INTREPID2_ORIENTATION_DEF_HPP__
16 #define __INTREPID2_ORIENTATION_DEF_HPP__
19 #if defined (__clang__) && !defined (__INTEL_COMPILER)
20 #pragma clang system_header
29 template<
typename cellVertViewType>
32 Orientation::getCellVertexMap(
typename cellVertViewType::non_const_value_type *subCellVerts,
33 ordinal_type &numVerts,
34 const shards::CellTopology cellTopo,
35 const cellVertViewType cellVertices,
36 const ordinal_type subCellDim,
37 const ordinal_type subCellOrd) {
38 static_assert(Kokkos::Impl::MemorySpaceAccess
39 <Kokkos::HostSpace,
typename cellVertViewType::device_type::memory_space>::accessible,
40 "host space cannot access cellVertViewType");
44 subCellVerts[0] = cellVertices(subCellOrd);
48 numVerts = cellTopo.getVertexCount(subCellDim, subCellOrd);
49 for (ordinal_type i=0;i<numVerts;++i)
50 subCellVerts[i] = cellVertices(cellTopo.getNodeMap(subCellDim, subCellOrd, i));
56 template<
typename subCellVertType>
59 Orientation::getOrientation(
const subCellVertType subCellVerts[],
60 const ordinal_type numVerts) {
63 #ifdef HAVE_INTREPID2_DEBUG
64 for(ordinal_type i=0;i<numVerts-1;++i)
65 for(ordinal_type j=i+1;j<numVerts;++j)
66 INTREPID2_TEST_FOR_ABORT( ( subCellVerts[i] == subCellVerts[j] ),
67 ">>> ERROR (Intrepid::Orientation::getOrientation): " \
68 "Invalid subCellVerts, some vertex ids are repeated");
71 ordinal_type rotation = 0;
72 for (ordinal_type i=1;i<numVerts;++i)
73 rotation = (subCellVerts[i] < subCellVerts[rotation]) ? i : rotation;
81 const ordinal_type axes[][2] = { {1,2}, {2,0}, {0,1} };
82 const ordinal_type flip = (subCellVerts[axes[rotation][0]] > subCellVerts[axes[rotation][1]]);
84 ort = flip*3 + rotation;
88 const ordinal_type axes[][2] = { {1,3}, {2,0}, {3,1}, {0,2} };
89 const ordinal_type flip = (subCellVerts[axes[rotation][0]] > subCellVerts[axes[rotation][1]]);
91 ort = flip*4 + rotation;
95 INTREPID2_TEST_FOR_ABORT(
true,
96 ">>> ERROR (Intrepid::Orientation::getOrientation): " \
97 "Invalid numVerts (2 (edge),3 (triangle) and 4 (quadrilateral) are allowed)");
104 template<
typename cellVertViewType>
107 Orientation::getOrientation(
const shards::CellTopology cellTopo,
108 const cellVertViewType cellVertices,
110 static_assert(Kokkos::Impl::MemorySpaceAccess
111 <Kokkos::HostSpace,
typename cellVertViewType::device_type::memory_space>::accessible,
112 "host space cannot access cellVertViewType");
115 auto dim = cellTopo.getDimension();
116 const ordinal_type nedge = (isSide && dim==1) ? 1 : cellTopo.getEdgeCount();
119 typename cellVertViewType::non_const_value_type vertsSubCell[2];
120 ordinal_type orts[12], nvertSubCell;
121 for (ordinal_type i=0;i<nedge;++i) {
122 Orientation::getCellVertexMap(vertsSubCell,
127 orts[i] = Orientation::getOrientation(vertsSubCell, nvertSubCell);
131 const ordinal_type nface = (isSide && dim==2) ? 1 : cellTopo.getFaceCount();
133 typename cellVertViewType::non_const_value_type vertsSubCell[4];
134 ordinal_type orts[6], nvertSubCell;
135 for (ordinal_type i=0;i<nface;++i) {
136 Orientation::getCellVertexMap(vertsSubCell,
141 orts[i] = Orientation::getOrientation(vertsSubCell, nvertSubCell);
151 const ordinal_type subcellOrd,
152 const shards::CellTopology cellTopo) {
153 ordinal_type r_val = -1;
155 const auto cellBaseKey = cellTopo.getBaseKey();
156 if (cellBaseKey == shards::Hexahedron<>::key) {
157 INTREPID2_TEST_FOR_EXCEPTION( !(subcellOrd < 6) &&
158 !(subsubcellOrd < 4),
160 "subcell and subsubcell information are not correct" );
161 const int quad_to_hex_edges[6][4] = { { 0, 9, 4, 8 },
167 r_val = quad_to_hex_edges[subcellOrd][subsubcellOrd];
168 }
else if (cellBaseKey == shards::Tetrahedron<>::key) {
169 INTREPID2_TEST_FOR_EXCEPTION( !(subcellOrd < 4) &&
170 !(subsubcellOrd < 3),
172 "subcell and subsubcell information are not correct" );
173 const ordinal_type tri_to_tet_edges[4][3] = { { 0, 4, 3 },
177 r_val = tri_to_tet_edges[subcellOrd][subsubcellOrd];
179 INTREPID2_TEST_FOR_EXCEPTION(
true, std::logic_error,
180 "cellTopo is not supported: try TET and HEX" );
185 KOKKOS_INLINE_FUNCTION
187 : _edgeOrt(0), _faceOrt(0) {}
189 KOKKOS_INLINE_FUNCTION
192 return (_edgeOrt == 0 && _faceOrt == 0);
195 KOKKOS_INLINE_FUNCTION
198 #ifdef HAVE_INTREPID2_DEBUG
199 INTREPID2_TEST_FOR_ABORT( !((numEdge == 1) || (3 <= numEdge && numEdge <= 12 )),
200 ">>> ERROR (Intrepid::Orientation::setEdgeOrientation): " \
204 for (ordinal_type i=0;i<numEdge;++i)
205 _edgeOrt |= (edgeOrt[i] & 1) << i;
208 KOKKOS_INLINE_FUNCTION
211 #ifdef HAVE_INTREPID2_DEBUG
212 INTREPID2_TEST_FOR_ABORT( !((numEdge == 1) || (3 <= numEdge && numEdge <= 12 )),
213 ">>> ERROR (Intrepid::Orientation::setEdgeOrientation): " \
216 for (ordinal_type i=0;i<numEdge;++i)
217 edgeOrt[i] = (_edgeOrt & (1 << i)) >> i;
220 KOKKOS_INLINE_FUNCTION
223 #ifdef HAVE_INTREPID2_DEBUG
224 INTREPID2_TEST_FOR_ABORT( !((numFace == 1) || (4 <= numFace && numFace <= 6 )),
225 ">>> ERROR (Intrepid::Orientation::setFaceOrientation): "
229 for (ordinal_type i=0;i<numFace;++i) {
230 const ordinal_type s = i*3;
231 _faceOrt |= (faceOrt[i] & 7) << s;
235 KOKKOS_INLINE_FUNCTION
238 #ifdef HAVE_INTREPID2_DEBUG
239 INTREPID2_TEST_FOR_ABORT( !((numFace == 1) || (4 <= numFace && numFace <= 6 )),
240 ">>> ERROR (Intrepid::Orientation::setEdgeOrientation): "
243 for (ordinal_type i=0;i<numFace;++i) {
244 const ordinal_type s = i*3;
245 faceOrt[i] = (_faceOrt & (7 << s)) >> s;
250 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()