1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Direct mesh changes based on v1.3 polyTopoChange syntax.
31 Instead of recording changes and executing them all in one go (as did
32 v1.3 polyTopoChange) this class actually holds the current
33 points/faces/cells and does the change immediately.
34 It can be asked to compress out all unused points/faces/cells and
35 renumber everything to be consistent.
38 - polyTopoChange can be copied.
39 - adding a face using non-existing cells causes all intermediate cells
40 to be added. So always first add cells/points and then faces.
41 (or set strict checking)
43 - any added/modified face can only use already existing vertices
44 - any added face can only use already existing cells
45 - no item can be removed more than once.
46 - removed cell: cell set to 0 faces.
47 - removed face: face set to 0 vertices.
48 - removed point: coordinate set to greatPoint (GREAT,GREAT,GREAT).
49 Note that this might give problems if this value is used already.
50 To see if point is equal to above value we don't use == (which might give
51 problems with roundoff error) but instead compare the individual component
53 - coupled patches: the reorderCoupledFaces routine (borrowed from
54 the couplePatches utility) reorders coupled patch faces and
55 uses the cyclicPolyPatch,processorPolyPatch functionality.
60 polyTopoChangeTemplates.C
62 \*---------------------------------------------------------------------------*/
64 #ifndef polyTopoChange_H
65 #define polyTopoChange_H
68 #include "DynamicList.H"
69 #include "labelList.H"
72 #include "pointField.H"
77 #include "mapPolyMesh.H"
78 #include "CompactListList.H"
79 #include "PackedBoolList.H"
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 // Forward declaration of classes
93 class polyBoundaryMesh;
99 /*---------------------------------------------------------------------------*\
100 Class polyTopoChange Declaration
101 \*---------------------------------------------------------------------------*/
105 // Static data members
107 //- Value of deleted point
108 static const point greatPoint;
113 //- Whether to allow referencing illegal points/cells/faces
114 // when adding/removing data.
120 //- Number of patches
126 //- Current point set
127 DynamicList<point> points_;
129 //- Original point label (or masterpoint for added points)
130 DynamicList<label> pointMap_;
132 //- For all original and added points contains new point label.
133 // (used to map return value of addPoint to new mesh point)
134 DynamicList<label> reversePointMap_;
137 DynamicList<label> pointZone_;
140 labelHashSet retiredPoints_;
146 DynamicList<face> faces_;
148 //- Patch for every external face (-1 for internal faces)
149 DynamicList<label> region_;
151 //- Owner for all faces
152 DynamicList<label> faceOwner_;
154 //- Neighbour for internal faces (-1 for external faces)
155 DynamicList<label> faceNeighbour_;
157 //- Original face label. Or master face for added-from-faces;
158 // -1 for faces added-from-edge or added-from-point)
159 DynamicList<label> faceMap_;
161 //- For all original and added faces contains new face label
162 // (used to map return value of addFace to new mesh face)
163 DynamicList<label> reverseFaceMap_;
165 //- Faces added from point (corresponding faceMap_ will
167 Map<label> faceFromPoint_;
169 //- Faces added from edge (corresponding faceMap_ will
171 Map<label> faceFromEdge_;
173 //- In mapping whether to reverse the flux.
174 PackedBoolList flipFaceFlux_;
177 DynamicList<label> faceZone_;
179 //- Orientation of face in zone
180 PackedBoolList faceZoneFlip_;
188 //- Original cell label or master cell for added-from-cell;
189 // -1 for cells added from face or edge.
190 DynamicList<label> cellMap_;
192 //- For all original and added cells contains new cell label
193 // (used to map return value of addCell to new mesh cell)
194 DynamicList<label> reverseCellMap_;
196 //- Cells added from point
197 Map<label> cellFromPoint_;
199 //- Cells added from edge
200 Map<label> cellFromEdge_;
202 //- Cells added from face
203 Map<label> cellFromFace_;
206 DynamicList<label> cellZone_;
209 // Private Member Functions
211 //- Reorder contents of container according to map
213 static void reorder(const labelList& map, DynamicList<T>&);
215 static void reorder(const labelList& map, List<DynamicList<T> >&);
217 static void renumberKey(const labelList& map, Map<T>&);
219 //- Renumber elements of container according to map
220 static void renumber(const labelList&, labelHashSet&);
221 //- Special handling of reverse maps which have <-1 in them
222 static void renumberReverseMap(const labelList&, DynamicList<label>&);
224 //- Renumber & compact elements of list according to map
225 static void renumberCompact(const labelList&, labelList&);
227 //- Get all set elements as a labelHashSet
228 static labelHashSet getSetIndices(const PackedBoolList&);
230 //- Count number of added and removed quantities from maps.
233 const labelList& map,
234 const labelList& reverseMap,
241 //- Print some stats about mesh
242 static void writeMeshStats(const polyMesh& mesh, Ostream&);
244 //- Calculate object maps. Requires reverseMap to have destination
245 // to be marked with <-1.
246 static void getMergeSets
248 const labelList& reverseCellMap,
249 const labelList& cellMap,
250 List<objectMap>& cellsFromCells
253 //- Check inputs to modFace or addFace
264 //- Construct cells (in packed storage)
267 const label nActiveFaces,
268 labelList& cellFaces,
269 labelList& cellFaceOffsets
272 //- Construct cellCells (in packed storage)
275 const label nActiveFaces,
276 CompactListList<label>& cellCells
279 //- Cell ordering (bandCompression). Returns number of remaining cells.
280 label getCellOrder(const CompactListList<label>&, labelList&) const;
282 //- Do upper-triangular ordering and patch ordering.
285 const label nActiveFaces,
286 const labelList& cellFaces,
287 const labelList& cellFaceOffsets,
290 labelList& patchSizes,
291 labelList& patchStarts
294 //- Compact and reorder faces according to map
295 void reorderCompactFaces
298 const labelList& oldToNew
301 //- Remove all unused/removed points/faces/cells and update
302 // face ordering (always), cell ordering (bandcompression,
304 // point ordering (sorted into internal and boundary points,
308 const bool orderCells,
309 const bool orderPoints,
310 label& nInternalPoints,
311 labelList& patchSizes,
312 labelList& patchStarts
315 //- Select either internal or external faces out of faceLabels
316 static labelList selectFaces
318 const primitiveMesh&,
319 const labelList& faceLabels,
320 const bool internalFacesOnly
323 //- Calculate mapping for patchpoints only
324 void calcPatchPointMap
326 const List<Map<label> >&,
327 const polyBoundaryMesh&,
331 void calcFaceInflationMaps
339 void calcCellInflationMaps
350 const polyMesh&, // mesh to get existing info from
351 polyMesh&, // mesh to change zones on
357 void calcFaceZonePointMap
360 const List<Map<label> >&,
367 //- Rotate face by number of positions
368 static face rotateFace(const face& f, const label nPos);
370 //- Do all coupled patch face reordering
371 void reorderCoupledFaces
373 const bool syncParallel,
374 const polyBoundaryMesh&,
375 const labelList& patchStarts,
376 const labelList& patchSizes,
377 const pointField& points
380 void compactAndReorder
383 const bool syncParallel,
384 const bool orderCells,
385 const bool orderPoints,
386 label& nInternalPoints,
387 pointField& newPoints,
388 labelList& patchSizes,
389 labelList& patchStarts,
390 List<objectMap>& pointsFromPoints,
391 List<objectMap>& facesFromPoints,
392 List<objectMap>& facesFromEdges,
393 List<objectMap>& facesFromFaces,
394 List<objectMap>& cellsFromPoints,
395 List<objectMap>& cellsFromEdges,
396 List<objectMap>& cellsFromFaces,
397 List<objectMap>& cellsFromCells,
398 List<Map<label> >& oldPatchMeshPointMaps,
399 labelList& oldPatchNMeshPoints,
400 labelList& oldPatchStarts,
401 List<Map<label> >& oldFaceZoneMeshPointMaps
406 //- Runtime type information
407 ClassName("polyTopoChange");
413 //- Construct without mesh. Either specify nPatches or use
414 // setNumPatches before trying to make a mesh (makeMesh, changeMesh)
415 polyTopoChange(const label nPatches, const bool strict = true);
417 //- Construct from mesh. Adds all points/face/cells from mesh.
418 polyTopoChange(const polyMesh& mesh, const bool strict = true);
425 //- Points. Shrunk after constructing mesh (or calling of compact())
426 const DynamicList<point>& points() const
431 const DynamicList<face>& faces() const
436 const DynamicList<label>& region() const
441 const DynamicList<label>& faceOwner() const
446 const DynamicList<label>& faceNeighbour() const
448 return faceNeighbour_;
451 //- Is point removed?
452 inline bool pointRemoved(const label pointI) const;
454 inline bool faceRemoved(const label faceI) const;
456 inline bool cellRemoved(const label cellI) const;
461 //- Clear all storage
464 //- Add all points/faces/cells of mesh. Additional offset for patch
469 const labelList& patchMap,
470 const labelList& pointZoneMap,
471 const labelList& faceZoneMap,
472 const labelList& cellZoneMap
475 //- Explicitly pre-size the dynamic storage for expected mesh
476 // size for if construct-without-mesh
484 //- Move all points. Incompatible with other topology changes.
485 void movePoints(const pointField& newPoints);
487 //- For compatibility with polyTopoChange: set topological action.
488 label setAction(const topoAction& action);
490 //- Add point. Return new point label.
492 // - masterPointID can be < 0 (appended points)
493 // - inCell = false: add retired point (to end of point list)
497 const label masterPointID,
502 //- Modify coordinate.
504 // - inCell = false: add retired point (to end of point list)
509 const label newZoneID,
513 //- Remove/merge point.
514 void removePoint(const label, const label);
516 //- Add face to cells. Return new face label.
517 // own,nei<0, zoneID>=0 : add inactive face (to end of face list)
523 const label masterPointID,
524 const label masterEdgeID,
525 const label masterFaceID,
526 const bool flipFaceFlux,
532 //- Modify vertices or cell of face.
539 const bool flipFaceFlux,
545 //- Remove/merge face.
546 void removeFace(const label, const label);
548 //- Add cell. Return new cell label.
551 const label masterPointID,
552 const label masterEdgeID,
553 const label masterFaceID,
554 const label masterCellID,
558 //- Modify zone of cell
559 void modifyCell(const label, const label zoneID);
561 //- Remove/merge cell.
562 void removeCell(const label, const label);
564 //- Explicitly set the number of patches if construct-without-mesh
566 inline void setNumPatches(const label nPatches);
571 //- Inplace changes mesh without change of patches.
572 // Adapts patch start/end and by default does parallel matching.
573 // Clears all data. Returns map.
574 // inflate = true : keep old mesh points. Put new points into the
575 // returned map (preMotionPoints) so we can use inflation. Any
576 // points out of nothing (appended points) are vector::zero.
577 // inflate = false: set mesh points directly. Empty preMotionPoints
579 // orderCells : whether to order the cells (see bandCompression.H)
580 // orderPoints : whether to order the points into internal first
581 // followed by boundary points. This is not fully consistent
582 // with upper-triangular ordering of points and edges so
583 // is only done when explicitly asked for.
584 autoPtr<mapPolyMesh> changeMesh
588 const bool syncParallel = true,
589 const bool orderCells = false,
590 const bool orderPoints = false
593 //- Create new mesh with old mesh patches
594 autoPtr<mapPolyMesh> makeMesh
596 autoPtr<fvMesh>& newMesh,
599 const bool syncParallel = true,
600 const bool orderCells = false,
601 const bool orderPoints = false
607 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
609 } // End namespace Foam
611 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
613 #include "polyTopoChangeI.H"
616 # include "polyTopoChangeTemplates.C"
619 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
623 // ************************************************************************* //