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

ENH: subsetMesh -exclude-patches (#2947)

STYLE: use -exclude-patches instead of -excludePatch for other utilities

- avoids inconsistencies with utilities like foamToVTK etc.
parent 14f7d44c
No related branches found
No related tags found
1 merge request!618Support select/ignore patches for subsetMesh, extend select/ignore to general selection (#2947)
...@@ -70,7 +70,7 @@ label getExposedPatchId(const polyMesh& mesh, const word& patchName) ...@@ -70,7 +70,7 @@ label getExposedPatchId(const polyMesh& mesh, const word& patchName)
Info<< "Adding exposed internal faces to " Info<< "Adding exposed internal faces to "
<< (patchId == -1 ? "new" : "existing") << (patchId == -1 ? "new" : "existing")
<< " patch \"" << patchName << "\"" << nl << endl; << " patch: " << patchName << nl << endl;
return patchId; return patchId;
} }
...@@ -357,6 +357,12 @@ int main(int argc, char *argv[]) ...@@ -357,6 +357,12 @@ int main(int argc, char *argv[])
"Add exposed internal faces to closest of specified patches" "Add exposed internal faces to closest of specified patches"
" instead of \"oldInternalFaces\"" " instead of \"oldInternalFaces\""
); );
argList::addOption
(
"exclude-patches",
"wordRes",
"Exclude single or multiple patches from the -patches selection"
);
argList::addBoolOption argList::addBoolOption
( (
"zone", "zone",
...@@ -400,52 +406,59 @@ int main(int argc, char *argv[]) ...@@ -400,52 +406,59 @@ int main(int argc, char *argv[])
// Default exposed patch id // Default exposed patch id
labelList exposedPatchIDs(one{}, -1); labelList exposedPatchIDs(one{}, -1);
if (args.found("patches")) wordRes includePatches, excludePatches;
{
const wordRes patchNames(args.getList<wordRe>("patches"));
if (patchNames.size() == 1 && patchNames.front().isLiteral()) if (!args.readListIfPresent<wordRe>("patches", includePatches))
{
if (args.found("patch"))
{ {
exposedPatchIDs.front() = includePatches.resize(1);
getExposedPatchId(mesh, patchNames.front()); includePatches.front() = args.get<word>("patch");
} }
else }
{ args.readListIfPresent<wordRe>("exclude-patches", excludePatches);
// Patches selected
labelHashSet patchIds
(
mesh.boundaryMesh().patchSet(patchNames)
);
// Only retain initial, non-processor patches
label nNonProcessor
(
mesh.boundaryMesh().nNonProcessor()
);
patchIds.filterKeys
(
[=](label patchi) { return (patchi < nNonProcessor); }
);
exposedPatchIDs = patchIds.sortedToc(); if (includePatches.size() == 1 && includePatches.front().isLiteral())
{
// Select a single patch - no exclude possible
exposedPatchIDs.front() =
getExposedPatchId(mesh, includePatches.front());
}
else if (!includePatches.empty())
{
// Patches selected (sorted order)
exposedPatchIDs =
mesh.boundaryMesh().indices(includePatches, excludePatches);
Info<< "Adding exposed internal faces to nearest of patches " // Only retain initial, non-processor patches
<< flatOutput(patchNames) << nl << endl; const label nNonProcessor
(
mesh.boundaryMesh().nNonProcessor()
);
if (exposedPatchIDs.empty()) forAll(exposedPatchIDs, i)
{
if (exposedPatchIDs[i] > nNonProcessor)
{ {
FatalErrorInFunction exposedPatchIDs.resize(i);
<< nl << "No patches matched. Patches: " break;
<< flatOutput(mesh.boundaryMesh().names()) << nl
<< exit(FatalError);
} }
} }
}
else if (args.found("patch")) const wordList allPatchNames(mesh.boundaryMesh().names());
{
exposedPatchIDs.front() = Info<< "Adding exposed internal faces to nearest of patches:" << nl
getExposedPatchId(mesh, args.get<word>("patch")); << " include: " << flatOutput(includePatches) << nl
<< " exclude: " << flatOutput(excludePatches) << nl
<< nl;
if (exposedPatchIDs.empty())
{
FatalErrorInFunction
<< nl << "No patches matched. Patches: "
<< flatOutput(allPatchNames) << nl
<< exit(FatalError);
}
} }
else else
{ {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -145,12 +145,13 @@ int main(int argc, char *argv[]) ...@@ -145,12 +145,13 @@ int main(int argc, char *argv[])
); );
argList::addOption argList::addOption
( (
"excludePatches", "exclude-patches",
"wordRes", "wordRes",
"Specify single patch or multiple patches to exclude from writing." "Specify single patch or multiple patches to exclude from -patches."
" Eg, 'outlet' or '( inlet \".*Wall\" )'", " Eg, 'outlet' or '( inlet \".*Wall\" )'",
true // mark as an advanced option true // mark as an advanced option
); );
argList::addOptionCompat("exclude-patches", {"excludePatches", 2306});
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"
...@@ -167,16 +168,13 @@ int main(int argc, char *argv[]) ...@@ -167,16 +168,13 @@ int main(int argc, char *argv[])
Info<< "Extracting surface from boundaryMesh ..." << nl << nl; Info<< "Extracting surface from boundaryMesh ..." << nl << nl;
const bool includeProcPatches = const bool includeProcPatches =
!( (!UPstream::parRun() && !args.found("excludeProcPatches"));
args.found("excludeProcPatches")
|| Pstream::parRun()
);
if (includeProcPatches) if (includeProcPatches)
{ {
Info<< "Including all processor patches." << nl << endl; Info<< "Including all processor patches." << nl << endl;
} }
else if (Pstream::parRun()) else if (UPstream::parRun())
{ {
Info<< "Excluding all processor patches." << nl << endl; Info<< "Excluding all processor patches." << nl << endl;
} }
...@@ -187,7 +185,7 @@ int main(int argc, char *argv[]) ...@@ -187,7 +185,7 @@ int main(int argc, char *argv[])
Info<< "Including patches " << flatOutput(includePatches) Info<< "Including patches " << flatOutput(includePatches)
<< nl << endl; << nl << endl;
} }
if (args.readListIfPresent<wordRe>("excludePatches", excludePatches)) if (args.readListIfPresent<wordRe>("exclude-patches", excludePatches))
{ {
Info<< "Excluding patches " << flatOutput(excludePatches) Info<< "Excluding patches " << flatOutput(excludePatches)
<< nl << endl; << nl << endl;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -45,11 +45,11 @@ Usage ...@@ -45,11 +45,11 @@ Usage
-patches '( front \".*back\" )' -patches '( front \".*back\" )'
\endverbatim \endverbatim
- \par -excludePatches NAME | LIST - \par -exclude-patches NAME | LIST
Exclude single or multiple patches (name or regex) from extracting. Exclude single or multiple patches (name or regex) from extracting.
For example, For example,
\verbatim \verbatim
-excludePatches '( inlet_1 inlet_2 "proc.*")' -exclude-patches '( inlet_1 inlet_2 "proc.*" )'
\endverbatim \endverbatim
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
...@@ -79,11 +79,12 @@ int main(int argc, char *argv[]) ...@@ -79,11 +79,12 @@ int main(int argc, char *argv[])
); );
argList::addOption argList::addOption
( (
"excludePatches", "exclude-patches",
"wordRes", "wordRes",
"Exclude single or multiple patches (name or regex) from extracting.\n" "Exclude single or multiple patches (name or regex) from extracting.\n"
"Eg, 'outlet' or '( inlet \".*Wall\" )'" "Eg, 'outlet' or '( inlet \".*Wall\" )'"
); );
argList::addOptionCompat("exclude-patches", {"excludePatches", 2306});
argList::addArgument("input", "The input surface file"); argList::addArgument("input", "The input surface file");
...@@ -114,7 +115,7 @@ int main(int argc, char *argv[]) ...@@ -114,7 +115,7 @@ int main(int argc, char *argv[])
Info<< "Including patches " << flatOutput(includePatches) Info<< "Including patches " << flatOutput(includePatches)
<< nl << endl; << nl << endl;
} }
if (args.readListIfPresent<wordRe>("excludePatches", excludePatches)) if (args.readListIfPresent<wordRe>("exclude-patches", excludePatches))
{ {
Info<< "Excluding patches " << flatOutput(excludePatches) Info<< "Excluding patches " << flatOutput(excludePatches)
<< nl << endl; << nl << endl;
......
...@@ -233,7 +233,7 @@ _of_complete_cache_[SRFSimpleFoam]="-case -decomposeParDict -fileHandler -world ...@@ -233,7 +233,7 @@ _of_complete_cache_[SRFSimpleFoam]="-case -decomposeParDict -fileHandler -world
_of_complete_cache_[star4ToFoam]="-case -fileHandler -scale | -ascii -noFunctionObjects -solids -doc -help" _of_complete_cache_[star4ToFoam]="-case -fileHandler -scale | -ascii -noFunctionObjects -solids -doc -help"
_of_complete_cache_[steadyParticleTracks]="-case -dict -fileHandler -region -time | -constant -latestTime -noFunctionObjects -noZero -verbose -doc -help" _of_complete_cache_[steadyParticleTracks]="-case -dict -fileHandler -region -time | -constant -latestTime -noFunctionObjects -noZero -verbose -doc -help"
_of_complete_cache_[stitchMesh]="-case -dict -fileHandler -region -toleranceDict | -integral -intermediate -overwrite -partial -perfect -doc -help" _of_complete_cache_[stitchMesh]="-case -dict -fileHandler -region -toleranceDict | -integral -intermediate -overwrite -partial -perfect -doc -help"
_of_complete_cache_[subsetMesh]="-case -decomposeParDict -fileHandler -patch -patches -region -resultTime -world | -mpi-threads -overwrite -parallel -zone -doc -help" _of_complete_cache_[subsetMesh]="-case -decomposeParDict -exclude-patches -fileHandler -patch -patches -region -resultTime -world | -mpi-threads -overwrite -parallel -zone -doc -help"
_of_complete_cache_[surfaceAdd]="-case -fileHandler -points -scale | -mergeRegions -noFunctionObjects -verbose -doc -help" _of_complete_cache_[surfaceAdd]="-case -fileHandler -points -scale | -mergeRegions -noFunctionObjects -verbose -doc -help"
_of_complete_cache_[surfaceBooleanFeatures]="-case -fileHandler -scale -trim | -invertedSpace -no-cgal -noFunctionObjects -perturb -surf1Baffle -surf2Baffle -doc -help" _of_complete_cache_[surfaceBooleanFeatures]="-case -fileHandler -scale -trim | -invertedSpace -no-cgal -noFunctionObjects -perturb -surf1Baffle -surf2Baffle -doc -help"
_of_complete_cache_[surfaceCheck]="-case -fileHandler -outputThreshold -writeSets | -blockMesh -checkSelfIntersection -noFunctionObjects -splitNonManifold -verbose -doc -help" _of_complete_cache_[surfaceCheck]="-case -fileHandler -outputThreshold -writeSets | -blockMesh -checkSelfIntersection -noFunctionObjects -splitNonManifold -verbose -doc -help"
...@@ -249,7 +249,7 @@ _of_complete_cache_[surfaceInflate]="-case -featureAngle -fileHandler -nSmooth | ...@@ -249,7 +249,7 @@ _of_complete_cache_[surfaceInflate]="-case -featureAngle -fileHandler -nSmooth |
_of_complete_cache_[surfaceLambdaMuSmooth]="-featureFile | -doc -help" _of_complete_cache_[surfaceLambdaMuSmooth]="-featureFile | -doc -help"
_of_complete_cache_[surfaceMeshConvert]="-case -dict -fileHandler -from -read-format -read-scale -to -write-format -write-scale | -clean -noFunctionObjects -tri -verbose -doc -help" _of_complete_cache_[surfaceMeshConvert]="-case -dict -fileHandler -from -read-format -read-scale -to -write-format -write-scale | -clean -noFunctionObjects -tri -verbose -doc -help"
_of_complete_cache_[surfaceMeshExport]="-case -dict -fileHandler -from -name -read-scale -to -write-format -write-scale | -clean -noFunctionObjects -verbose -doc -help" _of_complete_cache_[surfaceMeshExport]="-case -dict -fileHandler -from -name -read-scale -to -write-format -write-scale | -clean -noFunctionObjects -verbose -doc -help"
_of_complete_cache_[surfaceMeshExtract]="-case -decomposeParDict -excludePatches -faceZones -fileHandler -patches -region -time -world | -constant -excludeProcPatches -latestTime -mpi-threads -noFunctionObjects -noZero -parallel -doc -help" _of_complete_cache_[surfaceMeshExtract]="-case -decomposeParDict -exclude-patches -faceZones -fileHandler -patches -region -time -world | -constant -excludeProcPatches -latestTime -mpi-threads -noFunctionObjects -noZero -parallel -doc -help"
_of_complete_cache_[surfaceMeshImport]="-case -dict -fileHandler -from -name -read-format -read-scale -to -write-scale | -clean -noFunctionObjects -verbose -doc -help" _of_complete_cache_[surfaceMeshImport]="-case -dict -fileHandler -from -name -read-format -read-scale -to -write-scale | -clean -noFunctionObjects -verbose -doc -help"
_of_complete_cache_[surfaceMeshInfo]="-case -fileHandler -scale | -areas -noFunctionObjects -xml -doc -help" _of_complete_cache_[surfaceMeshInfo]="-case -fileHandler -scale | -areas -noFunctionObjects -xml -doc -help"
_of_complete_cache_[surfaceOrient]="-case -fileHandler -scale | -inside -noFunctionObjects -usePierceTest -doc -help" _of_complete_cache_[surfaceOrient]="-case -fileHandler -scale | -inside -noFunctionObjects -usePierceTest -doc -help"
...@@ -257,7 +257,7 @@ _of_complete_cache_[surfacePatch]="-case -dict -fileHandler | -noFunctionObjects ...@@ -257,7 +257,7 @@ _of_complete_cache_[surfacePatch]="-case -dict -fileHandler | -noFunctionObjects
_of_complete_cache_[surfacePointMerge]="-case -fileHandler -scale | -noFunctionObjects -doc -help" _of_complete_cache_[surfacePointMerge]="-case -fileHandler -scale | -noFunctionObjects -doc -help"
_of_complete_cache_[surfaceRedistributePar]="-case -decomposeParDict -fileHandler -world | -keepNonMapped -mpi-threads -noFunctionObjects -parallel -doc -help" _of_complete_cache_[surfaceRedistributePar]="-case -decomposeParDict -fileHandler -world | -keepNonMapped -mpi-threads -noFunctionObjects -parallel -doc -help"
_of_complete_cache_[surfaceRefineRedGreen]="-case -fileHandler -steps | -noFunctionObjects -doc -help" _of_complete_cache_[surfaceRefineRedGreen]="-case -fileHandler -steps | -noFunctionObjects -doc -help"
_of_complete_cache_[surfaceSplitByPatch]="-case -excludePatches -fileHandler -patches | -noFunctionObjects -doc -help" _of_complete_cache_[surfaceSplitByPatch]="-case -exclude-patches -fileHandler -patches | -noFunctionObjects -doc -help"
_of_complete_cache_[surfaceSplitByTopology]=" | -doc -help" _of_complete_cache_[surfaceSplitByTopology]=" | -doc -help"
_of_complete_cache_[surfaceSplitNonManifolds]="-case -fileHandler | -debug -noFunctionObjects -doc -help" _of_complete_cache_[surfaceSplitNonManifolds]="-case -fileHandler | -debug -noFunctionObjects -doc -help"
_of_complete_cache_[surfaceSubset]="-case -fileHandler | -noFunctionObjects -doc -help" _of_complete_cache_[surfaceSubset]="-case -fileHandler | -noFunctionObjects -doc -help"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment