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-2016 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  // Private data
162 
163  //- Reference to polyMesh
164  const polyMesh& mesh_;
165 
166  //- Number of old live points
167  const label nOldPoints_;
168 
169  //- Number of old live faces
170  const label nOldFaces_;
171 
172  //- Number of old live cells
173  const label nOldCells_;
174 
175  //- Old point map.
176  // Contains the old point label for all new points.
177  // - for preserved points this is the old point label.
178  // - for added points this is the master point ID
179  // - for points added with no master, this is -1
180  // Size of the list equals the size of new points
181  const labelList pointMap_;
182 
183  //- Points resulting from merging points
184  const List<objectMap> pointsFromPointsMap_;
185 
186  //- Old face map.
187  // Contains a list of old face labels for every new face.
188  // Size of the list equals the number of new faces
189  // - for preserved faces this is the old face label.
190  // - for faces added from faces this is the master face ID
191  // - for faces added with no master, this is -1
192  // - for faces added from points or edges, this is -1
193  const labelList faceMap_;
194 
195  //- Faces inflated from points
196  const List<objectMap> facesFromPointsMap_;
197 
198  //- Faces inflated from edges
199  const List<objectMap> facesFromEdgesMap_;
200 
201  //- Faces resulting from merging faces
202  const List<objectMap> facesFromFacesMap_;
203 
204  //- Old cell map.
205  // Contains old cell label for all preserved cells.
206  // Size of the list equals the number or preserved cells
207  const labelList cellMap_;
208 
209  //- Cells inflated from points
210  const List<objectMap> cellsFromPointsMap_;
211 
212  //- Cells inflated from edges
213  const List<objectMap> cellsFromEdgesMap_;
214 
215  //- Cells inflated from faces
216  const List<objectMap> cellsFromFacesMap_;
217 
218  //- Cells resulting from merging cells
219  const List<objectMap> cellsFromCellsMap_;
220 
221  //- Reverse point map
222  const labelList reversePointMap_;
223 
224  //- Reverse face map
225  const labelList reverseFaceMap_;
226 
227  //- Reverse cell map
228  const labelList reverseCellMap_;
229 
230  //- Map of flipped face flux faces
231  const labelHashSet flipFaceFlux_;
232 
233  //- Patch mesh point renumbering
234  const labelListList patchPointMap_;
235 
236  //- Point zone renumbering
237  // For every preserved point in zone give the old position.
238  // For added points, the index is set to -1
239  const labelListList pointZoneMap_;
240 
241  //- Face zone point renumbering
242  // For every preserved point in zone give the old position.
243  // For added points, the index is set to -1
244  const labelListList faceZonePointMap_;
245 
246  //- Face zone face renumbering
247  // For every preserved face in zone give the old position.
248  // For added faces, the index is set to -1
249  const labelListList faceZoneFaceMap_;
250 
251  //- Cell zone renumbering
252  // For every preserved cell in zone give the old position.
253  // For added cells, the index is set to -1
254  const labelListList cellZoneMap_;
255 
256  //- Pre-motion point positions.
257  // This specifies the correct way of blowing up zero-volume objects
258  const pointField preMotionPoints_;
259 
260  //- List of the old patch sizes
261  labelList oldPatchSizes_;
262 
263  //- List of the old patch start labels
264  const labelList oldPatchStarts_;
265 
266  //- List of numbers of mesh points per old patch
267  const labelList oldPatchNMeshPoints_;
268 
269  //- Optional old cell volumes (for mapping)
270  autoPtr<scalarField> oldCellVolumesPtr_;
271 
272 
273  // Private Member Functions
274 
275  //- Disallow default bitwise copy construct
276  mapPolyMesh(const mapPolyMesh&);
277 
278  //- Disallow default bitwise assignment
279  void operator=(const mapPolyMesh&);
280 
281 
282 public:
283 
284  // Constructors
285 
286  //- Construct from components. Copy (except for oldCellVolumes).
288  (
289  const polyMesh& mesh,
290  const label nOldPoints,
291  const label nOldFaces,
292  const label nOldCells,
293  const labelList& pointMap,
294  const List<objectMap>& pointsFromPoints,
295  const labelList& faceMap,
296  const List<objectMap>& facesFromPoints,
297  const List<objectMap>& facesFromEdges,
298  const List<objectMap>& facesFromFaces,
299  const labelList& cellMap,
300  const List<objectMap>& cellsFromPoints,
301  const List<objectMap>& cellsFromEdges,
302  const List<objectMap>& cellsFromFaces,
303  const List<objectMap>& cellsFromCells,
304  const labelList& reversePointMap,
305  const labelList& reverseFaceMap,
306  const labelList& reverseCellMap,
307  const labelHashSet& flipFaceFlux,
312  const labelListList& cellZoneMap,
314  const labelList& oldPatchStarts,
316  const autoPtr<scalarField>& oldCellVolumesPtr
317  );
318 
319  //- Construct from components and optionally reuse storage
321  (
322  const polyMesh& mesh,
323  const label nOldPoints,
324  const label nOldFaces,
325  const label nOldCells,
326  labelList& pointMap,
327  List<objectMap>& pointsFromPoints,
328  labelList& faceMap,
329  List<objectMap>& facesFromPoints,
330  List<objectMap>& facesFromEdges,
331  List<objectMap>& facesFromFaces,
332  labelList& cellMap,
333  List<objectMap>& cellsFromPoints,
334  List<objectMap>& cellsFromEdges,
335  List<objectMap>& cellsFromFaces,
336  List<objectMap>& cellsFromCells,
337  labelList& reversePointMap,
338  labelList& reverseFaceMap,
339  labelList& reverseCellMap,
340  labelHashSet& flipFaceFlux,
341  labelListList& patchPointMap,
342  labelListList& pointZoneMap,
343  labelListList& faceZonePointMap,
344  labelListList& faceZoneFaceMap,
345  labelListList& cellZoneMap,
346  pointField& preMotionPoints,
347  labelList& oldPatchStarts,
348  labelList& oldPatchNMeshPoints,
349  autoPtr<scalarField>& oldCellVolumesPtr,
350  const bool reuse
351  );
352 
353  // Member Functions
354 
355  // Access
356 
357  //- Return polyMesh
358  const polyMesh& mesh() const
359  {
360  return mesh_;
361  }
362 
363  //- Number of old points
364  label nOldPoints() const
365  {
366  return nOldPoints_;
367  }
368 
369  //- Number of old internal faces
370  label nOldInternalFaces() const
371  {
372  return oldPatchStarts_[0];
373  }
374 
375  //- Number of old faces
376  label nOldFaces() const
377  {
378  return nOldFaces_;
379  }
380 
381  //- Number of old cells
382  label nOldCells() const
383  {
384  return nOldCells_;
385  }
386 
387  //- Old point map.
388  // Contains the old point label for all new points.
389  // For preserved points this is the old point label.
390  // For added points this is the master point ID
391  const labelList& pointMap() const
392  {
393  return pointMap_;
394  }
395 
396  //- Points originating from points
397  const List<objectMap>& pointsFromPointsMap() const
398  {
399  return pointsFromPointsMap_;
400  }
401 
402  //- Old face map.
403  // Contains a list of old face labels for every new face.
404  // Warning: this map contains invalid entries for new faces
405  const labelList& faceMap() const
406  {
407  return faceMap_;
408  }
409 
410  //- Faces inflated from points
411  const List<objectMap>& facesFromPointsMap() const
412  {
413  return facesFromPointsMap_;
414  }
415 
416  //- Faces inflated from edges
417  const List<objectMap>& facesFromEdgesMap() const
418  {
419  return facesFromEdgesMap_;
420  }
421 
422  //- Faces originating from faces
423  const List<objectMap>& facesFromFacesMap() const
424  {
425  return facesFromFacesMap_;
426  }
427 
428  //- Old cell map.
429  // Contains old cell label for all preserved cells.
430  const labelList& cellMap() const
431  {
432  return cellMap_;
433  }
434 
435  //- Cells inflated from points
436  const List<objectMap>& cellsFromPointsMap() const
437  {
438  return cellsFromPointsMap_;
439  }
440 
441  //- Cells inflated from edges
442  const List<objectMap>& cellsFromEdgesMap() const
443  {
444  return cellsFromEdgesMap_;
445  }
446 
447  //- Cells inflated from faces
448  const List<objectMap>& cellsFromFacesMap() const
449  {
450  return cellsFromFacesMap_;
451  }
452 
453  //- Cells originating from cells
454  const List<objectMap>& cellsFromCellsMap() const
455  {
456  return cellsFromCellsMap_;
457  }
458 
459 
460  // Reverse maps
461 
462  //- Reverse point map
463  // Contains new point label for all old and added points
464  const labelList& reversePointMap() const
465  {
466  return reversePointMap_;
467  }
468 
469  //- If point is removed return point (on new mesh) it merged
470  // into
471  label mergedPoint(const label oldPointi) const
472  {
473  label i = reversePointMap_[oldPointi];
474 
475  if (i == -1)
476  {
477  return i;
478  }
479  else if (i < -1)
480  {
481  return -i-2;
482  }
483  else
484  {
486  << "old point label " << oldPointi
487  << " has reverseMap " << i << endl
488  << "Only call mergedPoint for removed points."
489  << abort(FatalError);
490  return -1;
491  }
492  }
493 
494  //- Reverse face map
495  // Contains new face label for all old and added faces
496  const labelList& reverseFaceMap() const
497  {
498  return reverseFaceMap_;
499  }
500 
501  //- If face is removed return face (on new mesh) it merged into
502  label mergedFace(const label oldFacei) const
503  {
504  label i = reverseFaceMap_[oldFacei];
505 
506  if (i == -1)
507  {
508  return i;
509  }
510  else if (i < -1)
511  {
512  return -i-2;
513  }
514  else
515  {
517  << "old face label " << oldFacei
518  << " has reverseMap " << i << endl
519  << "Only call mergedFace for removed faces."
520  << abort(FatalError);
521  return -1;
522  }
523  }
524 
525  //- Reverse cell map
526  // Contains new cell label for all old and added cells
527  const labelList& reverseCellMap() const
528  {
529  return reverseCellMap_;
530  }
531 
532  //- If cell is removed return cell (on new mesh) it merged into
533  label mergedCell(const label oldCelli) const
534  {
535  label i = reverseCellMap_[oldCelli];
536 
537  if (i == -1)
538  {
539  return i;
540  }
541  else if (i < -1)
542  {
543  return -i-2;
544  }
545  else
546  {
548  << "old cell label " << oldCelli
549  << " has reverseMap " << i << endl
550  << "Only call mergedCell for removed cells."
551  << abort(FatalError);
552  return -1;
553  }
554  }
555 
556  //- Map of flipped face flux faces
557  const labelHashSet& flipFaceFlux() const
558  {
559  return flipFaceFlux_;
560  }
561 
562  //- Patch point renumbering
563  // For every preserved point on a patch give the old position.
564  // For added points, the index is set to -1
565  const labelListList& patchPointMap() const
566  {
567  return patchPointMap_;
568  }
569 
570 
571  // Zone mapping
572 
573  //- Point zone renumbering
574  // For every preserved point in zone give the old position.
575  // For added points, the index is set to -1
576  const labelListList& pointZoneMap() const
577  {
578  return pointZoneMap_;
579  }
580 
581  //- Face zone point renumbering
582  // For every preserved point in zone give the old position.
583  // For added points, the index is set to -1
584  const labelListList& faceZonePointMap() const
585  {
586  return faceZonePointMap_;
587  }
588 
589  //- Face zone face renumbering
590  // For every preserved face in zone give the old position.
591  // For added faces, the index is set to -1
592  const labelListList& faceZoneFaceMap() const
593  {
594  return faceZoneFaceMap_;
595  }
596 
597  //- Cell zone renumbering
598  // For every preserved cell in zone give the old position.
599  // For added cells, the index is set to -1
600  const labelListList& cellZoneMap() const
601  {
602  return cellZoneMap_;
603  }
604 
605  //- Pre-motion point positions.
606  // This specifies the correct way of blowing up
607  // zero-volume objects
608  const pointField& preMotionPoints() const
609  {
610  return preMotionPoints_;
611  }
612 
613  //- Has valid preMotionPoints?
614  bool hasMotionPoints() const
615  {
616  return preMotionPoints_.size() > 0;
617  }
618 
619 
620  //- Return list of the old patch sizes
621  const labelList& oldPatchSizes() const
622  {
623  return oldPatchSizes_;
624  }
625 
626  //- Return list of the old patch start labels
627  const labelList& oldPatchStarts() const
628  {
629  return oldPatchStarts_;
630  }
631 
632  //- Return numbers of mesh points per old patch
633  const labelList& oldPatchNMeshPoints() const
634  {
635  return oldPatchNMeshPoints_;
636  }
637 
638 
639  // Geometric mapping data
641  bool hasOldCellVolumes() const
642  {
643  return oldCellVolumesPtr_.valid();
644  }
646  const scalarField& oldCellVolumes() const
647  {
648  return oldCellVolumesPtr_();
649  }
650 
651 };
652 
653 
654 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
655 
656 } // End namespace Foam
657 
658 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
659 
660 #endif
661 
662 // ************************************************************************* //
const List< objectMap > & cellsFromEdgesMap() const
Cells inflated from edges.
Definition: mapPolyMesh.H:441
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
const List< objectMap > & facesFromPointsMap() const
Faces inflated from points.
Definition: mapPolyMesh.H:410
const labelList & oldPatchNMeshPoints() const
Return numbers of mesh points per old patch.
Definition: mapPolyMesh.H:632
label mergedPoint(const label oldPointi) const
If point is removed return point (on new mesh) it merged.
Definition: mapPolyMesh.H:470
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const labelHashSet & flipFaceFlux() const
Map of flipped face flux faces.
Definition: mapPolyMesh.H:556
label mergedFace(const label oldFacei) const
If face is removed return face (on new mesh) it merged into.
Definition: mapPolyMesh.H:501
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
const labelList & oldPatchSizes() const
Return list of the old patch sizes.
Definition: mapPolyMesh.H:620
label nOldPoints() const
Number of old points.
Definition: mapPolyMesh.H:363
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool hasMotionPoints() const
Has valid preMotionPoints?
Definition: mapPolyMesh.H:613
const labelList & pointMap() const
Old point map.
Definition: mapPolyMesh.H:390
const labelList & oldPatchStarts() const
Return list of the old patch start labels.
Definition: mapPolyMesh.H:626
const List< objectMap > & cellsFromCellsMap() const
Cells originating from cells.
Definition: mapPolyMesh.H:453
const labelListList & pointZoneMap() const
Point zone renumbering.
Definition: mapPolyMesh.H:575
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
const List< objectMap > & facesFromEdgesMap() const
Faces inflated from edges.
Definition: mapPolyMesh.H:416
const List< objectMap > & pointsFromPointsMap() const
Points originating from points.
Definition: mapPolyMesh.H:396
const labelListList & cellZoneMap() const
Cell zone renumbering.
Definition: mapPolyMesh.H:599
const labelList & reverseFaceMap() const
Reverse face map.
Definition: mapPolyMesh.H:495
const labelListList & patchPointMap() const
Patch point renumbering.
Definition: mapPolyMesh.H:564
const labelListList & faceZoneFaceMap() const
Face zone face renumbering.
Definition: mapPolyMesh.H:591
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
label nOldInternalFaces() const
Number of old internal faces.
Definition: mapPolyMesh.H:369
label nOldFaces() const
Number of old faces.
Definition: mapPolyMesh.H:375
const List< objectMap > & cellsFromFacesMap() const
Cells inflated from faces.
Definition: mapPolyMesh.H:447
const labelListList & faceZonePointMap() const
Face zone point renumbering.
Definition: mapPolyMesh.H:583
label mergedCell(const label oldCelli) const
If cell is removed return cell (on new mesh) it merged into.
Definition: mapPolyMesh.H:532
label nOldCells() const
Number of old cells.
Definition: mapPolyMesh.H:381
bool hasOldCellVolumes() const
Definition: mapPolyMesh.H:640
const labelList & cellMap() const
Old cell map.
Definition: mapPolyMesh.H:429
const scalarField & oldCellVolumes() const
Definition: mapPolyMesh.H:645
const labelList & reverseCellMap() const
Reverse cell map.
Definition: mapPolyMesh.H:526
const labelList & faceMap() const
Old face map.
Definition: mapPolyMesh.H:404
const pointField & preMotionPoints() const
Pre-motion point positions.
Definition: mapPolyMesh.H:607
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
const List< objectMap > & facesFromFacesMap() const
Faces originating from faces.
Definition: mapPolyMesh.H:422
const polyMesh & mesh() const
Return polyMesh.
Definition: mapPolyMesh.H:357
Namespace for OpenFOAM.
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:463
const List< objectMap > & cellsFromPointsMap() const
Cells inflated from points.
Definition: mapPolyMesh.H:435