FreeFOAM The Cross-Platform CFD Toolkit
mapPolyMesh.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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::mapPolyMesh
26 
27 Description
28  Class containing mesh-to-mesh mapping information after a change
29  in polyMesh topology.
30 
31  General:
32  - pointMap/faceMap/cellMap: \n
33  from current mesh back to previous mesh.
34  (so to 'pull' the information onto the current mesh)
35  - reversePointMap/faceMap/cellMap: \n
36  from previous mesh to current. (so to 'push' information)
37 
38  In the topology change points/faces/cells
39  - can be unchanged. (faces might be renumbered though)
40  - can be removed (into nothing)
41  - can be removed into/merged with existing same entity
42  (so point merged with other point, face with other face, cell with
43  other cell. Note that probably only cell with cell is relevant)
44  - can be added from existing same 'master' entity
45  (so point from point, face from face and cell from cell)
46  - can be inflated: face out of edge or point,
47  cell out of face, edge or point.
48  - can be appended: added 'out of nothing'.
49 
50  All this information is nessecary to correctly map fields.
51 
52  @par points
53 
54  - unchanged:
55  - pointMap[pointI] contains old point label
56  - reversePointMap[oldPointI] contains new point label
57  - removed:
58  - reversePointMap[oldPointI] contains -1
59  - merged into point:
60  - reversePointMap[oldPointI] contains <-1 : -newPointI-2
61  - pointMap[pointI] contains the old master point label
62  - pointsFromPoints gives for pointI all the old point labels
63  (including the old master point!)
64  - added-from-same:
65  - pointMap[pointI] contains the old master point label
66  - appended:
67  - pointMap[pointI] contains -1
68 
69  @par faces
70 
71  - unchanged:
72  - faceMap[faceI] contains old face label
73  - reverseFaceMap[oldFaceI] contains new face label
74  - removed:
75  - reverseFaceMap[oldFaceI] contains -1
76  - merged into face:
77  - reverseFaceMap[oldFaceI] contains <-1 : -newFaceI-2
78  - faceMap[faceI] contains the old master face label
79  - facesFromFaces gives for faceI all the old face labels
80  (including the old master face!)
81  - added-from-same:
82  - faceMap[faceI] contains the old master face label
83  - inflated-from-edge:
84  - faceMap[faceI] contains -1
85  - facesFromEdges contains an entry with
86  - faceI
87  - list of faces(*) on old mesh that connected to the old edge
88  - inflated-from-point:
89  - faceMap[faceI] contains -1
90  - facesFromPoints contains an entry with
91  - faceI
92  - list of faces(*) on old mesh that connected to the old point
93  - appended:
94  - faceMap[faceI] contains -1
95 
96  Note (*) \n
97  if the newly inflated face is a boundary face the list of faces will
98  only be boundary faces; if the new face is an internal face they
99  will only be internal faces.
100 
101  @par cells
102 
103  - unchanged:
104  - cellMap[cellI] contains old cell label
105  - reverseCellMap[oldCellI] contains new cell label
106  - removed:
107  - reverseCellMap[oldCellI] contains -1
108  - merged into cell:
109  - reverseCellMap[oldCellI] contains <-1 : -newCellI-2
110  - cellMap[cellI] contains the old master cell label
111  - cellsFromCells gives for cellI all the old cell labels
112  (including the old master cell!)
113  - added-from-same:
114  - cellMap[cellI] contains the old master cell label
115  - inflated-from-face:
116  - cellMap[cellI] contains -1
117  - cellsFromFaces contains an entry with
118  - cellI
119  - list of cells on old mesh that connected to the old face
120  - inflated-from-edge:
121  - cellMap[cellI] contains -1
122  - cellsFromEdges contains an entry with
123  - cellI
124  - list of cells on old mesh that connected to the old edge
125  - inflated-from-point:
126  - cellMap[cellI] contains -1
127  - cellsFromPoints contains an entry with
128  - cellI
129  - list of cells on old mesh that connected to the old point
130  - appended:
131  - cellMap[cellI] contains -1
132 
133 
134 SourceFiles
135  mapPolyMesh.C
136 
137 \*---------------------------------------------------------------------------*/
138 
139 #ifndef mapPolyMesh_H
140 #define mapPolyMesh_H
141 
142 #include <OpenFOAM/labelList.H>
143 #include <OpenFOAM/objectMap.H>
144 #include <OpenFOAM/pointField.H>
145 #include <OpenFOAM/HashSet.H>
146 #include <OpenFOAM/Map.H>
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 namespace Foam
151 {
152 
153 class polyMesh;
154 
155 /*---------------------------------------------------------------------------*\
156  Class mapPolyMesh Declaration
157 \*---------------------------------------------------------------------------*/
158 
160 :
161  public refCount
162 {
163  // Private data
164 
165  //- Reference to polyMesh
166  const polyMesh& mesh_;
167 
168  //- Number of old live points
169  const label nOldPoints_;
170 
171  //- Number of old live faces
172  const label nOldFaces_;
173 
174  //- Number of old live cells
175  const label nOldCells_;
176 
177  //- Old point map.
178  // Contains the old point label for all new points.
179  // - for preserved points this is the old point label.
180  // - for added points this is the master point ID
181  // - for points added with no master, this is -1
182  // Size of the list equals the size of new points
183  const labelList pointMap_;
184 
185  //- Points resulting from merging points
186  const List<objectMap> pointsFromPointsMap_;
187 
188  //- Old face map.
189  // Contains a list of old face labels for every new face.
190  // Size of the list equals the number of new faces
191  // - for preserved faces this is the old face label.
192  // - for faces added from faces this is the master face ID
193  // - for faces added with no master, this is -1
194  // - for faces added from points or edges, this is -1
195  const labelList faceMap_;
196 
197  //- Faces inflated from points
198  const List<objectMap> facesFromPointsMap_;
199 
200  //- Faces inflated from edges
201  const List<objectMap> facesFromEdgesMap_;
202 
203  //- Faces resulting from merging faces
204  const List<objectMap> facesFromFacesMap_;
205 
206  //- Old cell map.
207  // Contains old cell label for all preserved cells.
208  // Size of the list equals the number or preserved cells
209  const labelList cellMap_;
210 
211  //- Cells inflated from points
212  const List<objectMap> cellsFromPointsMap_;
213 
214  //- Cells inflated from edges
215  const List<objectMap> cellsFromEdgesMap_;
216 
217  //- Cells inflated from faces
218  const List<objectMap> cellsFromFacesMap_;
219 
220  //- Cells resulting from merging cells
221  const List<objectMap> cellsFromCellsMap_;
222 
223  //- Reverse point map
224  const labelList reversePointMap_;
225 
226  //- Reverse face map
227  const labelList reverseFaceMap_;
228 
229  //- Reverse cell map
230  const labelList reverseCellMap_;
231 
232  //- Map of flipped face flux faces
233  const labelHashSet flipFaceFlux_;
234 
235  //- Patch mesh point renumbering
236  const labelListList patchPointMap_;
237 
238  //- Point zone renumbering
239  // For every preserved point in zone give the old position.
240  // For added points, the index is set to -1
241  const labelListList pointZoneMap_;
242 
243  //- Face zone point renumbering
244  // For every preserved point in zone give the old position.
245  // For added points, the index is set to -1
246  const labelListList faceZonePointMap_;
247 
248  //- Face zone face renumbering
249  // For every preserved face in zone give the old position.
250  // For added faces, the index is set to -1
251  const labelListList faceZoneFaceMap_;
252 
253  //- Cell zone renumbering
254  // For every preserved cell in zone give the old position.
255  // For added cells, the index is set to -1
256  const labelListList cellZoneMap_;
257 
258  //- Pre-motion point positions.
259  // This specifies the correct way of blowing up zero-volume objects
260  const pointField preMotionPoints_;
261 
262  //- List of the old patch sizes
263  labelList oldPatchSizes_;
264 
265  //- List of the old patch start labels
266  const labelList oldPatchStarts_;
267 
268  //- List of numbers of mesh points per old patch
269  const labelList oldPatchNMeshPoints_;
270 
271 
272  // Private Member Functions
273 
274  //- Disallow default bitwise copy construct
275  mapPolyMesh(const mapPolyMesh&);
276 
277  //- Disallow default bitwise assignment
278  void operator=(const mapPolyMesh&);
279 
280 
281 public:
282 
283  // Constructors
284 
285  //- Construct from components
287  (
288  const polyMesh& mesh,
289  const label nOldPoints,
290  const label nOldFaces,
291  const label nOldCells,
292  const labelList& pointMap,
293  const List<objectMap>& pointsFromPoints,
294  const labelList& faceMap,
295  const List<objectMap>& facesFromPoints,
296  const List<objectMap>& facesFromEdges,
297  const List<objectMap>& facesFromFaces,
298  const labelList& cellMap,
299  const List<objectMap>& cellsFromPoints,
300  const List<objectMap>& cellsFromEdges,
301  const List<objectMap>& cellsFromFaces,
302  const List<objectMap>& cellsFromCells,
303  const labelList& reversePointMap,
304  const labelList& reverseFaceMap,
305  const labelList& reverseCellMap,
306  const labelHashSet& flipFaceFlux,
311  const labelListList& cellZoneMap,
313  const labelList& oldPatchStarts,
315  );
316 
317  //- Construct from components and optionally reuse storage
319  (
320  const polyMesh& mesh,
321  const label nOldPoints,
322  const label nOldFaces,
323  const label nOldCells,
324  labelList& pointMap,
325  List<objectMap>& pointsFromPoints,
326  labelList& faceMap,
327  List<objectMap>& facesFromPoints,
328  List<objectMap>& facesFromEdges,
329  List<objectMap>& facesFromFaces,
330  labelList& cellMap,
331  List<objectMap>& cellsFromPoints,
332  List<objectMap>& cellsFromEdges,
333  List<objectMap>& cellsFromFaces,
334  List<objectMap>& cellsFromCells,
335  labelList& reversePointMap,
336  labelList& reverseFaceMap,
337  labelList& reverseCellMap,
338  labelHashSet& flipFaceFlux,
339  labelListList& patchPointMap,
340  labelListList& pointZoneMap,
341  labelListList& faceZonePointMap,
342  labelListList& faceZoneFaceMap,
343  labelListList& cellZoneMap,
344  pointField& preMotionPoints,
345  labelList& oldPatchStarts,
346  labelList& oldPatchNMeshPoints,
347  const bool reUse
348  );
349 
350  // Member Functions
351 
352  // Access
353 
354  //- Return polyMesh
355  const polyMesh& mesh() const
356  {
357  return mesh_;
358  }
359 
360  //- Number of old points
361  label nOldPoints() const
362  {
363  return nOldPoints_;
364  }
365 
366  //- Number of old internal faces
367  label nOldInternalFaces() const
368  {
369  return oldPatchStarts_[0];
370  }
371 
372  //- Number of old faces
373  label nOldFaces() const
374  {
375  return nOldFaces_;
376  }
377 
378  //- Number of old cells
379  label nOldCells() const
380  {
381  return nOldCells_;
382  }
383 
384  //- Old point map.
385  // Contains the old point label for all new points.
386  // For preserved points this is the old point label.
387  // For added points this is the master point ID
388  const labelList& pointMap() const
389  {
390  return pointMap_;
391  }
392 
393  //- Points originating from points
395  {
396  return pointsFromPointsMap_;
397  }
398 
399  //- Old face map.
400  // Contains a list of old face labels for every new face.
401  // Warning: this map contains invalid entries for new faces
402  const labelList& faceMap() const
403  {
404  return faceMap_;
405  }
406 
407  //- Faces inflated from points
409  {
410  return facesFromPointsMap_;
411  }
412 
413  //- Faces inflated from edges
415  {
416  return facesFromEdgesMap_;
417  }
418 
419  //- Faces originating from faces
421  {
422  return facesFromFacesMap_;
423  }
424 
425  //- Old cell map.
426  // Contains old cell label for all preserved cells.
427  const labelList& cellMap() const
428  {
429  return cellMap_;
430  }
431 
432  //- Cells inflated from points
434  {
435  return cellsFromPointsMap_;
436  }
437 
438  //- Cells inflated from edges
440  {
441  return cellsFromEdgesMap_;
442  }
443 
444  //- Cells inflated from faces
446  {
447  return cellsFromFacesMap_;
448  }
449 
450  //- Cells originating from cells
452  {
453  return cellsFromCellsMap_;
454  }
455 
456 
457  // Reverse maps
458 
459  //- Reverse point map
460  // Contains new point label for all old and added points
461  const labelList& reversePointMap() const
462  {
463  return reversePointMap_;
464  }
465 
466  //- If point is removed return point (on new mesh) it merged
467  // into
468  label mergedPoint(const label oldPointI) const
469  {
470  label i = reversePointMap_[oldPointI];
471 
472  if (i == -1)
473  {
474  return i;
475  }
476  else if (i < -1)
477  {
478  return -i-2;
479  }
480  else
481  {
482  FatalErrorIn("mergedPoint(const label) const")
483  << "old point label " << oldPointI
484  << " has reverseMap " << i << endl
485  << "Only call mergedPoint for removed points."
486  << abort(FatalError);
487  return -1;
488  }
489  }
490 
491  //- Reverse face map
492  // Contains new face label for all old and added faces
493  const labelList& reverseFaceMap() const
494  {
495  return reverseFaceMap_;
496  }
497 
498  //- If face is removed return face (on new mesh) it merged into
499  label mergedFace(const label oldFaceI) const
500  {
501  label i = reverseFaceMap_[oldFaceI];
502 
503  if (i == -1)
504  {
505  return i;
506  }
507  else if (i < -1)
508  {
509  return -i-2;
510  }
511  else
512  {
513  FatalErrorIn("mergedFace(const label) const")
514  << "old face label " << oldFaceI
515  << " has reverseMap " << i << endl
516  << "Only call mergedFace for removed faces."
517  << abort(FatalError);
518  return -1;
519  }
520  }
521 
522  //- Reverse cell map
523  // Contains new cell label for all old and added cells
524  const labelList& reverseCellMap() const
525  {
526  return reverseCellMap_;
527  }
528 
529  //- If cell is removed return cell (on new mesh) it merged into
530  label mergedCell(const label oldCellI) const
531  {
532  label i = reverseCellMap_[oldCellI];
533 
534  if (i == -1)
535  {
536  return i;
537  }
538  else if (i < -1)
539  {
540  return -i-2;
541  }
542  else
543  {
544  FatalErrorIn("mergedCell(const label) const")
545  << "old cell label " << oldCellI
546  << " has reverseMap " << i << endl
547  << "Only call mergedCell for removed cells."
548  << abort(FatalError);
549  return -1;
550  }
551  }
552 
553  //- Map of flipped face flux faces
554  const labelHashSet& flipFaceFlux() const
555  {
556  return flipFaceFlux_;
557  }
558 
559  //- Patch point renumbering
560  // For every preserved point on a patch give the old position.
561  // For added points, the index is set to -1
563  {
564  return patchPointMap_;
565  }
566 
567 
568  // Zone mapping
569 
570  //- Point zone renumbering
571  // For every preserved point in zone give the old position.
572  // For added points, the index is set to -1
574  {
575  return pointZoneMap_;
576  }
577 
578  //- Face zone point renumbering
579  // For every preserved point in zone give the old position.
580  // For added points, the index is set to -1
582  {
583  return faceZonePointMap_;
584  }
585 
586  //- Face zone face renumbering
587  // For every preserved face in zone give the old position.
588  // For added faces, the index is set to -1
590  {
591  return faceZoneFaceMap_;
592  }
593 
594  //- Cell zone renumbering
595  // For every preserved cell in zone give the old position.
596  // For added cells, the index is set to -1
597  const labelListList& cellZoneMap() const
598  {
599  return cellZoneMap_;
600  }
601 
602  //- Pre-motion point positions.
603  // This specifies the correct way of blowing up
604  // zero-volume objects
606  {
607  return preMotionPoints_;
608  }
609 
610  //- Has valid preMotionPoints?
611  bool hasMotionPoints() const
612  {
613  return preMotionPoints_.size() > 0;
614  }
615 
616 
617  //- Return list of the old patch sizes
618  const labelList& oldPatchSizes() const
619  {
620  return oldPatchSizes_;
621  }
622 
623  //- Return list of the old patch start labels
624  const labelList& oldPatchStarts() const
625  {
626  return oldPatchStarts_;
627  }
628 
629  //- Return numbers of mesh points per old patch
631  {
632  return oldPatchNMeshPoints_;
633  }
634 };
635 
636 
637 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
638 
639 } // End namespace Foam
640 
641 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
642 
643 #endif
644 
645 // ************************ vim: set sw=4 sts=4 et: ************************ //