From 35dba48db1adf676adb0f9023164b781cc748c88 Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> Date: Sun, 29 May 2016 22:51:15 +0100 Subject: [PATCH] createBaffles: filter zero-sized patches Resolves patch request http://bugs.openfoam.org/view.php?id=2103 Patch contributed by Mattijs Janssens --- .../createBaffles/createBaffles.C | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C index 59b81d8e0c0..f041be1c125 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); -- GitLab