polyMeshAdder.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-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2021 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::polyMeshAdder
29 
30 Description
31  Adds two meshes without using any polyMesh morphing.
32 
33  Gets faces to couple as faceCoupleInfo which is list of faces on both
34  meshes. Returns map from last mesh addition.
35 
36 SourceFiles
37  polyMeshAdder.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_polyMeshAdder_H
42 #define Foam_polyMeshAdder_H
43 
44 #include "autoPtr.H"
45 #include "polyMesh.H"
46 #include "mapAddedPolyMesh.H"
47 #include "faceCoupleInfo.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class IOobject;
56 class polyTopoChange;
57 
58 /*---------------------------------------------------------------------------*\
59  Class polyMeshAdder Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class polyMeshAdder
63 {
64  // Private Member Functions
65 
66  //- Index of patch in allPatches. Add if nonexisting.
67  static label patchIndex
68  (
69  const polyPatch&,
70  DynamicList<word>& allPatchNames,
71  DynamicList<word>& allPatchTypes
72  );
73 
74  //- Index of zone in all zones
75  static label zoneIndex(const word&, DynamicList<word>&);
76 
77  static void mergePatchNames
78  (
79  const polyBoundaryMesh& patches0,
80  const polyBoundaryMesh& patches1,
81 
82  DynamicList<word>& allPatchNames,
83  DynamicList<word>& allPatchTypes,
84 
85  labelList& from1ToAllPatches,
86  labelList& fromAllTo1Patches
87  );
88 
89  static List<polyPatch*> combinePatches
90  (
91  const polyMesh& mesh0,
92  const polyMesh& mesh1,
93  const polyBoundaryMesh& allBoundaryMesh,
94  const label nAllPatches,
95  const labelList& fromAllTo1Patches,
96 
97  const label nInternalFaces,
98  const labelList& nFaces,
99 
100  labelList& from0ToAllPatches,
101  labelList& from1ToAllPatches
102  );
103 
104  //- Determine order for internalFaces to be upper-triangular.
105  // Does not change order of external faces.
106  static labelList getFaceOrder
107  (
108  const cellList& cells,
109  const label nInternalFaces,
110  const labelList& owner,
111  const labelList& neighbour
112  );
113 
114  //- Extends face f with split points. cutEdgeToPoints gives for every
115  // edge the points introduced inbetween the endpoints.
116  static void insertVertices
117  (
118  const EdgeMap<labelList>& cutEdgeToPoints,
119  const Map<label>& meshToMaster,
120  const labelList& masterToCutPoints,
121  const face& masterFace,
122 
123  DynamicList<label>& workFace,
124  face& f
125  );
126 
127  //- Merges primitives of two meshes.
128  static void mergePrimitives
129  (
130  const polyMesh& mesh0,
131  const polyMesh& mesh1,
132  const faceCoupleInfo& coupleInfo,
133 
134  const label nAllPatches,
135  const labelList& fromAllTo1Patches,
136  const labelList& from1ToAllPatches,
137 
139  labelList& from0ToAllPoints,
140  labelList& from1ToAllPoints,
141 
142  faceList& allFaces,
143  labelList& allOwner,
144  labelList& allNeighbour,
145  label& nInternalFaces,
146  labelList& nFacesPerPatch,
147  label& nCells,
148 
149  labelList& from0ToAllFaces,
150  labelList& from1ToAllFaces,
151  labelList& from1ToAllCells
152  );
153 
154  //- Merge point zones
155  static void mergePointZones
156  (
157  const label nAllPoints,
158 
159  const pointZoneMesh& pz0,
160  const pointZoneMesh& pz1,
161  const labelList& from0ToAllPoints,
162  const labelList& from1ToAllPoints,
163 
164  DynamicList<word>& zoneNames,
165  labelList& from1ToAll,
166  List<DynamicList<label>>& pzPoints
167  );
168 
169  //- Merge face zones
170  static void mergeFaceZones
171  (
172  const labelList& allOwner,
173 
174  const polyMesh& mesh0,
175  const polyMesh& mesh1,
176  const labelList& from0ToAllFaces,
177  const labelList& from1ToAllFaces,
178  const labelList& from1ToAllCells,
179 
180  DynamicList<word>& zoneNames,
181  labelList& from1ToAll,
182  List<DynamicList<label>>& fzFaces,
183  List<DynamicList<bool>>& fzFlips
184  );
185 
186  //- Merge cell zones
187  static void mergeCellZones
188  (
189  const label nAllCells,
190 
191  const cellZoneMesh& cz0,
192  const cellZoneMesh& cz1,
193  const labelList& from1ToAllCells,
194 
195  DynamicList<word>& zoneNames,
196  labelList& from1ToAll,
197  List<DynamicList<label>>& czCells
198  );
199 
200  //- Merge point/face/cell zone information
201  static void mergeZones
202  (
203  const label nAllPoints,
204  const labelList& allOwner,
205  const label nAllCells,
206 
207  const polyMesh& mesh0,
208  const polyMesh& mesh1,
209  const labelList& from0ToAllPoints,
210  const labelList& from0ToAllFaces,
211  const labelList& from1ToAllPoints,
212  const labelList& from1ToAllFaces,
213  const labelList& from1ToAllCells,
214 
215  DynamicList<word>& pointZoneNames,
216  List<DynamicList<label>>& pzPoints,
217 
218  DynamicList<word>& faceZoneNames,
219  List<DynamicList<label>>& fzFaces,
220  List<DynamicList<bool>>& fzFlips,
221 
222  DynamicList<word>& cellZoneNames,
223  List<DynamicList<label>>& czCells
224  );
225 
226  //- Create new zones and add to new mesh.
227  static void addZones
228  (
229  const DynamicList<word>& pointZoneNames,
230  const List<DynamicList<label>>& pzPoints,
231 
232  const DynamicList<word>& faceZoneNames,
233  const List<DynamicList<label>>& fzFaces,
234  const List<DynamicList<bool>>& fzFlips,
235 
236  const DynamicList<word>& cellZoneNames,
237  const List<DynamicList<label>>& czCells,
238 
239  polyMesh& mesh
240  );
241 
242 
243  //- Multi-mesh addition
244 
245  //- Find n'th processor patch going to nbrProci. Usually n=0 except
246  //- for e.g. processorCyclic
247  static label procPatchIndex
248  (
249  const polyBoundaryMesh& pbm,
250  const label nbrProci,
251  const label n
252  );
253 
254  //- Determine shared points. Takes pairs of one-to-one patches
255  //0 that are converted into internal faces
256  static void compactPoints
257  (
258  const UPtrList<polyMesh>& meshes,
259  const labelListList& localBoundaryFace,
260  const labelListList& remoteFaceProc,
261  const labelListList& remoteBoundaryFace,
262  const labelListList& remoteFaceStart,
263  const globalIndex& globalPoints,
264 
265  labelListList& pointProcAddressing,
266  labelListList& localPoints
267  );
268 
269 
270 public:
271 
272  // Member Functions
273 
274 
275  //- Add two polyMeshes. Returns new polyMesh and map construct.
276  static autoPtr<polyMesh> add
277  (
278  const IOobject& io,
279  const polyMesh& mesh0,
280  const polyMesh& mesh1,
281  const faceCoupleInfo& coupleInfo,
283  );
284 
285  //- Inplace add mesh to polyMesh. Returns map construct.
287  (
288  polyMesh& mesh0,
289  const polyMesh& mesh1,
290  const faceCoupleInfo& coupleInfo,
291  const bool validBoundary = true
292  );
293 
294  // Point merging
295 
296  //- Find topologically and geometrically shared points.
297  //
298  // - should only be called for parallel correct mesh
299  // (since uses mesh.globalData)
300  // - returns Map from point to master point (all in mesh point
301  // labels) for any sets of points that need to be merged.
303  (
304  const polyMesh&,
305  const scalar mergeTol
306  );
307 
308  //- Helper: Merge points.
309  //
310  // - Gets map from point to destination point
311  // - Removes all points that don't map to themselves
312  // - Modifies all faces that use the points to be removed.
313  static void mergePoints
314  (
315  const polyMesh&,
316  const Map<label>& pointToMaster,
317  polyTopoChange& meshMod
318  );
319 
320 
321  // Multi-mesh merging. Expects same patches (apart from processor
322  // patches)
323 
324  //- Helper: find pairs of processor patches. Return number of
325  //- non-processor patches
326  static label procPatchPairs
327  (
328  const UPtrList<polyMesh>& meshes,
329  List<DynamicList<label>>& localPatch,
330  List<DynamicList<label>>& remoteMesh,
331  List<DynamicList<label>>& remotePatch
332  );
333 
334  //- Helper: expand list of coupled patches into pairs of coupled
335  //- faces
336  static void patchFacePairs
337  (
338  const UPtrList<polyMesh>& meshes,
339  const List<DynamicList<label>>& localPatch,
340  const List<DynamicList<label>>& remoteMesh,
341  const List<DynamicList<label>>& remotePatch,
342  labelListList& localBoundaryFace,
343  labelListList& remoteFaceMesh,
344  labelListList& remoteBoundaryFace
345  );
346 
347  //- Add multiple meshes
348  static void add
349  (
350  const UPtrList<polyMesh>& meshes,
351  const UList<labelList>& patchMap,
352 
353  const labelListList& localBoundaryFace,
354  const labelListList& remoteFaceMesh,
355  const labelListList& remoteBoundaryFace,
356  const labelListList& remoteFaceStart,
357 
358  const UList<labelList>& pointZoneMap,
359  const UList<labelList>& faceZoneMap,
360  const UList<labelList>& cellZoneMap,
361 
362  polyTopoChange& meshMod,
363  labelListList& cellProcAddressing,
364  labelListList& faceProcAddressing,
365  labelListList& pointProcAddressing
366  );
367 };
368 
369 
370 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 
372 } // End namespace Foam
373 
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 
376 #endif
377 
378 // ************************************************************************* //
const polyBoundaryMesh & pbm
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
Adds two meshes without using any polyMesh morphing.
Definition: polyMeshAdder.H:57
Container for information needed to couple to meshes. When constructed from two meshes and a geometri...
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:61
dynamicFvMesh & mesh
const cellShapeList & cells
static void mergePoints(const polyMesh &, const Map< label > &pointToMaster, polyTopoChange &meshMod)
Helper: Merge points.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
static label procPatchPairs(const UPtrList< polyMesh > &meshes, List< DynamicList< label >> &localPatch, List< DynamicList< label >> &remoteMesh, List< DynamicList< label >> &remotePatch)
Helper: find pairs of processor patches. Return number of non-processor patches.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
Map from edge (expressed as its endpoints) to value. Hashing (and ==) on an edge is symmetric...
Definition: edgeHashes.H:56
labelList f(nPoints)
Calculates points shared by more than two processor patches or cyclic patches.
Definition: globalPoints.H:98
static void patchFacePairs(const UPtrList< polyMesh > &meshes, const List< DynamicList< label >> &localPatch, const List< DynamicList< label >> &remoteMesh, const List< DynamicList< label >> &remotePatch, labelListList &localBoundaryFace, labelListList &remoteFaceMesh, labelListList &remoteBoundaryFace)
Helper: expand list of coupled patches into pairs of coupled faces.
Direct mesh changes based on v1.3 polyTopoChange syntax.
label n
tmp< pointField > allPoints(const Triangulation &t)
Extract all points in vertex-index order.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
static autoPtr< polyMesh > add(const IOobject &io, const polyMesh &mesh0, const polyMesh &mesh1, const faceCoupleInfo &coupleInfo, autoPtr< mapAddedPolyMesh > &mapPtr)
Add two polyMeshes. Returns new polyMesh and map construct.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
static Map< label > findSharedPoints(const polyMesh &, const scalar mergeTol)
Find topologically and geometrically shared points.
Namespace for OpenFOAM.