diff --git a/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C b/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C index dcb744e801cb896101cfaf5a17ffaf8983f21f0a..a369a195b8c8dcf1d22b6bb60656993fe04c5417 100644 --- a/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C +++ b/applications/utilities/mesh/manipulation/setsToZones/setsToZones.C @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) polyMesh::meshSubDir/"sets" ); - Pout<< "Searched : " << mesh.pointsInstance()/polyMesh::meshSubDir/"sets" + Info<< "Searched : " << mesh.pointsInstance()/polyMesh::meshSubDir/"sets" << nl << "Found : " << objects.names() << nl << endl; @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) IOobjectList pointObjects(objects.lookupClass(pointSet::typeName)); - Pout<< "pointSets:" << pointObjects.names() << endl; + //Pout<< "pointSets:" << pointObjects.names() << endl; for ( @@ -126,6 +126,7 @@ int main(int argc, char *argv[]) ) ); mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; + mesh.pointZones().instance() = mesh.facesInstance(); } else { @@ -133,57 +134,17 @@ int main(int argc, char *argv[]) << " with that of set " << set.name() << "." << endl; mesh.pointZones()[zoneID] = pointLabels; mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; + mesh.pointZones().instance() = mesh.facesInstance(); } } - IOobjectList cellObjects(objects.lookupClass(cellSet::typeName)); - - Pout<< "cellSets:" << cellObjects.names() << endl; - - for - ( - IOobjectList::const_iterator iter = cellObjects.begin(); - iter != cellObjects.end(); - ++iter - ) - { - // Not in memory. Load it. - cellSet set(*iter()); - SortableList<label> cellLabels(set.toc()); - - label zoneID = mesh.cellZones().findZoneID(set.name()); - if (zoneID == -1) - { - Info<< "Adding set " << set.name() << " as a cellZone." << endl; - label sz = mesh.cellZones().size(); - mesh.cellZones().setSize(sz+1); - mesh.cellZones().set - ( - sz, - new cellZone - ( - set.name(), //name - cellLabels, //addressing - sz, //index - mesh.cellZones() //pointZoneMesh - ) - ); - mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE; - } - else - { - Info<< "Overwriting contents of existing cellZone " << zoneID - << " with that of set " << set.name() << "." << endl; - mesh.cellZones()[zoneID] = cellLabels; - mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE; - } - } - IOobjectList faceObjects(objects.lookupClass(faceSet::typeName)); - Pout<< "faceSets:" << faceObjects.names() << endl; + HashSet<word> slaveCellSets; + + //Pout<< "faceSets:" << faceObjects.names() << endl; for ( @@ -203,9 +164,9 @@ int main(int argc, char *argv[]) { word setName(set.name() + "SlaveCells"); - Pout<< "Trying to load cellSet " << setName + Info<< "Trying to load cellSet " << setName << " to find out the slave side of the zone." << nl - << " If you do not care about the flipMap" + << "If you do not care about the flipMap" << " (i.e. do not use the sideness)" << nl << "use the -noFlipMap command line option." << endl; @@ -213,6 +174,9 @@ int main(int argc, char *argv[]) // Load corresponding cells cellSet cells(mesh, setName); + // Store setName to exclude from cellZones further on + slaveCellSets.insert(setName); + forAll(faceLabels, i) { label faceI = faceLabels[i]; @@ -227,7 +191,7 @@ int main(int argc, char *argv[]) && !cells.found(mesh.faceNeighbour()[faceI]) ) { - flip = true; + flip = false; } else if ( @@ -235,7 +199,7 @@ int main(int argc, char *argv[]) && cells.found(mesh.faceNeighbour()[faceI]) ) { - flip = false; + flip = true; } else { @@ -257,11 +221,11 @@ int main(int argc, char *argv[]) { if (cells.found(mesh.faceOwner()[faceI])) { - flip = true; + flip = false; } else { - flip = false; + flip = true; } } @@ -299,6 +263,7 @@ int main(int argc, char *argv[]) ) ); mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE; + mesh.faceZones().instance() = mesh.facesInstance(); } else { @@ -310,10 +275,63 @@ int main(int argc, char *argv[]) flipMap.shrink() ); mesh.faceZones().writeOpt() = IOobject::AUTO_WRITE; + mesh.faceZones().instance() = mesh.facesInstance(); + } + } + + + + IOobjectList cellObjects(objects.lookupClass(cellSet::typeName)); + + //Pout<< "cellSets:" << cellObjects.names() << endl; + + for + ( + IOobjectList::const_iterator iter = cellObjects.begin(); + iter != cellObjects.end(); + ++iter + ) + { + if (!slaveCellSets.found(iter.key())) + { + // Not in memory. Load it. + cellSet set(*iter()); + SortableList<label> cellLabels(set.toc()); + + label zoneID = mesh.cellZones().findZoneID(set.name()); + if (zoneID == -1) + { + Info<< "Adding set " << set.name() << " as a cellZone." << endl; + label sz = mesh.cellZones().size(); + mesh.cellZones().setSize(sz+1); + mesh.cellZones().set + ( + sz, + new cellZone + ( + set.name(), //name + cellLabels, //addressing + sz, //index + mesh.cellZones() //pointZoneMesh + ) + ); + mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE; + mesh.cellZones().instance() = mesh.facesInstance(); + } + else + { + Info<< "Overwriting contents of existing cellZone " << zoneID + << " with that of set " << set.name() << "." << endl; + mesh.cellZones()[zoneID] = cellLabels; + mesh.cellZones().writeOpt() = IOobject::AUTO_WRITE; + mesh.cellZones().instance() = mesh.facesInstance(); + } } } - Pout<< "Writing mesh." << endl; + + + Info<< "Writing mesh." << endl; if (!mesh.write()) { @@ -322,7 +340,7 @@ int main(int argc, char *argv[]) << exit(FatalError); } - Pout << nl << "End" << endl; + Info<< nl << "End" << endl; return 0; } diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C index 5e7a0b010bec6621e7340df8853e3f516f9add28..78a039d2509a50aec100ede83b1f77a0f8093f57 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.C @@ -58,23 +58,6 @@ const Foam::point Foam::polyTopoChange::greatPoint // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -// Renumber -void Foam::polyTopoChange::renumber -( - const labelList& map, - DynamicList<label>& elems -) -{ - forAll(elems, elemI) - { - if (elems[elemI] >= 0) - { - elems[elemI] = map[elems[elemI]]; - } - } -} - - // Renumber with special handling for merged items (marked with <-1) void Foam::polyTopoChange::renumberReverseMap ( @@ -208,6 +191,20 @@ void Foam::polyTopoChange::countMap } +Foam::labelHashSet Foam::polyTopoChange::getSetIndices(const PackedBoolList& lst) +{ + labelHashSet values(lst.count()); + forAll(lst, i) + { + if (lst[i]) + { + values.insert(i); + } + } + return values; +} + + void Foam::polyTopoChange::writeMeshStats(const polyMesh& mesh, Ostream& os) { const polyBoundaryMesh& patches = mesh.boundaryMesh(); @@ -782,9 +779,11 @@ void Foam::polyTopoChange::reorderCompactFaces renumberKey(oldToNew, faceFromPoint_); renumberKey(oldToNew, faceFromEdge_); - renumber(oldToNew, flipFaceFlux_); + inplaceReorder(oldToNew, flipFaceFlux_); + flipFaceFlux_.setCapacity(newSize); renumberKey(oldToNew, faceZone_); - renumberKey(oldToNew, faceZoneFlip_); + inplaceReorder(oldToNew, faceZoneFlip_); + faceZoneFlip_.setCapacity(newSize); } @@ -1097,6 +1096,18 @@ void Foam::polyTopoChange::compact { faces_[faceI] = faces_[faceI].reverseFace(); Swap(faceOwner_[faceI], faceNeighbour_[faceI]); + flipFaceFlux_[faceI] = + ( + flipFaceFlux_[faceI] + ? 0 + : 1 + ); + faceZoneFlip_[faceI] = + ( + faceZoneFlip_[faceI] + ? 0 + : 1 + ); } } } @@ -2302,9 +2313,9 @@ void Foam::polyTopoChange::addMesh faceMap_.setCapacity(faceMap_.size() + nAllFaces); faceFromPoint_.resize(faceFromPoint_.size() + nAllFaces/100); faceFromEdge_.resize(faceFromEdge_.size() + nAllFaces/100); - flipFaceFlux_.resize(flipFaceFlux_.size() + nAllFaces/100); + flipFaceFlux_.setCapacity(faces_.size() + nAllFaces); faceZone_.resize(faceZone_.size() + nAllFaces/100); - faceZoneFlip_.resize(faceZoneFlip_.size() + nAllFaces/100); + faceZoneFlip_.setCapacity(faces_.size() + nAllFaces); // Precalc offset zones @@ -2716,15 +2727,12 @@ Foam::label Foam::polyTopoChange::addFace } reverseFaceMap_.append(faceI); - if (flipFaceFlux) - { - flipFaceFlux_.insert(faceI); - } + flipFaceFlux_[faceI] = (flipFaceFlux ? 1 : 0); if (zoneID >= 0) { faceZone_.insert(faceI, zoneID); - faceZoneFlip_.insert(faceI, zoneFlip); + faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0); } return faceI; @@ -2754,34 +2762,27 @@ void Foam::polyTopoChange::modifyFace faceNeighbour_[faceI] = nei; region_[faceI] = patchID; - if (flipFaceFlux) - { - flipFaceFlux_.insert(faceI); - } - else - { - flipFaceFlux_.erase(faceI); - } + flipFaceFlux_[faceI] = (flipFaceFlux ? 1 : 0); Map<label>::iterator faceFnd = faceZone_.find(faceI); if (faceFnd != faceZone_.end()) { + faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0); + if (zoneID >= 0) { faceFnd() = zoneID; - faceZoneFlip_.find(faceI)() = zoneFlip; } else { faceZone_.erase(faceFnd); - faceZoneFlip_.erase(faceI); } } else if (zoneID >= 0) { faceZone_.insert(faceI, zoneID); - faceZoneFlip_.insert(faceI, zoneFlip); + faceZoneFlip_[faceI] = (zoneFlip ? 1 : 0); } } @@ -2823,9 +2824,9 @@ void Foam::polyTopoChange::removeFace(const label faceI, const label mergeFaceI) } faceFromEdge_.erase(faceI); faceFromPoint_.erase(faceI); - flipFaceFlux_.erase(faceI); + flipFaceFlux_[faceI] = 0; faceZone_.erase(faceI); - faceZoneFlip_.erase(faceI); + faceZoneFlip_[faceI] = 0; } @@ -3119,6 +3120,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::changeMesh labelListList faceZonePointMap(mesh.faceZones().size()); calcFaceZonePointMap(mesh, oldFaceZoneMeshPointMaps, faceZonePointMap); + labelHashSet flipFaceFluxSet(getSetIndices(flipFaceFlux_)); return autoPtr<mapPolyMesh> ( @@ -3147,7 +3149,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::changeMesh reverseFaceMap_, reverseCellMap_, - flipFaceFlux_, + flipFaceFluxSet, patchPointMap, @@ -3410,6 +3412,8 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::makeMesh writeMeshStats(mesh, Pout); } + labelHashSet flipFaceFluxSet(getSetIndices(flipFaceFlux_)); + return autoPtr<mapPolyMesh> ( new mapPolyMesh @@ -3437,7 +3441,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::makeMesh reverseFaceMap_, reverseCellMap_, - flipFaceFlux_, + flipFaceFluxSet, patchPointMap, diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.H b/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.H index 9d0dce468c6cb288b2659587a5a5100931195fb8..77801e21f0dc33b703585f15ef3ffbd65a5c70ad 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.H +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/polyTopoChange.H @@ -171,13 +171,13 @@ class polyTopoChange Map<label> faceFromEdge_; //- In mapping whether to reverse the flux. - labelHashSet flipFaceFlux_; + PackedBoolList flipFaceFlux_; //- Zone of face Map<label> faceZone_; //- Orientation of face in zone - Map<bool> faceZoneFlip_; + PackedBoolList faceZoneFlip_; //- Active faces label nActiveFaces_; @@ -216,8 +216,7 @@ class polyTopoChange template<class T> static void renumberKey(const labelList& map, Map<T>&); - //- Renumber elements of list according to map - static void renumber(const labelList&, DynamicList<label>&); + //- Renumber elements of container according to map static void renumber(const labelList&, labelHashSet&); //- Special handling of reverse maps which have <-1 in them static void renumberReverseMap(const labelList&, DynamicList<label>&); @@ -225,6 +224,9 @@ class polyTopoChange //- Renumber & compact elements of list according to map static void renumberCompact(const labelList&, labelList&); + //- Get all set elements as a labelHashSet + static labelHashSet getSetIndices(const PackedBoolList&); + //- Count number of added and removed quantities from maps. static void countMap (