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.
This commit is contained in:
Henry Weller
2024-03-15 10:24:46 +00:00
parent 81c2c42ca4
commit b41e0857ef
22 changed files with 188 additions and 359 deletions

View File

@ -1252,8 +1252,7 @@ int main(int argc, char *argv[])
{ {
meshMod.addCell meshMod.addCell
( (
celli, // masterCellID celli // masterCellID
-1 // zoneID
); );
} }

View File

@ -252,6 +252,8 @@ int main(int argc, char *argv[])
// Create a mesh from topo changes. // Create a mesh from topo changes.
autoPtr<polyTopoChangeMap> map = meshMod().changeMesh(mesh()); autoPtr<polyTopoChangeMap> map = meshMod().changeMesh(mesh());
extruder.updateZones();
mesh().topoChange(map); mesh().topoChange(map);
{ {

View File

@ -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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::extrude2DMesh::extrude2DMesh Foam::extrude2DMesh::extrude2DMesh
@ -88,12 +63,12 @@ Foam::extrude2DMesh::extrude2DMesh
: :
mesh_(mesh), mesh_(mesh),
dict_(dict), dict_(dict),
// patchDict_(dict.subDict("patchInfo")),
model_(model), model_(model),
modelType_(dict.lookup("extrudeModel")), modelType_(dict.lookup("extrudeModel")),
patchType_(dict.lookup("patchType")), patchType_(dict.lookup("patchType")),
frontPatchi_(-1), frontPatchi_(-1),
backPatchi_(-1) backPatchi_(-1),
cellZonesAddedCells_(mesh.cellZones().size())
{ {
check2D(); check2D();
} }
@ -146,14 +121,6 @@ void Foam::extrude2DMesh::addFrontBackPatches()
patches patches
).ptr(); ).ptr();
// newPatches[frontPatchi_] = polyPatch::New
// (
// "front",
// patchDict_,
// frontPatchi_,
// patches
// ).ptr();
Info<< "Adding patch " << newPatches[frontPatchi_]->name() Info<< "Adding patch " << newPatches[frontPatchi_]->name()
<< " at index " << frontPatchi_ << " at index " << frontPatchi_
<< " for front faces." << nl << endl; << " for front faces." << nl << endl;
@ -174,14 +141,6 @@ void Foam::extrude2DMesh::addFrontBackPatches()
patches patches
).ptr(); ).ptr();
// newPatches[frontPatchi_] = polyPatch::New
// (
// "back",
// patchDict_,
// backPatchi_,
// patches
// ).ptr();
Info<< "Adding patch " << newPatches[backPatchi_]->name() Info<< "Adding patch " << newPatches[backPatchi_]->name()
<< " at index " << backPatchi_ << " at index " << backPatchi_
<< " for back faces." << nl << endl; << " for back faces." << nl << endl;
@ -203,15 +162,20 @@ void Foam::extrude2DMesh::setRefinement
for (label layer = 0; layer < nLayers; ++layer) for (label layer = 0; layer < nLayers; ++layer)
{ {
label offset = layer * mesh_.nCells(); const label offset = layer*mesh_.nCells();
forAll(mesh_.cells(), celli) forAll(mesh_.cells(), celli)
{ {
meshMod.addCell const label newCelli = meshMod.addCell
( (
celli + offset, // masterCellID, celli + offset // masterCellID
mesh_.cellZones().whichZone(celli) // zoneID
); );
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[2] = f[1] + nextLayerOffset;
newFace[3] = f[0] + 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(); label offset = layer * mesh_.nCells();
meshMod.addFace 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]);
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -68,8 +68,6 @@ class extrude2DMesh
const dictionary dict_; const dictionary dict_;
// const dictionary patchDict_;
const extrudeModel& model_; const extrudeModel& model_;
const word modelType_; const word modelType_;
@ -77,16 +75,18 @@ class extrude2DMesh
const word patchType_; const word patchType_;
label frontPatchi_; label frontPatchi_;
label backPatchi_; label backPatchi_;
//- Zones of the added cells
List<labelHashSet> cellZonesAddedCells_;
// Private Member Functions // Private Member Functions
//- Check the mesh is 2D //- Check the mesh is 2D
void check2D() const; void check2D() const;
//- Find extrusion direction
// void findExtrudeDirection();
public: public:
@ -115,17 +115,6 @@ public:
//- Add front and back patches //- Add front and back patches
void addFrontBackPatches(); 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 label frontPatchi() const
{ {
return frontPatchi_; return frontPatchi_;
@ -136,6 +125,13 @@ public:
return backPatchi_; 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 // Member Operators

View File

@ -630,6 +630,8 @@ int main(int argc, char *argv[])
layerExtrude.updateZones(meshFromMesh()); layerExtrude.updateZones(meshFromMesh());
meshFromMesh().topoChange(map);
layerExtrude.topoChange layerExtrude.topoChange
( (
map(), map(),

View File

@ -100,11 +100,11 @@ Foam::label Foam::mergePolyMesh::zoneIndex
const word& curName 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()); pointZoneNames_.setCapacity(2*curPointZoneNames.size());
} }
forAll(curPointZoneNames, zoneI) forAll(curPointZoneNames, zonei)
{ {
pointZoneNames_.append(curPointZoneNames[zoneI]); pointZoneNames_.append(curPointZoneNames[zonei]);
} }
pointZonesAddedPoints_.setSize(pointZoneNames_.size()); pointZonesAddedPoints_.setSize(pointZoneNames_.size());
@ -162,9 +162,9 @@ Foam::mergePolyMesh::mergePolyMesh(polyMesh& mesh)
{ {
faceZoneNames_.setCapacity(2*curFaceZoneNames.size()); faceZoneNames_.setCapacity(2*curFaceZoneNames.size());
} }
forAll(curFaceZoneNames, zoneI) forAll(curFaceZoneNames, zonei)
{ {
faceZoneNames_.append(curFaceZoneNames[zoneI]); faceZoneNames_.append(curFaceZoneNames[zonei]);
} }
// Cell zones // Cell zones
@ -174,14 +174,14 @@ Foam::mergePolyMesh::mergePolyMesh(polyMesh& mesh)
{ {
cellZoneNames_.setCapacity(2*curCellZoneNames.size()); 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 * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -192,17 +192,15 @@ void Foam::mergePolyMesh::addMesh(const polyMesh& m)
// Add points // Add points
label zoneID = -1;
const pointField& p = m.points(); const pointField& p = m.points();
labelList renumberPoints(p.size()); labelList renumberPoints(p.size());
const meshPointZones& pz = m.pointZones(); const meshPointZones& pz = m.pointZones();
labelList pointZoneIndices(pz.size()); 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()); pointZonesAddedPoints_.setSize(pointZoneNames_.size());
} }
@ -215,12 +213,10 @@ void Foam::mergePolyMesh::addMesh(const polyMesh& m)
pointi < m.nPoints() // Is in cell? pointi < m.nPoints() // Is in cell?
); );
// Grab zone ID. If a point is not in a zone, it will return -1 const labelList zones(pz.whichZones(pointi));
zoneID = pz.whichZone(pointi); forAll(zones, zonei)
if (zoneID >= 0)
{ {
pointZonesAddedPoints_[pointZoneIndices[zoneID]] pointZonesAddedPoints_[pointZoneIndices[zonei]]
.insert(renumberPoints[pointi]); .insert(renumberPoints[pointi]);
} }
} }
@ -233,27 +229,22 @@ void Foam::mergePolyMesh::addMesh(const polyMesh& m)
const meshCellZones& cz = m.cellZones(); const meshCellZones& cz = m.cellZones();
labelList cellZoneIndices(cz.size()); 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) forAll(c, celli)
{ {
// Grab zone ID. If a cell is not in a zone, it will return -1 renumberCells[celli] = meshMod_.addCell(-1);
zoneID = cz.whichZone(celli);
if (zoneID >= 0) const labelList zones(cz.whichZones(celli));
forAll(zones, zonei)
{ {
// Translate zone ID into the new index cellZonesAddedCells_[cellZoneIndices[zonei]]
zoneID = cellZoneIndices[zoneID]; .insert(renumberCells[celli]);
} }
renumberCells[celli] = meshMod_.addCell
(
-1, // Master cell
zoneID // Zone for cell
);
} }
// Add faces // Add faces
@ -276,9 +267,9 @@ void Foam::mergePolyMesh::addMesh(const polyMesh& m)
const meshFaceZones& fz = m.faceZones(); const meshFaceZones& fz = m.faceZones();
labelList faceZoneIndices(fz.size()); 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(); const faceList& f = m.faces();
@ -438,14 +429,14 @@ void Foam::mergePolyMesh::merge()
mesh_.pointZones().setSize(pointZoneNames_.size()); mesh_.pointZones().setSize(pointZoneNames_.size());
for (label zoneI = nZones; zoneI < pointZoneNames_.size(); zoneI++) for (label zonei = nZones; zonei < pointZoneNames_.size(); zonei++)
{ {
mesh_.pointZones().set mesh_.pointZones().set
( (
zoneI, zonei,
new pointZone new pointZone
( (
pointZoneNames_[zoneI], pointZoneNames_[zonei],
labelList(), labelList(),
mesh_.pointZones() mesh_.pointZones()
) )
@ -464,14 +455,14 @@ void Foam::mergePolyMesh::merge()
mesh_.cellZones().setSize(cellZoneNames_.size()); mesh_.cellZones().setSize(cellZoneNames_.size());
for (label zoneI = nZones; zoneI < cellZoneNames_.size(); zoneI++) for (label zonei = nZones; zonei < cellZoneNames_.size(); zonei++)
{ {
mesh_.cellZones().set mesh_.cellZones().set
( (
zoneI, zonei,
new cellZone new cellZone
( (
cellZoneNames_[zoneI], cellZoneNames_[zonei],
labelList(), labelList(),
mesh_.cellZones() mesh_.cellZones()
) )
@ -490,14 +481,14 @@ void Foam::mergePolyMesh::merge()
mesh_.faceZones().setSize(faceZoneNames_.size()); mesh_.faceZones().setSize(faceZoneNames_.size());
for (label zoneI = nZones; zoneI < faceZoneNames_.size(); zoneI++) for (label zonei = nZones; zonei < faceZoneNames_.size(); zonei++)
{ {
mesh_.faceZones().set mesh_.faceZones().set
( (
zoneI, zonei,
new faceZone new faceZone
( (
faceZoneNames_[zoneI], faceZoneNames_[zonei],
labelList(), labelList(),
boolList(), boolList(),
mesh_.faceZones() mesh_.faceZones()
@ -507,16 +498,24 @@ void Foam::mergePolyMesh::merge()
} }
// Change mesh // Change mesh
meshMod_.changeMesh(mesh_); autoPtr<polyTopoChangeMap> map(meshMod_.changeMesh(mesh_));
// Clear topo change for the next operation
meshMod_.clear();
// Add the new points to the pointZones in the merged mesh // Add the new points to the pointZones in the merged mesh
forAll(pointZonesAddedPoints_, zonei) forAll(pointZonesAddedPoints_, zonei)
{ {
mesh_.pointZones()[zonei].insert(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();
} }

View File

@ -75,6 +75,9 @@ class mergePolyMesh
//- Cell zone names //- Cell zone names
DynamicList<word> cellZoneNames_; DynamicList<word> cellZoneNames_;
//- Zones of the added cells
List<labelHashSet> cellZonesAddedCells_;
// Private Member Functions // Private Member Functions

View File

@ -933,8 +933,7 @@ void Foam::meshDualiser::setRefinement
pointToDualCells_[pointi].setSize(1); pointToDualCells_[pointi].setSize(1);
pointToDualCells_[pointi][0] = meshMod.addCell pointToDualCells_[pointi][0] = meshMod.addCell
( (
-1, // masterCellID, -1 // masterCellID,
-1 // zoneID
); );
if (dualCcStr.valid()) if (dualCcStr.valid())
{ {
@ -973,8 +972,7 @@ void Foam::meshDualiser::setRefinement
{ {
pointToDualCells_[pointi][pCelli] = meshMod.addCell pointToDualCells_[pointi][pCelli] = meshMod.addCell
( (
-1, // masterCellID -1 // masterCellID
-1
); );
if (dualCcStr.valid()) if (dualCcStr.valid())
{ {
@ -994,8 +992,7 @@ void Foam::meshDualiser::setRefinement
pointToDualCells_[pointi].setSize(1); pointToDualCells_[pointi].setSize(1);
pointToDualCells_[pointi][0] = meshMod.addCell pointToDualCells_[pointi][0] = meshMod.addCell
( (
-1, // masterCellID, -1 // masterCellID,
-1 // zoneID
); );
if (dualCcStr.valid()) if (dualCcStr.valid())

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org \\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -561,6 +561,9 @@ public:
// time directories // time directories
readUpdateState readUpdate(); readUpdateState readUpdate();
//- Update zones using the given map
void topoChangeZones(const polyTopoChangeMap&);
//- Update topology using the given map //- Update topology using the given map
virtual void topoChange(const polyTopoChangeMap&); virtual void topoChange(const polyTopoChangeMap&);

View File

@ -36,6 +36,14 @@ Description
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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) void Foam::polyMesh::topoChange(const polyTopoChangeMap& map)
{ {
if (debug) if (debug)
@ -49,9 +57,7 @@ void Foam::polyMesh::topoChange(const polyTopoChangeMap& map)
boundary_.topoChange(); boundary_.topoChange();
// Update zones // Update zones
pointZones_.topoChange(map); topoChangeZones(map);
faceZones_.topoChange(map);
cellZones_.topoChange(map);
// Remove the stored tet base points // Remove the stored tet base points
tetBasePtIsPtr_.clear(); tetBasePtIsPtr_.clear();

View File

@ -132,26 +132,18 @@ void Foam::cellZone::topoChange(const polyTopoChangeMap& map)
{ {
clearAddressing(); clearAddressing();
/* labelHashSet newIndices;
labelList newAddressing(size()); const labelList& cellMap = map.cellMap();
label nCells = 0;
const labelList& cellMap = map.reverseCellMap(); forAll(cellMap, celli)
forAll(*this, i)
{ {
const label celli = operator[](i); if (cellMap[celli] >= 0 && localIndex(cellMap[celli]) != -1)
if (cellMap[celli] >= 0)
{ {
newAddressing[nCells] = cellMap[celli]; newIndices.insert(celli);
nCells++;
} }
} }
newAddressing.setSize(nCells); labelList::operator=(newIndices.sortedToc());
transfer(newAddressing);
*/
} }

View File

@ -3014,12 +3014,10 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::meshRefinement::zonify
mesh_.cellZones()[zonei].insert(cellZoneNewCells[zonei]); mesh_.cellZones()[zonei].insert(cellZoneNewCells[zonei]);
} }
// Topochange container // Topochange container
polyTopoChange meshMod(mesh_); polyTopoChange meshMod(mesh_);
// Get coupled neighbour cellZone. Set to -1 on non-coupled patches. // Get coupled neighbour cellZone. Set to -1 on non-coupled patches.
labelList neiCellZone; labelList neiCellZone;
syncTools::swapBoundaryCellList(mesh_, cellToZone, neiCellZone); syncTools::swapBoundaryCellList(mesh_, cellToZone, neiCellZone);
@ -3038,12 +3036,10 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::meshRefinement::zonify
} }
// Get per face whether is it master (of a coupled set of faces) // Get per face whether is it master (of a coupled set of faces)
const PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh_)); const PackedBoolList isMasterFace(syncTools::getMasterFaces(mesh_));
// faceZones // faceZones
// ~~~~~~~~~ // ~~~~~~~~~
// Faces on faceZones come in two variants: // Faces on faceZones come in two variants:

View File

@ -503,8 +503,7 @@ void Foam::createShellMesh::setRefinement
{ {
addedCells[nLayers*facei+layerI] = meshMod.addCell addedCells[nLayers*facei+layerI] = meshMod.addCell
( (
cellToFaceMap.size(), // masterCellID cellToFaceMap.size() // masterCellID
-1 // zoneID
); );
cellToFaceMap.append(facei); cellToFaceMap.append(facei);
} }

View File

@ -590,6 +590,9 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::fvMeshDistribute::repatch
autoPtr<polyTopoChangeMap> map = meshMod.changeMesh(mesh_, true); autoPtr<polyTopoChangeMap> map = meshMod.changeMesh(mesh_, true);
// Update zones
mesh_.topoChangeZones(map);
// Update fields // Update fields
mesh_.mapFields(map); mesh_.mapFields(map);
@ -772,6 +775,9 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::fvMeshDistribute::mergeSharedPoints
// Note: parallel comms allowed. // Note: parallel comms allowed.
autoPtr<polyTopoChangeMap> map = meshMod.changeMesh(mesh_, true); autoPtr<polyTopoChangeMap> map = meshMod.changeMesh(mesh_, true);
// Update zones
mesh_.topoChangeZones(map);
// Update fields // Update fields
mesh_.mapFields(map); mesh_.mapFields(map);
@ -1278,6 +1284,9 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::fvMeshDistribute::doRemoveCells
// Note: no parallel comms allowed. // Note: no parallel comms allowed.
autoPtr<polyTopoChangeMap> map = meshMod.changeMesh(mesh_, false); autoPtr<polyTopoChangeMap> map = meshMod.changeMesh(mesh_, false);
// Update zones
mesh_.topoChangeZones(map);
// Update fields // Update fields
mesh_.mapFields(map); mesh_.mapFields(map);

View File

@ -606,11 +606,7 @@ void Foam::meshCutter::setRefinement
if (cellLoops[celli].size()) if (cellLoops[celli].size())
{ {
// Add a cell to the existing cell // Add a cell to the existing cell
label addedCelli = meshMod.addCell label addedCelli = meshMod.addCell(celli);
(
celli, // master cell
mesh().cellZones().whichZone(celli) // zone for cell
);
addedCells_.insert(celli, addedCelli); addedCells_.insert(celli, addedCelli);

View File

@ -421,6 +421,7 @@ Foam::addPatchCellLayer::addPatchCellLayer
addToMesh_(addToMesh), addToMesh_(addToMesh),
addedPoints_(0), addedPoints_(0),
pointZonesAddedPoints_(mesh.pointZones().size()), pointZonesAddedPoints_(mesh.pointZones().size()),
cellZonesAddedCells_(mesh.cellZones().size()),
layerFaces_(0) layerFaces_(0)
{} {}
@ -1009,9 +1010,9 @@ void Foam::addPatchCellLayer::setRefinement
true // supports a cell true // supports a cell
); );
const label zonei = mesh_.pointZones().whichZone(meshPointi); forAll(mesh_.pointZones(), zonei)
{
if (zonei != -1) if (mesh_.pointZones()[zonei].localIndex(meshPointi) != -1)
{ {
pointZonesAddedPoints_[zonei].insert pointZonesAddedPoints_[zonei].insert
( (
@ -1021,6 +1022,7 @@ void Foam::addPatchCellLayer::setRefinement
} }
} }
} }
}
// Create points for additional layers // Create points for additional layers
@ -1033,7 +1035,7 @@ void Foam::addPatchCellLayer::setRefinement
point pt = mesh_.points()[meshPointi]; point pt = mesh_.points()[meshPointi];
vector disp = firstLayerDisp[patchPointi]; vector disp = firstLayerDisp[patchPointi];
const label zonei = mesh_.pointZones().whichZone(meshPointi); const labelList zones(mesh_.pointZones().whichZones(meshPointi));
forAll(addedPoints_[patchPointi], i) forAll(addedPoints_[patchPointi], i)
{ {
@ -1048,7 +1050,7 @@ void Foam::addPatchCellLayer::setRefinement
addedPoints_[patchPointi][i] = addedVertI; addedPoints_[patchPointi][i] = addedVertI;
if (zonei != -1) forAll(zones, zonei)
{ {
pointZonesAddedPoints_[zonei].insert(addedVertI); pointZonesAddedPoints_[zonei].insert(addedVertI);
} }
@ -1071,11 +1073,11 @@ void Foam::addPatchCellLayer::setRefinement
{ {
addedCells[patchFacei].setSize(nFaceLayers[patchFacei]); 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++) for (label i = 0; i < nFaceLayers[patchFacei]; i++)
@ -1084,13 +1086,19 @@ void Foam::addPatchCellLayer::setRefinement
// for now add from cell so we can map easily. // for now add from cell so we can map easily.
addedCells[patchFacei][i] = meshMod.addCell addedCells[patchFacei][i] = meshMod.addCell
( (
(addToMesh_ ? mesh_.faceOwner()[meshFacei] : -1), // master (addToMesh_ ? mesh_.faceOwner()[meshFacei] : -1)
ownZoneI // zone for cell );
forAll(ownZones, zonei)
{
cellZonesAddedCells_[zonei].insert
(
addedCells[patchFacei][i]
); );
} }
} }
} }
}
// Create faces on top of the original patch faces. // Create faces on top of the original patch faces.
@ -1684,6 +1692,12 @@ void Foam::addPatchCellLayer::updateZones(polyMesh& mesh)
{ {
mesh.pointZones()[zonei].insert(pointZonesAddedPoints_[zonei]); mesh.pointZones()[zonei].insert(pointZonesAddedPoints_[zonei]);
} }
// Add the cellZones to the merged mesh
forAll(cellZonesAddedCells_, zonei)
{
mesh.cellZones()[zonei].insert(cellZonesAddedCells_[zonei]);
}
} }

View File

@ -175,6 +175,9 @@ class addPatchCellLayer
//- Zones of the added points //- Zones of the added points
List<labelHashSet> pointZonesAddedPoints_; List<labelHashSet> pointZonesAddedPoints_;
//- Zones of the added cells
List<labelHashSet> cellZonesAddedCells_;
//- For all patchfaces: list of layer faces. //- For all patchfaces: list of layer faces.
// - empty if no face extruded // - empty if no face extruded
// - first face is original boundary face // - first face is original boundary face

View File

@ -3632,15 +3632,9 @@ Foam::labelListList Foam::hexRef8::setRefinement
// Update cell level // Update cell level
newCellLevel[celli] = cellLevel_[celli]+1; newCellLevel[celli] = cellLevel_[celli]+1;
for (label i = 1; i < 8; i++) for (label i = 1; i < 8; i++)
{ {
cAdded[i] = meshMod.addCell cAdded[i] = meshMod.addCell(celli);
(
celli, // master cell
mesh_.cellZones().whichZone(celli) // zone for cell
);
newCellLevel(cAdded[i]) = cellLevel_[celli] + 1; newCellLevel(cAdded[i]) = cellLevel_[celli] + 1;
} }
} }

View File

@ -796,12 +796,6 @@ void Foam::polyTopoChange::getFaceOrder
} }
} }
// if (debug)
//{
// Pout<< "patchSizes:" << patchSizes << nl
// << "patchStarts:" << patchStarts << endl;
//}
labelList workPatchStarts(patchStarts); labelList workPatchStarts(patchStarts);
for (label facei = 0; facei < nActiveFaces; facei++) for (label facei = 0; facei < nActiveFaces; facei++)
@ -899,7 +893,6 @@ void Foam::polyTopoChange::compact
cellMap_.shrink(); cellMap_.shrink();
reverseCellMap_.shrink(); reverseCellMap_.shrink();
cellZone_.shrink();
// Compact points // Compact points
@ -1149,9 +1142,6 @@ void Foam::polyTopoChange::compact
cellMap_.setCapacity(newCelli); cellMap_.setCapacity(newCelli);
renumberReverseMap(localCellMap, reverseCellMap_); renumberReverseMap(localCellMap, reverseCellMap_);
reorder(localCellMap, cellZone_);
cellZone_.setCapacity(newCelli);
// Renumber owner/neighbour. Take into account if neighbour suddenly // Renumber owner/neighbour. Take into account if neighbour suddenly
// gets lower cell than owner. // gets lower cell than owner.
forAll(faceOwner_, facei) 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), faceZoneFlip_(0),
nActiveFaces_(0), nActiveFaces_(0),
cellMap_(0), cellMap_(0),
reverseCellMap_(0), reverseCellMap_(0)
cellZone_(0)
{} {}
@ -1809,8 +1735,7 @@ Foam::polyTopoChange::polyTopoChange
faceZoneFlip_(0), faceZoneFlip_(0),
nActiveFaces_(0), nActiveFaces_(0),
cellMap_(0), cellMap_(0),
reverseCellMap_(0), reverseCellMap_(0)
cellZone_(0)
{ {
// Add points // Add points
{ {
@ -1825,19 +1750,12 @@ Foam::polyTopoChange::polyTopoChange
// Add points in mesh order // Add points in mesh order
for (label pointi = 0; pointi < mesh.nPoints(); pointi++) for (label pointi = 0; pointi < mesh.nPoints(); pointi++)
{ {
addPoint addPoint(points[pointi], pointi, true);
(
points[pointi],
pointi,
true
);
} }
} }
// Add cells // Add cells
{ {
const meshCellZones& cellZones = mesh.cellZones();
// Resize // Resize
// Note: polyMesh does not allow retired cells anymore. So allCells // Note: polyMesh does not allow retired cells anymore. So allCells
@ -1846,43 +1764,11 @@ Foam::polyTopoChange::polyTopoChange
cellMap_.setCapacity(cellMap_.size() + nAllCells); cellMap_.setCapacity(cellMap_.size() + nAllCells);
reverseCellMap_.setCapacity(reverseCellMap_.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 // Add cells in mesh order
for (label celli = 0; celli < nAllCells; celli++) for (label celli = 0; celli < nAllCells; celli++)
{ {
// Add cell from cell addCell(celli);
addCell(celli, newZoneID[celli]);
} }
} }
@ -2001,7 +1887,6 @@ void Foam::polyTopoChange::clear()
cellMap_.clearStorage(); cellMap_.clearStorage();
reverseCellMap_.clearStorage(); reverseCellMap_.clearStorage();
cellZone_.clearStorage();
} }
@ -2028,7 +1913,6 @@ void Foam::polyTopoChange::setCapacity
cellMap_.setCapacity(nCells); cellMap_.setCapacity(nCells);
reverseCellMap_.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 Foam::label Foam::polyTopoChange::addCell(const label masterCellID)
(
const label masterCellID,
const label zoneID
)
{ {
const label celli = cellMap_.size(); const label celli = cellMap_.size();
cellMap_.append(masterCellID); cellMap_.append(masterCellID);
reverseCellMap_.append(celli); reverseCellMap_.append(celli);
cellZone_.append(zoneID);
return celli; return celli;
} }
@ -2318,7 +2197,6 @@ void Foam::polyTopoChange::removeCell(const label celli, const label mergeCelli)
{ {
reverseCellMap_[celli] = -1; reverseCellMap_[celli] = -1;
} }
cellZone_[celli] = -1;
} }
@ -2465,7 +2343,6 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::polyTopoChange::changeMesh
{ {
faceZone_.clearStorage(); faceZone_.clearStorage();
faceZoneFlip_.clearStorage(); faceZoneFlip_.clearStorage();
cellZone_.clearStorage();
} }
@ -2689,12 +2566,6 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::polyTopoChange::makeMesh
{ {
forAll(oldPointZones, i) forAll(oldPointZones, i)
{ {
// pZonePtrs[i] = new pointZone
// (
// oldPointZones[i].name(),
// labelList(0),
// newMesh.pointZones()
// );
pZonePtrs[i] = oldPointZones[i].clone(newMesh.pointZones()).ptr(); pZonePtrs[i] = oldPointZones[i].clone(newMesh.pointZones()).ptr();
} }
} }
@ -2719,12 +2590,7 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::polyTopoChange::makeMesh
{ {
forAll(oldCellZones, i) forAll(oldCellZones, i)
{ {
cZonePtrs[i] = new cellZone cZonePtrs[i] = oldCellZones[i].clone(newMesh.cellZones()).ptr();
(
oldCellZones[i].name(),
labelList(0),
newMesh.cellZones()
);
} }
} }
@ -2735,7 +2601,6 @@ Foam::autoPtr<Foam::polyTopoChangeMap> Foam::polyTopoChange::makeMesh
{ {
faceZone_.clearStorage(); faceZone_.clearStorage();
faceZoneFlip_.clearStorage(); faceZoneFlip_.clearStorage();
cellZone_.clearStorage();
} }
// Patch point renumbering // Patch point renumbering

View File

@ -100,7 +100,7 @@ class polyTopoChange
// Private Data // Private Data
//- Whether to allow referencing illegal points/cells/faces //- Whether to allow referencing illegal points/cells/faces
// when adding/removing data. // when adding/removing data
bool strict_; bool strict_;
@ -118,7 +118,7 @@ class polyTopoChange
//- Original point label (or masterpoint for added points) //- Original point label (or masterpoint for added points)
DynamicList<label> pointMap_; DynamicList<label> pointMap_;
//- For all original and added points contains new point label. //- For all original and added points contains new point label
// (used to map return value of addPoint to new mesh point) // (used to map return value of addPoint to new mesh point)
DynamicList<label> reversePointMap_; DynamicList<label> reversePointMap_;
@ -152,7 +152,7 @@ class polyTopoChange
// (used to map return value of addFace to new mesh face) // (used to map return value of addFace to new mesh face)
DynamicList<label> reverseFaceMap_; DynamicList<label> reverseFaceMap_;
//- In mapping whether to reverse the flux. //- In mapping whether to reverse the flux
PackedBoolList flipFaceFlux_; PackedBoolList flipFaceFlux_;
//- Zone of face //- Zone of face
@ -168,29 +168,29 @@ class polyTopoChange
// Cells // Cells
//- Original cell label or master cell for added-from-cell; //- Original cell label or master cell for added-from-cell;
// -1 for cells added from face or edge. // -1 for cells added from face or edge
DynamicList<label> cellMap_; DynamicList<label> cellMap_;
//- For all original and added cells contains new cell label //- For all original and added cells contains new cell label
// (used to map return value of addCell to new mesh cell) // (used to map return value of addCell to new mesh cell)
DynamicList<label> reverseCellMap_; DynamicList<label> reverseCellMap_;
//- Zone of cell
DynamicList<label> cellZone_;
// Private Member Functions // Private Member Functions
//- Reorder contents of container according to map //- Reorder contents of container according to map
template<class T> template<class T>
static void reorder(const labelList& map, DynamicList<T>&); static void reorder(const labelList& map, DynamicList<T>&);
template<class T> template<class T>
static void reorder(const labelList& map, List<DynamicList<T>>&); static void reorder(const labelList& map, List<DynamicList<T>>&);
template<class T> template<class T>
static void renumberKey(const labelList& map, Map<T>&); static void renumberKey(const labelList& map, Map<T>&);
//- Renumber elements of container according to map //- Renumber elements of container according to map
static void renumber(const labelList&, labelHashSet&); static void renumber(const labelList&, labelHashSet&);
//- Special handling of reverse maps which have <-1 in them //- Special handling of reverse maps which have <-1 in them
static void renumberReverseMap(const labelList&, DynamicList<label>&); static void renumberReverseMap(const labelList&, DynamicList<label>&);
@ -200,7 +200,7 @@ class polyTopoChange
//- Get all set elements as a labelHashSet //- Get all set elements as a labelHashSet
static labelHashSet getSetIndices(const PackedBoolList&); static labelHashSet getSetIndices(const PackedBoolList&);
//- Count number of added and removed quantities from maps. //- Count number of added and removed quantities from maps
static void countMap static void countMap
( (
const labelList& map, const labelList& map,
@ -215,7 +215,7 @@ class polyTopoChange
static void writeMeshStats(const polyMesh& mesh, Ostream&); static void writeMeshStats(const polyMesh& mesh, Ostream&);
//- Calculate object maps. Requires reverseMap to have destination //- Calculate object maps. Requires reverseMap to have destination
// to be marked with <-1. // to be marked with < -1
static void getMergeSets static void getMergeSets
( (
const labelList& reverseCellMap, const labelList& reverseCellMap,
@ -255,14 +255,14 @@ class polyTopoChange
CompactListList<label>& cellCells CompactListList<label>& cellCells
) const; ) const;
//- Cell ordering (bandCompression). Returns number of remaining cells. //- Cell ordering (bandCompression). Returns number of remaining cells
label getCellOrder label getCellOrder
( (
const CompactListList<label>&, const CompactListList<label>&,
labelList& labelList&
) const; ) const;
//- Do upper-triangular ordering and patch ordering. //- Do upper-triangular ordering and patch ordering
void getFaceOrder void getFaceOrder
( (
const label nActiveFaces, const label nActiveFaces,
@ -381,7 +381,7 @@ public:
// setNumPatches before trying to make a mesh (makeMesh, changeMesh) // setNumPatches before trying to make a mesh (makeMesh, changeMesh)
polyTopoChange(const label nPatches, const bool strict = true); polyTopoChange(const label nPatches, const bool strict = true);
//- Construct from mesh. Adds all points/face/cells from mesh. //- Construct from mesh. Adds all points/face/cells from mesh
polyTopoChange(const polyMesh& mesh, const bool strict = true); polyTopoChange(const polyMesh& mesh, const bool strict = true);
@ -439,7 +439,7 @@ public:
const label nCells const label nCells
); );
//- Add point. Return new point label. //- Add point and return new point index
// Notes: // Notes:
// - masterPointID can be < 0 (appended points) // - masterPointID can be < 0 (appended points)
// - inCell = false: add retired point (to end of point list) // - inCell = false: add retired point (to end of point list)
@ -450,7 +450,7 @@ public:
const bool inCell const bool inCell
); );
//- Modify coordinate. //- Modify coordinate
// Notes: // Notes:
// - inCell = false: add retired point (to end of point list) // - inCell = false: add retired point (to end of point list)
void modifyPoint void modifyPoint
@ -460,10 +460,10 @@ public:
const bool inCell const bool inCell
); );
//- Remove/merge point. //- Remove point / merge points
void removePoint(const label, const label); void removePoint(const label, const label);
//- Add face to cells. Return new face label. //- Add face to cells and return new face index
// own,nei<0, zoneID>=0 : add inactive face (to end of face list) // own,nei<0, zoneID>=0 : add inactive face (to end of face list)
label addFace label addFace
( (
@ -477,7 +477,7 @@ public:
const bool zoneFlip const bool zoneFlip
); );
//- Modify vertices or cell of face. //- Modify vertices or cell of face
void modifyFace void modifyFace
( (
const face& f, const face& f,
@ -490,23 +490,20 @@ public:
const bool zoneFlip const bool zoneFlip
); );
//- Remove/merge face. //- Remove face / merge faces
void removeFace(const label, const label); void removeFace(const label, const label);
//- Add cell. Return new cell label. //- Add cell and return new cell index
label addCell label addCell(const label masterCellID);
(
const label masterCellID,
const label zoneID
);
//- Remove/merge cell. //- Remove cell / merge cells
void removeCell(const label, const label); void removeCell(const label, const label);
//- Explicitly set the number of patches if construct-without-mesh //- Explicitly set the number of patches if construct-without-mesh
// used. // used
inline void setNumPatches(const label nPatches); inline void setNumPatches(const label nPatches);
// Other // Other
//- Inplace changes mesh without change of patches. //- Inplace changes mesh without change of patches.

View File

@ -8,7 +8,7 @@ rm -rf constant/polyMesh/sets
runApplication blockMesh runApplication blockMesh
runApplication snappyHexMesh -overwrite runApplication snappyHexMesh -overwrite
runApplication splitMeshRegions -cellZones -overwrite runApplication splitMeshRegions -cellZones -defaultRegionName fluid -overwrite
runApplication decomposePar -allRegions runApplication decomposePar -allRegions
runParallel $(getApplication) runParallel $(getApplication)
runApplication reconstructPar -allRegions runApplication reconstructPar -allRegions

View File

@ -30,7 +30,7 @@ vertices
blocks blocks
( (
hex (0 1 2 3 4 5 6 7) fluid (20 24 60) simpleGrading (1 1 1) hex (0 1 2 3 4 5 6 7) (20 24 60) simpleGrading (1 1 1)
); );
defaultPatch defaultPatch