ENH: reduced warnings about createBaffles on processor patches (#2781)

- coupled patches are treated distinctly and independently of
  internalFacesOnly, it makes little sense to report them with a
  warning about turning off boundary faces (which would not work
  anyhow).

STYLE: update code style for createBaffles
This commit is contained in:
Mark Olesen
2023-05-16 10:16:38 +02:00
parent a581a8cb8d
commit f7a7f1c14c

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -139,7 +139,7 @@ void filterPatches(fvMesh& mesh, const wordHashSet& addedPatchNames)
( (
isA<coupledPolyPatch>(pp) isA<coupledPolyPatch>(pp)
|| returnReduceOr(pp.size()) || returnReduceOr(pp.size())
|| addedPatchNames.found(pp.name()) || addedPatchNames.contains(pp.name())
) )
{ {
// Coupled (and unknown size) or uncoupled and used // Coupled (and unknown size) or uncoupled and used
@ -248,8 +248,8 @@ void createFaces
const bool internalFacesOnly, const bool internalFacesOnly,
const fvMesh& mesh, const fvMesh& mesh,
const faceZone& fZone, const faceZone& fZone,
const labelList& newMasterPatches, const labelUList& newMasterPatches,
const labelList& newSlavePatches, const labelUList& newSlavePatches,
polyTopoChange& meshMod, polyTopoChange& meshMod,
bitSet& modifiedFace, bitSet& modifiedFace,
label& nModified label& nModified
@ -259,12 +259,15 @@ void createFaces
forAll(newMasterPatches, i) forAll(newMasterPatches, i)
{ {
const label newMasterPatchi = newMasterPatches[i];
const label newSlavePatchi = newSlavePatches[i];
// Pass 1. Do selected side of zone // Pass 1. Do selected side of zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (label facei = 0; facei < mesh.nInternalFaces(); facei++) for (label facei = 0; facei < mesh.nInternalFaces(); ++facei)
{ {
label zoneFacei = fZone.whichFace(facei); const label zoneFacei = fZone.whichFace(facei);
if (zoneFacei != -1) if (zoneFacei != -1)
{ {
@ -278,7 +281,7 @@ void createFaces
facei, // label of face facei, // label of face
mesh.faceOwner()[facei],// owner mesh.faceOwner()[facei],// owner
false, // face flip false, // face flip
newMasterPatches[i], // patch for face newMasterPatchi, // patch for face
fZone.index(), // zone for face fZone.index(), // zone for face
false, // face flip in zone false, // face flip in zone
modifiedFace // modify or add status modifiedFace // modify or add status
@ -297,14 +300,14 @@ void createFaces
facei, // label of face facei, // label of face
mesh.faceNeighbour()[facei],// owner mesh.faceNeighbour()[facei],// owner
true, // face flip true, // face flip
newMasterPatches[i], // patch for face newMasterPatchi, // patch for face
fZone.index(), // zone for face fZone.index(), // zone for face
false, // face flip in zone false, // face flip in zone
modifiedFace // modify or add status modifiedFace // modify or add status
); );
} }
nModified++; ++nModified;
} }
} }
@ -312,9 +315,9 @@ void createFaces
// Pass 2. Do other side of zone // Pass 2. Do other side of zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (label facei = 0; facei < mesh.nInternalFaces(); facei++) for (label facei = 0; facei < mesh.nInternalFaces(); ++facei)
{ {
label zoneFacei = fZone.whichFace(facei); const label zoneFacei = fZone.whichFace(facei);
if (zoneFacei != -1) if (zoneFacei != -1)
{ {
@ -328,7 +331,7 @@ void createFaces
facei, // label of face facei, // label of face
mesh.faceNeighbour()[facei], // owner mesh.faceNeighbour()[facei], // owner
true, // face flip true, // face flip
newSlavePatches[i], // patch for face newSlavePatchi, // patch for face
fZone.index(), // zone for face fZone.index(), // zone for face
true, // face flip in zone true, // face flip in zone
modifiedFace // modify or add modifiedFace // modify or add
@ -344,7 +347,7 @@ void createFaces
facei, // label of face facei, // label of face
mesh.faceOwner()[facei],// owner mesh.faceOwner()[facei],// owner
false, // face flip false, // face flip
newSlavePatches[i], // patch for face newSlavePatchi, // patch for face
fZone.index(), // zone for face fZone.index(), // zone for face
true, // face flip in zone true, // face flip in zone
modifiedFace // modify or add status modifiedFace // modify or add status
@ -371,13 +374,11 @@ void createFaces
forAll(pbm, patchi) forAll(pbm, patchi)
{ {
const polyPatch& pp = pbm[patchi]; const polyPatch& pp = pbm[patchi];
const bool isCoupled = pp.coupled();
const label newMasterPatchi = newMasterPatches[i];
const label newSlavePatchi = newSlavePatches[i];
if if
( (
pp.coupled() isCoupled
&& ( && (
pbm[newMasterPatchi].coupled() pbm[newMasterPatchi].coupled()
|| pbm[newSlavePatchi].coupled() || pbm[newSlavePatchi].coupled()
@ -387,7 +388,7 @@ void createFaces
// Do not allow coupled faces to be moved to different // Do not allow coupled faces to be moved to different
// coupled patches. // coupled patches.
} }
else if (pp.coupled() || !internalFacesOnly) else if (isCoupled || !internalFacesOnly)
{ {
forAll(pp, i) forAll(pp, i)
{ {
@ -397,16 +398,14 @@ void createFaces
if (zoneFacei != -1) if (zoneFacei != -1)
{ {
if (patchWarned.insert(patchi)) if (!isCoupled && patchWarned.insert(patchi))
{ {
WarningInFunction WarningInFunction
<< "Found boundary face (in patch " << "Found boundary face (patch " << pp.name()
<< pp.name()
<< ") in faceZone " << fZone.name() << ") in faceZone " << fZone.name()
<< " to convert to baffle patches " << " to convert to baffle patches "
<< pbm[newMasterPatchi].name() << "/" << pbm[newMasterPatchi].name() << "/"
<< pbm[newSlavePatchi].name() << pbm[newSlavePatchi].name() << nl
<< endl
<< " Set internalFacesOnly to true in the" << " Set internalFacesOnly to true in the"
<< " createBaffles control dictionary if you" << " createBaffles control dictionary if you"
<< " don't wish to convert boundary faces." << " don't wish to convert boundary faces."
@ -428,7 +427,7 @@ void createFaces
modifiedFace // modify or add modifiedFace // modify or add
); );
nModified++; ++nModified;
} }
} }
} }
@ -547,21 +546,16 @@ int main(int argc, char *argv[])
// Creating (if necessary) faceZones // Creating (if necessary) faceZones
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
forAll(selectors, selectorI) for (const faceSelection& selector : selectors)
{ {
const word& name = selectors[selectorI].name(); const word& name = selector.name();
if (mesh.faceZones().findZoneID(name) == -1) if (mesh.faceZones().findZoneID(name) == -1)
{ {
mesh.faceZones().clearAddressing(); mesh.faceZones().clearAddressing();
const label zoneID = mesh.faceZones().size(); const label zoneID = mesh.faceZones().size();
mesh.faceZones().setSize(zoneID+1); mesh.faceZones().emplace_back(name, zoneID, mesh.faceZones());
mesh.faceZones().set
(
zoneID,
new faceZone(name, labelList(), false, zoneID, mesh.faceZones())
);
} }
} }
@ -572,29 +566,28 @@ int main(int argc, char *argv[])
//- Per face zoneID it is in and flip status. //- Per face zoneID it is in and flip status.
labelList faceToZoneID(mesh.nFaces(), -1); labelList faceToZoneID(mesh.nFaces(), -1);
boolList faceToFlip(mesh.nFaces(), false); boolList faceToFlip(mesh.nFaces(), false);
forAll(selectors, selectorI) for (faceSelection& selector : selectors)
{ {
const word& name = selectors[selectorI].name(); const word& name = selector.name();
label zoneID = mesh.faceZones().findZoneID(name); const label zoneID = mesh.faceZones().findZoneID(name);
selectors[selectorI].select(zoneID, faceToZoneID, faceToFlip); selector.select(zoneID, faceToZoneID, faceToFlip);
} }
// Add faces to faceZones // Add faces to faceZones
labelList nFaces(mesh.faceZones().size(), Zero); labelList nFaces(mesh.faceZones().size(), Zero);
forAll(faceToZoneID, facei) for (const label zoneID : faceToZoneID)
{ {
label zoneID = faceToZoneID[facei];
if (zoneID != -1) if (zoneID != -1)
{ {
nFaces[zoneID]++; ++nFaces[zoneID];
} }
} }
forAll(selectors, selectorI) for (const faceSelection& selector : selectors)
{ {
const word& name = selectors[selectorI].name(); const word& name = selector.name();
label zoneID = mesh.faceZones().findZoneID(name); const label zoneID = mesh.faceZones().findZoneID(name);
label& n = nFaces[zoneID]; label& n = nFaces[zoneID];
labelList addr(n); labelList addr(n);
@ -635,13 +628,15 @@ int main(int argc, char *argv[])
// ~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~
wordHashSet bafflePatches; wordHashSet bafflePatches;
{ {
forAll(selectors, selectorI) for (const faceSelection& selector : selectors)
{ {
const dictionary& dict = selectors[selectorI].dict(); const dictionary& dict = selector.dict();
const word& groupName = selector.name();
const dictionary* patchesDictPtr = dict.findDict("patches");
if (dict.found("patches")) if (patchesDictPtr)
{ {
for (const entry& dEntry : dict.subDict("patches")) for (const entry& dEntry : *patchesDictPtr)
{ {
const word patchName(dEntry.dict().get<word>("name")); const word patchName(dEntry.dict().get<word>("name"));
@ -650,10 +645,10 @@ int main(int argc, char *argv[])
} }
else else
{ {
const word masterName = selectors[selectorI].name() + "_master"; const word masterName(groupName + "_master");
bafflePatches.insert(masterName); bafflePatches.insert(masterName);
const word slaveName = selectors[selectorI].name() + "_slave"; const word slaveName(groupName + "_slave");
bafflePatches.insert(slaveName); bafflePatches.insert(slaveName);
} }
} }
@ -679,14 +674,15 @@ int main(int argc, char *argv[])
// wordHashSet addedPatches; // wordHashSet addedPatches;
{ {
const polyBoundaryMesh& pbm = mesh.boundaryMesh(); const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(selectors, selectorI) for (const faceSelection& selector : selectors)
{ {
const dictionary& dict = selectors[selectorI].dict(); const dictionary& dict = selector.dict();
const word& groupName = selectors[selectorI].name(); const word& groupName = selector.name();
const dictionary* patchesDictPtr = dict.findDict("patches");
if (dict.found("patches")) if (patchesDictPtr)
{ {
for (const entry& dEntry : dict.subDict("patches")) for (const entry& dEntry : *patchesDictPtr)
{ {
const dictionary& dict = dEntry.dict(); const dictionary& dict = dEntry.dict();
@ -717,8 +713,8 @@ int main(int argc, char *argv[])
else else
{ {
const dictionary& patchSource = dict.subDict("patchPairs"); const dictionary& patchSource = dict.subDict("patchPairs");
const word masterName = groupName + "_master"; const word masterName(groupName + "_master");
const word slaveName = groupName + "_slave"; const word slaveName(groupName + "_slave");
word groupNameMaster = groupName; word groupNameMaster = groupName;
word groupNameSlave = groupName; word groupNameSlave = groupName;
@ -776,22 +772,23 @@ int main(int argc, char *argv[])
bitSet modifiedFace(mesh.nFaces()); bitSet modifiedFace(mesh.nFaces());
label nModified = 0; label nModified = 0;
forAll(selectors, selectorI) for (const faceSelection& selector : selectors)
{ {
const word& name = selectors[selectorI].name(); const word& groupName = selector.name();
label zoneID = mesh.faceZones().findZoneID(name); const dictionary& dict = selector.dict();
const faceZone& fZone = mesh.faceZones()[zoneID]; const dictionary* patchesDictPtr = dict.findDict("patches");
const dictionary& dict = selectors[selectorI].dict(); const label zoneID = mesh.faceZones().findZoneID(groupName);
const faceZone& fZone = mesh.faceZones()[zoneID];
DynamicList<label> newMasterPatches; DynamicList<label> newMasterPatches;
DynamicList<label> newSlavePatches; DynamicList<label> newSlavePatches;
if (dict.found("patches")) if (patchesDictPtr)
{ {
bool master = true; bool master = true;
for (const entry& dEntry : dict.subDict("patches")) for (const entry& dEntry : *patchesDictPtr)
{ {
const word patchName(dEntry.dict().get<word>("name")); const word patchName(dEntry.dict().get<word>("name"));
@ -799,22 +796,22 @@ int main(int argc, char *argv[])
if (master) if (master)
{ {
newMasterPatches.append(patchi); newMasterPatches.push_back(patchi);
} }
else else
{ {
newSlavePatches.append(patchi); newSlavePatches.push_back(patchi);
} }
master = !master; master = !master;
} }
} }
else else
{ {
const word masterName = selectors[selectorI].name() + "_master"; const word masterName(groupName + "_master");
newMasterPatches.append(pbm.findPatchID(masterName)); newMasterPatches.push_back(pbm.findPatchID(masterName));
const word slaveName = selectors[selectorI].name() + "_slave"; const word slaveName(groupName + "_slave");
newSlavePatches.append(pbm.findPatchID(slaveName)); newSlavePatches.push_back(pbm.findPatchID(slaveName));
} }
@ -881,26 +878,26 @@ int main(int argc, char *argv[])
{ {
const polyBoundaryMesh& pbm = mesh.boundaryMesh(); const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(selectors, selectorI) for (const faceSelection& selector : selectors)
{ {
const dictionary& dict = selectors[selectorI].dict(); const dictionary& dict = selector.dict();
if (dict.found("patches")) const word& groupName = selector.name();
const dictionary* patchesDict = dict.findDict("patches");
if (patchesDict)
{ {
for (const entry& dEntry : dict.subDict("patches")) for (const entry& dEntry : *patchesDict)
{ {
const dictionary& dict = dEntry.dict(); const dictionary& dict = dEntry.dict();
const word patchName(dict.get<word>("name")); const word patchName(dict.get<word>("name"));
const label patchi = pbm.findPatchID(patchName);
label patchi = pbm.findPatchID(patchName); const dictionary* patchFieldsDictPtr
= dict.findDict("patchFields");
if (dEntry.dict().found("patchFields")) if (patchFieldsDictPtr)
{ {
const dictionary& patchFieldsDict = const dictionary& patchFieldsDict = *patchFieldsDictPtr;
dEntry.dict().subDict
(
"patchFields"
);
fvMeshTools::setPatchFields fvMeshTools::setPatchFields
( (
@ -918,14 +915,13 @@ int main(int argc, char *argv[])
const bool sameGroup = const bool sameGroup =
patchSource.getOrDefault("sameGroup", true); patchSource.getOrDefault("sameGroup", true);
const word& groupName = selectors[selectorI].name(); const dictionary* patchFieldsDictPtr
= dict.findDict("patchFields");
if (patchSource.found("patchFields")) if (patchFieldsDictPtr)
{ {
dictionary patchFieldsDict = patchSource.subDict // Work on a copy
( dictionary patchFieldsDict(*patchFieldsDictPtr);
"patchFields"
);
if (sameGroup) if (sameGroup)
{ {
@ -939,15 +935,14 @@ int main(int argc, char *argv[])
} }
} }
const labelList& patchIDs = const labelList& patchIDs = pbm.groupPatchIDs()[groupName];
pbm.groupPatchIDs()[groupName];
forAll(patchIDs, i) for (const label patchi : patchIDs)
{ {
fvMeshTools::setPatchFields fvMeshTools::setPatchFields
( (
mesh, mesh,
patchIDs[i], patchi,
patchFieldsDict patchFieldsDict
); );
} }