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) 2011-2013 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::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 necessary 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 "labelList.H"
143 #include "objectMap.H"
144 #include "pointField.H"
145 #include "HashSet.H"
146 #include "Map.H"
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 namespace Foam
151 {
152 
153 class polyMesh;
154 
155 /*---------------------------------------------------------------------------*\
156  Class mapPolyMesh Declaration
157 \*---------------------------------------------------------------------------*/
159 class mapPolyMesh
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  //- Optional old cell volumes (for mapping)
272  autoPtr<scalarField> oldCellVolumesPtr_;
273 
274 
275  // Private Member Functions
276 
277  //- Disallow default bitwise copy construct
278  mapPolyMesh(const mapPolyMesh&);
279 
280  //- Disallow default bitwise assignment
281  void operator=(const mapPolyMesh&);
282 
283 
284 public:
285 
286  // Constructors
287 
288  //- Construct from components. Copy (except for oldCellVolumes).
290  (
291  const polyMesh& mesh,
292  const label nOldPoints,
293  const label nOldFaces,
294  const label nOldCells,
295  const labelList& pointMap,
296  const List<objectMap>& pointsFromPoints,
297  const labelList& faceMap,
298  const List<objectMap>& facesFromPoints,
299  const List<objectMap>& facesFromEdges,
300  const List<objectMap>& facesFromFaces,
301  const labelList& cellMap,
302  const List<objectMap>& cellsFromPoints,
303  const List<objectMap>& cellsFromEdges,
304  const List<objectMap>& cellsFromFaces,
305  const List<objectMap>& cellsFromCells,
306  const labelList& reversePointMap,
307  const labelList& reverseFaceMap,
308  const labelList& reverseCellMap,
309  const labelHashSet& flipFaceFlux,
314  const labelListList& cellZoneMap,
316  const labelList& oldPatchStarts,
318  const autoPtr<scalarField>& oldCellVolumesPtr
319  );
320 
321  //- Construct from components and optionally reuse storage
323  (
324  const polyMesh& mesh,
325  const label nOldPoints,
326  const label nOldFaces,
327  const label nOldCells,
328  labelList& pointMap,
329  List<objectMap>& pointsFromPoints,
330  labelList& faceMap,
331  List<objectMap>& facesFromPoints,
332  List<objectMap>& facesFromEdges,
333  List<objectMap>& facesFromFaces,
334  labelList& cellMap,
335  List<objectMap>& cellsFromPoints,
336  List<objectMap>& cellsFromEdges,
337  List<objectMap>& cellsFromFaces,
338  List<objectMap>& cellsFromCells,
339  labelList& reversePointMap,
340  labelList& reverseFaceMap,
341  labelList& reverseCellMap,
342  labelHashSet& flipFaceFlux,
343  labelListList& patchPointMap,
344  labelListList& pointZoneMap,
345  labelListList& faceZonePointMap,
346  labelListList& faceZoneFaceMap,
347  labelListList& cellZoneMap,
348  pointField& preMotionPoints,
349  labelList& oldPatchStarts,
350  labelList& oldPatchNMeshPoints,
351  autoPtr<scalarField>& oldCellVolumesPtr,
352  const bool reUse
353  );
354 
355  // Member Functions
356 
357  // Access
358 
359  //- Return polyMesh
360  const polyMesh& mesh() const
361  {
362  return mesh_;
363  }
364 
365  //- Number of old points
366  label nOldPoints() const
367  {
368  return nOldPoints_;
369  }
370 
371  //- Number of old internal faces
372  label nOldInternalFaces() const
373  {
374  return oldPatchStarts_[0];
375  }
376 
377  //- Number of old faces
378  label nOldFaces() const
379  {
380  return nOldFaces_;
381  }
382 
383  //- Number of old cells
384  label nOldCells() const
385  {
386  return nOldCells_;
387  }
388 
389  //- Old point map.
390  // Contains the old point label for all new points.
391  // For preserved points this is the old point label.
392  // For added points this is the master point ID
393  const labelList& pointMap() const
394  {
395  return pointMap_;
396  }
397 
398  //- Points originating from points
399  const List<objectMap>& pointsFromPointsMap() const
400  {
401  return pointsFromPointsMap_;
402  }
403 
404  //- Old face map.
405  // Contains a list of old face labels for every new face.
406  // Warning: this map contains invalid entries for new faces
407  const labelList& faceMap() const
408  {
409  return faceMap_;
410  }
411 
412  //- Faces inflated from points
413  const List<objectMap>& facesFromPointsMap() const
414  {
415  return facesFromPointsMap_;
416  }
417 
418  //- Faces inflated from edges
419  const List<objectMap>& facesFromEdgesMap() const
420  {
421  return facesFromEdgesMap_;
422  }
423 
424  //- Faces originating from faces
425  const List<objectMap>& facesFromFacesMap() const
426  {
427  return facesFromFacesMap_;
428  }
429 
430  //- Old cell map.
431  // Contains old cell label for all preserved cells.
432  const labelList& cellMap() const
433  {
434  return cellMap_;
435  }
436 
437  //- Cells inflated from points
438  const List<objectMap>& cellsFromPointsMap() const
439  {
440  return cellsFromPointsMap_;
441  }
442 
443  //- Cells inflated from edges
444  const List<objectMap>& cellsFromEdgesMap() const
445  {
446  return cellsFromEdgesMap_;
447  }
448 
449  //- Cells inflated from faces
450  const List<objectMap>& cellsFromFacesMap() const
451  {
452  return cellsFromFacesMap_;
453  }
454 
455  //- Cells originating from cells
456  const List<objectMap>& cellsFromCellsMap() const
457  {
458  return cellsFromCellsMap_;
459  }
460 
461 
462  // Reverse maps
463 
464  //- Reverse point map
465  // Contains new point label for all old and added points
466  const labelList& reversePointMap() const
467  {
468  return reversePointMap_;
469  }
470 
471  //- If point is removed return point (on new mesh) it merged
472  // into
473  label mergedPoint(const label oldPointI) const
474  {
475  label i = reversePointMap_[oldPointI];
476 
477  if (i == -1)
478  {
479  return i;
480  }
481  else if (i < -1)
482  {
483  return -i-2;
484  }
485  else
486  {
487  FatalErrorIn("mergedPoint(const label) const")
488  << "old point label " << oldPointI
489  << " has reverseMap " << i << endl
490  << "Only call mergedPoint for removed points."
491  << abort(FatalError);
492  return -1;
493  }
494  }
495 
496  //- Reverse face map
497  // Contains new face label for all old and added faces
498  const labelList& reverseFaceMap() const
499  {
500  return reverseFaceMap_;
501  }
502 
503  //- If face is removed return face (on new mesh) it merged into
504  label mergedFace(const label oldFaceI) const
505  {
506  label i = reverseFaceMap_[oldFaceI];
507 
508  if (i == -1)
509  {
510  return i;
511  }
512  else if (i < -1)
513  {
514  return -i-2;
515  }
516  else
517  {
518  FatalErrorIn("mergedFace(const label) const")
519  << "old face label " << oldFaceI
520  << " has reverseMap " << i << endl
521  << "Only call mergedFace for removed faces."
522  << abort(FatalError);
523  return -1;
524  }
525  }
526 
527  //- Reverse cell map
528  // Contains new cell label for all old and added cells
529  const labelList& reverseCellMap() const
530  {
531  return reverseCellMap_;
532  }
533 
534  //- If cell is removed return cell (on new mesh) it merged into
535  label mergedCell(const label oldCellI) const
536  {
537  label i = reverseCellMap_[oldCellI];
538 
539  if (i == -1)
540  {
541  return i;
542  }
543  else if (i < -1)
544  {
545  return -i-2;
546  }
547  else
548  {
549  FatalErrorIn("mergedCell(const label) const")
550  << "old cell label " << oldCellI
551  << " has reverseMap " << i << endl
552  << "Only call mergedCell for removed cells."
553  << abort(FatalError);
554  return -1;
555  }
556  }
557 
558  //- Map of flipped face flux faces
559  const labelHashSet& flipFaceFlux() const
560  {
561  return flipFaceFlux_;
562  }
563 
564  //- Patch point renumbering
565  // For every preserved point on a patch give the old position.
566  // For added points, the index is set to -1
567  const labelListList& patchPointMap() const
568  {
569  return patchPointMap_;
570  }
571 
572 
573  // Zone mapping
574 
575  //- Point zone renumbering
576  // For every preserved point in zone give the old position.
577  // For added points, the index is set to -1
578  const labelListList& pointZoneMap() const
579  {
580  return pointZoneMap_;
581  }
582 
583  //- Face zone point renumbering
584  // For every preserved point in zone give the old position.
585  // For added points, the index is set to -1
586  const labelListList& faceZonePointMap() const
587  {
588  return faceZonePointMap_;
589  }
590 
591  //- Face zone face renumbering
592  // For every preserved face in zone give the old position.
593  // For added faces, the index is set to -1
594  const labelListList& faceZoneFaceMap() const
595  {
596  return faceZoneFaceMap_;
597  }
598 
599  //- Cell zone renumbering
600  // For every preserved cell in zone give the old position.
601  // For added cells, the index is set to -1
602  const labelListList& cellZoneMap() const
603  {
604  return cellZoneMap_;
605  }
606 
607  //- Pre-motion point positions.
608  // This specifies the correct way of blowing up
609  // zero-volume objects
610  const pointField& preMotionPoints() const
611  {
612  return preMotionPoints_;
613  }
614 
615  //- Has valid preMotionPoints?
616  bool hasMotionPoints() const
617  {
618  return preMotionPoints_.size() > 0;
619  }
620 
621 
622  //- Return list of the old patch sizes
623  const labelList& oldPatchSizes() const
624  {
625  return oldPatchSizes_;
626  }
627 
628  //- Return list of the old patch start labels
629  const labelList& oldPatchStarts() const
630  {
631  return oldPatchStarts_;
632  }
633 
634  //- Return numbers of mesh points per old patch
635  const labelList& oldPatchNMeshPoints() const
636  {
637  return oldPatchNMeshPoints_;
638  }
639 
640 
641  // Geometric mapping data
643  bool hasOldCellVolumes() const
644  {
645  return oldCellVolumesPtr_.valid();
646  }
648  const scalarField& oldCellVolumes() const
649  {
650  return oldCellVolumesPtr_();
651  }
652 
653 };
654 
655 
656 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
657 
658 } // End namespace Foam
659 
660 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
661 
662 #endif
663 
664 // ************************************************************************* //
const List< objectMap > & pointsFromPointsMap() const
Points originating from points.
Definition: mapPolyMesh.H:398
const labelList & oldPatchNMeshPoints() const
Return numbers of mesh points per old patch.
Definition: mapPolyMesh.H:634
const List< objectMap > & facesFromEdgesMap() const
Faces inflated from edges.
Definition: mapPolyMesh.H:418
const labelListList & faceZonePointMap() const
Face zone point renumbering.
Definition: mapPolyMesh.H:585
const labelList & reverseFaceMap() const
Reverse face map.
Definition: mapPolyMesh.H:497
const polyMesh & mesh() const
Return polyMesh.
Definition: mapPolyMesh.H:359
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:465
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
const List< objectMap > & facesFromPointsMap() const
Faces inflated from points.
Definition: mapPolyMesh.H:412
bool hasMotionPoints() const
Has valid preMotionPoints?
Definition: mapPolyMesh.H:615
const labelListList & faceZoneFaceMap() const
Face zone face renumbering.
Definition: mapPolyMesh.H:593
const List< objectMap > & cellsFromPointsMap() const
Cells inflated from points.
Definition: mapPolyMesh.H:437
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
const List< objectMap > & facesFromFacesMap() const
Faces originating from faces.
Definition: mapPolyMesh.H:424
Namespace for OpenFOAM.
label nOldFaces() const
Number of old faces.
Definition: mapPolyMesh.H:377
const scalarField & oldCellVolumes() const
Definition: mapPolyMesh.H:647
const pointField & preMotionPoints() const
Pre-motion point positions.
Definition: mapPolyMesh.H:609
bool hasOldCellVolumes() const
Definition: mapPolyMesh.H:642
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
label mergedPoint(const label oldPointI) const
If point is removed return point (on new mesh) it merged.
Definition: mapPolyMesh.H:472
label mergedCell(const label oldCellI) const
If cell is removed return cell (on new mesh) it merged into.
Definition: mapPolyMesh.H:534
label mergedFace(const label oldFaceI) const
If face is removed return face (on new mesh) it merged into.
Definition: mapPolyMesh.H:503
const labelList & faceMap() const
Old face map.
Definition: mapPolyMesh.H:406
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Reference counter for various OpenFOAM components.
Definition: refCount.H:45
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
label nOldInternalFaces() const
Number of old internal faces.
Definition: mapPolyMesh.H:371
error FatalError
const labelList & pointMap() const
Old point map.
Definition: mapPolyMesh.H:392
const labelList & reverseCellMap() const
Reverse cell map.
Definition: mapPolyMesh.H:528
const labelListList & patchPointMap() const
Patch point renumbering.
Definition: mapPolyMesh.H:566
const labelHashSet & flipFaceFlux() const
Map of flipped face flux faces.
Definition: mapPolyMesh.H:558
const List< objectMap > & cellsFromFacesMap() const
Cells inflated from faces.
Definition: mapPolyMesh.H:449
const List< objectMap > & cellsFromCellsMap() const
Cells originating from cells.
Definition: mapPolyMesh.H:455
const labelList & oldPatchSizes() const
Return list of the old patch sizes.
Definition: mapPolyMesh.H:622
const labelList & oldPatchStarts() const
Return list of the old patch start labels.
Definition: mapPolyMesh.H:628
label nOldPoints() const
Number of old points.
Definition: mapPolyMesh.H:365
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
const labelListList & pointZoneMap() const
Point zone renumbering.
Definition: mapPolyMesh.H:577
const List< objectMap > & cellsFromEdgesMap() const
Cells inflated from edges.
Definition: mapPolyMesh.H:443
const labelListList & cellZoneMap() const
Cell zone renumbering.
Definition: mapPolyMesh.H:601
label nOldCells() const
Number of old cells.
Definition: mapPolyMesh.H:383
const labelList & cellMap() const
Old cell map.
Definition: mapPolyMesh.H:431