49 #ifndef __INTREPID2_CELLTOOLS_DEF_INCLUSION_HPP__
50 #define __INTREPID2_CELLTOOLS_DEF_INCLUSION_HPP__
53 #if defined (__clang__) && !defined (__INTEL_COMPILER)
54 #pragma clang system_header
66 template<
typename SpT>
67 template<
typename pointValueType,
class ...pointProperties>
71 const shards::CellTopology cellTopo,
72 const double threshold) {
73 #ifdef HAVE_INTREPID2_DEBUG
74 INTREPID2_TEST_FOR_EXCEPTION( point.rank() != 1, std::invalid_argument,
75 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): Point must have rank 1. ");
76 INTREPID2_TEST_FOR_EXCEPTION( point.extent(0) != cellTopo.getDimension(), std::invalid_argument,
77 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): Point and cell dimensions do not match. ");
79 bool testResult =
true;
81 const double t = threshold;
84 const double minus_one = -1.0 - t;
85 const double plus_one = 1.0 + t;
86 const double minus_zero = -t;
91 const auto key = cellTopo.getBaseKey();
94 case shards::Line<>::key :
95 if( !(minus_one <= point(0) && point(0) <= plus_one)) testResult =
false;
98 case shards::Triangle<>::key : {
100 if( distance > threshold ) testResult =
false;
104 case shards::Quadrilateral<>::key :
105 if(!( (minus_one <= point(0) && point(0) <= plus_one) &&
106 (minus_one <= point(1) && point(1) <= plus_one) ) ) testResult =
false;
109 case shards::Tetrahedron<>::key : {
112 if( distance > threshold ) testResult =
false;
116 case shards::Hexahedron<>::key :
117 if(!((minus_one <= point(0) && point(0) <= plus_one) &&
118 (minus_one <= point(1) && point(1) <= plus_one) &&
119 (minus_one <= point(2) && point(2) <= plus_one)))
125 case shards::Wedge<>::key : {
127 if( distance > threshold ||
128 point(2) < minus_one || point(2) > plus_one)
136 case shards::Pyramid<>::key : {
137 const auto left = minus_one + point(2);
138 const auto right = plus_one - point(2);
139 if(!( (left <= point(0) && point(0) <= right) && \
140 (left <= point(1) && point(1) <= right) &&
141 (minus_zero <= point(2) && point(2) <= plus_one) ) ) \
147 INTREPID2_TEST_FOR_EXCEPTION( !( (key == shards::Line<>::key ) ||
148 (key == shards::Triangle<>::key) ||
149 (key == shards::Quadrilateral<>::key) ||
150 (key == shards::Tetrahedron<>::key) ||
151 (key == shards::Hexahedron<>::key) ||
152 (key == shards::Wedge<>::key) ||
153 (key == shards::Pyramid<>::key) ),
154 std::invalid_argument,
155 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): Invalid cell topology. ");
225 template<
typename SpT>
226 template<
typename inCellValueType,
class ...inCellProperties,
227 typename pointValueType,
class ...pointProperties>
231 const Kokkos::DynRankView<pointValueType,pointProperties...> points,
232 const shards::CellTopology cellTopo,
233 const double threshold ) {
234 #ifdef HAVE_INTREPID2_DEBUG
236 INTREPID2_TEST_FOR_EXCEPTION( inCell.rank() != (points.rank()-1), std::invalid_argument,
237 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): rank difference between inCell and points is 1.");
238 const ordinal_type iend = inCell.rank();
239 for (ordinal_type i=0;i<iend;++i) {
240 INTREPID2_TEST_FOR_EXCEPTION( inCell.extent(i) != points.extent(i), std::invalid_argument,
241 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): dimension mismatch between inCell and points.");
247 switch (points.rank()) {
249 const ordinal_type iend = points.extent(0);
250 for (ordinal_type i=0;i<iend;++i) {
251 const auto point = Kokkos::subview(points, i, Kokkos::ALL());
252 inCell(i) = checkPointInclusion(point, cellTopo, threshold);
258 iend = points.extent(0),
259 jend = points.extent(1);
260 for (ordinal_type i=0;i<iend;++i)
261 for (ordinal_type j=0;j<jend;++j) {
262 const auto point = Kokkos::subview(points, i, j, Kokkos::ALL());
263 inCell(i, j) = checkPointInclusion(point, cellTopo, threshold);
270 template<
typename SpT>
271 template<
typename inCellValueType,
class ...inCellProperties,
272 typename pointValueType,
class ...pointProperties,
273 typename cellWorksetValueType,
class ...cellWorksetProperties>
277 const Kokkos::DynRankView<pointValueType,pointProperties...> points,
278 const Kokkos::DynRankView<cellWorksetValueType,cellWorksetProperties...> cellWorkset,
279 const shards::CellTopology cellTopo,
280 const double threshold ) {
281 #ifdef HAVE_INTREPID2_DEBUG
283 const auto key = cellTopo.getBaseKey();
284 INTREPID2_TEST_FOR_EXCEPTION( key != shards::Line<>::key &&
285 key != shards::Triangle<>::key &&
286 key != shards::Quadrilateral<>::key &&
287 key != shards::Tetrahedron<>::key &&
288 key != shards::Hexahedron<>::key &&
289 key != shards::Wedge<>::key &&
290 key != shards::Pyramid<>::key,
291 std::invalid_argument,
292 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): cell topology not supported");
294 INTREPID2_TEST_FOR_EXCEPTION( points.rank() != 3, std::invalid_argument,
295 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): Points must have rank 3. ");
296 INTREPID2_TEST_FOR_EXCEPTION( cellWorkset.rank() != 3, std::invalid_argument,
297 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): cellWorkset must have rank 3. ");
298 INTREPID2_TEST_FOR_EXCEPTION( points.extent(2) != cellTopo.getDimension(), std::invalid_argument,
299 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): Points and cell dimensions do not match. ");
300 INTREPID2_TEST_FOR_EXCEPTION( cellWorkset.extent(2) != cellTopo.getDimension(), std::invalid_argument,
301 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): cellWorkset and cell dimensions do not match. ");
302 INTREPID2_TEST_FOR_EXCEPTION( points.extent(0) != cellWorkset.extent(0) , std::invalid_argument,
303 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): cellWorkset and points dimension(0) does not match. ");
307 numCells = cellWorkset.extent(0),
308 numPoints = points.extent(1),
309 spaceDim = cellTopo.getDimension();
311 using result_layout =
typename DeduceLayout< decltype(points) >::result_layout;
312 using device_type =
typename decltype(points)::device_type;
313 auto vcprop = Kokkos::common_view_alloc_prop(points);
314 using common_value_type =
typename decltype(vcprop)::value_type;
315 Kokkos::DynRankView< common_value_type, result_layout, device_type > refPoints ( Kokkos::view_alloc(
"CellTools::checkPointwiseInclusion::refPoints", vcprop), numCells, numPoints, spaceDim);
318 mapToReferenceFrame(refPoints, points, cellWorkset, cellTopo);
319 checkPointwiseInclusion(inCell, refPoints, cellTopo, threshold);