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