Skip to content
Snippets Groups Projects
Commit 6d81e16a authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: improve surfaceSplitByPatch controls (#1600)

- uses MeshedSurface instead of triSurface to prevent automatic
  triangulation.

- supports '-patches' and '-excludePatches' controls as per foamToVTK.
  For example,

    surfaceSplitByPatch -patches '( ".*rider.*" )'  motorBike.obj
parent dccef265
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment