From b41e0857ef56b26b31f1f053fbee503698812e61 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 15 Mar 2024 10:24:46 +0000 Subject: [PATCH] polyTopoChange: Removed restrictive cellZone functionality Now cellZones are handled directly by the applications and the new cellZone::topoChange function so that any cell can now be in any number of zones, significantly increasing the flexibility and usefulness of cellZones. The same rationalisation and generalisation will be applied to faceZones in the future. --- .../fluent3DMeshToFoam/fluent3DMeshToFoam.L | 3 +- .../generation/extrude2DMesh/extrude2DMesh.C | 2 + .../extrude2DMesh/extrude2DMesh.C | 85 +++------- .../extrude2DMesh/extrude2DMesh.H | 30 ++-- .../mesh/generation/extrudeMesh/extrudeMesh.C | 2 + .../manipulation/mergeMeshes/mergePolyMesh.C | 97 ++++++------ .../manipulation/mergeMeshes/mergePolyMesh.H | 3 + .../manipulation/polyDualMesh/meshDualiser.C | 9 +- src/OpenFOAM/meshes/polyMesh/polyMesh.H | 5 +- src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C | 12 +- .../meshes/polyMesh/zones/cellZone/cellZone.C | 20 +-- .../meshRefinement/meshRefinementBaffles.C | 4 - .../createShellMesh/createShellMesh.C | 3 +- .../fvMeshDistribute/fvMeshDistribute.C | 9 ++ .../meshModifiers/meshCutter/meshCutter.C | 6 +- .../polyTopoChange/addPatchCellLayer.C | 44 ++++-- .../polyTopoChange/addPatchCellLayer.H | 3 + .../polyTopoChange/hexRef8/hexRef8.C | 10 +- .../polyTopoChange/polyTopoChange.C | 147 +----------------- .../polyTopoChange/polyTopoChange.H | 49 +++--- tutorials/multiRegion/CHT/heatedDuct/Allrun | 2 +- .../CHT/heatedDuct/system/blockMeshDict | 2 +- 22 files changed, 188 insertions(+), 359 deletions(-) diff --git a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L index 68f4c82589..af13dd5328 100644 --- a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L +++ b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L @@ -1252,8 +1252,7 @@ int main(int argc, char *argv[]) { meshMod.addCell ( - celli, // masterCellID - -1 // zoneID + celli // masterCellID ); } diff --git a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh.C b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh.C index 7ef48e1d1b..0fe1acd2a8 100644 --- a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh.C +++ b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh.C @@ -252,6 +252,8 @@ int main(int argc, char *argv[]) // Create a mesh from topo changes. autoPtr map = meshMod().changeMesh(mesh()); + extruder.updateZones(); + mesh().topoChange(map); { diff --git a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh/extrude2DMesh/extrude2DMesh.C b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh/extrude2DMesh/extrude2DMesh.C index c98b35747a..31250a3bd3 100644 --- a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh/extrude2DMesh/extrude2DMesh.C +++ b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh/extrude2DMesh/extrude2DMesh.C @@ -52,31 +52,6 @@ void Foam::extrude2DMesh::check2D() const } -//void Foam::extrude2DMesh::findExtrudeDirection() -//{ -// scalar minRange = great; - -// for (direction dir = 0; dir < 3; dir++) -// { -// scalarField cmpts(mesh_.points().component(dir)); - -// scalar range = max(cmpts)-min(cmpts); - -// Info<< "Direction:" << dir << " range:" << range << endl; - -// if (range < minRange) -// { -// minRange = range; -// extrudeDir_ = dir; -// } -// } - -// Info<< "Extruding in direction " << extrudeDir_ -// << " with thickness " << thickness_ << nl -// << endl; -//} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::extrude2DMesh::extrude2DMesh @@ -88,12 +63,12 @@ Foam::extrude2DMesh::extrude2DMesh : mesh_(mesh), dict_(dict), - // patchDict_(dict.subDict("patchInfo")), model_(model), modelType_(dict.lookup("extrudeModel")), patchType_(dict.lookup("patchType")), frontPatchi_(-1), - backPatchi_(-1) + backPatchi_(-1), + cellZonesAddedCells_(mesh.cellZones().size()) { check2D(); } @@ -146,14 +121,6 @@ void Foam::extrude2DMesh::addFrontBackPatches() patches ).ptr(); -// newPatches[frontPatchi_] = polyPatch::New -// ( -// "front", -// patchDict_, -// frontPatchi_, -// patches -// ).ptr(); - Info<< "Adding patch " << newPatches[frontPatchi_]->name() << " at index " << frontPatchi_ << " for front faces." << nl << endl; @@ -174,14 +141,6 @@ void Foam::extrude2DMesh::addFrontBackPatches() patches ).ptr(); -// newPatches[frontPatchi_] = polyPatch::New -// ( -// "back", -// patchDict_, -// backPatchi_, -// patches -// ).ptr(); - Info<< "Adding patch " << newPatches[backPatchi_]->name() << " at index " << backPatchi_ << " for back faces." << nl << endl; @@ -203,15 +162,20 @@ void Foam::extrude2DMesh::setRefinement for (label layer = 0; layer < nLayers; ++layer) { - label offset = layer * mesh_.nCells(); + const label offset = layer*mesh_.nCells(); forAll(mesh_.cells(), celli) { - meshMod.addCell + const label newCelli = meshMod.addCell ( - celli + offset, // masterCellID, - mesh_.cellZones().whichZone(celli) // zoneID + celli + offset // masterCellID ); + + const labelList zones(mesh_.cellZones().whichZones(celli)); + forAll(zones, zonei) + { + cellZonesAddedCells_[zonei].insert(newCelli); + } } } @@ -275,23 +239,6 @@ void Foam::extrude2DMesh::setRefinement newFace[2] = f[1] + nextLayerOffset; newFace[3] = f[0] + nextLayerOffset; -//{ -// vector n = newFace.normal(pointField(meshMod.points())); -// label own = mesh_.faceOwner()[facei]; -// const labelList& ownPoints = mesh_.cellPoints()[own]; -// point ownCc = sum(pointField(mesh_.points(), ownPoints))/ownPoints.size(); -// label nei = mesh_.faceNeighbour()[facei]; -// const labelList& neiPoints = mesh_.cellPoints()[nei]; -// point neiCc = sum(pointField(mesh_.points(), neiPoints))/neiPoints.size(); -// vector d = neiCc - ownCc; - -// Pout<< "face:" << facei << " at:" << f.centre(mesh_.points()) << endl -// << " own:" << own << " at:" << ownCc << endl -// << " nei:" << nei << " at:" << neiCc << endl -// << " sign:" << (n & d) << endl -// << endl; -//} - label offset = layer * mesh_.nCells(); meshMod.addFace @@ -569,4 +516,14 @@ void Foam::extrude2DMesh::setRefinement } +void Foam::extrude2DMesh::updateZones() +{ + // Add the cellZones to the merged mesh + forAll(cellZonesAddedCells_, zonei) + { + mesh_.cellZones()[zonei].insert(cellZonesAddedCells_[zonei]); + } +} + + // ************************************************************************* // diff --git a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh/extrude2DMesh/extrude2DMesh.H b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh/extrude2DMesh/extrude2DMesh.H index 44542e4adb..4e44d19a54 100644 --- a/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh/extrude2DMesh/extrude2DMesh.H +++ b/applications/utilities/mesh/generation/extrude2DMesh/extrude2DMesh/extrude2DMesh/extrude2DMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -68,8 +68,6 @@ class extrude2DMesh const dictionary dict_; - // const dictionary patchDict_; - const extrudeModel& model_; const word modelType_; @@ -77,16 +75,18 @@ class extrude2DMesh const word patchType_; label frontPatchi_; + label backPatchi_; + //- Zones of the added cells + List cellZonesAddedCells_; + + // Private Member Functions //- Check the mesh is 2D void check2D() const; - //- Find extrusion direction - // void findExtrudeDirection(); - public: @@ -115,17 +115,6 @@ public: //- Add front and back patches void addFrontBackPatches(); - //- Play commands into polyTopoChange to extrude mesh. - void setRefinement(polyTopoChange&); - - //- Force recalculation of locally stored data on topological change - void topoChange(const polyTopoChangeMap&) - {} - - //- Force recalculation of locally stored data for mesh distribution - void distribute(const polyDistributionMap&) - {} - label frontPatchi() const { return frontPatchi_; @@ -136,6 +125,13 @@ public: return backPatchi_; } + //- Play commands into polyTopoChange to extrude mesh. + void setRefinement(polyTopoChange&); + + //- Update the mesh zones + // adding the point and cell zones for the added layer + void updateZones(); + // Member Operators diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C b/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C index f4e9207a6d..38bce28409 100644 --- a/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C @@ -630,6 +630,8 @@ int main(int argc, char *argv[]) layerExtrude.updateZones(meshFromMesh()); + meshFromMesh().topoChange(map); + layerExtrude.topoChange ( map(), diff --git a/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C b/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C index 825d0320d9..9590169576 100644 --- a/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C +++ b/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C @@ -100,11 +100,11 @@ Foam::label Foam::mergePolyMesh::zoneIndex const word& curName ) { - forAll(names, zoneI) + forAll(names, zonei) { - if (names[zoneI] == curName) + if (names[zonei] == curName) { - return zoneI; + return zonei; } } @@ -148,9 +148,9 @@ Foam::mergePolyMesh::mergePolyMesh(polyMesh& mesh) pointZoneNames_.setCapacity(2*curPointZoneNames.size()); } - forAll(curPointZoneNames, zoneI) + forAll(curPointZoneNames, zonei) { - pointZoneNames_.append(curPointZoneNames[zoneI]); + pointZoneNames_.append(curPointZoneNames[zonei]); } pointZonesAddedPoints_.setSize(pointZoneNames_.size()); @@ -162,9 +162,9 @@ Foam::mergePolyMesh::mergePolyMesh(polyMesh& mesh) { faceZoneNames_.setCapacity(2*curFaceZoneNames.size()); } - forAll(curFaceZoneNames, zoneI) + forAll(curFaceZoneNames, zonei) { - faceZoneNames_.append(curFaceZoneNames[zoneI]); + faceZoneNames_.append(curFaceZoneNames[zonei]); } // Cell zones @@ -174,16 +174,16 @@ Foam::mergePolyMesh::mergePolyMesh(polyMesh& mesh) { cellZoneNames_.setCapacity(2*curCellZoneNames.size()); } - forAll(curCellZoneNames, zoneI) + + forAll(curCellZoneNames, zonei) { - cellZoneNames_.append(curCellZoneNames[zoneI]); + cellZoneNames_.append(curCellZoneNames[zonei]); } + + cellZonesAddedCells_.setSize(cellZoneNames_.size()); } -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::mergePolyMesh::addMesh(const polyMesh& m) @@ -192,17 +192,15 @@ void Foam::mergePolyMesh::addMesh(const polyMesh& m) // Add points - label zoneID = -1; - const pointField& p = m.points(); labelList renumberPoints(p.size()); const meshPointZones& pz = m.pointZones(); labelList pointZoneIndices(pz.size()); - forAll(pz, zoneI) + forAll(pz, zonei) { - pointZoneIndices[zoneI] = zoneIndex(pointZoneNames_, pz[zoneI].name()); + pointZoneIndices[zonei] = zoneIndex(pointZoneNames_, pz[zonei].name()); pointZonesAddedPoints_.setSize(pointZoneNames_.size()); } @@ -215,12 +213,10 @@ void Foam::mergePolyMesh::addMesh(const polyMesh& m) pointi < m.nPoints() // Is in cell? ); - // Grab zone ID. If a point is not in a zone, it will return -1 - zoneID = pz.whichZone(pointi); - - if (zoneID >= 0) + const labelList zones(pz.whichZones(pointi)); + forAll(zones, zonei) { - pointZonesAddedPoints_[pointZoneIndices[zoneID]] + pointZonesAddedPoints_[pointZoneIndices[zonei]] .insert(renumberPoints[pointi]); } } @@ -233,27 +229,22 @@ void Foam::mergePolyMesh::addMesh(const polyMesh& m) const meshCellZones& cz = m.cellZones(); labelList cellZoneIndices(cz.size()); - forAll(cz, zoneI) + forAll(cz, zonei) { - cellZoneIndices[zoneI] = zoneIndex(cellZoneNames_, cz[zoneI].name()); + cellZoneIndices[zonei] = zoneIndex(cellZoneNames_, cz[zonei].name()); + cellZonesAddedCells_.setSize(cellZoneNames_.size()); } forAll(c, celli) { - // Grab zone ID. If a cell is not in a zone, it will return -1 - zoneID = cz.whichZone(celli); + renumberCells[celli] = meshMod_.addCell(-1); - if (zoneID >= 0) + const labelList zones(cz.whichZones(celli)); + forAll(zones, zonei) { - // Translate zone ID into the new index - zoneID = cellZoneIndices[zoneID]; + cellZonesAddedCells_[cellZoneIndices[zonei]] + .insert(renumberCells[celli]); } - - renumberCells[celli] = meshMod_.addCell - ( - -1, // Master cell - zoneID // Zone for cell - ); } // Add faces @@ -276,9 +267,9 @@ void Foam::mergePolyMesh::addMesh(const polyMesh& m) const meshFaceZones& fz = m.faceZones(); labelList faceZoneIndices(fz.size()); - forAll(fz, zoneI) + forAll(fz, zonei) { - faceZoneIndices[zoneI] = zoneIndex(faceZoneNames_, fz[zoneI].name()); + faceZoneIndices[zonei] = zoneIndex(faceZoneNames_, fz[zonei].name()); } const faceList& f = m.faces(); @@ -438,14 +429,14 @@ void Foam::mergePolyMesh::merge() mesh_.pointZones().setSize(pointZoneNames_.size()); - for (label zoneI = nZones; zoneI < pointZoneNames_.size(); zoneI++) + for (label zonei = nZones; zonei < pointZoneNames_.size(); zonei++) { mesh_.pointZones().set ( - zoneI, + zonei, new pointZone ( - pointZoneNames_[zoneI], + pointZoneNames_[zonei], labelList(), mesh_.pointZones() ) @@ -464,14 +455,14 @@ void Foam::mergePolyMesh::merge() mesh_.cellZones().setSize(cellZoneNames_.size()); - for (label zoneI = nZones; zoneI < cellZoneNames_.size(); zoneI++) + for (label zonei = nZones; zonei < cellZoneNames_.size(); zonei++) { mesh_.cellZones().set ( - zoneI, + zonei, new cellZone ( - cellZoneNames_[zoneI], + cellZoneNames_[zonei], labelList(), mesh_.cellZones() ) @@ -490,14 +481,14 @@ void Foam::mergePolyMesh::merge() mesh_.faceZones().setSize(faceZoneNames_.size()); - for (label zoneI = nZones; zoneI < faceZoneNames_.size(); zoneI++) + for (label zonei = nZones; zonei < faceZoneNames_.size(); zonei++) { mesh_.faceZones().set ( - zoneI, + zonei, new faceZone ( - faceZoneNames_[zoneI], + faceZoneNames_[zonei], labelList(), boolList(), mesh_.faceZones() @@ -507,16 +498,24 @@ void Foam::mergePolyMesh::merge() } // Change mesh - meshMod_.changeMesh(mesh_); - - // Clear topo change for the next operation - meshMod_.clear(); + autoPtr map(meshMod_.changeMesh(mesh_)); // Add the new points to the pointZones in the merged mesh forAll(pointZonesAddedPoints_, zonei) { mesh_.pointZones()[zonei].insert(pointZonesAddedPoints_[zonei]); } + + // Add the new cells to the cellZones in the merged mesh + forAll(cellZonesAddedCells_, zonei) + { + mesh_.cellZones()[zonei].insert(cellZonesAddedCells_[zonei]); + } + + mesh_.topoChange(map); + + // Clear topo change for the next operation + meshMod_.clear(); } diff --git a/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.H b/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.H index 461d63bce9..b5cf310ac5 100644 --- a/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.H +++ b/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.H @@ -75,6 +75,9 @@ class mergePolyMesh //- Cell zone names DynamicList cellZoneNames_; + //- Zones of the added cells + List cellZonesAddedCells_; + // Private Member Functions diff --git a/applications/utilities/mesh/manipulation/polyDualMesh/meshDualiser.C b/applications/utilities/mesh/manipulation/polyDualMesh/meshDualiser.C index 9e8164f244..1edfce5b9f 100644 --- a/applications/utilities/mesh/manipulation/polyDualMesh/meshDualiser.C +++ b/applications/utilities/mesh/manipulation/polyDualMesh/meshDualiser.C @@ -933,8 +933,7 @@ void Foam::meshDualiser::setRefinement pointToDualCells_[pointi].setSize(1); pointToDualCells_[pointi][0] = meshMod.addCell ( - -1, // masterCellID, - -1 // zoneID + -1 // masterCellID, ); if (dualCcStr.valid()) { @@ -973,8 +972,7 @@ void Foam::meshDualiser::setRefinement { pointToDualCells_[pointi][pCelli] = meshMod.addCell ( - -1, // masterCellID - -1 + -1 // masterCellID ); if (dualCcStr.valid()) { @@ -994,8 +992,7 @@ void Foam::meshDualiser::setRefinement pointToDualCells_[pointi].setSize(1); pointToDualCells_[pointi][0] = meshMod.addCell ( - -1, // masterCellID, - -1 // zoneID + -1 // masterCellID, ); if (dualCcStr.valid()) diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H index 7362bbbbc2..c191f2ef0f 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -561,6 +561,9 @@ public: // time directories readUpdateState readUpdate(); + //- Update zones using the given map + void topoChangeZones(const polyTopoChangeMap&); + //- Update topology using the given map virtual void topoChange(const polyTopoChangeMap&); diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C b/src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C index 531c1aa36c..5fefe415cf 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshUpdate.C @@ -36,6 +36,14 @@ Description // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +void Foam::polyMesh::topoChangeZones(const polyTopoChangeMap& map) +{ + pointZones_.topoChange(map); + faceZones_.topoChange(map); + cellZones_.topoChange(map); +} + + void Foam::polyMesh::topoChange(const polyTopoChangeMap& map) { if (debug) @@ -49,9 +57,7 @@ void Foam::polyMesh::topoChange(const polyTopoChangeMap& map) boundary_.topoChange(); // Update zones - pointZones_.topoChange(map); - faceZones_.topoChange(map); - cellZones_.topoChange(map); + topoChangeZones(map); // Remove the stored tet base points tetBasePtIsPtr_.clear(); diff --git a/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.C b/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.C index 61edceec72..21d16fd9b9 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/cellZone/cellZone.C @@ -132,26 +132,18 @@ void Foam::cellZone::topoChange(const polyTopoChangeMap& map) { clearAddressing(); - /* - labelList newAddressing(size()); - label nCells = 0; + labelHashSet newIndices; + const labelList& cellMap = map.cellMap(); - const labelList& cellMap = map.reverseCellMap(); - - forAll(*this, i) + forAll(cellMap, celli) { - const label celli = operator[](i); - - if (cellMap[celli] >= 0) + if (cellMap[celli] >= 0 && localIndex(cellMap[celli]) != -1) { - newAddressing[nCells] = cellMap[celli]; - nCells++; + newIndices.insert(celli); } } - newAddressing.setSize(nCells); - transfer(newAddressing); - */ + labelList::operator=(newIndices.sortedToc()); } diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C index 64276491d9..1469ec0324 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinementBaffles.C @@ -3014,12 +3014,10 @@ Foam::autoPtr Foam::meshRefinement::zonify mesh_.cellZones()[zonei].insert(cellZoneNewCells[zonei]); } - // Topochange container polyTopoChange meshMod(mesh_); - // Get coupled neighbour cellZone. Set to -1 on non-coupled patches. labelList neiCellZone; syncTools::swapBoundaryCellList(mesh_, cellToZone, neiCellZone); @@ -3038,12 +3036,10 @@ Foam::autoPtr Foam::meshRefinement::zonify } - // Get per face whether is it master (of a coupled set of faces) const PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh_)); - // faceZones // ~~~~~~~~~ // Faces on faceZones come in two variants: diff --git a/src/polyTopoChange/createShellMesh/createShellMesh.C b/src/polyTopoChange/createShellMesh/createShellMesh.C index 110ee70b6a..fe6699991a 100644 --- a/src/polyTopoChange/createShellMesh/createShellMesh.C +++ b/src/polyTopoChange/createShellMesh/createShellMesh.C @@ -503,8 +503,7 @@ void Foam::createShellMesh::setRefinement { addedCells[nLayers*facei+layerI] = meshMod.addCell ( - cellToFaceMap.size(), // masterCellID - -1 // zoneID + cellToFaceMap.size() // masterCellID ); cellToFaceMap.append(facei); } diff --git a/src/polyTopoChange/fvMeshDistribute/fvMeshDistribute.C b/src/polyTopoChange/fvMeshDistribute/fvMeshDistribute.C index 69ae444fc4..3494f97337 100644 --- a/src/polyTopoChange/fvMeshDistribute/fvMeshDistribute.C +++ b/src/polyTopoChange/fvMeshDistribute/fvMeshDistribute.C @@ -590,6 +590,9 @@ Foam::autoPtr Foam::fvMeshDistribute::repatch autoPtr map = meshMod.changeMesh(mesh_, true); + // Update zones + mesh_.topoChangeZones(map); + // Update fields mesh_.mapFields(map); @@ -772,6 +775,9 @@ Foam::autoPtr Foam::fvMeshDistribute::mergeSharedPoints // Note: parallel comms allowed. autoPtr map = meshMod.changeMesh(mesh_, true); + // Update zones + mesh_.topoChangeZones(map); + // Update fields mesh_.mapFields(map); @@ -1278,6 +1284,9 @@ Foam::autoPtr Foam::fvMeshDistribute::doRemoveCells // Note: no parallel comms allowed. autoPtr map = meshMod.changeMesh(mesh_, false); + // Update zones + mesh_.topoChangeZones(map); + // Update fields mesh_.mapFields(map); diff --git a/src/polyTopoChange/meshCut/meshModifiers/meshCutter/meshCutter.C b/src/polyTopoChange/meshCut/meshModifiers/meshCutter/meshCutter.C index 9c07549914..5a2a6c71b8 100644 --- a/src/polyTopoChange/meshCut/meshModifiers/meshCutter/meshCutter.C +++ b/src/polyTopoChange/meshCut/meshModifiers/meshCutter/meshCutter.C @@ -606,11 +606,7 @@ void Foam::meshCutter::setRefinement if (cellLoops[celli].size()) { // Add a cell to the existing cell - label addedCelli = meshMod.addCell - ( - celli, // master cell - mesh().cellZones().whichZone(celli) // zone for cell - ); + label addedCelli = meshMod.addCell(celli); addedCells_.insert(celli, addedCelli); diff --git a/src/polyTopoChange/polyTopoChange/addPatchCellLayer.C b/src/polyTopoChange/polyTopoChange/addPatchCellLayer.C index 867d1d9c92..bd2acf7461 100644 --- a/src/polyTopoChange/polyTopoChange/addPatchCellLayer.C +++ b/src/polyTopoChange/polyTopoChange/addPatchCellLayer.C @@ -421,6 +421,7 @@ Foam::addPatchCellLayer::addPatchCellLayer addToMesh_(addToMesh), addedPoints_(0), pointZonesAddedPoints_(mesh.pointZones().size()), + cellZonesAddedCells_(mesh.cellZones().size()), layerFaces_(0) {} @@ -1009,14 +1010,15 @@ void Foam::addPatchCellLayer::setRefinement true // supports a cell ); - const label zonei = mesh_.pointZones().whichZone(meshPointi); - - if (zonei != -1) + forAll(mesh_.pointZones(), zonei) { - pointZonesAddedPoints_[zonei].insert - ( - copiedPatchPoints[patchPointi] - ); + if (mesh_.pointZones()[zonei].localIndex(meshPointi) != -1) + { + pointZonesAddedPoints_[zonei].insert + ( + copiedPatchPoints[patchPointi] + ); + } } } } @@ -1033,7 +1035,7 @@ void Foam::addPatchCellLayer::setRefinement point pt = mesh_.points()[meshPointi]; vector disp = firstLayerDisp[patchPointi]; - const label zonei = mesh_.pointZones().whichZone(meshPointi); + const labelList zones(mesh_.pointZones().whichZones(meshPointi)); forAll(addedPoints_[patchPointi], i) { @@ -1048,7 +1050,7 @@ void Foam::addPatchCellLayer::setRefinement addedPoints_[patchPointi][i] = addedVertI; - if (zonei != -1) + forAll(zones, zonei) { pointZonesAddedPoints_[zonei].insert(addedVertI); } @@ -1071,11 +1073,11 @@ void Foam::addPatchCellLayer::setRefinement { addedCells[patchFacei].setSize(nFaceLayers[patchFacei]); - label meshFacei = pp.addressing()[patchFacei]; + const label meshFacei = pp.addressing()[patchFacei]; - label ownZoneI = mesh_.cellZones().whichZone + const labelList ownZones ( - mesh_.faceOwner()[meshFacei] + mesh_.cellZones().whichZones( mesh_.faceOwner()[meshFacei]) ); for (label i = 0; i < nFaceLayers[patchFacei]; i++) @@ -1084,15 +1086,21 @@ void Foam::addPatchCellLayer::setRefinement // for now add from cell so we can map easily. addedCells[patchFacei][i] = meshMod.addCell ( - (addToMesh_ ? mesh_.faceOwner()[meshFacei] : -1), // master - ownZoneI // zone for cell + (addToMesh_ ? mesh_.faceOwner()[meshFacei] : -1) ); + + forAll(ownZones, zonei) + { + cellZonesAddedCells_[zonei].insert + ( + addedCells[patchFacei][i] + ); + } } } } - // Create faces on top of the original patch faces. // These faces are created from original patch faces outwards so in order // of increasing cell number. So orientation should be same as original @@ -1684,6 +1692,12 @@ void Foam::addPatchCellLayer::updateZones(polyMesh& mesh) { mesh.pointZones()[zonei].insert(pointZonesAddedPoints_[zonei]); } + + // Add the cellZones to the merged mesh + forAll(cellZonesAddedCells_, zonei) + { + mesh.cellZones()[zonei].insert(cellZonesAddedCells_[zonei]); + } } diff --git a/src/polyTopoChange/polyTopoChange/addPatchCellLayer.H b/src/polyTopoChange/polyTopoChange/addPatchCellLayer.H index 53df0596c3..e95af7822a 100644 --- a/src/polyTopoChange/polyTopoChange/addPatchCellLayer.H +++ b/src/polyTopoChange/polyTopoChange/addPatchCellLayer.H @@ -175,6 +175,9 @@ class addPatchCellLayer //- Zones of the added points List pointZonesAddedPoints_; + //- Zones of the added cells + List cellZonesAddedCells_; + //- For all patchfaces: list of layer faces. // - empty if no face extruded // - first face is original boundary face diff --git a/src/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C b/src/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C index f07fd9afce..1e2a3bbf31 100644 --- a/src/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C +++ b/src/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C @@ -3632,16 +3632,10 @@ Foam::labelListList Foam::hexRef8::setRefinement // Update cell level newCellLevel[celli] = cellLevel_[celli]+1; - for (label i = 1; i < 8; i++) { - cAdded[i] = meshMod.addCell - ( - celli, // master cell - mesh_.cellZones().whichZone(celli) // zone for cell - ); - - newCellLevel(cAdded[i]) = cellLevel_[celli]+1; + cAdded[i] = meshMod.addCell(celli); + newCellLevel(cAdded[i]) = cellLevel_[celli] + 1; } } } diff --git a/src/polyTopoChange/polyTopoChange/polyTopoChange.C b/src/polyTopoChange/polyTopoChange/polyTopoChange.C index c60fc83adc..d58b2f267a 100644 --- a/src/polyTopoChange/polyTopoChange/polyTopoChange.C +++ b/src/polyTopoChange/polyTopoChange/polyTopoChange.C @@ -796,12 +796,6 @@ void Foam::polyTopoChange::getFaceOrder } } - // if (debug) - //{ - // Pout<< "patchSizes:" << patchSizes << nl - // << "patchStarts:" << patchStarts << endl; - //} - labelList workPatchStarts(patchStarts); for (label facei = 0; facei < nActiveFaces; facei++) @@ -899,7 +893,6 @@ void Foam::polyTopoChange::compact cellMap_.shrink(); reverseCellMap_.shrink(); - cellZone_.shrink(); // Compact points @@ -1149,9 +1142,6 @@ void Foam::polyTopoChange::compact cellMap_.setCapacity(newCelli); renumberReverseMap(localCellMap, reverseCellMap_); - reorder(localCellMap, cellZone_); - cellZone_.setCapacity(newCelli); - // Renumber owner/neighbour. Take into account if neighbour suddenly // gets lower cell than owner. forAll(faceOwner_, facei) @@ -1412,69 +1402,6 @@ void Foam::polyTopoChange::resetZones ); } } - - - // cellZones - // ~~~~~~~~~ - - { - const meshCellZones& cellZones = mesh.cellZones(); - - labelList nCells(cellZones.size(), 0); - - forAll(cellZone_, celli) - { - label zoneI = cellZone_[celli]; - - if (zoneI >= cellZones.size()) - { - FatalErrorInFunction - << "Illegal zoneID " << zoneI << " for cell " - << celli << abort(FatalError); - } - - if (zoneI >= 0) - { - nCells[zoneI]++; - } - } - - labelListList addressing(cellZones.size()); - forAll(addressing, zoneI) - { - addressing[zoneI].setSize(nCells[zoneI]); - } - nCells = 0; - - forAll(cellZone_, celli) - { - label zoneI = cellZone_[celli]; - - if (zoneI >= 0) - { - addressing[zoneI][nCells[zoneI]++] = celli; - } - } - // Sort the addressing - forAll(addressing, zoneI) - { - stableSort(addressing[zoneI]); - } - - // Reset the addressing on the zone - forAll(newMesh.cellZones(), zoneI) - { - if (debug) - { - Pout<< "cellZone:" << zoneI - << " name:" << newMesh.cellZones()[zoneI].name() - << " size:" << addressing[zoneI].size() - << endl; - } - - newMesh.cellZones()[zoneI] = addressing[zoneI]; - } - } } @@ -1780,8 +1707,7 @@ Foam::polyTopoChange::polyTopoChange(const label nPatches, const bool strict) faceZoneFlip_(0), nActiveFaces_(0), cellMap_(0), - reverseCellMap_(0), - cellZone_(0) + reverseCellMap_(0) {} @@ -1809,8 +1735,7 @@ Foam::polyTopoChange::polyTopoChange faceZoneFlip_(0), nActiveFaces_(0), cellMap_(0), - reverseCellMap_(0), - cellZone_(0) + reverseCellMap_(0) { // Add points { @@ -1825,19 +1750,12 @@ Foam::polyTopoChange::polyTopoChange // Add points in mesh order for (label pointi = 0; pointi < mesh.nPoints(); pointi++) { - addPoint - ( - points[pointi], - pointi, - true - ); + addPoint(points[pointi], pointi, true); } } // Add cells { - const meshCellZones& cellZones = mesh.cellZones(); - // Resize // Note: polyMesh does not allow retired cells anymore. So allCells @@ -1846,43 +1764,11 @@ Foam::polyTopoChange::polyTopoChange cellMap_.setCapacity(cellMap_.size() + nAllCells); reverseCellMap_.setCapacity(reverseCellMap_.size() + nAllCells); - cellZone_.setCapacity(cellZone_.size() + nAllCells); - - - // Precalc offset zones - labelList newZoneID(nAllCells, -1); - - forAll(cellZones, zoneI) - { - const labelList& cellLabels = cellZones[zoneI]; - - forAll(cellLabels, j) - { - label celli = cellLabels[j]; - - if (newZoneID[celli] != -1) - { - WarningInFunction - << "Cell:" << celli - << " centre:" << mesh.cellCentres()[celli] - << " is in two zones:" - << cellZones[newZoneID[celli]].name() - << " and " << cellZones[zoneI].name() << endl - << " This is not supported." - << " Continuing with first zone only." << endl; - } - else - { - newZoneID[celli] = zoneI; - } - } - } // Add cells in mesh order for (label celli = 0; celli < nAllCells; celli++) { - // Add cell from cell - addCell(celli, newZoneID[celli]); + addCell(celli); } } @@ -2001,7 +1887,6 @@ void Foam::polyTopoChange::clear() cellMap_.clearStorage(); reverseCellMap_.clearStorage(); - cellZone_.clearStorage(); } @@ -2028,7 +1913,6 @@ void Foam::polyTopoChange::setCapacity cellMap_.setCapacity(nCells); reverseCellMap_.setCapacity(nCells); - cellZone_.setCapacity(nCells); } @@ -2276,16 +2160,11 @@ void Foam::polyTopoChange::removeFace(const label facei, const label mergeFacei) } -Foam::label Foam::polyTopoChange::addCell -( - const label masterCellID, - const label zoneID -) +Foam::label Foam::polyTopoChange::addCell(const label masterCellID) { const label celli = cellMap_.size(); cellMap_.append(masterCellID); reverseCellMap_.append(celli); - cellZone_.append(zoneID); return celli; } @@ -2318,7 +2197,6 @@ void Foam::polyTopoChange::removeCell(const label celli, const label mergeCelli) { reverseCellMap_[celli] = -1; } - cellZone_[celli] = -1; } @@ -2465,7 +2343,6 @@ Foam::autoPtr Foam::polyTopoChange::changeMesh { faceZone_.clearStorage(); faceZoneFlip_.clearStorage(); - cellZone_.clearStorage(); } @@ -2689,12 +2566,6 @@ Foam::autoPtr Foam::polyTopoChange::makeMesh { forAll(oldPointZones, i) { - // pZonePtrs[i] = new pointZone - // ( - // oldPointZones[i].name(), - // labelList(0), - // newMesh.pointZones() - // ); pZonePtrs[i] = oldPointZones[i].clone(newMesh.pointZones()).ptr(); } } @@ -2719,12 +2590,7 @@ Foam::autoPtr Foam::polyTopoChange::makeMesh { forAll(oldCellZones, i) { - cZonePtrs[i] = new cellZone - ( - oldCellZones[i].name(), - labelList(0), - newMesh.cellZones() - ); + cZonePtrs[i] = oldCellZones[i].clone(newMesh.cellZones()).ptr(); } } @@ -2735,7 +2601,6 @@ Foam::autoPtr Foam::polyTopoChange::makeMesh { faceZone_.clearStorage(); faceZoneFlip_.clearStorage(); - cellZone_.clearStorage(); } // Patch point renumbering diff --git a/src/polyTopoChange/polyTopoChange/polyTopoChange.H b/src/polyTopoChange/polyTopoChange/polyTopoChange.H index 4bee845980..4e8244e8d4 100644 --- a/src/polyTopoChange/polyTopoChange/polyTopoChange.H +++ b/src/polyTopoChange/polyTopoChange/polyTopoChange.H @@ -100,7 +100,7 @@ class polyTopoChange // Private Data //- Whether to allow referencing illegal points/cells/faces - // when adding/removing data. + // when adding/removing data bool strict_; @@ -118,7 +118,7 @@ class polyTopoChange //- Original point label (or masterpoint for added points) DynamicList