ENH: splitMeshRegions: optionally add regionName to all patches

This commit is contained in:
mattijs
2012-10-08 14:56:05 +01:00
parent 31afe2d5d3
commit eca5475f04

View File

@ -55,6 +55,8 @@ Description
this if you don't mind having disconnected domains in a single region.
This option requires all cells to be in one (and one only) cellZone.
- prefixRegion prefixes all normal patches with region name (interface
(patches already have region name prefix)
- Should work in parallel.
cellZones can differ on either side of processor boundaries in which case
@ -389,6 +391,40 @@ void reorderPatches
}
// Prepend prefix to selected patches.
void renamePatches
(
fvMesh& mesh,
const word& prefix,
const labelList& patchesToRename
)
{
polyBoundaryMesh& polyPatches =
const_cast<polyBoundaryMesh&>(mesh.boundaryMesh());
forAll(patchesToRename, i)
{
label patchI = patchesToRename[i];
polyPatch& pp = polyPatches[patchI];
if (isA<coupledPolyPatch>(pp))
{
WarningIn
(
"renamePatches(fvMesh&, const word&, const labelList&"
) << "Encountered coupled patch " << pp.name()
<< ". Will only rename the patch itself,"
<< " not any referred patches."
<< " This might have to be done by hand."
<< endl;
}
pp.name() = prefix + '_' + pp.name();
}
// Recalculate any demand driven data (e.g. group to name lookup)
polyPatches.updateMesh();
}
template<class GeoField>
void subsetVolFields
(
@ -987,6 +1023,7 @@ void createAndWriteRegion
const fvMesh& mesh,
const labelList& cellRegion,
const wordList& regionNames,
const bool prefixRegion,
const labelList& faceToInterface,
const labelList& interfacePatches,
const label regionI,
@ -1017,6 +1054,7 @@ void createAndWriteRegion
addedPatches.insert(interfacePatches[interfaceI]+1);
}
Info<< "Mapping fields" << endl;
// Map existing fields
@ -1109,6 +1147,7 @@ void createAndWriteRegion
// Create reordering list to move patches-to-be-deleted to end
labelList oldToNew(newPatches.size(), -1);
DynamicList<label> sharedPatches(newPatches.size());
label newI = 0;
Info<< "Deleting empty patches" << endl;
@ -1122,7 +1161,12 @@ void createAndWriteRegion
{
if (returnReduce(pp.size(), sumOp<label>()) > 0)
{
oldToNew[patchI] = newI++;
oldToNew[patchI] = newI;
if (!addedPatches.found(patchI))
{
sharedPatches.append(newI);
}
newI++;
}
}
}
@ -1152,6 +1196,15 @@ void createAndWriteRegion
reorderPatches(newMesh(), oldToNew, nNewPatches);
// Rename shared patches with region name
if (prefixRegion)
{
Info<< "Prefixing patches with region name" << endl;
renamePatches(newMesh(), regionNames[regionI], sharedPatches);
}
Info<< "Writing new mesh" << endl;
newMesh().setInstance(newMeshInstance);
@ -1672,6 +1725,11 @@ int main(int argc, char *argv[])
"useFaceZones",
"use faceZones to patch inter-region faces instead of single patch"
);
argList::addBoolOption
(
"prefixRegion",
"prefix region name to all patches, not just coupling patches"
);
#include "setRootCase.H"
#include "createTime.H"
@ -1696,6 +1754,8 @@ int main(int argc, char *argv[])
const bool detectOnly = args.optionFound("detectOnly");
const bool sloppyCellZones = args.optionFound("sloppyCellZones");
const bool useFaceZones = args.optionFound("useFaceZones");
const bool prefixRegion = args.optionFound("prefixRegion");
if
(
@ -2226,6 +2286,7 @@ int main(int argc, char *argv[])
mesh,
cellRegion,
regionNames,
prefixRegion,
faceToInterface,
interfacePatches,
regionI,
@ -2246,6 +2307,7 @@ int main(int argc, char *argv[])
mesh,
cellRegion,
regionNames,
prefixRegion,
faceToInterface,
interfacePatches,
regionI,
@ -2266,6 +2328,7 @@ int main(int argc, char *argv[])
mesh,
cellRegion,
regionNames,
prefixRegion,
faceToInterface,
interfacePatches,
regionI,