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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2024 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::mapPolyMesh
29 
30 Description
31  Class containing mesh-to-mesh mapping information after a change
32  in polyMesh topology.
33 
34  General:
35  - pointMap/faceMap/cellMap: \n
36  from current mesh back to previous mesh.
37  (so to 'pull' the information onto the current mesh)
38  - reversePointMap/faceMap/cellMap: \n
39  from previous mesh to current. (so to 'push' information)
40 
41  In the topology change points/faces/cells
42  - can be unchanged. (faces might be renumbered though)
43  - can be removed (into nothing)
44  - can be removed into/merged with existing same entity
45  (so point merged with other point, face with other face, cell with
46  other cell. Note that probably only cell with cell is relevant)
47  - can be added from existing same 'master' entity
48  (so point from point, face from face and cell from cell)
49  - can be inflated: face out of edge or point,
50  cell out of face, edge or point.
51  - can be appended: added 'out of nothing'.
52 
53  All this information is necessary to correctly map fields.
54 
55  \par points
56 
57  - unchanged:
58  - pointMap[pointi] contains old point label
59  - reversePointMap[oldPointi] contains new point label
60  - removed:
61  - reversePointMap[oldPointi] contains -1
62  - merged into point:
63  - reversePointMap[oldPointi] contains <-1 : -newPointi-2
64  - pointMap[pointi] contains the old master point label
65  - pointsFromPoints gives for pointi all the old point labels
66  (including the old master point!)
67  - added-from-same:
68  - pointMap[pointi] contains the old master point label
69  - appended:
70  - pointMap[pointi] contains -1
71 
72  \par faces
73 
74  - unchanged:
75  - faceMap[facei] contains old face label
76  - reverseFaceMap[oldFacei] contains new face label
77  - removed:
78  - reverseFaceMap[oldFacei] contains -1
79  - merged into face:
80  - reverseFaceMap[oldFacei] contains <-1 : -newFacei-2
81  - faceMap[facei] contains the old master face label
82  - facesFromFaces gives for facei all the old face labels
83  (including the old master face!)
84  - added-from-same:
85  - faceMap[facei] contains the old master face label
86  - inflated-from-edge:
87  - faceMap[facei] contains -1
88  - facesFromEdges contains an entry with
89  - facei
90  - list of faces(*) on old mesh that connected to the old edge
91  - inflated-from-point:
92  - faceMap[facei] contains -1
93  - facesFromPoints contains an entry with
94  - facei
95  - list of faces(*) on old mesh that connected to the old point
96  - appended:
97  - faceMap[facei] contains -1
98 
99  Note (*) \n
100  if the newly inflated face is a boundary face the list of faces will
101  only be boundary faces; if the new face is an internal face they
102  will only be internal faces.
103 
104  \par cells
105 
106  - unchanged:
107  - cellMap[celli] contains old cell label
108  - reverseCellMap[oldCelli] contains new cell label
109  - removed:
110  - reverseCellMap[oldCelli] contains -1
111  - merged into cell:
112  - reverseCellMap[oldCelli] contains <-1 : -newCelli-2
113  - cellMap[celli] contains the old master cell label
114  - cellsFromCells gives for celli all the old cell labels
115  (including the old master cell!)
116  - added-from-same:
117  - cellMap[celli] contains the old master cell label
118  - inflated-from-face:
119  - cellMap[celli] contains -1
120  - cellsFromFaces contains an entry with
121  - celli
122  - list of cells on old mesh that connected to the old face
123  - inflated-from-edge:
124  - cellMap[celli] contains -1
125  - cellsFromEdges contains an entry with
126  - celli
127  - list of cells on old mesh that connected to the old edge
128  - inflated-from-point:
129  - cellMap[celli] contains -1
130  - cellsFromPoints contains an entry with
131  - celli
132  - list of cells on old mesh that connected to the old point
133  - appended:
134  - cellMap[celli] contains -1
135 
136 
137 SourceFiles
138  mapPolyMesh.C
139 
140 \*---------------------------------------------------------------------------*/
141 
142 #ifndef mapPolyMesh_H
143 #define mapPolyMesh_H
144 
145 #include "labelList.H"
146 #include "objectMap.H"
147 #include "pointField.H"
148 #include "HashSet.H"
149 #include "Map.H"
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 namespace Foam
154 {
155 
156 // Forward Declarations
157 class polyMesh;
159 /*---------------------------------------------------------------------------*\
160  Class mapPolyMesh Declaration
161 \*---------------------------------------------------------------------------*/
162 
163 class mapPolyMesh
164 {
165  // Private Data
166 
167  //- Reference to polyMesh
168  const polyMesh& mesh_;
169 
170  //- Number of old live points
171  const label nOldPoints_;
172 
173  //- Number of old live faces
174  const label nOldFaces_;
175 
176  //- Number of old live cells
177  const label nOldCells_;
178 
179  //- Old point map.
180  // Contains the old point label for all new points.
181  // - for preserved points this is the old point label.
182  // - for added points this is the master point ID
183  // - for points added with no master, this is -1
184  // Size of the list equals the size of new points
185  const labelList pointMap_;
186 
187  //- Points resulting from merging points
188  const List<objectMap> pointsFromPointsMap_;
189 
190  //- Old face map.
191  // Contains a list of old face labels for every new face.
192  // Size of the list equals the number of new faces
193  // - for preserved faces this is the old face label.
194  // - for faces added from faces this is the master face ID
195  // - for faces added with no master, this is -1
196  // - for faces added from points or edges, this is -1
197  const labelList faceMap_;
198 
199  //- Faces inflated from points
200  const List<objectMap> facesFromPointsMap_;
201 
202  //- Faces inflated from edges
203  const List<objectMap> facesFromEdgesMap_;
204 
205  //- Faces resulting from merging faces
206  const List<objectMap> facesFromFacesMap_;
207 
208  //- Old cell map.
209  // Contains old cell label for all preserved cells.
210  // Size of the list equals the number or preserved cells
211  const labelList cellMap_;
212 
213  //- Cells inflated from points
214  const List<objectMap> cellsFromPointsMap_;
215 
216  //- Cells inflated from edges
217  const List<objectMap> cellsFromEdgesMap_;
218 
219  //- Cells inflated from faces
220  const List<objectMap> cellsFromFacesMap_;
221 
222  //- Cells resulting from merging cells
223  const List<objectMap> cellsFromCellsMap_;
224 
225  //- Reverse point map
226  const labelList reversePointMap_;
227 
228  //- Reverse face map
229  const labelList reverseFaceMap_;
230 
231  //- Reverse cell map
232  const labelList reverseCellMap_;
233 
234  //- Map of flipped face flux faces
235  const labelHashSet flipFaceFlux_;
236 
237  //- Patch mesh point renumbering
238  labelListList patchPointMap_;
239 
240  //- Point zone renumbering
241  // For every preserved point in zone give the old position.
242  // For added points, the index is set to -1
243  labelListList pointZoneMap_;
244 
245  //- Face zone point renumbering
246  // For every preserved point in zone give the old position.
247  // For added points, the index is set to -1
248  labelListList faceZonePointMap_;
249 
250  //- Face zone face renumbering
251  // For every preserved face in zone give the old position.
252  // For added faces, the index is set to -1
253  labelListList faceZoneFaceMap_;
254 
255  //- Cell zone renumbering
256  // For every preserved cell in zone give the old position.
257  // For added cells, the index is set to -1
258  labelListList cellZoneMap_;
259 
260  //- Pre-motion point positions.
261  // This specifies the correct way of blowing up zero-volume objects
262  const pointField preMotionPoints_;
263 
264  //- List of the old patch sizes
265  labelList oldPatchSizes_;
266 
267  //- List of the old patch start labels
268  const labelList oldPatchStarts_;
269 
270  //- List of numbers of mesh points per old patch
271  labelList oldPatchNMeshPoints_;
272 
273  //- Optional old cell volumes (for mapping)
274  autoPtr<scalarField> oldCellVolumesPtr_;
275 
276 
277 public:
278 
279  // Generated Methods
280 
281  //- No copy construct
282  mapPolyMesh(const mapPolyMesh&) = delete;
283 
284  //- No copy assignment
285  void operator=(const mapPolyMesh&) = delete;
286 
287 
288  // Constructors
289 
290  //- Construct from mesh
291  mapPolyMesh(const polyMesh& mesh);
292 
293  //- Copy construct from components,
294  //- except for oldCellVolumes which is move construct
296  (
297  const polyMesh& mesh,
298  const label nOldPoints,
299  const label nOldFaces,
300  const label nOldCells,
301  const labelList& pointMap,
302  const List<objectMap>& pointsFromPoints,
303  const labelList& faceMap,
304  const List<objectMap>& facesFromPoints,
305  const List<objectMap>& facesFromEdges,
306  const List<objectMap>& facesFromFaces,
307  const labelList& cellMap,
308  const List<objectMap>& cellsFromPoints,
309  const List<objectMap>& cellsFromEdges,
310  const List<objectMap>& cellsFromFaces,
311  const List<objectMap>& cellsFromCells,
312  const labelList& reversePointMap,
313  const labelList& reverseFaceMap,
314  const labelList& reverseCellMap,
315  const labelHashSet& flipFaceFlux,
320  const labelListList& cellZoneMap,
322  const labelList& oldPatchStarts,
324  const autoPtr<scalarField>& oldCellVolumesPtr
325  );
326 
327  //- Construct from components and optionally reuse storage
329  (
330  const polyMesh& mesh,
331  const label nOldPoints,
332  const label nOldFaces,
333  const label nOldCells,
335  List<objectMap>& pointsFromPoints,
337  List<objectMap>& facesFromPoints,
338  List<objectMap>& facesFromEdges,
339  List<objectMap>& facesFromFaces,
341  List<objectMap>& cellsFromPoints,
342  List<objectMap>& cellsFromEdges,
343  List<objectMap>& cellsFromFaces,
344  List<objectMap>& cellsFromCells,
357  autoPtr<scalarField>& oldCellVolumesPtr,
358  const bool reuse
359  );
360 
361 
362  // Member Functions
363 
364  // Access
365 
366  //- Return polyMesh
367  const polyMesh& mesh() const noexcept
368  {
369  return mesh_;
370  }
371 
372  //- Number of old points
373  label nOldPoints() const noexcept
374  {
375  return nOldPoints_;
376  }
377 
378  //- Number of old internal faces
379  label nOldInternalFaces() const
380  {
381  return oldPatchStarts_[0];
382  }
383 
384  //- Number of old faces
385  label nOldFaces() const noexcept
386  {
387  return nOldFaces_;
388  }
389 
390  //- Number of old cells
391  label nOldCells() const noexcept
392  {
393  return nOldCells_;
394  }
395 
396  //- Old point map.
397  // Contains the old point label for all new points.
398  // For preserved points this is the old point label.
399  // For added points this is the master point ID
400  const labelList& pointMap() const noexcept
401  {
402  return pointMap_;
403  }
404 
405  //- Points originating from points
407  {
408  return pointsFromPointsMap_;
409  }
410 
411  //- Old face map.
412  // Contains a list of old face labels for every new face.
413  // Warning: this map contains invalid entries for new faces
414  const labelList& faceMap() const noexcept
415  {
416  return faceMap_;
417  }
418 
419  //- Faces inflated from points
421  {
422  return facesFromPointsMap_;
423  }
424 
425  //- Faces inflated from edges
427  {
428  return facesFromEdgesMap_;
429  }
430 
431  //- Faces originating from faces
433  {
434  return facesFromFacesMap_;
435  }
436 
437  //- Old cell map.
438  // Contains old cell label for all preserved cells.
439  const labelList& cellMap() const noexcept
440  {
441  return cellMap_;
442  }
443 
444  //- Cells inflated from points
446  {
447  return cellsFromPointsMap_;
448  }
449 
450  //- Cells inflated from edges
452  {
453  return cellsFromEdgesMap_;
454  }
455 
456  //- Cells inflated from faces
458  {
459  return cellsFromFacesMap_;
460  }
461 
462  //- Cells originating from cells
464  {
465  return cellsFromCellsMap_;
466  }
467 
468 
469  // Reverse maps
470 
471  //- Reverse point map
472  // Contains new point label for all old and added points
473  const labelList& reversePointMap() const noexcept
474  {
475  return reversePointMap_;
476  }
477 
478  //- If point is removed return point (on new mesh) it merged
479  // into
480  label mergedPoint(const label oldPointi) const
481  {
482  label i = reversePointMap_[oldPointi];
483 
484  if (i == -1)
485  {
486  return i;
487  }
488  else if (i < -1)
489  {
490  return -i-2;
491  }
492  else
493  {
495  << "old point label " << oldPointi
496  << " has reverseMap " << i << endl
497  << "Only call mergedPoint for removed points."
498  << abort(FatalError);
499  return -1;
500  }
501  }
502 
503  //- Reverse face map
504  // Contains new face label for all old and added faces
505  const labelList& reverseFaceMap() const noexcept
506  {
507  return reverseFaceMap_;
508  }
509 
510  //- If face is removed return face (on new mesh) it merged into
511  label mergedFace(const label oldFacei) const
512  {
513  label i = reverseFaceMap_[oldFacei];
514 
515  if (i == -1)
516  {
517  return i;
518  }
519  else if (i < -1)
520  {
521  return -i-2;
522  }
523  else
524  {
526  << "old face label " << oldFacei
527  << " has reverseMap " << i << endl
528  << "Only call mergedFace for removed faces."
529  << abort(FatalError);
530  return -1;
531  }
532  }
533 
534  //- Reverse cell map
535  // Contains new cell label for all old and added cells
536  const labelList& reverseCellMap() const noexcept
537  {
538  return reverseCellMap_;
539  }
540 
541  //- If cell is removed return cell (on new mesh) it merged into
542  label mergedCell(const label oldCelli) const
543  {
544  label i = reverseCellMap_[oldCelli];
546  if (i == -1)
547  {
548  return i;
549  }
550  else if (i < -1)
551  {
552  return -i-2;
553  }
554  else
555  {
557  << "old cell label " << oldCelli
558  << " has reverseMap " << i << endl
559  << "Only call mergedCell for removed cells."
560  << abort(FatalError);
561  return -1;
562  }
563  }
564 
565  //- Map of flipped face flux faces
566  const labelHashSet& flipFaceFlux() const noexcept
567  {
568  return flipFaceFlux_;
569  }
570 
571  //- Patch point renumbering
572  // For every preserved point on a patch give the old position.
573  // For added points, the index is set to -1
574  const labelListList& patchPointMap() const noexcept
575  {
576  return patchPointMap_;
577  }
578 
579 
580  // Zone mapping
581 
582  //- Point zone renumbering
583  // For every preserved point in zone give the old position.
584  // For added points, the index is set to -1
585  const labelListList& pointZoneMap() const noexcept
586  {
587  return pointZoneMap_;
588  }
589 
590  //- Face zone point renumbering
591  // For every preserved point in zone give the old position.
592  // For added points, the index is set to -1
594  {
595  return faceZonePointMap_;
596  }
597 
598  //- Face zone face renumbering
599  // For every preserved face in zone give the old position.
600  // For added faces, the index is set to -1
601  const labelListList& faceZoneFaceMap() const noexcept
602  {
603  return faceZoneFaceMap_;
604  }
605 
606  //- Cell zone renumbering
607  // For every preserved cell in zone give the old position.
608  // For added cells, the index is set to -1
609  const labelListList& cellZoneMap() const noexcept
610  {
611  return cellZoneMap_;
612  }
613 
614  //- Pre-motion point positions.
615  // This specifies the correct way of blowing up
616  // zero-volume objects
617  const pointField& preMotionPoints() const noexcept
618  {
619  return preMotionPoints_;
620  }
621 
622  //- Has valid preMotionPoints?
623  bool hasMotionPoints() const noexcept
624  {
625  return !preMotionPoints_.empty();
626  }
627 
629  //- Return list of the old patch sizes
630  const labelList& oldPatchSizes() const noexcept
631  {
632  return oldPatchSizes_;
633  }
634 
635  //- Return list of the old patch start labels
636  const labelList& oldPatchStarts() const noexcept
637  {
638  return oldPatchStarts_;
639  }
640 
641  //- Return numbers of mesh points per old patch
642  const labelList& oldPatchNMeshPoints() const noexcept
643  {
644  return oldPatchNMeshPoints_;
645  }
646 
647 
648  // Geometric mapping data
649 
650  bool hasOldCellVolumes() const noexcept
651  {
652  return bool(oldCellVolumesPtr_);
653  }
654 
655  const scalarField& oldCellVolumes() const
656  {
657  return *oldCellVolumesPtr_;
658  }
659 };
660 
661 
662 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
663 
664 } // End namespace Foam
665 
666 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
667 
668 #endif
669 
670 // ************************************************************************* //
void operator=(const mapPolyMesh &)=delete
No copy assignment.
const polyMesh & mesh() const noexcept
Return polyMesh.
Definition: mapPolyMesh.H:440
const labelHashSet & flipFaceFlux() const noexcept
Map of flipped face flux faces.
Definition: mapPolyMesh.H:690
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
const labelList & oldPatchNMeshPoints() const noexcept
Return numbers of mesh points per old patch.
Definition: mapPolyMesh.H:792
bool hasOldCellVolumes() const noexcept
Definition: mapPolyMesh.H:800
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:675
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
const labelListList & faceZoneFaceMap() const noexcept
Face zone face renumbering.
Definition: mapPolyMesh.H:737
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
const List< objectMap > & facesFromPointsMap() const noexcept
Faces inflated from points.
Definition: mapPolyMesh.H:511
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
label nOldInternalFaces() const
Number of old internal faces.
Definition: mapPolyMesh.H:456
const labelList & reverseFaceMap() const noexcept
Reverse face map.
Definition: mapPolyMesh.H:620
const labelList & oldPatchSizes() const noexcept
Return list of the old patch sizes.
Definition: mapPolyMesh.H:776
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
label mergedPoint(const label oldPointi) const
If point is removed return point (on new mesh) it merged.
Definition: mapPolyMesh.H:592
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
const List< objectMap > & cellsFromCellsMap() const noexcept
Cells originating from cells.
Definition: mapPolyMesh.H:569
const labelList & cellMap() const noexcept
Old cell map.
Definition: mapPolyMesh.H:537
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const List< objectMap > & cellsFromPointsMap() const noexcept
Cells inflated from points.
Definition: mapPolyMesh.H:545
const labelList & pointMap() const noexcept
Old point map.
Definition: mapPolyMesh.H:484
const labelList & reverseCellMap() const noexcept
Reverse cell map.
Definition: mapPolyMesh.H:656
mapPolyMesh(const mapPolyMesh &)=delete
No copy construct.
const labelList & reversePointMap() const noexcept
Reverse point map.
Definition: mapPolyMesh.H:582
label mergedCell(const label oldCelli) const
If cell is removed return cell (on new mesh) it merged into.
Definition: mapPolyMesh.H:664
errorManip< error > abort(error &err)
Definition: errorManip.H:139
const labelListList & pointZoneMap() const noexcept
Point zone renumbering.
Definition: mapPolyMesh.H:715
const direction noexcept
Definition: Scalar.H:258
label nOldCells() const noexcept
Number of old cells.
Definition: mapPolyMesh.H:472
const labelListList & cellZoneMap() const noexcept
Cell zone renumbering.
Definition: mapPolyMesh.H:748
const List< objectMap > & facesFromEdgesMap() const noexcept
Faces inflated from edges.
Definition: mapPolyMesh.H:519
const List< objectMap > & pointsFromPointsMap() const noexcept
Points originating from points.
Definition: mapPolyMesh.H:492
bool hasMotionPoints() const noexcept
Has valid preMotionPoints?
Definition: mapPolyMesh.H:767
label nOldPoints() const noexcept
Number of old points.
Definition: mapPolyMesh.H:448
const labelList & oldPatchStarts() const noexcept
Return list of the old patch start labels.
Definition: mapPolyMesh.H:784
const labelListList & patchPointMap() const noexcept
Patch point renumbering.
Definition: mapPolyMesh.H:701
label mergedFace(const label oldFacei) const
If face is removed return face (on new mesh) it merged into.
Definition: mapPolyMesh.H:628
const scalarField & oldCellVolumes() const
Definition: mapPolyMesh.H:805
const List< objectMap > & cellsFromEdgesMap() const noexcept
Cells inflated from edges.
Definition: mapPolyMesh.H:553
label nOldFaces() const noexcept
Number of old faces.
Definition: mapPolyMesh.H:464
const List< objectMap > & cellsFromFacesMap() const noexcept
Cells inflated from faces.
Definition: mapPolyMesh.H:561
const labelListList & faceZonePointMap() const noexcept
Face zone point renumbering.
Definition: mapPolyMesh.H:726
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:75
const labelList & faceMap() const noexcept
Old face map.
Definition: mapPolyMesh.H:503
List< label > labelList
A List of labels.
Definition: List.H:62
const List< objectMap > & facesFromFacesMap() const noexcept
Faces originating from faces.
Definition: mapPolyMesh.H:527
const pointField & preMotionPoints() const noexcept
Pre-motion point positions.
Definition: mapPolyMesh.H:759
Namespace for OpenFOAM.