diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C index 2172dc24abbdb7bf879243a34aa814cfe4a9f6bd..3732c7e4ec1d9d17f5f55226666ba345b4a0e463 100644 --- a/applications/utilities/mesh/manipulation/setSet/setSet.C +++ b/applications/utilities/mesh/manipulation/setSet/setSet.C @@ -42,6 +42,9 @@ Description #include "writePatch.H" #include "writePointSet.H" #include "IOobjectList.H" +#include "cellZoneSet.H" +#include "faceZoneSet.H" +#include "pointZoneSet.H" #include <stdio.h> @@ -253,6 +256,7 @@ void printHelp(Ostream& os) << " list - prints the contents of the set" << endl << " clear - clears the set" << endl << " invert - inverts the set" << endl + << " remove - remove the set" << endl << " new <source> - sets to set to the source set" << endl << " add <source> - adds all elements from the source set" << endl << " delete <source> - deletes ,," << endl @@ -278,9 +282,19 @@ void printHelp(Ostream& os) << "List set:" << endl << " cellSet c0 list" << endl << endl - << "Zones can be set from corresponding sets:" << endl - << " faceZone f0Zone new setToZone f0" << endl - << " cellZone c0Zone new setToZone c0" << endl + << "Zones can be set using zoneSets from corresponding sets:" << endl + << " cellZoneSet c0Zone new setToZone c0" << endl + << " faceZoneSet f0Zone new setToZone f0" << endl + << endl + << "or if orientation is important:" << endl + << " faceZoneSet f0Zone new setsToZone f0 c0" << endl + << endl + << "ZoneSets can be manipulated using the general actions:" << endl + << " list - prints the contents of the set" << endl + << " clear - clears the set" << endl + << " invert - inverts the set (undefined orientation)" + << endl + << " remove - remove the set" << endl << endl; } @@ -323,10 +337,126 @@ void printAllSets(const polyMesh& mesh, Ostream& os) os << '\t' << set.name() << "\tsize:" << set.size() << endl; } } + + const cellZoneMesh& cellZones = mesh.cellZones(); + if (cellZones.size()) + { + os << "cellZones:" << endl; + forAll(cellZones, i) + { + const cellZone& zone = cellZones[i]; + os << '\t' << zone.name() << "\tsize:" << zone.size() << endl; + } + } + const faceZoneMesh& faceZones = mesh.faceZones(); + if (faceZones.size()) + { + os << "faceZones:" << endl; + forAll(faceZones, i) + { + const faceZone& zone = faceZones[i]; + os << '\t' << zone.name() << "\tsize:" << zone.size() << endl; + } + } + const pointZoneMesh& pointZones = mesh.pointZones(); + if (pointZones.size()) + { + os << "pointZones:" << endl; + forAll(pointZones, i) + { + const pointZone& zone = pointZones[i]; + os << '\t' << zone.name() << "\tsize:" << zone.size() << endl; + } + } + os << endl; } +template<class ZoneType> +void removeZone +( + ZoneMesh<ZoneType, polyMesh>& zones, + const word& setName +) +{ + label zoneID = zones.findZoneID(setName); + + if (zoneID != -1) + { + Info<< "Removing zone " << setName << " at index " << zoneID << endl; + // Shuffle to last position + labelList oldToNew(zones.size()); + label newI = 0; + forAll(oldToNew, i) + { + if (i != zoneID) + { + oldToNew[i] = newI++; + } + } + oldToNew[zoneID] = newI; + zones.reorder(oldToNew); + // Remove last element + zones.setSize(zones.size()-1); + zones.clearAddressing(); + zones.write(); + } +} + + +// Physically remove a set +void removeSet +( + const polyMesh& mesh, + const word& setType, + const word& setName +) +{ + // Remove the file + IOobjectList objects + ( + mesh, + mesh.pointsInstance(), + polyMesh::meshSubDir/"sets" + ); + + if (objects.found(setName)) + { + // Remove file + fileName object = objects[setName]->objectPath(); + Info<< "Removing file " << object << endl; + rm(object); + } + + // See if zone + if (setType == cellZoneSet::typeName) + { + removeZone + ( + const_cast<cellZoneMesh&>(mesh.cellZones()), + setName + ); + } + else if (setType == faceZoneSet::typeName) + { + removeZone + ( + const_cast<faceZoneMesh&>(mesh.faceZones()), + setName + ); + } + else if (setType == pointZoneSet::typeName) + { + removeZone + ( + const_cast<pointZoneMesh&>(mesh.pointZones()), + setName + ); + } +} + + // Read command and execute. Return true if ok, false otherwise. bool doCommand ( @@ -369,38 +499,29 @@ bool doCommand IOobject::readOption r; - if + if (action == topoSetSource::REMOVE) + { + removeSet(mesh, setType, setName); + } + else if ( (action == topoSetSource::NEW) || (action == topoSetSource::CLEAR) ) { r = IOobject::NO_READ; - - //backup(setType, mesh, setName, setName + "_old"); - currentSetPtr = topoSet::New(setType, mesh, setName, typSize); } else { r = IOobject::MUST_READ; - currentSetPtr = topoSet::New(setType, mesh, setName, r); - topoSet& currentSet = currentSetPtr(); - // Presize it according to current mesh data. currentSet.resize(max(currentSet.size(), typSize)); } - if (currentSetPtr.empty()) - { - Pout<< " Cannot construct/load set " - << topoSet::localPath(mesh, setName) << endl; - - ok = false; - } - else + if (currentSetPtr.valid()) { topoSet& currentSet = currentSetPtr(); @@ -409,12 +530,6 @@ bool doCommand << " Action:" << actionName << endl; - //if ((r == IOobject::MUST_READ) && (action != topoSetSource::LIST)) - //{ - // // currentSet has been read so can make copy. - // backup(setType, mesh, setName, currentSet, setName + "_old"); - //} - switch (action) { case topoSetSource::CLEAR: @@ -748,6 +863,10 @@ int main(int argc, char *argv[]) // Print some mesh info printMesh(runTime, mesh); + // Print current sets + printAllSets(mesh, Pout); + + std::ifstream* fileStreamPtr(NULL); @@ -769,11 +888,10 @@ int main(int argc, char *argv[]) #if READLINE != 0 else if (!read_history(historyFile)) { - Info<< "Successfully read history from " << historyFile << endl; + Pout<< "Successfully read history from " << historyFile << endl; } #endif - Pout<< "Please type 'help', 'quit' or a set command after prompt." << endl; bool ok = true; diff --git a/src/meshTools/sets/topoSetSource/topoSetSource.C b/src/meshTools/sets/topoSetSource/topoSetSource.C index 7579ffffad5c33ba25c2efd399cb528606e96b8c..8135859129cd9ace2980ee02d1e6e65e11c96ef6 100644 --- a/src/meshTools/sets/topoSetSource/topoSetSource.C +++ b/src/meshTools/sets/topoSetSource/topoSetSource.C @@ -101,7 +101,7 @@ autoPtr<topoSetSource> topoSetSource::New Foam::HashTable<Foam::string>* Foam::topoSetSource::usageTablePtr_ = NULL; template<> -const char* Foam::NamedEnum<Foam::topoSetSource::setAction, 7>::names[] = +const char* Foam::NamedEnum<Foam::topoSetSource::setAction, 8>::names[] = { "clear", "new", @@ -109,11 +109,12 @@ const char* Foam::NamedEnum<Foam::topoSetSource::setAction, 7>::names[] = "add", "delete", "subset", - "list" + "list", + "remove" }; -const Foam::NamedEnum<Foam::topoSetSource::setAction, 7> +const Foam::NamedEnum<Foam::topoSetSource::setAction, 8> Foam::topoSetSource::actionNames_; diff --git a/src/meshTools/sets/topoSetSource/topoSetSource.H b/src/meshTools/sets/topoSetSource/topoSetSource.H index 26fa39af9eb0041ab9c20e88eeed55a3704f8a5c..b1c68a14c14e058a6ceb5b8354ef29f2ba9cc6f4 100644 --- a/src/meshTools/sets/topoSetSource/topoSetSource.H +++ b/src/meshTools/sets/topoSetSource/topoSetSource.H @@ -77,7 +77,8 @@ public: ADD, DELETE, SUBSET, - LIST + LIST, + REMOVE }; protected: @@ -120,7 +121,7 @@ protected: private: - static const NamedEnum<setAction, 7> actionNames_; + static const NamedEnum<setAction, 8> actionNames_; static const string illegalSource_; diff --git a/src/meshTools/sets/topoSets/cellZoneSet.C b/src/meshTools/sets/topoSets/cellZoneSet.C index d2467fe43a4ac8b5c8ad5d655328f8ab123bc845..061cecb47539ce94ed3e202abe5b3f7307c3fc86 100644 --- a/src/meshTools/sets/topoSets/cellZoneSet.C +++ b/src/meshTools/sets/topoSets/cellZoneSet.C @@ -262,6 +262,8 @@ bool cellZoneSet::writeObject { cellZones[zoneID] = addressing_; } + cellZones.clearAddressing(); + return ok && cellZones.write(); } diff --git a/src/meshTools/sets/topoSets/faceZoneSet.C b/src/meshTools/sets/topoSets/faceZoneSet.C index 5e980ad783895fb5660ec4e7542fccefa5525cb8..4e215a1ee2b6dd6dbc42efb7578a36848a2f244a 100644 --- a/src/meshTools/sets/topoSets/faceZoneSet.C +++ b/src/meshTools/sets/topoSets/faceZoneSet.C @@ -356,6 +356,8 @@ bool faceZoneSet::writeObject { faceZones[zoneID].resetAddressing(addressing_, flipMap_); } + faceZones.clearAddressing(); + return ok && faceZones.write(); } diff --git a/src/meshTools/sets/topoSets/pointZoneSet.C b/src/meshTools/sets/topoSets/pointZoneSet.C index d68956e3b3782ef0e00c75bf7302182076b54f8b..acab1e51a9f25b44b4270a7f96c81f3675295afb 100644 --- a/src/meshTools/sets/topoSets/pointZoneSet.C +++ b/src/meshTools/sets/topoSets/pointZoneSet.C @@ -262,6 +262,8 @@ bool pointZoneSet::writeObject { pointZones[zoneID] = addressing_; } + pointZones.clearAddressing(); + return ok && pointZones.write(); }