polyTopoChange.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) 2018-2022 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::polyTopoChange
29
30Description
31 Direct mesh changes based on v1.3 polyTopoChange syntax.
32
33 Instead of recording changes and executing them all in one go (as did
34 v1.3 polyTopoChange) this class actually holds the current
35 points/faces/cells and does the change immediately.
36 It can be asked to compress out all unused points/faces/cells and
37 renumber everything to be consistent.
38
39 Note:
40 - polyTopoChange can be copied.
41 - adding a face using non-existing cells causes all intermediate cells
42 to be added. So always first add cells/points and then faces.
43 (or set strict checking)
44 - strict checking:
45 - any added/modified face can only use already existing vertices
46 - any added face can only use already existing cells
47 - no item can be removed more than once.
48 - removed cell: cell set to 0 faces.
49 - removed face: face set to 0 vertices.
50 - removed point: coordinate set to vector::max (VGREAT,VGREAT,VGREAT).
51 Note that this might give problems if this value is used already.
52 To see if point is equal to above value we don't use == (which might give
53 problems with roundoff error) but instead compare the individual component
54 with >.
55 - coupled patches: the reorderCoupledFaces routine (borrowed from
56 the couplePatches utility) reorders coupled patch faces and
57 uses the cyclicPolyPatch,processorPolyPatch functionality.
58
59SourceFiles
60 polyTopoChange.C
61 polyTopoChangeI.H
62 polyTopoChangeTemplates.C
63
64\*---------------------------------------------------------------------------*/
65
66#ifndef polyTopoChange_H
67#define polyTopoChange_H
68
69#include "DynamicList.H"
70#include "labelList.H"
71#include "pointField.H"
72#include "Map.H"
73#include "HashSet.H"
74#include "bitSet.H"
75
76// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77
78namespace Foam
79{
80
81// Forward Declarations
82class face;
83class primitiveMesh;
84class polyMesh;
85class Time;
86class fileName;
87class polyBoundaryMesh;
88class polyPatch;
89class dictionary;
90class topoAction;
91class objectMap;
92class IOobject;
93class mapPolyMesh;
94template<class T> class CompactListList;
95
96/*---------------------------------------------------------------------------*\
97 Class polyTopoChange Declaration
98\*---------------------------------------------------------------------------*/
100class polyTopoChange
101{
102 // Private data
103
104 //- Whether to allow referencing illegal points/cells/faces
105 // when adding/removing data.
106 bool strict_;
107
108
109 // Patches
110
111 //- Number of patches
112 label nPatches_;
113
114
115 // Points
116
117 //- Current point set
118 DynamicList<point> points_;
119
120 //- Original point label (or masterpoint for added points)
121 DynamicList<label> pointMap_;
122
123 //- For all original and added points contains new point label.
124 //- (used to map return value of addPoint to new mesh point)
125 DynamicList<label> reversePointMap_;
126
127 //- Zone of point
128 Map<label> pointZone_;
129
130 //- Retired points
131 labelHashSet retiredPoints_;
132
133
134 // Faces
135
136 //- Current faceList
137 DynamicList<face> faces_;
138
139 //- Patch for every external face (-1 for internal faces)
140 DynamicList<label> region_;
141
142 //- Owner for all faces
143 DynamicList<label> faceOwner_;
144
145 //- Neighbour for internal faces (-1 for external faces)
146 DynamicList<label> faceNeighbour_;
147
148 //- Original face label. Or master face for added-from-faces;
149 // -1 for faces added-from-edge or added-from-point)
150 DynamicList<label> faceMap_;
151
152 //- For all original and added faces contains new face label
153 // (used to map return value of addFace to new mesh face)
154 DynamicList<label> reverseFaceMap_;
155
156 //- Faces added from point (corresponding faceMap_ will
157 // be -1)
158 Map<label> faceFromPoint_;
159
160 //- Faces added from edge (corresponding faceMap_ will
161 // be -1)
162 Map<label> faceFromEdge_;
163
164 //- In mapping whether to reverse the flux.
165 bitSet flipFaceFlux_;
166
167 //- Zone of face
168 Map<label> faceZone_;
169
170 //- Orientation of face in zone
171 bitSet faceZoneFlip_;
172
173 //- Active faces
174 label nActiveFaces_;
175
176
177 // Cells
178
179 //- Original cell label or master cell for added-from-cell;
180 // -1 for cells added from face or edge.
181 DynamicList<label> cellMap_;
182
183 //- For all original and added cells contains new cell label
184 // (used to map return value of addCell to new mesh cell)
185 DynamicList<label> reverseCellMap_;
186
187 //- Cells added from point
188 Map<label> cellFromPoint_;
189
190 //- Cells added from edge
191 Map<label> cellFromEdge_;
192
193 //- Cells added from face
194 Map<label> cellFromFace_;
195
196 //- Zone of cell
197 DynamicList<label> cellZone_;
198
199
200 // Private Member Functions
201
202 //- Reorder contents of container according to oldToNew map
203 template<class Type>
204 static void reorder
205 (
206 const labelUList& oldToNew,
208 );
209
210 template<class Type>
211 static void reorder
212 (
213 const labelUList& oldToNew,
215 );
216
217 template<class Type>
218 static void renumberKey
219 (
220 const labelUList& oldToNew,
221 Map<Type>& map
222 );
223
224 //- Renumber elements of container according to oldToNew map
225 static void renumber
226 (
227 const labelUList& oldToNew,
228 labelHashSet& labels
229 );
230
231 //- Special handling of reverse maps which have <-1 in them
232 static void renumberReverseMap
233 (
234 const labelUList& oldToNew,
235 DynamicList<label>& elems
236 );
237
238 //- Renumber & compact elements of list according to map
239 static void renumberCompact
240 (
241 const labelUList& oldToNew,
242 labelList& elems
243 );
244
245 //- Count number of added and removed quantities from maps.
246 static void countMap
247 (
248 const labelUList& map,
249 const labelUList& reverseMap,
250 label& nAdd,
251 label& nInflate,
252 label& nMerge,
253 label& nRemove
254 );
255
256 //- Print some stats about mesh
257 static void writeMeshStats(const polyMesh& mesh, Ostream& os);
258
259 //- Calculate object maps. Requires reverseMap to have destination
260 // to be marked with <-1.
261 static void getMergeSets
262 (
263 const labelUList& reverseCellMap,
264 const labelUList& cellMap,
265 List<objectMap>& cellsFromCells
266 );
267
268 //- Are all face vertices valid
269 bool hasValidPoints(const face& f) const;
270
271 //- Return face points
272 pointField facePoints(const face& f) const;
273
274 //- Check inputs to modFace or addFace
275 void checkFace
276 (
277 const face& f,
278 const label facei,
279 const label own,
280 const label nei,
281 const label patchi,
282 const label zoneI
283 ) const;
284
285 //- Construct cells (in packed storage)
286 void makeCells
287 (
288 const label nActiveFaces,
289 labelList& cellFaces,
290 labelList& cellFaceOffsets
291 ) const;
292
293 //- Construct cellCells (in packed storage)
294 void makeCellCells
295 (
296 const label nActiveFaces,
297 CompactListList<label>& cellCells
298 ) const;
299
300 //- Cell ordering (bandCompression). Returns number of remaining cells.
301 label getCellOrder
302 (
303 const CompactListList<label>& cellCellAddressing,
304 labelList& oldToNew
305 ) const;
306
307 //- Do upper-triangular ordering and patch ordering.
308 void getFaceOrder
309 (
310 const label nActiveFaces,
311 const labelUList& cellFaces,
312 const labelUList& cellFaceOffsets,
313
314 labelList& oldToNew,
315 labelList& patchSizes,
316 labelList& patchStarts
317 ) const;
318
319 //- Compact and reorder faces according to map
320 void reorderCompactFaces
321 (
322 const label newSize,
323 const labelUList& oldToNew
324 );
325
326 //- Remove all unused/removed points/faces/cells and update
327 //- face ordering (always), cell ordering (bandcompression,
328 //- orderCells=true),
329 //- point ordering (sorted into internal and boundary points,
330 //- orderPoints=true)
331 void compact
332 (
333 const bool orderCells,
334 const bool orderPoints,
335 label& nInternalPoints,
336 labelList& patchSizes,
337 labelList& patchStarts
338 );
339
340 //- Select either internal or external faces out of faceLabels
341 static labelList selectFaces
342 (
343 const primitiveMesh& mesh,
344 const labelUList& faceLabels,
345 const bool internalFacesOnly
346 );
347
348 //- Calculate mapping for patchpoints only
349 void calcPatchPointMap
350 (
351 const UList<Map<label>>& oldPatchMeshPointMaps,
352 const labelUList& patchMap,
354 labelListList& patchPointMap
355 ) const;
356
357 void calcFaceInflationMaps
358 (
359 const polyMesh& mesh,
360 List<objectMap>& facesFromPoints,
361 List<objectMap>& facesFromEdges,
362 List<objectMap>& facesFromFaces
363 ) const;
364
365 void calcCellInflationMaps
366 (
367 const polyMesh& mesh,
368 List<objectMap>& cellsFromPoints,
369 List<objectMap>& cellsFromEdges,
370 List<objectMap>& cellsFromFaces,
371 List<objectMap>& cellsFromCells
372 ) const;
373
374 void resetZones
375 (
376 const polyMesh& mesh, // mesh to get existing info from
377 polyMesh& newMesh, // mesh to change zones on
378 labelListList& pointZoneMap,
379 labelListList& faceZoneFaceMap,
380 labelListList& cellZoneMap
381 ) const;
382
383 void calcFaceZonePointMap
384 (
385 const polyMesh& mesh,
386 const UList<Map<label>>& oldFaceZoneMeshPointMaps,
387 labelListList& faceZonePointMap
388 ) const;
389
390
391 // Coupling
392
393 //- Do all coupled patch face reordering
394 void reorderCoupledFaces
395 (
396 const bool syncParallel,
398 const labelUList& patchMap, // new back to old patch labels
399 const labelUList& patchStarts,
400 const labelUList& patchSizes,
401 const pointField& points
402 );
403
404 void compactAndReorder
405 (
406 const polyMesh& mesh,
407 const labelUList& patchMap, // from new to old patch
408 const bool syncParallel,
409 const bool orderCells,
410 const bool orderPoints,
411 label& nInternalPoints,
412 pointField& newPoints,
413 labelList& patchSizes,
414 labelList& patchStarts,
415 List<objectMap>& pointsFromPoints,
416 List<objectMap>& facesFromPoints,
417 List<objectMap>& facesFromEdges,
418 List<objectMap>& facesFromFaces,
419 List<objectMap>& cellsFromPoints,
420 List<objectMap>& cellsFromEdges,
421 List<objectMap>& cellsFromFaces,
422 List<objectMap>& cellsFromCells,
423 List<Map<label>>& oldPatchMeshPointMaps,
424 labelList& oldPatchNMeshPoints,
425 labelList& oldPatchStarts,
426 List<Map<label>>& oldFaceZoneMeshPointMaps
427 );
428
429public:
430
431 //- Runtime type information
432 ClassName("polyTopoChange");
433
434
435
436 // Constructors
437
438 //- Construct without mesh. Either specify nPatches or use
439 //- setNumPatches before trying to make a mesh (makeMesh, changeMesh)
440 polyTopoChange(const label nPatches, const bool strict = true);
441
442 //- Construct from mesh. Adds all points/face/cells from mesh.
443 polyTopoChange(const polyMesh& mesh, const bool strict = true);
444
445
446 // Member Functions
447
448 // Access
449
450 //- Points. Shrunk after constructing mesh (or calling of compact())
451 const DynamicList<point>& points() const
452 {
453 return points_;
454 }
456 const DynamicList<face>& faces() const
457 {
458 return faces_;
459 }
461 const DynamicList<label>& region() const
462 {
463 return region_;
464 }
466 const DynamicList<label>& faceOwner() const
467 {
468 return faceOwner_;
469 }
471 const DynamicList<label>& faceNeighbour() const
472 {
473 return faceNeighbour_;
474 }
475
476 //- Is point removed?
477 //- Considered removed if point is GREAT.
478 inline bool pointRemoved(const label pointi) const;
479
480 //- Is face removed?
481 //- Considered removed if face is empty
482 inline bool faceRemoved(const label facei) const;
483
484 //- Is cell removed?
485 //- Considered removed if the cellMap is -2
486 inline bool cellRemoved(const label celli) const;
487
488
489 // Edit
490
491 //- Clear all storage
492 void clear();
493
494 //- Add all points/faces/cells of mesh. Additional offset for patch
495 //- or zone ids.
496 void addMesh
497 (
498 const polyMesh& mesh,
499 const labelUList& patchMap,
500 const labelUList& pointZoneMap,
501 const labelUList& faceZoneMap,
502 const labelUList& cellZoneMap
503 );
504
505 //- Explicitly pre-size the dynamic storage for expected mesh
506 //- size for if construct-without-mesh
507 void setCapacity
508 (
509 const label nPoints,
510 const label nFaces,
511 const label nCells
512 );
513
514 //- Shrink storage (does not remove any elements; just compacts
515 //- dynamic lists
516 void shrink();
517
518 //- Move all points. Incompatible with other topology changes.
519 void movePoints(const pointField& newPoints);
520
521 //- For compatibility with polyTopoChange: set topological action.
522 label setAction(const topoAction& action);
523
524 //- Add point. Return new point label.
525 // Notes:
526 // - masterPointID can be < 0 (appended points)
527 // - inCell = false: add retired point (to end of point list)
528 label addPoint
529 (
530 const point& pt,
531 const label masterPointID,
532 const label zoneID,
533 const bool inCell
534 );
535
536 //- Modify coordinate.
537 // Notes:
538 // - zoneID = +ve (add to zoneID), -ve (remove from zones)
539 // - inCell = false: add retired point (to end of point list)
540 void modifyPoint
541 (
542 const label pointi,
543 const point& pt,
544 const label zoneID,
545 const bool inCell
546 );
547
548 //- Remove/merge point.
549 void removePoint(const label pointi, const label mergePointi);
550
551 //- Add face to cells. Return new face label.
552 // own,nei<0, zoneID>=0 : add inactive face (to end of face list)
553 label addFace
554 (
555 const face& f,
556 const label own,
557 const label nei,
558 const label masterPointID,
559 const label masterEdgeID,
560 const label masterFaceID,
561 const bool flipFaceFlux,
562 const label patchID,
563 const label zoneID,
564 const bool zoneFlip
565 );
566
567 //- Modify vertices or cell of face.
568 void modifyFace
569 (
570 const face& f,
571 const label facei,
572 const label own,
573 const label nei,
574 const bool flipFaceFlux,
575 const label patchID,
576 const label zoneID,
577 const bool zoneFlip
578 );
579
580 //- Remove/merge face.
581 void removeFace(const label facei, const label mergeFacei);
582
583 //- Add cell. Return new cell label.
584 label addCell
585 (
586 const label masterPointID,
587 const label masterEdgeID,
588 const label masterFaceID,
589 const label masterCellID,
590 const label zoneID
591 );
592
593 //- Modify zone of cell
594 void modifyCell(const label celli, const label zoneID);
595
596 //- Remove/merge cell.
597 void removeCell(const label celli, const label mergeCelli);
598
599 //- Explicitly set the number of patches if construct-without-mesh
600 //- used.
601 inline void setNumPatches(const label nPatches);
602
603 // Other
604
605 //- Inplace changes mesh without change of patches.
606 // Adapts patch start/end and by default does parallel matching.
607 // Clears all data. Returns map.
608 // inflate = true : keep old mesh points. Put new points into the
609 // returned map (preMotionPoints) so we can use inflation. Any
610 // points out of nothing (appended points) are vector::zero.
611 // inflate = false: set mesh points directly. Empty preMotionPoints
612 // in the map.
613 // orderCells : whether to order the cells (see bandCompression.H)
614 // orderPoints : whether to order the points into internal first
615 // followed by boundary points. This is not fully consistent
616 // with upper-triangular ordering of points and edges so
617 // is only done when explicitly asked for.
619 (
620 polyMesh& mesh,
621 const labelUList& patchMap,
622 const bool inflate,
623 const bool syncParallel = true,
624 const bool orderCells = false,
625 const bool orderPoints = false
626 );
627
628 //- Without patch mapping
630 (
631 polyMesh& mesh,
632 const bool inflate,
633 const bool syncParallel = true,
634 const bool orderCells = false,
635 const bool orderPoints = false
636 );
637
638 //- Create new mesh with old mesh patches. Additional dictionaries
639 // (fv* etc) read according to IO flags
640 template<class Type>
642 (
643 autoPtr<Type>& newMesh,
644 const IOobject& io,
645 const polyMesh& mesh,
646 const labelUList& patchMap,
647 const bool syncParallel = true,
648 const bool orderCells = false,
649 const bool orderPoints = false
650 );
651
652 //- Create new mesh with old mesh patches. Additional dictionaries
653 // (fv* etc) read according to IO flags
654 template<class Type>
656 (
657 autoPtr<Type>& newMesh,
658 const IOobject& io,
659 const polyMesh& mesh,
660 const bool syncParallel = true,
661 const bool orderCells = false,
662 const bool orderPoints = false
663 );
664};
665
666
667// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
668
669} // End namespace Foam
670
671// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
672
673#include "polyTopoChangeI.H"
674
675#ifdef NoRepository
677#endif
678
679// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
680
681#endif
682
683// ************************************************************************* //
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Direct mesh changes based on v1.3 polyTopoChange syntax.
void movePoints(const pointField &newPoints)
Move all points. Incompatible with other topology changes.
bool cellRemoved(const label celli) const
const DynamicList< face > & faces() const
label addPoint(const point &pt, const label masterPointID, const label zoneID, const bool inCell)
Add point. Return new point label.
void removeCell(const label celli, const label mergeCelli)
Remove/merge cell.
bool pointRemoved(const label pointi) const
void modifyPoint(const label pointi, const point &pt, const label zoneID, const bool inCell)
Modify coordinate.
label setAction(const topoAction &action)
For compatibility with polyTopoChange: set topological action.
const DynamicList< label > & region() const
void setNumPatches(const label nPatches)
void setCapacity(const label nPoints, const label nFaces, const label nCells)
label addCell(const label masterPointID, const label masterEdgeID, const label masterFaceID, const label masterCellID, const label zoneID)
Add cell. Return new cell label.
bool faceRemoved(const label facei) const
void addMesh(const polyMesh &mesh, const labelUList &patchMap, const labelUList &pointZoneMap, const labelUList &faceZoneMap, const labelUList &cellZoneMap)
void removePoint(const label pointi, const label mergePointi)
Remove/merge point.
void modifyCell(const label celli, const label zoneID)
Modify zone of cell.
void modifyFace(const face &f, const label facei, const label own, const label nei, const bool flipFaceFlux, const label patchID, const label zoneID, const bool zoneFlip)
Modify vertices or cell of face.
void removeFace(const label facei, const label mergeFacei)
Remove/merge face.
const DynamicList< label > & faceOwner() const
label addFace(const face &f, const label own, const label nei, const label masterPointID, const label masterEdgeID, const label masterFaceID, const bool flipFaceFlux, const label patchID, const label zoneID, const bool zoneFlip)
Add face to cells. Return new face label.
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const labelUList &patchMap, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
ClassName("polyTopoChange")
Runtime type information.
autoPtr< mapPolyMesh > makeMesh(autoPtr< Type > &newMesh, const IOobject &io, const polyMesh &mesh, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Create new mesh with old mesh patches. Additional dictionaries.
const DynamicList< point > & points() const
Points. Shrunk after constructing mesh (or calling of compact())
void clear()
Clear all storage.
const DynamicList< label > & faceNeighbour() const
autoPtr< mapPolyMesh > makeMesh(autoPtr< Type > &newMesh, const IOobject &io, const polyMesh &mesh, const labelUList &patchMap, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Create new mesh with old mesh patches. Additional dictionaries.
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79
A virtual base class for topological actions.
Definition: topoAction.H:52
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition: className.H:67
faceListList boundary
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
const label nPatches
label nPoints
const labelIOList & zoneID
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
ListType reorder(const labelUList &oldToNew, const ListType &input, const bool prune=false)
Reorder the elements of a list.
labelList f(nPoints)