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