polyTopoChange.H
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::polyTopoChange 00026 00027 Description 00028 Direct mesh changes based on v1.3 polyTopoChange syntax. 00029 00030 Instead of recording changes and executing them all in one go (as did 00031 v1.3 polyTopoChange) this class actually holds the current 00032 points/faces/cells and does the change immediately. 00033 It can be asked to compress out all unused points/faces/cells and 00034 renumber everything to be consistent. 00035 00036 Note: 00037 - polyTopoChange can be copied. 00038 - adding a face using non-existing cells causes all intermediate cells 00039 to be added. So always first add cells/points and then faces. 00040 (or set strict checking) 00041 - strict checking: 00042 - any added/modified face can only use already existing vertices 00043 - any added face can only use already existing cells 00044 - no item can be removed more than once. 00045 - removed cell: cell set to 0 faces. 00046 - removed face: face set to 0 vertices. 00047 - removed point: coordinate set to vector::max (VGREAT,VGREAT,VGREAT). 00048 Note that this might give problems if this value is used already. 00049 To see if point is equal to above value we don't use == (which might give 00050 problems with roundoff error) but instead compare the individual component 00051 with >. 00052 - coupled patches: the reorderCoupledFaces routine (borrowed from 00053 the couplePatches utility) reorders coupled patch faces and 00054 uses the cyclicPolyPatch,processorPolyPatch functionality. 00055 00056 SourceFiles 00057 polyTopoChange.C 00058 polyTopoChangeI.H 00059 polyTopoChangeTemplates.C 00060 00061 \*---------------------------------------------------------------------------*/ 00062 00063 #ifndef polyTopoChange_H 00064 #define polyTopoChange_H 00065 00066 #include "DynamicList.H" 00067 #include "labelList.H" 00068 #include "pointField.H" 00069 #include "Map.H" 00070 #include "HashSet.H" 00071 #include "mapPolyMesh.H" 00072 #include "PackedBoolList.H" 00073 00074 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00075 00076 namespace Foam 00077 { 00078 00079 // Forward declaration of classes 00080 class face; 00081 class primitiveMesh; 00082 class polyMesh; 00083 class fvMesh; 00084 class Time; 00085 class fileName; 00086 class polyBoundaryMesh; 00087 class polyPatch; 00088 class dictionary; 00089 class topoAction; 00090 class objectMap; 00091 class IOobject; 00092 template<class T, class Container> class CompactListList; 00093 00094 /*---------------------------------------------------------------------------*\ 00095 Class polyTopoChange Declaration 00096 \*---------------------------------------------------------------------------*/ 00097 00098 class polyTopoChange 00099 { 00100 // Private data 00101 00102 //- Whether to allow referencing illegal points/cells/faces 00103 // when adding/removing data. 00104 bool strict_; 00105 00106 00107 // Patches 00108 00109 //- Number of patches 00110 label nPatches_; 00111 00112 00113 // Points 00114 00115 //- Current point set 00116 DynamicList<point> points_; 00117 00118 //- Original point label (or masterpoint for added points) 00119 DynamicList<label> pointMap_; 00120 00121 //- For all original and added points contains new point label. 00122 // (used to map return value of addPoint to new mesh point) 00123 DynamicList<label> reversePointMap_; 00124 00125 //- Zone of point 00126 Map<label> pointZone_; 00127 00128 //- Retired points 00129 labelHashSet retiredPoints_; 00130 00131 00132 // Faces 00133 00134 //- Current faceList 00135 DynamicList<face> faces_; 00136 00137 //- Patch for every external face (-1 for internal faces) 00138 DynamicList<label> region_; 00139 00140 //- Owner for all faces 00141 DynamicList<label> faceOwner_; 00142 00143 //- Neighbour for internal faces (-1 for external faces) 00144 DynamicList<label> faceNeighbour_; 00145 00146 //- Original face label. Or master face for added-from-faces; 00147 // -1 for faces added-from-edge or added-from-point) 00148 DynamicList<label> faceMap_; 00149 00150 //- For all original and added faces contains new face label 00151 // (used to map return value of addFace to new mesh face) 00152 DynamicList<label> reverseFaceMap_; 00153 00154 //- Faces added from point (corresponding faceMap_ will 00155 // be -1) 00156 Map<label> faceFromPoint_; 00157 00158 //- Faces added from edge (corresponding faceMap_ will 00159 // be -1) 00160 Map<label> faceFromEdge_; 00161 00162 //- In mapping whether to reverse the flux. 00163 PackedBoolList flipFaceFlux_; 00164 00165 //- Zone of face 00166 Map<label> faceZone_; 00167 00168 //- Orientation of face in zone 00169 PackedBoolList faceZoneFlip_; 00170 00171 //- Active faces 00172 label nActiveFaces_; 00173 00174 00175 // Cells 00176 00177 //- Original cell label or master cell for added-from-cell; 00178 // -1 for cells added from face or edge. 00179 DynamicList<label> cellMap_; 00180 00181 //- For all original and added cells contains new cell label 00182 // (used to map return value of addCell to new mesh cell) 00183 DynamicList<label> reverseCellMap_; 00184 00185 //- Cells added from point 00186 Map<label> cellFromPoint_; 00187 00188 //- Cells added from edge 00189 Map<label> cellFromEdge_; 00190 00191 //- Cells added from face 00192 Map<label> cellFromFace_; 00193 00194 //- Zone of cell 00195 DynamicList<label> cellZone_; 00196 00197 00198 // Private Member Functions 00199 00200 //- Reorder contents of container according to map 00201 template<class T> 00202 static void reorder(const labelList& map, DynamicList<T>&); 00203 template<class T> 00204 static void reorder(const labelList& map, List<DynamicList<T> >&); 00205 template<class T> 00206 static void renumberKey(const labelList& map, Map<T>&); 00207 00208 //- Renumber elements of container according to map 00209 static void renumber(const labelList&, labelHashSet&); 00210 //- Special handling of reverse maps which have <-1 in them 00211 static void renumberReverseMap(const labelList&, DynamicList<label>&); 00212 00213 //- Renumber & compact elements of list according to map 00214 static void renumberCompact(const labelList&, labelList&); 00215 00216 //- Get all set elements as a labelHashSet 00217 static labelHashSet getSetIndices(const PackedBoolList&); 00218 00219 //- Count number of added and removed quantities from maps. 00220 static void countMap 00221 ( 00222 const labelList& map, 00223 const labelList& reverseMap, 00224 label& nAdd, 00225 label& nInflate, 00226 label& nMerge, 00227 label& nRemove 00228 ); 00229 00230 //- Print some stats about mesh 00231 static void writeMeshStats(const polyMesh& mesh, Ostream&); 00232 00233 //- Calculate object maps. Requires reverseMap to have destination 00234 // to be marked with <-1. 00235 static void getMergeSets 00236 ( 00237 const labelList& reverseCellMap, 00238 const labelList& cellMap, 00239 List<objectMap>& cellsFromCells 00240 ); 00241 00242 //- Are all face vertices valid 00243 bool hasValidPoints(const face&) const; 00244 00245 //- Return face points 00246 pointField facePoints(const face& f) const; 00247 00248 //- Check inputs to modFace or addFace 00249 void checkFace 00250 ( 00251 const face&, 00252 const label faceI, 00253 const label own, 00254 const label nei, 00255 const label patchI, 00256 const label zoneI 00257 ) const; 00258 00259 //- Construct cells (in packed storage) 00260 void makeCells 00261 ( 00262 const label nActiveFaces, 00263 labelList& cellFaces, 00264 labelList& cellFaceOffsets 00265 ) const; 00266 00267 //- Construct cellCells (in packed storage) 00268 void makeCellCells 00269 ( 00270 const label nActiveFaces, 00271 CompactListList<label, labelList>& cellCells 00272 ) const; 00273 00274 //- Cell ordering (bandCompression). Returns number of remaining cells. 00275 label getCellOrder 00276 ( 00277 const CompactListList<label, labelList>&, 00278 labelList& 00279 ) const; 00280 00281 //- Do upper-triangular ordering and patch ordering. 00282 void getFaceOrder 00283 ( 00284 const label nActiveFaces, 00285 const labelList& cellFaces, 00286 const labelList& cellFaceOffsets, 00287 00288 labelList& oldToNew, 00289 labelList& patchSizes, 00290 labelList& patchStarts 00291 ) const; 00292 00293 //- Compact and reorder faces according to map 00294 void reorderCompactFaces 00295 ( 00296 const label newSize, 00297 const labelList& oldToNew 00298 ); 00299 00300 //- Remove all unused/removed points/faces/cells and update 00301 // face ordering (always), cell ordering (bandcompression, 00302 // orderCells=true), 00303 // point ordering (sorted into internal and boundary points, 00304 // orderPoints=true) 00305 void compact 00306 ( 00307 const bool orderCells, 00308 const bool orderPoints, 00309 label& nInternalPoints, 00310 labelList& patchSizes, 00311 labelList& patchStarts 00312 ); 00313 00314 //- Select either internal or external faces out of faceLabels 00315 static labelList selectFaces 00316 ( 00317 const primitiveMesh&, 00318 const labelList& faceLabels, 00319 const bool internalFacesOnly 00320 ); 00321 00322 //- Calculate mapping for patchpoints only 00323 void calcPatchPointMap 00324 ( 00325 const List<Map<label> >&, 00326 const polyBoundaryMesh&, 00327 labelListList& 00328 ) const; 00329 00330 void calcFaceInflationMaps 00331 ( 00332 const polyMesh&, 00333 List<objectMap>&, 00334 List<objectMap>&, 00335 List<objectMap>& 00336 ) const; 00337 00338 void calcCellInflationMaps 00339 ( 00340 const polyMesh&, 00341 List<objectMap>&, 00342 List<objectMap>&, 00343 List<objectMap>&, 00344 List<objectMap>& 00345 ) const; 00346 00347 void resetZones 00348 ( 00349 const polyMesh&, // mesh to get existing info from 00350 polyMesh&, // mesh to change zones on 00351 labelListList&, 00352 labelListList&, 00353 labelListList& 00354 ) const; 00355 00356 void calcFaceZonePointMap 00357 ( 00358 const polyMesh&, 00359 const List<Map<label> >&, 00360 labelListList& 00361 ) const; 00362 00363 00364 // Coupling 00365 00366 //- Do all coupled patch face reordering 00367 void reorderCoupledFaces 00368 ( 00369 const bool syncParallel, 00370 const polyBoundaryMesh&, 00371 const labelList& patchStarts, 00372 const labelList& patchSizes, 00373 const pointField& points 00374 ); 00375 00376 void compactAndReorder 00377 ( 00378 const polyMesh&, 00379 const bool syncParallel, 00380 const bool orderCells, 00381 const bool orderPoints, 00382 label& nInternalPoints, 00383 pointField& newPoints, 00384 labelList& patchSizes, 00385 labelList& patchStarts, 00386 List<objectMap>& pointsFromPoints, 00387 List<objectMap>& facesFromPoints, 00388 List<objectMap>& facesFromEdges, 00389 List<objectMap>& facesFromFaces, 00390 List<objectMap>& cellsFromPoints, 00391 List<objectMap>& cellsFromEdges, 00392 List<objectMap>& cellsFromFaces, 00393 List<objectMap>& cellsFromCells, 00394 List<Map<label> >& oldPatchMeshPointMaps, 00395 labelList& oldPatchNMeshPoints, 00396 labelList& oldPatchStarts, 00397 List<Map<label> >& oldFaceZoneMeshPointMaps 00398 ); 00399 00400 public: 00401 00402 //- Runtime type information 00403 ClassName("polyTopoChange"); 00404 00405 00406 00407 // Constructors 00408 00409 //- Construct without mesh. Either specify nPatches or use 00410 // setNumPatches before trying to make a mesh (makeMesh, changeMesh) 00411 polyTopoChange(const label nPatches, const bool strict = true); 00412 00413 //- Construct from mesh. Adds all points/face/cells from mesh. 00414 polyTopoChange(const polyMesh& mesh, const bool strict = true); 00415 00416 00417 // Member Functions 00418 00419 // Access 00420 00421 //- Points. Shrunk after constructing mesh (or calling of compact()) 00422 const DynamicList<point>& points() const 00423 { 00424 return points_; 00425 } 00426 00427 const DynamicList<face>& faces() const 00428 { 00429 return faces_; 00430 } 00431 00432 const DynamicList<label>& region() const 00433 { 00434 return region_; 00435 } 00436 00437 const DynamicList<label>& faceOwner() const 00438 { 00439 return faceOwner_; 00440 } 00441 00442 const DynamicList<label>& faceNeighbour() const 00443 { 00444 return faceNeighbour_; 00445 } 00446 00447 //- Is point removed? 00448 inline bool pointRemoved(const label pointI) const; 00449 //- Is face removed? 00450 inline bool faceRemoved(const label faceI) const; 00451 //- Is cell removed? 00452 inline bool cellRemoved(const label cellI) const; 00453 00454 00455 // Edit 00456 00457 //- Clear all storage 00458 void clear(); 00459 00460 //- Add all points/faces/cells of mesh. Additional offset for patch 00461 // or zone ids. 00462 void addMesh 00463 ( 00464 const polyMesh&, 00465 const labelList& patchMap, 00466 const labelList& pointZoneMap, 00467 const labelList& faceZoneMap, 00468 const labelList& cellZoneMap 00469 ); 00470 00471 //- Explicitly pre-size the dynamic storage for expected mesh 00472 // size for if construct-without-mesh 00473 void setCapacity 00474 ( 00475 const label nPoints, 00476 const label nFaces, 00477 const label nCells 00478 ); 00479 00480 //- Move all points. Incompatible with other topology changes. 00481 void movePoints(const pointField& newPoints); 00482 00483 //- For compatibility with polyTopoChange: set topological action. 00484 label setAction(const topoAction& action); 00485 00486 //- Add point. Return new point label. 00487 // Notes: 00488 // - masterPointID can be < 0 (appended points) 00489 // - inCell = false: add retired point (to end of point list) 00490 label addPoint 00491 ( 00492 const point&, 00493 const label masterPointID, 00494 const label zoneID, 00495 const bool inCell 00496 ); 00497 00498 //- Modify coordinate. 00499 // Notes: 00500 // - inCell = false: add retired point (to end of point list) 00501 void modifyPoint 00502 ( 00503 const label, 00504 const point&, 00505 const label newZoneID, 00506 const bool inCell 00507 ); 00508 00509 //- Remove/merge point. 00510 void removePoint(const label, const label); 00511 00512 //- Add face to cells. Return new face label. 00513 // own,nei<0, zoneID>=0 : add inactive face (to end of face list) 00514 label addFace 00515 ( 00516 const face& f, 00517 const label own, 00518 const label nei, 00519 const label masterPointID, 00520 const label masterEdgeID, 00521 const label masterFaceID, 00522 const bool flipFaceFlux, 00523 const label patchID, 00524 const label zoneID, 00525 const bool zoneFlip 00526 ); 00527 00528 //- Modify vertices or cell of face. 00529 void modifyFace 00530 ( 00531 const face& f, 00532 const label faceI, 00533 const label own, 00534 const label nei, 00535 const bool flipFaceFlux, 00536 const label patchID, 00537 const label zoneID, 00538 const bool zoneFlip 00539 ); 00540 00541 //- Remove/merge face. 00542 void removeFace(const label, const label); 00543 00544 //- Add cell. Return new cell label. 00545 label addCell 00546 ( 00547 const label masterPointID, 00548 const label masterEdgeID, 00549 const label masterFaceID, 00550 const label masterCellID, 00551 const label zoneID 00552 ); 00553 00554 //- Modify zone of cell 00555 void modifyCell(const label, const label zoneID); 00556 00557 //- Remove/merge cell. 00558 void removeCell(const label, const label); 00559 00560 //- Explicitly set the number of patches if construct-without-mesh 00561 // used. 00562 inline void setNumPatches(const label nPatches); 00563 00564 // Other 00565 00566 //- Inplace changes mesh without change of patches. 00567 // Adapts patch start/end and by default does parallel matching. 00568 // Clears all data. Returns map. 00569 // inflate = true : keep old mesh points. Put new points into the 00570 // returned map (preMotionPoints) so we can use inflation. Any 00571 // points out of nothing (appended points) are vector::zero. 00572 // inflate = false: set mesh points directly. Empty preMotionPoints 00573 // in the map. 00574 // orderCells : whether to order the cells (see bandCompression.H) 00575 // orderPoints : whether to order the points into internal first 00576 // followed by boundary points. This is not fully consistent 00577 // with upper-triangular ordering of points and edges so 00578 // is only done when explicitly asked for. 00579 autoPtr<mapPolyMesh> changeMesh 00580 ( 00581 polyMesh& mesh, 00582 const bool inflate, 00583 const bool syncParallel = true, 00584 const bool orderCells = false, 00585 const bool orderPoints = false 00586 ); 00587 00588 //- Create new mesh with old mesh patches 00589 autoPtr<mapPolyMesh> makeMesh 00590 ( 00591 autoPtr<fvMesh>& newMesh, 00592 const IOobject& io, 00593 const polyMesh& mesh, 00594 const bool syncParallel = true, 00595 const bool orderCells = false, 00596 const bool orderPoints = false 00597 ); 00598 00599 }; 00600 00601 00602 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00603 00604 } // End namespace Foam 00605 00606 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00607 00608 #include "polyTopoChangeI.H" 00609 00610 #ifdef NoRepository 00611 # include "polyTopoChangeTemplates.C" 00612 #endif 00613 00614 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00615 00616 #endif 00617 00618 // ************************************************************************* //
