ENH: createPatch: do not remove added patches. Fixes #2726

This commit is contained in:
mattijs
2025-08-20 15:13:09 +01:00
parent 8357b7e28b
commit 9c13057b80
3 changed files with 52 additions and 12 deletions

View File

@ -42,14 +42,14 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "cyclicPolyPatch.H"
#include "syncTools.H"
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "OFstream.H" #include "OFstream.H"
#include "meshTools.H" #include "meshTools.H"
#include "faceSet.H" #include "faceSet.H"
#include "IOPtrList.H" #include "IOPtrList.H"
#include "cyclicPolyPatch.H"
#include "syncTools.H"
#include "polyTopoChange.H" #include "polyTopoChange.H"
#include "polyModifyFace.H" #include "polyModifyFace.H"
#include "polyAddFace.H" #include "polyAddFace.H"
@ -942,6 +942,9 @@ int main(int argc, char *argv[])
} }
// Maintain list of added patches so we exclude them from filtering
// later on
List<DynamicList<word>> allAddedPatches(meshes.size());
// Loop over all regions // Loop over all regions
@ -1036,6 +1039,7 @@ int main(int argc, char *argv[])
fvPatchFieldBase::calculatedType(), fvPatchFieldBase::calculatedType(),
true true
); );
allAddedPatches[meshi].append(ppPtr->name());
} }
} }
} }
@ -1087,6 +1091,7 @@ int main(int argc, char *argv[])
fvPatchFieldBase::calculatedType(), fvPatchFieldBase::calculatedType(),
true true
); );
allAddedPatches[meshi].append(ppPtr->name());
} }
} }
} }
@ -1116,6 +1121,7 @@ int main(int argc, char *argv[])
fvPatchFieldBase::calculatedType(), fvPatchFieldBase::calculatedType(),
true true
); );
allAddedPatches[meshi].append(ppPtr->name());
} }
} }
} }
@ -1453,7 +1459,7 @@ int main(int argc, char *argv[])
Info<< "Removing patches with no faces in them." << nl << endl; Info<< "Removing patches with no faces in them." << nl << endl;
const wordList oldPatchNames(mesh.boundaryMesh().names()); const wordList oldPatchNames(mesh.boundaryMesh().names());
const wordList oldPatchTypes(mesh.boundaryMesh().types()); const wordList oldPatchTypes(mesh.boundaryMesh().types());
fvMeshTools::removeEmptyPatches(mesh, true); fvMeshTools::removeEmptyPatches(mesh, allAddedPatches[meshi], true);
forAll(oldPatchNames, patchi) forAll(oldPatchNames, patchi)
{ {
const word& pName = oldPatchNames[patchi]; const word& pName = oldPatchNames[patchi];

View File

@ -369,6 +369,7 @@ void Foam::fvMeshTools::reorderPatches
Foam::labelList Foam::fvMeshTools::removeEmptyPatches Foam::labelList Foam::fvMeshTools::removeEmptyPatches
( (
fvMesh& mesh, fvMesh& mesh,
const wordList& keepPatches,
const bool validBoundary const bool validBoundary
) )
{ {
@ -385,6 +386,13 @@ Foam::labelList Foam::fvMeshTools::removeEmptyPatches
const polyPatch& pp = pbm[patchI]; const polyPatch& pp = pbm[patchI];
if (!isA<processorPolyPatch>(pp)) if (!isA<processorPolyPatch>(pp))
{
if (keepPatches.found(pp.name()))
{
newToOld[newI] = patchI;
oldToNew[patchI] = newI++;
}
else
{ {
label nFaces = pp.size(); label nFaces = pp.size();
if (validBoundary) if (validBoundary)
@ -399,13 +407,21 @@ Foam::labelList Foam::fvMeshTools::removeEmptyPatches
} }
} }
} }
}
// Same for processor patches (but need no reduction) // Same for processor patches (but need no reduction)
forAll(pbm, patchI) forAll(pbm, patchI)
{ {
const polyPatch& pp = pbm[patchI]; const polyPatch& pp = pbm[patchI];
if (isA<processorPolyPatch>(pp) && pp.size()) if
(
isA<processorPolyPatch>(pp)
&& (
pp.size()
|| keepPatches.found(pp.name())
)
)
{ {
newToOld[newI] = patchI; newToOld[newI] = patchI;
oldToNew[patchI] = newI++; oldToNew[patchI] = newI++;
@ -429,6 +445,16 @@ Foam::labelList Foam::fvMeshTools::removeEmptyPatches
} }
Foam::labelList Foam::fvMeshTools::removeEmptyPatches
(
fvMesh& mesh,
const bool validBoundary
)
{
return removeEmptyPatches(mesh, wordList::null(), validBoundary);
}
void Foam::fvMeshTools::setBasicGeometry(fvMesh& mesh) void Foam::fvMeshTools::setBasicGeometry(fvMesh& mesh)
{ {
// Set the fvGeometryScheme to basic since it does not require // Set the fvGeometryScheme to basic since it does not require

View File

@ -156,6 +156,14 @@ public:
// to old patches // to old patches
static labelList removeEmptyPatches(fvMesh&, const bool validBoundary); static labelList removeEmptyPatches(fvMesh&, const bool validBoundary);
//- Remove zero sized patches unless explicitly forced to preserve.
// See above.
static labelList removeEmptyPatches
(
fvMesh&,
const wordList& keepPatches,
const bool validBoundary
);
//- Set the fvGeometryScheme to basic (to avoid parallel communication) //- Set the fvGeometryScheme to basic (to avoid parallel communication)
static void setBasicGeometry(fvMesh& mesh); static void setBasicGeometry(fvMesh& mesh);