Intrepid2
Intrepid2_CellToolsDefInclusion.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
10
16#ifndef __INTREPID2_CELLTOOLS_DEF_INCLUSION_HPP__
17#define __INTREPID2_CELLTOOLS_DEF_INCLUSION_HPP__
18
19// disable clang warnings
20#if defined (__clang__) && !defined (__INTEL_COMPILER)
21#pragma clang system_header
22#endif
23
24namespace Intrepid2 {
25
26 //============================================================================================//
27 // //
28 // Inclusion tests //
29 // //
30 //============================================================================================//
31
32
33 template<typename DeviceType>
34 template<typename PointViewType>
35 typename ScalarTraits<typename PointViewType::value_type>::scalar_type
38 const shards::CellTopology cellTopo) {
39#ifdef HAVE_INTREPID2_DEBUG
40 INTREPID2_TEST_FOR_EXCEPTION( point.rank() != 1, std::invalid_argument,
41 ">>> ERROR (Intrepid2::CellTools::parametricDistance): Point must have rank 1. ");
42 INTREPID2_TEST_FOR_EXCEPTION( point.extent(0) != cellTopo.getDimension(), std::invalid_argument,
43 ">>> ERROR (Intrepid2::CellTools::parametricDistance): Point and cell dimensions do not match. ");
44#endif
45 // A cell with extended topology has the same reference cell as a cell with base topology.
46 // => testing for inclusion in a reference Triangle<> and a reference Triangle<6> relies on
47 // on the same set of inequalities. To eliminate unnecessary cases we switch on the base topology
48 const auto key = cellTopo.getBaseKey();
49 using scalar_type = typename ScalarTraits<typename PointViewType::value_type>::scalar_type;
50 scalar_type distance(0);
51 switch (key) {
52 case shards::Line<>::key :
53 distance = ParametricDistance<shards::Line<>::key>::distance(point);
54 break;
55 case shards::ShellLine<>::key :
56 distance = ParametricDistance<shards::ShellLine<>::key>::distance(point);
57 break;
58 case shards::Triangle<>::key :
59 distance = ParametricDistance<shards::Triangle<>::key>::distance(point);
60 break;
61 case shards::ShellTriangle<>::key :
62 distance = ParametricDistance<shards::ShellTriangle<>::key>::distance(point);
63 break;
64 case shards::ShellQuadrilateral<>::key :
66 break;
67 case shards::Quadrilateral<>::key :
68 distance = ParametricDistance<shards::Quadrilateral<>::key>::distance(point);
69 break;
70 case shards::Tetrahedron<>::key :
71 distance = ParametricDistance<shards::Tetrahedron<>::key>::distance(point);
72 break;
73 case shards::Hexahedron<>::key :
74 distance = ParametricDistance<shards::Hexahedron<>::key>::distance(point);
75 break;
76 case shards::Wedge<>::key :
77 distance = ParametricDistance<shards::Wedge<>::key>::distance(point);
78 break;
79 case shards::Pyramid<>::key :
80 distance = ParametricDistance<shards::Pyramid<>::key>::distance(point);
81 break;
82 default:
83 INTREPID2_TEST_FOR_EXCEPTION( true, std::invalid_argument,
84 ">>> ERROR (Intrepid2::CellTools::parametricDistance): Invalid cell topology. ");
85 }
86 return distance;
87 }
88
89
90 template<unsigned cellTopologyKey,
91 typename OutputViewType,
92 typename InputViewType>
93 struct checkPointInclusionFunctor {
94 OutputViewType output_;
95 InputViewType input_;
96 using ScalarType = typename ScalarTraits<typename InputViewType::value_type>::scalar_type;
97 ScalarType threshold_;
98
99 KOKKOS_INLINE_FUNCTION
100 checkPointInclusionFunctor( OutputViewType output,
101 const InputViewType input,
102 const ScalarType threshold)
103 : output_(output),
104 input_(input),
105 threshold_(threshold) {}
106
107 KOKKOS_INLINE_FUNCTION
108 void
109 operator()(const ordinal_type i) const {
110 const auto in = Kokkos::subview(input_,i,Kokkos::ALL());
111 const bool check = ParametricDistance<cellTopologyKey>::distance(in) <= 1.0 + threshold_;
112 output_(i) = check;
113 }
114
115 KOKKOS_INLINE_FUNCTION
116 void
117 operator()(const ordinal_type i, const ordinal_type j) const {
118 const auto in = Kokkos::subview(input_,i,j,Kokkos::ALL());
119 const bool check = ParametricDistance<cellTopologyKey>::distance(in) <= 1.0 + threshold_;
120 output_(i,j) = check;
121 }
122 };
123
124
125 template<typename DeviceType>
126 template<unsigned cellTopologyKey,
127 typename OutputViewType,
128 typename InputViewType>
130 checkPointwiseInclusion( OutputViewType inCell,
131 const InputViewType points,
132 const typename ScalarTraits<typename InputViewType::value_type>::scalar_type threshold) {
133
134 using FunctorType = checkPointInclusionFunctor<cellTopologyKey,decltype(inCell),decltype(points)>;
135 if (points.rank() == 2) { // inCell.rank() == 1
136 Kokkos::RangePolicy<typename DeviceType::execution_space> policy(0, points.extent(0));
137 Kokkos::parallel_for(policy, FunctorType(inCell, points, threshold));
138 } else { //points.rank() == 3, inCell.rank() == 2
139 Kokkos::MDRangePolicy<typename DeviceType::execution_space,Kokkos::Rank<2>> policy({0,0},{points.extent(0),points.extent(1)});
140 Kokkos::parallel_for(policy, FunctorType(inCell, points, threshold));
141 }
142 }
143
144
145 template<typename DeviceType>
146 template<typename InCellViewType,
147 typename InputViewType>
148 void
150 checkPointwiseInclusion( InCellViewType inCell,
151 const InputViewType points,
152 const shards::CellTopology cellTopo,
153 const typename ScalarTraits<typename InputViewType::value_type>::scalar_type threshold ) {
154#ifdef HAVE_INTREPID2_DEBUG
155 {
156 INTREPID2_TEST_FOR_EXCEPTION( (inCell.rank() != 1) && (inCell.rank() != 2), std::invalid_argument,
157 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): InCell must have rank 1 or 2. ");
158 INTREPID2_TEST_FOR_EXCEPTION( points.extent(points.rank()-1) != cellTopo.getDimension(), std::invalid_argument,
159 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): Points and cell dimensions do not match. ");
160 INTREPID2_TEST_FOR_EXCEPTION( inCell.rank() != (points.rank()-1), std::invalid_argument,
161 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): rank difference between inCell and points is 1.");
162 const ordinal_type iend = inCell.rank();
163
164 for (ordinal_type i=0;i<iend;++i) {
165 INTREPID2_TEST_FOR_EXCEPTION( inCell.extent(i) != points.extent(i), std::invalid_argument,
166 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): dimension mismatch between inCell and points. " );
167 }
168 }
169#endif
170
171 const auto key = cellTopo.getBaseKey();
172 switch (key) {
173
174 case shards::Line<>::key :
175 checkPointwiseInclusion<shards::Line<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
176 break;
177
178 case shards::Beam<>::key :
179 checkPointwiseInclusion<shards::Beam<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
180 break;
181
182 case shards::ShellLine<>::key :
183 checkPointwiseInclusion<shards::ShellLine<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
184 break;
185
186 case shards::Triangle<>::key :
187 checkPointwiseInclusion<shards::Triangle<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
188 break;
189
190 case shards::ShellTriangle<>::key :
191 checkPointwiseInclusion<shards::ShellTriangle<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
192 break;
193
194 case shards::Quadrilateral<>::key :
195 checkPointwiseInclusion<shards::Quadrilateral<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
196 break;
197
198 case shards::ShellQuadrilateral<>::key :
199 checkPointwiseInclusion<shards::ShellQuadrilateral<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
200 break;
201
202 case shards::Tetrahedron<>::key :
203 checkPointwiseInclusion<shards::Tetrahedron<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
204 break;
205
206 case shards::Hexahedron<>::key :
207 checkPointwiseInclusion<shards::Hexahedron<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
208 break;
209
210 case shards::Wedge<>::key :
211 checkPointwiseInclusion<shards::Wedge<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
212 break;
213
214 case shards::Pyramid<>::key :
215 checkPointwiseInclusion<shards::Pyramid<>::key,decltype(inCell),decltype(points)>(inCell, points, threshold);
216 break;
217
218 default:
219 INTREPID2_TEST_FOR_EXCEPTION( true,
220 std::invalid_argument,
221 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): Invalid cell topology. ");
222 }
223 }
224
225 template<typename DeviceType>
226 template<typename inCellValueType, class ...inCellProperties,
227 typename pointValueType, class ...pointProperties,
228 typename cellWorksetValueType, class ...cellWorksetProperties>
229 bool
231 checkPointwiseInclusion( Kokkos::DynRankView<inCellValueType,inCellProperties...> inCell,
232 const Kokkos::DynRankView<pointValueType,pointProperties...> points,
233 const Kokkos::DynRankView<cellWorksetValueType,cellWorksetProperties...> cellWorkset,
234 const shards::CellTopology cellTopo,
235 const typename ScalarTraits<pointValueType>::scalar_type threshold,
236 const typename ScalarTraits<pointValueType>::scalar_type shellThickness ) {
237#ifdef HAVE_INTREPID2_DEBUG
238 {
239 const auto key = cellTopo.getBaseKey();
240 const bool isShellorBeam = (key == shards::Beam<>::key) || (key == shards::ShellLine<>::key) || (key == shards::ShellTriangle<>::key) || (key == shards::ShellQuadrilateral<>::key);
241 INTREPID2_TEST_FOR_EXCEPTION( key != shards::Line<>::key &&
242 key != shards::Triangle<>::key &&
243 key != shards::Quadrilateral<>::key &&
244 key != shards::Tetrahedron<>::key &&
245 key != shards::Hexahedron<>::key &&
246 key != shards::Wedge<>::key &&
247 key != shards::Pyramid<>::key &&
248 !isShellorBeam,
249 std::invalid_argument,
250 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): cell topology not supported");
251 INTREPID2_TEST_FOR_EXCEPTION( inCell.rank() != 2, std::invalid_argument,
252 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): InCell must have rank 2. ");
253 INTREPID2_TEST_FOR_EXCEPTION( cellWorkset.rank() != 3, std::invalid_argument,
254 ">>> ERROR (Intrepid2::CellTools::checkPointwiseInclusion): cellWorkset must have rank 3. ");
255 INTREPID2_TEST_FOR_EXCEPTION( (points.rank() == 3) && (points.extent(0) != cellWorkset.extent(0)) , std::invalid_argument,
256 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): cellWorkset and points have incompatible dimensions. ");
257 INTREPID2_TEST_FOR_EXCEPTION( isShellorBeam && (shellThickness < 0.0) , std::invalid_argument,
258 ">>> ERROR (Intrepid2::CellTools::checkPointInclusion): beam and shell topologies require cell thickness information. ");
259 }
260#endif
261 const ordinal_type
262 numCells = cellWorkset.extent(0),
263 numPoints = points.extent(points.rank()-2),
264 spaceDim = cellTopo.getDimension();
265
266 auto refPoints = Impl::createMatchingDynRankView(points, "CellTools::checkPointwiseInclusion::refPoints", numCells, numPoints, spaceDim);
267
268 bool isValid(false);
269
270 // expect refPoints(CPD), points (CPD or PD), cellWorkset(CND)
271 if(points.rank() == 3)
272 isValid = mapToReferenceFrame(refPoints, points, cellWorkset, cellTopo, shellThickness);
273 else { //points.rank() == 2
274 auto cellPoints = Impl::createMatchingDynRankView(points, "CellTools::checkPointwiseInclusion::physCellPoints", numCells, numPoints, points.extent_int(1));
275 RealSpaceTools<DeviceType>::clone(cellPoints,points);
276 isValid = mapToReferenceFrame(refPoints, cellPoints, cellWorkset, cellTopo, shellThickness);
277 }
278 checkPointwiseInclusion(inCell, refPoints, cellTopo, threshold);
279 return isValid;
280 }
281
282}
283
284#endif
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...
static ScalarTraits< typenamePointViewType::value_type >::scalar_type parametricDistance(const PointViewType refPoint, const shards::CellTopology cellTopo)
Compute the parametric distance of the point in the specified reference cell. The parametric distance...
static bool mapToReferenceFrame(Kokkos::DynRankView< refPointValueType, refPointProperties... > refPoints, const Kokkos::DynRankView< physPointValueType, physPointProperties... > physPoints, const Kokkos::DynRankView< worksetCellValueType, worksetCellProperties... > worksetCell, const shards::CellTopology cellTopo, const physPointValueType shellThickness=-1.0)
Computes , the inverse of the reference-to-physical frame map using a default initial guess.
static void checkPointwiseInclusion(OutputViewType inCell, const InputViewType refPoints, const typename ScalarTraits< typename InputViewType::value_type >::scalar_type thresh=threshold< typename ScalarTraits< typename InputViewType::value_type >::scalar_type >())
Checks every point for inclusion in the reference cell of a given topology. The points can belong to ...
virtual ordinal_type getDimension() const
Returns dimension of the integration domain.
static void clone(Kokkos::DynRankView< outputValueType, outputProperties... > output, const Kokkos::DynRankView< inputValueType, inputProperties... > input)
Clone input array.
This class implements a distance function that computes the parametric distance of a point in a refer...