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