diff --git a/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C b/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C index f49d334e5b617d6a0efc3e3e4aca4265d650bacf..2bcb2335956abf64176a47263a4843a859aa820d 100644 --- a/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C +++ b/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C @@ -31,12 +31,34 @@ Group grpSurfaceUtilities Description - Writes regions of triSurface to separate files. + Writes surface regions to separate files. + +Usage + \b surfaceSplitByPatch [OPTION] + + Options: + - \par -patches NAME | LIST + Specify single patch or multiple patches (name or regex) to extract + For example, + \verbatim + -patches top + -patches '( front \".*back\" )' + \endverbatim + + - \par -excludePatches NAME | LIST + Specify single or multiple patches (name or regex) not to extract. + For example, + \verbatim + -excludePatches '( inlet_1 inlet_2 "proc.*")' + \endverbatim \*---------------------------------------------------------------------------*/ #include "argList.H" -#include "triSurface.H" +#include "MeshedSurface.H" +#include "MeshedSurfacesFwd.H" +#include "geometricSurfacePatch.H" +#include "stringListOps.H" using namespace Foam; @@ -48,65 +70,103 @@ int main(int argc, char *argv[]) ( "Write surface mesh regions to separate files" ); - argList::noParallel(); + argList::addOption + ( + "patches", + "wordRes", + "Specify single patch or multiple patches to write\n" + "Eg, 'top' or '( front \".*back\" )'" + ); + argList::addOption + ( + "excludePatches", + "wordRes", + "Specify single patch or multiple patches to exclude from writing." + " Eg, 'outlet' or '( inlet \".*Wall\" )'" + ); + argList::addArgument("input", "The input surface file"); + argList args(argc, argv); const fileName surfName = args[1]; - Info<< "Reading surf from " << surfName << " ..." << nl << endl; + const fileName surfBase(surfName.lessExt()); + + const word extension(surfName.ext()); + - fileName surfBase = surfName.lessExt(); + Info<< nl + << "Read surface from " << surfName << " ..." << nl << endl; - word extension = surfName.ext(); + meshedSurface surf(surfName); - triSurface surf(surfName); + const surfZoneList& zones = surf.surfZones(); - Info<< "Writing regions to separate files ..." - << nl << endl; + Info<< " " << surf.size() << " faces with " + << zones.size() << " zones" << nl << nl; - const geometricSurfacePatchList& patches = surf.patches(); + wordRes includePatches, excludePatches; - forAll(patches, patchi) + if (args.readListIfPresent<wordRe>("patches", includePatches)) { - const geometricSurfacePatch& pp = patches[patchi]; + Info<< "Including patches " << flatOutput(includePatches) + << nl << endl; + } + if (args.readListIfPresent<wordRe>("excludePatches", excludePatches)) + { + Info<< "Excluding patches " << flatOutput(excludePatches) + << nl << endl; + } - word patchName(pp.name()); + // Identity if both whitelist and blacklist are empty + const labelList zoneIndices + ( + stringListOps::findMatching + ( + zones, + includePatches, + excludePatches, + nameOp<surfZone>() + ) + ); - if (patchName.empty()) - { - patchName = geometricSurfacePatch::defaultName(patchi); - } - fileName outFile(surfBase + '_' + patchName + '.' + extension); + Info<< "Writing regions to " + << zoneIndices.size() << " separate files ..." << nl << endl; - Info<< " Writing patch " << patchName << " to file " << outFile - << endl; + // Faces to subset + bitSet includeMap(surf.size()); - // Collect faces of region - boolList includeMap(surf.size(), false); + for (const label zonei : zoneIndices) + { + const surfZone& zn = zones[zonei]; - forAll(surf, facei) - { - const labelledTri& f = surf[facei]; + includeMap.reset(); + includeMap.set(zn.range()); + + word patchName(zn.name()); - if (f.region() == patchi) - { - includeMap[facei] = true; - } + if (patchName.empty()) + { + // In case people expect the same names as with triSurface + patchName = geometricSurfacePatch::defaultName(zonei); } - // Subset triSurface + fileName outFile(surfBase + '_' + patchName + '.' + extension); - triSurface subSurf(surf.subsetMesh(includeMap)); + Info<< " Zone " << zonei << " (" << zn.size() << " faces) " + << patchName + << " to file " << outFile << nl; - subSurf.write(outFile); + // Subset and write + surf.subsetMesh(includeMap).write(outFile); } - Info<< "End\n" << endl; + Info<< "\nEnd\n" << endl; return 0; }