faceCoupleInfo.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::faceCoupleInfo
29 
30 Description
31  Container for information needed to couple to meshes. When constructed
32  from two meshes and a geometric tolerance finds the corresponding
33  boundary faces.
34 
35  The information it keeps is the set of faces&points (cutFaces,
36  cutPoints) that should replace a set of faces on the master
37  (masterPatch) and a set of faces on the slave (slavePatch)
38 
39 
40  Uses same tolerance to match faces and points on matched faces since
41  they both originate from the same points and the tolerance usually
42  comes from writing these points with limited precision (6 by default)
43 
44  -# Perfect match:
45  - one-to-one match for faces and points.
46  - the cut is always the 'most connected' of the master and slave so
47  multiple master or slave points might point to the same cut point.
48 
49  \verbatim
50  e.g. master:
51 
52  +--+
53  | |
54  | |
55  +--+
56  +--+
57  | |
58  | |
59  +--+
60  slave:
61  +--+
62  | |
63  | |
64  +--+
65  +--+
66  | |
67  | |
68  +--+
69  \endverbatim
70  adding both together creates a singly connected 2x2 cavity so suddenly
71  the duplicate master points and the duplicate slave points all become
72  a single cut point.
73 
74 
75  -# Subdivision match:
76  - Can be constructed from slave being subdivision of master with the
77  polyPatch constructor.
78  - Does not include above shared-point detection!
79 
80  Notes on multiple slave faces per master:
81 
82  As long as
83  - all master edges are present in slave
84  - slave can have extra edges/points/faces BUT all subfaces have to have
85  at least one point on a maste face.
86 
87  \verbatim
88  So master:
89  +-------+
90  | |
91  | |
92  | |
93  | |
94  | |
95  | |
96  | |
97  +-------+
98 
99  slave:
100  +---+---+
101  |\ | /|
102  | \ | / |
103  | \|/ |
104  +---+---+
105  | /|\ |
106  | / | \ |
107  |/ | \|
108  +---+---+
109  is ok.
110  \endverbatim
111 
112  For this kind of matching the order is:
113  - match cutpoint to masterpoint
114  - find those cutEdges that align with a master edge. This gives two sets
115  of cut edges: those that have a master equivalent ('border edges') and
116  those that don't ('internal edges'). The border edges now divide the
117  cutFaces into regions with the same masterFace correspondence.
118  - find cutFaces that are fully determined by the border edges they use.
119  - all cutFaces that are connected through an internal edge have the same
120  master face.
121 
122 
123  Note: matching refined faces onto master is a bit dodgy and will probably
124  only work for unwarped faces. Also it will fail if e.g. face is split
125  into 3x3 since then middle face has no point/edge in common with master.
126  (problem is in face matching (findSlavesCoveringMaster), probably
127  point/edge matching might just work)
128 
129 
130 SourceFiles
131  faceCoupleInfo.C
132 
133 
134 \*---------------------------------------------------------------------------*/
135 
136 #ifndef faceCoupleInfo_H
137 #define faceCoupleInfo_H
138 
139 #include "pointField.H"
140 #include "indirectPrimitivePatch.H"
141 #include "primitiveFacePatch.H"
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 namespace Foam
146 {
147 
149 
150 
151 // Forward Declarations
152 class face;
153 class primitiveMesh;
154 class polyPatch;
155 class polyMesh;
156 
157 /*---------------------------------------------------------------------------*\
158  Class faceCoupleInfo Declaration
159 \*---------------------------------------------------------------------------*/
160 
161 class faceCoupleInfo
162 {
163  // Private Data
164 
165  //- Angle matching tolerance.
166  static const scalar angleTol_;
167 
168  //- Master patch
169  unique_ptr<indirectPrimitivePatch> masterPatchPtr_;
170 
171  //- Slave patch
172  unique_ptr<indirectPrimitivePatch> slavePatchPtr_;
173 
174 
175  //- Description of cut.
176  // - Cut is the matching area between the slave
177  // and the master.
178  // - cut is the finest of master and slave. It can never be
179  // coarser than either one of them. (so face addressing we keep is
180  // cut-to-master and cut-to-slave)
181  // - multiple master or slave points can end up becoming one cut point
182  // (so point addressing we keep is master-to-cut and slave-to-cut)
183 
184  // Cut consists of faces and points (note: could be expressed as some
185  // kind of PrimitivePatch which holds points instead of reference to
186  // them)
187  // Orientation of cutFaces should be same as masterFaces!
188  pointField cutPoints_;
189 
190  unique_ptr<primitiveFacePatch> cutFacesPtr_;
191 
192  //- Additional point coupling information. Is between points on
193  // boundary of both meshes.
194 
195  // Addressing to/from cut
196 
197  //- master
198  labelList cutToMasterFaces_;
199  labelList masterToCutPoints_;
200 
201  //- slave
202  labelList cutToSlaveFaces_;
203  labelList slaveToCutPoints_;
204 
205  //- For edges originating from splitting of edges:
206  // given the two endpoints of the unsplit edge give the list
207  // of inbetween vertices
208  edgeLookup cutEdgeToPoints_;
209 
210 
211  // Private Member Functions
212 
213  // Debugging
214 
215  //- Calculate face centres from (subset of) faces.
216  template<template<class> class FaceList>
217  static pointField calcFaceCentres
218  (
219  const FaceList<face>&,
220  const pointField&,
221  const label start,
222  const label size
223  );
224 
225  //- Calculate face point averages from (subset of) faces.
226  template<template<class> class FaceList>
227  static pointField calcFacePointAverages
228  (
229  const FaceList<face>&,
230  const pointField&,
231  const label start,
232  const label size
233  );
234 
235  //- Write edges
236  static void writeOBJ
237  (
238  const fileName& fName,
239  const edgeList& edges,
240  const pointField& points,
241  const bool compact = true
242  );
243 
244  //- Write edges
245  static void writeOBJ
246  (
247  const fileName& fName,
248  const pointField& points0,
249  const pointField& points1
250  );
251 
252  //- Write connections between corresponding points and faces
253  // as .obj files.
254  void writePointsFaces() const;
255 
256  //- Write connections between corresponding edges as .obj files.
257  void writeEdges(const labelList&, const labelList&) const;
258 
259 
260  // Edge handling/matching
261 
262  //- Find corresponding edges on patch when having only a map for
263  // the points.
264  labelList findMappedEdges
265  (
266  const edgeList& edges,
267  const labelList& pointMap,
269  );
270 
271  //- Check if edge on slavePatch corresponds to an edge between faces
272  // in two different polyPatches on the mesh.
273  bool regionEdge(const polyMesh&, const label slaveEdgeI) const;
274 
275  //- Finds edge connected to point most aligned with master edge.
276  label mostAlignedCutEdge
277  (
278  const bool report,
279  const polyMesh& slaveMesh,
280  const bool patchDivision,
281  const labelList& cutToMasterEdges,
282  const labelList& cutToSlaveEdges,
283  const label pointi,
284  const label edgeStart,
285  const label edgeEnd
286  ) const;
287 
288  //- From (many-to-one) map of cut edges to master edges determine
289  // points inbetween. I.e. just string up the edges. Stores this
290  // all on cutEdgeToPoints_
291  void setCutEdgeToPoints(const labelList& cutToMasterEdges);
292 
293  // Face matching
294 
295  //- Matches two faces.
296  // Determines rotation for f1 to match up with f0,
297  // i.e. the index in f0 of the first point of f1.
298  static label matchFaces
299  (
300  const scalar absTol,
301  const pointField& points0,
302  const face& f0,
303  const pointField& points1,
304  const face& f1,
305  const bool sameOrientation
306  );
307 
308  //- Matches points on patch to points on cut.
309  static bool matchPointsThroughFaces
310  (
311  const scalar absTol,
312  const pointField& cutPoints,
313  const faceList& cutFaces,
314  const pointField& patchPoints,
315  const faceList& patchFaces,
316  const bool sameOrientation,
317 
318  labelList& patchToCutPoints,// patch to (uncompacted) cut points
319  labelList& cutToCompact, // compaction list
320  labelList& compactToCut // compaction list
321  );
322 
323  //- Returns max distance to masterF of any point on cutF.
324  static scalar maxDistance
325  (
326  const face& cutF,
327  const pointField& cutPoints,
328  const face& masterF,
329  const pointField& masterPoints
330  );
331 
332  //- Finds matching (boundary)face centres.
333  // Since faces identical uses geometric match on face centres.
334  static void findPerfectMatchingFaces
335  (
336  const primitiveMesh& mesh0,
337  const primitiveMesh& mesh1,
338  const scalar absTol,
339 
340  labelList& mesh0Faces,
341  labelList& mesh1Faces
342  );
343 
344  //- Find matching (boundary)faces. Matching if slave is on top of
345  // master face (slaves is subdivision of master)
346  static void findSlavesCoveringMaster
347  (
348  const primitiveMesh& mesh0,
349  const primitiveMesh& mesh1,
350  const scalar absTol,
351 
352  labelList& mesh0Faces,
353  labelList& mesh1Faces
354  );
355 
356  //- Grow cutToMasterFace across 'internal' edges.
357  label growCutFaces(const labelList&, Map<labelList>&);
358 
359  void checkMatch(const labelList& cutToMasterEdges) const;
360 
361  //- Gets a list of cutFaces (that use a master edge) and the
362  // candidate master faces.
363  // Checks among these master faces if there is only one remaining
364  // unmatched one.
365  label matchEdgeFaces(const labelList&, Map<labelList>& candidates);
366 
367  //- Gets a list of cutFaces (that use a master edge) and the
368  // candidate master faces.
369  // Finds most aligned master face.
370  label geometricMatchEdgeFaces(Map<labelList>& candidates);
371 
372  //- Used by perfectPointMatch. Determine match from cut points to
373  // slave points (for perfect matching faces)
374  void perfectSlavePointMatch(const scalar absTol);
375 
376  //- Find point and edge correspondence for perfect matching faces
377  void perfectPointMatch(const scalar absTol, const bool);
378 
379  //- Find point and edge correspondence for slaves being subdivision of
380  // master.
381  void subDivisionMatch
382  (
383  const polyMesh& slaveMesh,
384  const bool patchDivision,
385  const scalar absTol
386  );
387 
388 public:
389 
390  //- Runtime type information
391  ClassName("faceCoupleInfo");
392 
393 
394  // Constructors
395 
396  //- Construct from two meshes and absolute tolerance.
397  // Finds out matches geometrically. No checking for nonsense match.
398  // Tolerance is absolute one so use with care.
399  // perfectMatch : each point/edge/face has corresponding point on other
400  // side
401  // if this is false then assumes slave is subdivision.
402  // Matching then will work only for non-warped faces
403  // since does nearest-to-face comparison with absTol.
405  (
406  const polyMesh& mesh0,
407  const polyMesh& mesh1,
408  const scalar absTol,
409  const bool perfectMatch
410  );
411 
412  //- Construct from meshes and subset of mesh faces
413  // (i.e. indirectPrimitivePatch addressing)
414  // All faces in patch are considered matched (but don't have to be
415  // ordered)
416  // perfectMatch : each point/edge/face has corresponding point on other
417  // side
418  // orderedFaces : faces in patch are ordered (so masterAddressing[i]
419  // matches slaveAddressing[i])
420  // patchDivision: faces in slave mesh that originate from the
421  // same master face have the same patch. Used by some triangulation
422  // methods.
424  (
425  const polyMesh& masterMesh,
426  const labelList& masterAddressing,
427  const polyMesh& slaveMesh,
428  const labelList& slaveAddressing,
429  const scalar absTol,
430  const bool perfectMatch,
431  const bool orderedFaces,
432  const bool patchDivision
433  );
434 
435 
436  //- Destructor
437  ~faceCoupleInfo() = default;
438 
439 
440 
441  // Member Functions
442 
443  //- Utility functions
444 
445  //- Get patch face labels
446  static labelList faceLabels(const polyPatch&);
447 
448  //- Create Map from List
449  static Map<label> makeMap(const labelList&);
450  static Map<labelList> makeMap(const labelListList&);
451 
452 
453  // Access
454 
455  //- Addressing engine for coupled faces on mesh0
456  const indirectPrimitivePatch& masterPatch() const
457  {
458  return *masterPatchPtr_;
459  }
460 
461  //- Addressing engine for coupled faces on mesh1
462  const indirectPrimitivePatch& slavePatch() const
463  {
464  return *slavePatchPtr_;
465  }
466 
467  //- Addressing engine for combined set of faces.
468  const primitiveFacePatch& cutFaces() const
469  {
470  return *cutFacesPtr_;
471  }
472 
473  //- Points for combined set of faces.
474  const pointField& cutPoints() const
475  {
476  return cutPoints_;
477  }
478 
479 
480  // Addressing from meshes to cut and vice versa.
481 
482  //- Master face for every face on cut. Will always be at least
483  // one but there might be multiple cut faces pointing to the same
484  // master
485  const labelList& cutToMasterFaces() const
486  {
487  return cutToMasterFaces_;
488  }
489  const labelList& masterToCutPoints() const
490  {
491  return masterToCutPoints_;
492  }
493 
494  const labelList& cutToSlaveFaces() const
495  {
496  return cutToSlaveFaces_;
497  }
498  const labelList& slaveToCutPoints() const
499  {
500  return slaveToCutPoints_;
501  }
502 
503  //- From two cut points (original edge) to list of inserted
504  // points
505  const edgeLookup& cutEdgeToPoints() const
506  {
507  return cutEdgeToPoints_;
508  }
509 
510  };
511 
512 
513 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
514 
515 } // End namespace Foam
516 
517 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
518 
519 #ifdef NoRepository
520  #include "faceCoupleInfoTemplates.C"
521 #endif
522 
523 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
524 
525 #endif
526 
527 // ************************************************************************* //
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::faceCoupleInfo::cutToMasterFaces
const labelList & cutToMasterFaces() const
Master face for every face on cut. Will always be at least.
Definition: faceCoupleInfo.H:484
primitiveFacePatch.H
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::faceCoupleInfo::cutEdgeToPoints
const edgeLookup & cutEdgeToPoints() const
From two cut points (original edge) to list of inserted.
Definition: faceCoupleInfo.H:504
Foam::edgeLookup
HashTable< labelList, edge, Hash< edge > > edgeLookup
Definition: faceCoupleInfo.H:147
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::faceCoupleInfo::slavePatch
const indirectPrimitivePatch & slavePatch() const
Addressing engine for coupled faces on mesh1.
Definition: faceCoupleInfo.H:461
Foam::faceCoupleInfo::masterToCutPoints
const labelList & masterToCutPoints() const
Definition: faceCoupleInfo.H:488
Foam::faceCoupleInfo::faceLabels
static labelList faceLabels(const polyPatch &)
Utility functions.
Definition: faceCoupleInfo.C:2093
Foam::Field< vector >
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::faceCoupleInfo::faceCoupleInfo
faceCoupleInfo(const polyMesh &mesh0, const polyMesh &mesh1, const scalar absTol, const bool perfectMatch)
Construct from two meshes and absolute tolerance.
Definition: faceCoupleInfo.C:1917
indirectPrimitivePatch.H
Foam::faceCoupleInfo::ClassName
ClassName("faceCoupleInfo")
Runtime type information.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
pointField.H
points0
pointField points0(pointIOField(IOobject("points", mesh.time().constant(), polyMesh::meshSubDir, mesh, IOobject::MUST_READ, IOobject::NO_WRITE, false)))
faceCoupleInfoTemplates.C
Foam::faceCoupleInfo::cutToSlaveFaces
const labelList & cutToSlaveFaces() const
Definition: faceCoupleInfo.H:493
Foam::List< label >
Foam::faceCoupleInfo::~faceCoupleInfo
~faceCoupleInfo()=default
Destructor.
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::faceCoupleInfo
Container for information needed to couple to meshes. When constructed from two meshes and a geometri...
Definition: faceCoupleInfo.H:160
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::faceCoupleInfo::cutFaces
const primitiveFacePatch & cutFaces() const
Addressing engine for combined set of faces.
Definition: faceCoupleInfo.H:467
Foam::faceCoupleInfo::makeMap
static Map< label > makeMap(const labelList &)
Create Map from List.
Definition: faceCoupleInfo.C:2107
Foam::faceCoupleInfo::masterPatch
const indirectPrimitivePatch & masterPatch() const
Addressing engine for coupled faces on mesh0.
Definition: faceCoupleInfo.H:455
Foam::faceCoupleInfo::cutPoints
const pointField & cutPoints() const
Points for combined set of faces.
Definition: faceCoupleInfo.H:473
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79
Foam::faceCoupleInfo::slaveToCutPoints
const labelList & slaveToCutPoints() const
Definition: faceCoupleInfo.H:497
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78