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