diff --git a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C index 59b81d8e0c0fa3d5fbad68f56d0d2dc8da09d696..f041be1c1251915efc8c12967ff70199d88ef1d6 100644 --- a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C +++ b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C @@ -34,6 +34,7 @@ Description - if the patch already exists will not override it nor its fields - if the patch does not exist it will be created together with 'calculated' patchfields unless the field is mentioned in the patchFields section. + - any 0-sized patches (since faces have been moved out) will get removed \*---------------------------------------------------------------------------*/ @@ -106,6 +107,75 @@ label addPatch } +// Filter out the empty patches. +void filterPatches(fvMesh& mesh, const HashSet<word>& addedPatchNames) +{ + // Remove any zero-sized ones. Assumes + // - processor patches are already only there if needed + // - all other patches are available on all processors + // - but coupled ones might still be needed, even if zero-size + // (e.g. processorCyclic) + // See also logic in createPatch. + const polyBoundaryMesh& pbm = mesh.boundaryMesh(); + + labelList oldToNew(pbm.size(), -1); + label newPatchi = 0; + forAll(pbm, patchi) + { + const polyPatch& pp = pbm[patchi]; + + if (!isA<processorPolyPatch>(pp)) + { + if + ( + isA<coupledPolyPatch>(pp) + || returnReduce(pp.size(), sumOp<label>()) + || addedPatchNames.found(pp.name()) + ) + { + // Coupled (and unknown size) or uncoupled and used + oldToNew[patchi] = newPatchi++; + } + } + } + + forAll(pbm, patchi) + { + const polyPatch& pp = pbm[patchi]; + + if (isA<processorPolyPatch>(pp)) + { + oldToNew[patchi] = newPatchi++; + } + } + + + const label nKeepPatches = newPatchi; + + // Shuffle unused ones to end + if (nKeepPatches != pbm.size()) + { + Info<< endl + << "Removing zero-sized patches:" << endl << incrIndent; + + forAll(oldToNew, patchi) + { + if (oldToNew[patchi] == -1) + { + Info<< indent << pbm[patchi].name() + << " type " << pbm[patchi].type() + << " at position " << patchi << endl; + oldToNew[patchi] = newPatchi++; + } + } + Info<< decrIndent; + + fvMeshTools::reorderPatches(mesh, oldToNew, nKeepPatches, true); + Info<< endl; + } +} + + void modifyOrAddFace ( polyTopoChange& meshMod, @@ -892,6 +962,11 @@ int main(int argc, char *argv[]) mesh.movePoints(map().preMotionPoints()); } + + // Remove any now zero-sized patches + filterPatches(mesh, bafflePatches); + + if (overwrite) { mesh.setInstance(oldInstance);