intersectionPatchToPatch.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) 2021-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::patchToPatches::intersection
26 
27 Description
28  Class to generate patchToPatch coupling geometry. A full geometric
29  intersection is done between a face and those opposite, and coupling
30  geometry is calculated accordingly.
31 
32 SourceFiles
33  intersection.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef intersectionPatchToPatch_H
38 #define intersectionPatchToPatch_H
39 
40 #include "patchToPatch.H"
41 #include "polygonTriangulate.H"
42 #include "triFaceList.H"
43 #include "triIntersectLocation.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 namespace patchToPatches
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class intersection Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class intersection
57 :
58  public patchToPatch
59 {
60 public:
61 
62  // Public Structures
63 
64  //- Structure to store the geometry associated with part of a patch
65  // face
66  struct part
67  {
68  //- The area of this part
69  vector area;
70 
71  //- The centre of this part
72  point centre;
73 
74  //- Default construct
75  part()
76  :
77  area(Zero),
78  centre(patchToPatchTools::NaN<point>())
79  {}
80 
81  //- Default construct
82  part(const zero&)
83  :
84  part()
85  {}
86 
87  //- Construct from an area and a centre
88  part(const vector& a, const point& c)
89  :
90  area(a),
91  centre(c)
92  {}
93 
94  //- Construct from a polygon
95  template<class PointField>
96  part(const PointField& ps)
97  :
98  area(face::area(ps)),
99  centre(face::centre(ps))
100  {}
101 
102  //- Negate this part
103  part operator-() const
104  {
105  return part(- area, centre);
106  }
107 
108  //- Add another part to this one
109  void operator+=(const part& p)
110  {
111  const scalar magArea = mag(area);
112  const scalar magPArea = mag(p.area);
113 
114  area = area + p.area;
115 
116  centre =
117  magArea == 0 ? p.centre
118  : magPArea == 0 ? centre
119  : (magArea*centre + magPArea*p.centre)/(magArea + magPArea);
120  }
121 
122  //- Subtract another part from this one
123  void operator-=(const part& p)
124  {
125  this->operator+=(-p);
126  }
127 
128  //- Equality comparison
129  friend bool operator==(const part& a, const part& b)
130  {
131  return a.area == b.area && a.centre == b.centre;
132  }
133 
134  //- Inequality comparison
135  friend bool operator!=(const part& a, const part& b)
136  {
137  return !(a == b);
138  }
139 
140  //- Output stream operator
141  friend Ostream& operator<<(Ostream& os, const part& p)
142  {
143  return os << p.area << p.centre;
144  }
145 
146  //- Input stream operator
147  friend Istream& operator>>(Istream& is, part& p)
148  {
149  return is >> p.area >> p.centre;
150  }
151  };
152 
153  //- Structure to store the geometry associated with the coupling
154  // between parts of two patch faces
155  struct couple
156  :
157  public part
158  {
159  //- The neighbour part
160  part nbr;
161 
162  //- Default construct
163  couple()
164  :
165  part(),
166  nbr()
167  {}
168 
169  //- Construct from a coupled pair of parts
170  couple(const part& p, const part& nbrP)
171  :
172  part(p),
173  nbr(nbrP)
174  {}
175 
176  //- Equality comparison
177  friend bool operator==(const couple& a, const couple& b)
178  {
179  return
180  static_cast<const part&>(a) == static_cast<const part&>(b)
181  && a.nbr == b.nbr;
182  }
183 
184  //- Inequality comparison
185  friend bool operator!=(const couple& a, const couple& b)
186  {
187  return !(a == b);
188  }
189 
190  //- Output stream operator
191  friend Ostream& operator<<(Ostream& os, const couple& c)
192  {
193  return os << static_cast<const part&>(c) << c.nbr;
194  }
195 
196  //- Input stream operator
197  friend Istream& operator>>(Istream& is, couple& c)
198  {
199  return is >> static_cast<part&>(c) >> c.nbr;
200  }
201  };
202 
203 
204 private:
205 
206  // Private Member Data
207 
208  // Geometry
209 
210  //- The coupling geometry for for each source face
211  List<DynamicList<couple>> srcCouples_;
212 
213  //- The proportion of the source faces that are coupled
214  List<scalar> srcCoverage_;
215 
216  //- The non-coupled geometry associated with each source edge
217  List<part> srcEdgeParts_;
218 
219  //- The non-coupled geometry associated with mismatch in each
220  // source face's couplings
221  List<part> srcErrorParts_;
222 
223  //- The coupling geometry for for each target face
224  List<DynamicList<couple>> tgtCouples_;
225 
226  //- The proportion of the target faces that are coupled
227  List<scalar> tgtCoverage_;
228 
229 
230  //- Triangulation engine
231  mutable polygonTriangulate triEngine_;
232 
233 
234  // Workspace
235 
236  //- Source face triangulation points
237  mutable List<triFaceList> srcTriPoints_;
238 
239  //- Source face triangulation edges
240  mutable List<List<FixedList<label, 3>>> srcTriFaceEdges_;
241 
242  //- Target face triangulation points
243  mutable List<triFaceList> tgtTriPoints_;
244 
245  //- Target face triangulation edges
246  mutable List<List<FixedList<label, 3>>> tgtTriFaceEdges_;
247 
248  //- Source intersection points
249  mutable DynamicList<point> ictSrcPoints_;
250 
251  //- Source intersection point normals
252  mutable DynamicList<vector> ictSrcPointNormals_;
253 
254  //- Target intersection points
255  mutable DynamicList<point> ictTgtPoints_;
256 
257  //- Intersection locations
258  mutable DynamicList<triIntersect::location> ictPointLocations_;
259 
260  //- Source face edge parts
261  DynamicList<part> srcFaceEdgePart_;
262 
263  //- Target face edge parts
264  DynamicList<part> tgtFaceEdgePart_;
265 
266  //- Source face edge parts
267  List<List<part>> srcFaceEdgeParts_;
268 
269 
270  // Debugging
271 
272  //- Intersection points
273  mutable DynamicList<point> debugPoints_;
274 
275  //- Intersection faces
276  mutable DynamicList<labelList> debugFaces_;
277 
278  //- The source face associated with each intersection face
279  mutable DynamicList<label> debugFaceSrcFaces_;
280 
281  //- The target face associated with each intersection face
282  mutable DynamicList<label> debugFaceTgtFaces_;
283 
284  //- The side of the intersection each face is on; 1 is the source
285  // side, -1 is the target side, and 0 is a face that spans the
286  // intersection volume; e.g., an edge or error face.
287  mutable DynamicList<label> debugFaceSides_;
288 
289 
290  // Private Static Member Functions
291 
292  //- Return the values at the points of a tri face
293  template<class Type>
294  static FixedList<Type, 3> triPointValues
295  (
296  const triFace& t,
297  const UList<Type>& values
298  );
299 
300 
301  // Private Member Functions
302 
303  //- Get the bound box for a source face
304  virtual treeBoundBox srcBox
305  (
306  const face& srcFace,
307  const pointField& srcPoints,
308  const vectorField& srcPointNormals
309  ) const;
310 
311  //- Intersect two faces
312  virtual bool intersectFaces
313  (
314  const primitiveOldTimePatch& srcPatch,
315  const vectorField& srcPointNormals,
316  const vectorField& srcPointNormals0,
317  const primitiveOldTimePatch& tgtPatch,
318  const label srcFacei,
319  const label tgtFacei
320  );
321 
322  //- Initialise the workspace
323  virtual void initialise
324  (
325  const primitiveOldTimePatch& srcPatch,
326  const vectorField& srcPointNormals,
327  const vectorField& srcPointNormals0,
328  const primitiveOldTimePatch& tgtPatch
329  );
330 
331  //- Finalise the intersection locally. Trims the local target patch
332  // so that only parts that actually intersect the source remain.
333  // Returns new-to-old map for trimming target-associated data.
334  virtual labelList finaliseLocal
335  (
336  const primitiveOldTimePatch& srcPatch,
337  const vectorField& srcPointNormals,
338  const vectorField& srcPointNormals0,
339  const primitiveOldTimePatch& tgtPatch
340  );
341 
342  //- Send data that resulted from an intersection between the source
343  // patch and a distributed source-local-target patch back to the
344  // original target processes
345  virtual void rDistributeTgt(const primitiveOldTimePatch& tgtPatch);
346 
347  //- Finalise the intersection
348  virtual label finalise
349  (
350  const primitiveOldTimePatch& srcPatch,
351  const vectorField& srcPointNormals,
352  const vectorField& srcPointNormals0,
353  const primitiveOldTimePatch& tgtPatch,
354  const transformer& tgtToSrc
355  );
356 
357  //- For each source face, the coupled target weights
358  virtual tmpNrc<List<DynamicList<scalar>>> srcWeights() const;
359 
360  //- For each target face, the coupled source weights
361  virtual tmpNrc<List<DynamicList<scalar>>> tgtWeights() const;
362 
363 
364 public:
365 
366  //- Runtime type information
367  TypeName("intersection");
368 
369 
370  // Static Data Members
371 
372  //- Extra debugging for intersections between specific faces. Named
373  // "intersectionSrcFace" and "intersectionTgtFace" respectively.
374  static int debugSrcFacei, debugTgtFacei;
375 
376 
377  // Static Member Functions
378 
379  //- Get the bound box for a source face
381  (
382  const face& srcFace,
383  const pointField& srcPoints,
384  const vectorField& srcPointNormals
385  );
386 
387 
388  // Constructors
389 
390  //- Construct from components
391  intersection(const bool reverse);
392 
393 
394  //- Destructor
395  ~intersection();
396 
397 
398  // Member Functions
399 
400  //- For each source face, the source and target areas for each
401  // target coupling
402  inline const List<DynamicList<couple>>& srcCouples() const;
403 
404  //- For each source edge, the non-coupled geometry associated
405  // with its projection
406  inline const List<part>& srcEdgeParts() const;
407 
408  //- For each source face, the area associated with mismatch
409  // across the coupling
410  inline const List<part>& srcErrorParts() const;
411 
412  //- For each target face, the target and source areas for each
413  // source coupling
414  inline const List<DynamicList<couple>>& tgtCouples() const;
415 
416  //- Return the proportion of the source faces that are coupled
417  inline const List<scalar>& srcCoverage() const;
418 
419  //- Return the proportion of the target faces that are coupled
420  inline const List<scalar>& tgtCoverage() const;
421 };
422 
423 
424 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
425 
426 } // End namespace patchToPatches
427 } // End namespace Foam
428 
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
430 
432 
433 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
434 
435 #endif
436 
437 // ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
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
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Class to generate coupling geometry between two primitive patches.
Definition: patchToPatch.H:56
tmp< Field< Type > > tgtToSrc(const Field< Type > &tgtFld) const
Interpolate a target patch field to the source with no left.
bool reverse() const
Flag to indicate that the two patches are co-directional and.
Definition: patchToPatchI.H:31
Class to generate patchToPatch coupling geometry. A full geometric intersection is done between a fac...
TypeName("intersection")
Runtime type information.
const List< DynamicList< couple > > & tgtCouples() const
For each target face, the target and source areas for each.
const List< part > & srcErrorParts() const
For each source face, the area associated with mismatch.
const List< DynamicList< couple > > & srcCouples() const
For each source face, the source and target areas for each.
const List< scalar > & srcCoverage() const
Return the proportion of the source faces that are coupled.
static treeBoundBox srcBoxStatic(const face &srcFace, const pointField &srcPoints, const vectorField &srcPointNormals)
Get the bound box for a source face.
static int debugSrcFacei
Extra debugging for intersections between specific faces. Named.
const List< part > & srcEdgeParts() const
For each source edge, the non-coupled geometry associated.
intersection(const bool reverse)
Construct from components.
const List< scalar > & tgtCoverage() const
Return the proportion of the target faces that are coupled.
Triangulation of three-dimensional polygons.
A class for managing temporary objects without reference counting.
Definition: tmpNrc.H:53
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space.
Definition: transformer.H:84
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:90
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:71
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:50
volScalarField & b
Definition: createFields.H:27
const dimensionedScalar c
Speed of light in a vacuum.
static Type NaN()
Return a primitive with all components set to NaN.
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
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
dimensioned< scalar > mag(const dimensioned< Type > &)
volScalarField & p
Structure to store the geometry associated with the coupling.
friend bool operator==(const couple &a, const couple &b)
Equality comparison.
friend bool operator!=(const couple &a, const couple &b)
Inequality comparison.
friend Istream & operator>>(Istream &is, couple &c)
Input stream operator.
friend Ostream & operator<<(Ostream &os, const couple &c)
Output stream operator.
Structure to store the geometry associated with part of a patch.
void operator-=(const part &p)
Subtract another part from this one.
friend Istream & operator>>(Istream &is, part &p)
Input stream operator.
friend Ostream & operator<<(Ostream &os, const part &p)
Output stream operator.
friend bool operator!=(const part &a, const part &b)
Inequality comparison.
friend bool operator==(const part &a, const part &b)
Equality comparison.
void operator+=(const part &p)
Add another part to this one.
Class to encapsulate the topology of a point within a triangle intersection.