TriPatchIntersection.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::TriPatchIntersection
26 
27 Description
28  Patch intersection based on triangular faces. Intersects and combines two
29  triangulated patches incrementally. The intersected surface is valid at
30  every stage of the process. Failure to intersect does not produce a
31  catastrophic error. Rather, it results in regions of the surface remaining
32  associated with only one of the source or the target patch.
33 
34 SourceFiles
35  TriPatchIntersection.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef TriPatchIntersection_H
40 #define TriPatchIntersection_H
41 
42 #include "PatchIntersection.H"
43 #include "star.H"
44 #include "polygonTriangulate.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class TriPatchIntersection Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 template<class SrcPatchType, class TgtPatchType>
57 :
58  public PatchIntersection<SrcPatchType, TgtPatchType>
59 {
60 private:
61 
62  // Private Data
63 
64  // Points
65 
66  //- The source points
67  DynamicField<point> srcPoints_;
68 
69  //- The source point normals
70  DynamicField<vector> srcPointNormals_;
71 
72  //- The target points. Reference to base class data.
73  DynamicField<point>& tgtPoints_;
74 
75  //- Point-point addressing. Facilitates quick point removal.
76  // Instead of shuffling up, when points are combined this just
77  // acts as a redirect. Everything gets resolved on clean.
78  DynamicList<label> pointPoints_;
79 
80 
81  // Edges
82 
83  //- The two triangles adjacent to each edge
84  DynamicList<labelPair> edgeTris_;
85 
86  //- ...
87  DynamicList<labelPair> intersectEdgeFaces_;
88 
89  //- ...
90  DynamicList<labelPair> nonIntersectEdgeFaces_;
91 
92 
93  // Tris
94 
95  //- The triangles' points
96  DynamicList<triFace> triPoints_;
97 
98  //- The triangles' edges
100 
101  //- The source patch face associated with each triangle. -1 if not
102  // associated with a source face.
103  DynamicList<label> triSrcFace_;
104 
105  //- The target patch face associated with each triangle. -1 if not
106  // associated with a target face.
107  DynamicList<label> triTgtFace_;
108 
109  //- The triangles constructed from each source patch face
110  List<DynamicList<label>> srcFaceTris_;
111 
112  //- The triangles constructed from each target patch face
113  List<DynamicList<label>> tgtFaceTris_;
114 
115 
116  // Faces
117 
118  //- ...
119  DynamicList<labelList> faceEdges_;
120 
121 
122  // Removal
123 
124  //- Indices of triangles that have been removed. Prevents shuffling
125  // up and re-allocation during intersection. Cleared out on clean.
126  DynamicList<label> removedTris_;
127 
128  //- Indices of edges that have been removed. Prevents shuffling
129  // up and re-allocation during intersection. Cleared out on clean.
130  DynamicList<label> removedEdges_;
131 
132 
133  // Front propagation
134 
135  //- The edges in the front along which the intersection propagates
136  DynamicList<label> frontEdgeEdges_;
137 
138  //- Inverse of the above
139  DynamicList<label> edgeFrontEdges_;
140 
141 
142  // Insertion
143 
144  //- Indices of triangles considered candidates for insertion
145  DynamicList<label> candidateTriTris_;
146 
147  //- Inverse of the above
148  DynamicList<label> triCandidateTris_;
149 
150 
151  // Marking
152 
153  //- Indices of triangles that have been "marked". Used for multiple
154  // purposes.
155  DynamicList<label> markedTriTris_;
156 
157  //- Inverse of the above
158  DynamicList<label> triMarkedTris_;
159 
160 
161  // Triangulation
162 
163  //- Triangulation engine
164  polygonTriangulate polygonTriangulate_;
165 
166 
167  // Polygon generation
168 
169  //- Star propagation engine
170  star star_;
171 
172 
173  // Debugging
174 
175  //- Iteration counter with which to number surface files
176  label writei_;
177 
178 
179  // Private Member Functions
180 
181  //- Check consistency of the mesh
182  void checkPatchFace(const label patchFacei, const bool isSrc) const;
183  void checkPatchEdge(const label patchFacei, const bool isSrc) const;
184  void checkPatchFaces(const bool isSrc) const;
185 
186  //- Remove an edge
187  void removeEdge(const label edgei);
188 
189  //- Remove a tri
190  void removeTri(const label trii);
191 
192  //- Create a new triangle and return it's index
193  label newTrii();
194 
195  //- Create a new edge and return it's index
196  label newEdgei();
197 
198  //- Create a new point and return it's index
199  label newPointi();
200 
201  //- Return a point of a given triangle
202  label triPoint(const label trii, const label triPointi) const;
203 
204  //- Return the points of a given triangle
205  triFace triPoints(const label trii) const;
206 
207  //- Get the values on the points of a given triangle
208  template <class Type>
209  FixedList<Type, 3> triPointValues
210  (
211  const label trii,
212  const UList<Type> values
213  ) const;
214 
215  //- Get a list indicating whether a tri "owns" it's edges; i.e.,
216  // whether they are numbered in the same order as the points
217  FixedList<bool, 3> triOwns(const label trii) const;
218 
219  //- Get the shared point indices of another tri in a tri, or -1 if
220  // the point is not shared
221  FixedList<label, 3> triOtherTriPoints
222  (
223  const label trii,
224  const label otherTrii
225  ) const;
226 
227  //- Get the shared edge indices of another tri in a tri, or -1 if
228  // the point is not shared
229  FixedList<label, 3> triOtherTriEdges
230  (
231  const label trii,
232  const label otherTrii
233  ) const;
234 
235  //- Return the tri-edge-points for a given tri-edge
236  edge triEdgePoints(const label trii, const label triEdgei) const;
237 
238  //- Return the edge-points for a given edge
239  edge edgePoints(const label edgei) const;
240 
241  //- Return a point for the given patch face
242  label patchFacePoint
243  (
244  const label patchFacei,
245  const label patchFacePointi,
246  const bool isSrc
247  ) const;
248 
249  //- Return the points for the given patch face
250  triFace patchFacePoints
251  (
252  const label patchFacei,
253  const bool isSrc
254  ) const;
255 
256  //- Get the values on the points of a given patch face
257  template <class Type>
258  FixedList<Type, 3> patchFacePointValues
259  (
260  const label patchFacei,
261  const bool isSrc,
262  const UList<Type>& values
263  ) const;
264 
265  //- Get a list indicating whether a patch face "owns" it's edges; i.e.,
266  // whether they are numbered in the same order as the points
267  FixedList<bool, 3> patchFaceOwns
268  (
269  const label patchFacei,
270  const bool isSrc
271  ) const;
272 
273  //- Get the shared point indices of another patch face in a patch face,
274  // or -1 if the point is not shared
275  FixedList<label, 3> patchFaceOtherPatchFacePoints
276  (
277  const label patchFacei,
278  const label otherPatchFacei,
279  const bool isSrc
280  ) const;
281 
282  //- Return a patch point for the given patch face
283  label patchFacePatchPoint
284  (
285  const label patchFacei,
286  const label patchFacePointi,
287  const bool isSrc
288  ) const;
289 
290  //- Return the patch points for the given patch face
291  triFace patchFacePatchPoints
292  (
293  const label patchFacei,
294  const bool isSrc
295  ) const;
296 
297  //- Return a patch edge for the given patch face
298  label patchFacePatchEdge
299  (
300  const label patchFacei,
301  const label patchFaceEdgei,
302  const bool isSrc
303  ) const;
304 
305  //- Return the patch edges for the given patch face
306  triFace patchFacePatchEdges
307  (
308  const label patchFacei,
309  const bool isSrc
310  ) const;
311 
312  //- Compute the patch edge that a given edge lies along
313  label edgePatchEdge(const label edgei, const bool isSrc) const;
314 
315  //- Compute the patch edges that a given edge lies along
316  labelPair edgePatchEdges(const label edgei) const;
317 
318  //- Add a tri. Return the new tri label.
319  label addTri
320  (
321  const triFace& pointis,
322  const FixedList<label, 3>& edgeis,
323  const label patchFacei,
324  const bool isSrc
325  );
326 
327  //- Flip an edge
328  void flipEdge(const label edgei);
329 
330  //- Return the signed distance squared of the given point outside of a
331  // triangle's circumcircle. A negative value means the point is inside
332  // the circle.
333  scalar circumDistSqr(const label trii, const label pointi) const;
334 
335  //- Insert points into the given tri or edge. If an edge, points are to
336  // be given in order along the edge.
337  void insertPoints
338  (
339  const label triOrEdgei,
340  const bool isTri,
341  const UList<label>& pointis,
342  UList<label>& insertionEdgeis,
343  const UList<label>& fixedEdgeis
344  );
345 
346  //- Return whether or not a point can be intersected with the other side
347  bool pointCanIntersect(const label pointi) const;
348 
349  //- Return whether or not an edge can be intersected with the other side
350  bool edgeCanIntersect(const label pointi) const;
351 
352  /*
353  //- Snap points to points and edges between two tris
354  // !!! Not a good idea. Gets tangled up. Need to snap entire faces.
355  bool snapTris(const label srcTrii, const label tgtTrii);
356  */
357 
358  //- Snap points to points and edges between two patch faces
359  void snapPatchFaceTris
360  (
361  const label srcFacei,
362  const label tgtFacei,
363  const scalar snapTol
364  );
365 
366  //- Intersect two tris
367  bool intersectTris(const label srcTrii, const label tgtTrii);
368 
369  //- Intersect the triangulations of the given patch faces
370  void intersectPatchFaceTris
371  (
372  const label srcFacei,
373  const label tgtFacei
374  );
375 
376  //- Make the triangulations of the given patch faces conform
377  bool conformPatchFaceTris
378  (
379  const label patchFacei,
380  const label otherPatchFacei,
381  const bool isSrc
382  );
383 
384  //- Make the triangulations of the given patch faces conform
385  bool conformPatchFaceTris
386  (
387  const label srcFacei,
388  const label tgtFacei
389  );
390 
391  //- Combine conformal parts of the given patch faces into intersection
392  // faces
393  bool combinePatchFaceTris(const label srcFacei, const label tgtFacei);
394 
395  //- Initialise the member data
396  void initialise(const vectorField& srcPointNormals);
397 
398  //- Clean up removed tris and edges
399  void clean();
400 
401  //- Finalise the data in the base class
402  void finalise();
403 
404  //- Undo the finalise process so the intersection process can continue
405  void unFinalise();
406 
407  //- Write the current state of the surfaces for debugging purposes
408  void write();
409 
410  //- Write the current state of the given patch face triangulation for
411  // debugging purposes
412  void writePatchFace(const label patchFacei, const bool isSrc) const;
413 
414 
415 public:
416 
417  // Runtime type information
418 
419  virtual word type() const
420  {
421  return "tri" + patchIntersection::typeName.capitalise();
422  }
423 
424 
425  // Constructors
426 
427  //- Construct from a source and a target patch
429  (
430  const SrcPatchType& srcPatch,
431  const TgtPatchType& tgtPatch,
432  const scalar snapTol
433  );
434 
435  //- Construct from a source and a target patch, and specified source
436  // point normals
438  (
439  const SrcPatchType& srcPatch,
440  const vectorField& srcPointNormals,
441  const TgtPatchType& tgtPatch,
442  const scalar snapTol
443  );
444 
445 
446  // Member Functions
447 
448  // Access
449 
450  //- ...
451  inline const DynamicList<labelList>& faceEdges() const
452  {
453  return faceEdges_;
454  }
455 
456  //- ...
457  inline const DynamicList<labelPair>& intersectEdgeFaces() const
458  {
459  return intersectEdgeFaces_;
460  }
461 
462  //- ...
463  inline const DynamicList<labelPair>& nonIntersectEdgeFaces() const
464  {
465  return nonIntersectEdgeFaces_;
466  }
467 
468 
469  //- Destructor
470  virtual ~TriPatchIntersection();
471 };
472 
473 
474 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
475 
476 } // End namespace Foam
477 
478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
479 
480 #ifdef NoRepository
481  #include "TriPatchIntersection.C"
482 #endif
483 
484 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
485 
486 #endif
487 
488 // ************************************************************************* //
Dynamically sized Field.
Definition: DynamicField.H:72
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
Base class for patch intersections. Provides storage and access to the intersection points and faces ...
const SrcPatchType & srcPatch() const
The source patch.
const TgtPatchType & tgtPatch() const
The target patch.
Patch intersection based on triangular faces. Intersects and combines two triangulated patches increm...
virtual ~TriPatchIntersection()
Destructor.
const DynamicList< labelPair > & intersectEdgeFaces() const
...
TriPatchIntersection(const SrcPatchType &srcPatch, const TgtPatchType &tgtPatch, const scalar snapTol)
Construct from a source and a target patch.
const DynamicList< labelList > & faceEdges() const
...
const DynamicList< labelPair > & nonIntersectEdgeFaces() const
...
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
Triangulation of three-dimensional polygons.
Engine for constructing a star-shaped domain by walking.
Definition: star.H:50
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:71
A class for handling words, derived from string.
Definition: word.H:62
word capitalise() const
Return the word with the first letter capitalised.
Definition: wordI.H:131
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59