Documentation 6b54b78464
Loading...
Searching...
No Matches
CADTElemClass.hpp
Go to the documentation of this file.
1/*!
2 * \file CADTElemClass.hpp
3 * \brief Class for storing an ADT of (linear) elements in an arbitrary number of dimensions.
4 * \author E. van der Weide
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#pragma once
29
30#include "./CADTBaseClass.hpp"
32#include "../parallelization/omp_structure.hpp"
33
34/*!
35 * \class CADTElemClass
36 * \ingroup ADT
37 * \brief Class for storing an ADT of (linear) elements in an arbitrary number of dimensions.
38 * \author E. van der Weide
39 * \version 8.5.0 "Harrier"
40 */
42 private:
43 unsigned short nDim; /*!< \brief Number of spatial dimensions. */
44
45 vector<su2double> coorPoints; /*!< \brief Vector, which contains the coordinates
46 of the points in the ADT. */
47 vector<su2double> BBoxCoor; /*!< \brief Vector, which contains the coordinates
48 of the bounding boxes of the elements. */
49
50 vector<unsigned short> elemVTK_Type; /*!< \brief Vector, which the type of the elements
51 using the VTK convention. */
52 vector<unsigned long> nDOFsPerElem; /*!< \brief Vector, which contains the number of DOFs
53 of the elements in the ADT in cumulative
54 storage format. */
55 vector<unsigned long> elemConns; /*!< \brief Vector, which contains the connectivities
56 of the elements in the ADT. */
57 vector<unsigned short> localMarkers; /*!< \brief Vector, which contains the marker ID's
58 of the elements in the ADT. */
59 vector<unsigned long> localElemIDs; /*!< \brief Vector, which contains the local element ID's
60 of the elements in the ADT. */
61 vector<int> ranksOfElems; /*!< \brief Vector, which contains the ranks
62 of the elements in the ADT. */
63#ifdef HAVE_OMP
64 vector<vector<CBBoxTargetClass> > BBoxTargets; /*!< \brief Vector, used to store possible bounding box
65 candidates during the nearest element search. */
66#else
67 array<vector<CBBoxTargetClass>, 1> BBoxTargets;
68#endif
69 public:
70 /*!
71 * \brief Constructor of the class.
72 * \param[in] val_nDim Number of spatial dimensions of the problem.
73 * \param[in] val_coor Coordinates of the local points to be stored in the ADT.
74 * \param[in,out] val_connElem Local connectivity of the elements to be stored in the ADT.
75 In parallel mode the connectivities are corrected for the
76 offset in node numbers of the rank.
77 * \param[in] val_VTKElem Type of the elements using the VTK convention.
78 * \param[in] val_markerID Markers of the local elements.
79 * \param[in] val_elemID Local element IDs of the elements.
80 * \param[in] globalTree Whether or not a global tree must be built. If false
81 a local ADT is built.
82 */
83 CADTElemClass(unsigned short val_nDim, vector<su2double>& val_coor, vector<unsigned long>& val_connElem,
84 vector<unsigned short>& val_VTKElem, vector<unsigned short>& val_markerID,
85 vector<unsigned long>& val_elemID, const bool globalTree);
86
87 /*!
88 * \brief Function, which determines the element that contains the given coordinate.
89 * \note This simply forwards the call to the implementation function selecting the right
90 * working variables for the current thread.
91 * \param[in] coor Coordinate which the element must contain.
92 * \param[out] markerID Local marker ID of the element containing the coordinate.
93 * \param[out] elemID Local element ID of the element containing the coordinate.
94 * \param[out] rankID Rank on which element containing the coordinate is stored.
95 * \param[out] parCoor Parametric coordinates of coor inside the element,
96 which contains the coordinate.
97 * \param[out] weightsInterpol Interpolation weights of coor inside the element,
98 which contains the coordinate.
99 * \return True if an element is found, false if not.
100 */
101 inline bool DetermineContainingElement(const su2double* coor, unsigned short& markerID, unsigned long& elemID,
102 int& rankID, su2double* parCoor, su2double* weightsInterpol) {
103 const auto iThread = omp_get_thread_num();
104 return DetermineContainingElement_impl(FrontLeaves[iThread], FrontLeavesNew[iThread], coor, markerID, elemID,
105 rankID, parCoor, weightsInterpol);
106 }
107
108 /*!
109 * \brief Function, which determines the nearest element in the ADT for the given coordinate.
110 * \note This simply forwards the call to the implementation function selecting the right
111 * working variables for the current thread.
112 * \param[in] coor Coordinate for which the nearest element in the ADT must be determined.
113 * \param[out] dist Distance to the nearest element in the ADT.
114 * \param[out] markerID Local marker ID of the nearest element in the ADT.
115 * \param[out] elemID Local element ID of the nearest element in the ADT.
116 * \param[out] rankID Rank on which the nearest element in the ADT is stored.
117 */
118 inline void DetermineNearestElement(const su2double* coor, su2double& dist, unsigned short& markerID,
119 unsigned long& elemID, int& rankID) {
120 const auto iThread = omp_get_thread_num();
121 DetermineNearestElement_impl(BBoxTargets[iThread], FrontLeaves[iThread], FrontLeavesNew[iThread], coor, dist,
122 markerID, elemID, rankID);
123 }
124
125 private:
126 /*!
127 * \brief Implementation of DetermineContainingElement.
128 * \note Working variables (first two) passed explicitly for thread safety.
129 */
130 bool DetermineContainingElement_impl(vector<unsigned long>& frontLeaves, vector<unsigned long>& frontLeavesNew,
131 const su2double* coor, unsigned short& markerID, unsigned long& elemID,
132 int& rankID, su2double* parCoor, su2double* weightsInterpol) const;
133
134 /*!
135 * \brief Implementation of DetermineNearestElement.
136 * \note Working variables (first three) passed explicitly for thread safety.
137 */
138 void DetermineNearestElement_impl(vector<CBBoxTargetClass>& BBoxTargets, vector<unsigned long>& frontLeaves,
139 vector<unsigned long>& frontLeavesNew, const su2double* coor, su2double& dist,
140 unsigned short& markerID, unsigned long& elemID, int& rankID) const;
141
142 /*!
143 * \brief Function, which checks whether or not the given coordinate is
144 inside the given element.
145 * \param[in] elemID ID of the element for which the containment
146 must be checked.
147 * \param[in] coor Coordinate for which the containment must be checked.
148 * \param[out] parCoor Parametric coordinates of coor if it is inside the
149 given element.
150 * \param[out] weightsInterpol Interpolation weights of coor if it is inside the
151 given element.
152 * \return True if coor is inside the element and false otherwise.
153 */
154 bool CoorInElement(const unsigned long elemID, const su2double* coor, su2double* parCoor,
155 su2double* weightsInterpol) const;
156
157 /*!
158 * \brief Function, which checks whether or not the given coordinate is
159 inside the given quadrilateral.
160 * \param[in] elemID ID of the quadrilateral for which the containment
161 must be checked.
162 * \param[in] coor Coordinate for which the containment must be checked.
163 * \param[out] parCoor Parametric coordinates of coor if it is inside the
164 given quadrilateral.
165 * \param[out] weightsInterpol Interpolation weights of coor if it is inside the
166 given quadrilateral.
167 * \return True if coor is inside the quadrilateral and false otherwise.
168 */
169 bool CoorInQuadrilateral(const unsigned long elemID, const su2double* coor, su2double* parCoor,
170 su2double* weightsInterpol) const;
171
172 /*!
173 * \brief Function, which checks whether or not the given coordinate is
174 inside the given triangle.
175 * \param[in] elemID ID of the triangle for which the containment
176 must be checked.
177 * \param[in] coor Coordinate for which the containment must be checked.
178 * \param[out] parCoor Parametric coordinates of coor if it is inside the
179 given triangle.
180 * \param[out] weightsInterpol Interpolation weights of coor if it is inside the
181 given triangle.
182 * \return True if coor is inside the triangle and false otherwise.
183 */
184 bool CoorInTriangle(const unsigned long elemID, const su2double* coor, su2double* parCoor,
185 su2double* weightsInterpol) const;
186
187 /*!
188 * \brief Function, which checks whether or not the given coordinate is
189 inside the given hexahedron.
190 * \param[in] elemID ID of the hexahedron for which the containment
191 must be checked.
192 * \param[in] coor Coordinate for which the containment must be checked.
193 * \param[out] parCoor Parametric coordinates of coor if it is inside the
194 given hexahedron.
195 * \param[out] weightsInterpol Interpolation weights of coor if it is inside the
196 given hexahedron.
197 * \return True if coor is inside the hexahedron and false otherwise.
198 */
199 bool CoorInHexahedron(const unsigned long elemID, const su2double* coor, su2double* parCoor,
200 su2double* weightsInterpol) const;
201
202 /*!
203 * \brief Function, which checks whether or not the given coordinate is
204 inside the given prism.
205 * \param[in] elemID ID of the prism for which the containment
206 must be checked.
207 * \param[in] coor Coordinate for which the containment must be checked.
208 * \param[out] parCoor Parametric coordinates of coor if it is inside the
209 given prism.
210 * \param[out] weightsInterpol Interpolation weights of coor if it is inside the
211 given prism.
212 * \return True if coor is inside the prism and false otherwise.
213 */
214 bool CoorInPrism(const unsigned long elemID, const su2double* coor, su2double* parCoor,
215 su2double* weightsInterpol) const;
216
217 /*!
218 * \brief Function, which checks whether or not the given coordinate is
219 inside the given pyramid.
220 * \param[in] elemID ID of the pyramid for which the containment
221 must be checked.
222 * \param[in] coor Coordinate for which the containment must be checked.
223 * \param[out] parCoor Parametric coordinates of coor if it is inside the
224 given pyramid.
225 * \param[out] weightsInterpol Interpolation weights of coor if it is inside the
226 given pyramid.
227 * \return True if coor is inside the pyramid and false otherwise.
228 */
229 bool CoorInPyramid(const unsigned long elemID, const su2double* coor, su2double* parCoor,
230 su2double* weightsInterpol) const;
231
232 /*!
233 * \brief Function, which checks whether or not the given coordinate is
234 inside the given tetrahedron.
235 * \param[in] elemID ID of the tetrahedron for which the containment
236 must be checked.
237 * \param[in] coor Coordinate for which the containment must be checked.
238 * \param[out] parCoor Parametric coordinates of coor if it is inside the
239 given tetrahedron.
240 * \param[out] weightsInterpol Interpolation weights of coor if it is inside the
241 given tetrahedron.
242 * \return True if coor is inside the tetrahedron and false otherwise.
243 */
244 bool CoorInTetrahedron(const unsigned long elemID, const su2double* coor, su2double* parCoor,
245 su2double* weightsInterpol) const;
246
247 /*!
248 * \brief Function, which provides an initial guess for the parametric coordinates
249 of the given point inside a hexahedron by splitting it into tetrahedra.
250 * \param[in] xRelC Coordinates of the point to be investigated relative to
251 vertex 0 of the hexahedron.
252 * \param[in] xRel Coordinates of the vertices of the hexahedron relative to
253 vertex 0.
254 * \param[out] parCoor Initial guess of the parametric coordinates.
255 * \return True if the initial guess is within the hexahedron and
256 false otherwise.
257 */
258 bool InitialGuessContainmentHexahedron(const su2double xRelC[3], const su2double xRel[8][3],
259 su2double* parCoor) const;
260
261 /*!
262 * \brief Function, which provides an initial guess for the parametric coordinates
263 of the given point inside a prism by splitting it into tetrahedra.
264 * \param[in] xRelC Coordinates of the point to be investigated relative to
265 vertex 0 of the prism.
266 * \param[in] xRel Coordinates of the vertices of the prism relative to
267 vertex 0.
268 * \param[out] parCoor Initial guess of the parametric coordinates.
269 * \return True if the initial guess is within the prism and
270 false otherwise.
271 */
272 bool InitialGuessContainmentPrism(const su2double xRelC[3], const su2double xRel[6][3], su2double* parCoor) const;
273
274 /*!
275 * \brief Function, which provides an initial guess for the parametric coordinates
276 of the given point inside a pyramid by splitting it into tetrahedra.
277 * \param[in] xRelC Coordinates of the point to be investigated relative to
278 vertex 0 of the pyramid.
279 * \param[in] xRel Coordinates of the vertices of the pyramid relative to
280 vertex 0.
281 * \param[out] parCoor Initial guess of the parametric coordinates.
282 * \return True if the initial guess is within the pyramid and
283 false otherwise.
284 */
285 bool InitialGuessContainmentPyramid(const su2double xRelC[3], const su2double xRel[5][3], su2double* parCoor) const;
286
287 /*!
288 * \brief Function, which computes the distance squared of the given coordinate
289 to the given element.
290 * \param[in] elemID ID of the element to which the distance must be determined.
291 * \param[in] coor Coordinate for which the distance to the element must be determined.
292 * \param[out] dist2Elem Distance squared from the coordinate to the element.
293 */
294 void Dist2ToElement(const unsigned long elemID, const su2double* coor, su2double& dist2Elem) const;
295 /*!
296 * \brief Function, which computes the distance squared of the given coordinate
297 to a linear line element.
298 * \param[in] i0 Starting index in coorPoints, where the coordinates of the
299 first point of the line are stored.
300 * \param[in] i1 Starting index in coorPoints, where the coordinates of the
301 second point of the line are stored.
302 * \param[in] coor Coordinate for which the distance to the line must be determined.
303 * \param[out] dist2Line Distance squared from the coordinate to the line.
304 */
305 void Dist2ToLine(const unsigned long i0, const unsigned long i1, const su2double* coor, su2double& dist2Line) const;
306 /*!
307 * \brief Function, which computes the distance squared of the given coordinate
308 to a linear quadrilateral element if the projection is inside the quad.
309 * \param[in] i0 Starting index in coorPoints, where the coordinates of the
310 first point of the quadrilateral are stored.
311 * \param[in] i1 Starting index in coorPoints, where the coordinates of the
312 second point of the quadrilateral are stored.
313 * \param[in] i2 Starting index in coorPoints, where the coordinates of the
314 third point of the quadrilateral are stored.
315 * \param[in] i3 Starting index in coorPoints, where the coordinates of the
316 fourth point of the quadrilateral are stored.
317 * \param[in] coor Coordinate for which the distance to the quadrilateral
318 must be determined.
319 * \param[out] r Parametric coordinate of the projection.
320 * \param[out] s Parametric coordinate of the projection.
321 * \param[out] dist2Quad Distance squared from the coordinate to the quadrilateral.
322 * \return True if the projection is inside the quadrilateral and false otherwise.
323 */
324 bool Dist2ToQuadrilateral(const unsigned long i0, const unsigned long i1, const unsigned long i2,
325 const unsigned long i3, const su2double* coor, su2double& r, su2double& s,
326 su2double& dist2Quad) const;
327 /*!
328 * \brief Function, which computes the distance squared of the given coordinate
329 to a linear triangular element if the projection is inside the triangle.
330 * \param[in] i0 Starting index in coorPoints, where the coordinates of the
331 first point of the triangle are stored.
332 * \param[in] i1 Starting index in coorPoints, where the coordinates of the
333 second point of the triangle are stored.
334 * \param[in] i2 Starting index in coorPoints, where the coordinates of the
335 third point of the triangle are stored.
336 * \param[in] coor Coordinate for which the distance to the triangle must be determined.
337 * \param[out] dist2Tria Distance squared from the coordinate to the triangle.
338 * \param[out] r Parametric coordinate of the projection.
339 * \param[out] s Parametric coordinate of the projection.
340 * \return True if the projection is inside the triangle and false otherwise.
341 */
342 bool Dist2ToTriangle(const unsigned long i0, const unsigned long i1, const unsigned long i2, const su2double* coor,
343 su2double& dist2Tria, su2double& r, su2double& s) const;
344 /*!
345 * \brief Default constructor of the class, disabled.
346 */
347 CADTElemClass() = delete;
348};
Base class for storing an ADT in an arbitrary number of dimensions.
Class for storing the information of a possible bounding box candidate during a minimum distance sear...
Base class for storing an ADT in an arbitrary number of dimensions.
Definition CADTBaseClass.hpp:45
array< vector< unsigned long >, 1 > FrontLeaves
Definition CADTBaseClass.hpp:57
array< vector< unsigned long >, 1 > FrontLeavesNew
Definition CADTBaseClass.hpp:58
Class for storing an ADT of (linear) elements in an arbitrary number of dimensions.
Definition CADTElemClass.hpp:41
bool DetermineContainingElement(const su2double *coor, unsigned short &markerID, unsigned long &elemID, int &rankID, su2double *parCoor, su2double *weightsInterpol)
Function, which determines the element that contains the given coordinate.
Definition CADTElemClass.hpp:101
void DetermineNearestElement(const su2double *coor, su2double &dist, unsigned short &markerID, unsigned long &elemID, int &rankID)
Function, which determines the nearest element in the ADT for the given coordinate.
Definition CADTElemClass.hpp:118
passivedouble su2double
Definition code_config.hpp:181
constexpr int omp_get_thread_num()
Index of current thread, akin to MPI rank.
Definition omp_structure.hpp:85