Commit 92dbf49a authored by mattijs's avatar mattijs
Browse files

allow multiple coincident baffles

parent 04b82d92
......@@ -48,12 +48,164 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void createBaffles
(
const polyMesh& mesh,
const label faceI,
const label oldPatchI,
const labelList& newPatches,
PackedBoolList& doneFace,
polyTopoChange& meshMod
)
{
const polyBoundaryMesh& patches = mesh.boundaryMesh();
const faceZoneMesh& faceZones = mesh.faceZones();
const face& f = mesh.faces()[faceI];
label zoneID = faceZones.whichZone(faceI);
bool zoneFlip = false;
if (zoneID >= 0)
{
const faceZone& fZone = faceZones[zoneID];
zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
}
label nei = -1;
if (oldPatchI == -1)
{
nei = mesh.faceNeighbour()[faceI];
}
face revFace(f.reverseFace());
forAll(newPatches, i)
{
if (oldPatchI == -1)
{
// Internal face
if (doneFace.set(faceI))
{
// First usage of face. Modify.
meshMod.setAction
(
polyModifyFace
(
f, // modified face
faceI, // label of face
mesh.faceOwner()[faceI], // owner
-1, // neighbour
false, // face flip
newPatches[i], // patch for face
false, // remove from zone
zoneID, // zone for face
zoneFlip // face flip in zone
)
);
}
else
{
// Second or more usage of face. Add.
meshMod.setAction
(
polyAddFace
(
f, // modified face
mesh.faceOwner()[faceI], // owner
-1, // neighbour
-1, // master point
-1, // master edge
faceI, // master face
false, // face flip
newPatches[i], // patch for face
zoneID, // zone for face
zoneFlip // face flip in zone
)
);
}
meshMod.setAction
(
polyAddFace
(
revFace, // modified face
nei, // owner
-1, // neighbour
-1, // masterPointID
-1, // masterEdgeID
faceI, // masterFaceID,
true, // face flip
newPatches[i], // patch for face
zoneID, // zone for face
zoneFlip // face flip in zone
)
);
}
else if
(
patches[oldPatchI].coupled()
&& patches[newPatches[i]].coupled()
)
{
// Do not allow coupled patches to be moved to different coupled
// patches.
//WarningIn("createBaffles()")
// << "Not moving face from coupled patch "
// << patches[oldPatchI].name()
// << " to another coupled patch " << patches[newPatches[i]]
// << endl;
}
else
{
if (doneFace.set(faceI))
{
meshMod.setAction
(
polyModifyFace
(
f, // modified face
faceI, // label of face
mesh.faceOwner()[faceI], // owner
-1, // neighbour
false, // face flip
newPatches[i], // patch for face
false, // remove from zone
zoneID, // zone for face
zoneFlip // face flip in zone
)
);
}
else
{
meshMod.setAction
(
polyAddFace
(
f, // modified face
mesh.faceOwner()[faceI], // owner
-1, // neighbour
-1, // master point
-1, // master edge
faceI, // master face
false, // face flip
newPatches[i], // patch for face
zoneID, // zone for face
zoneFlip // face flip in zone
)
);
}
}
}
}
// Main program:
int main(int argc, char *argv[])
{
argList::validArgs.append("set");
argList::validArgs.append("patch");
argList::validOptions.insert("additionalPatches", "(patch2 .. patchN)");
argList::validOptions.insert("overwrite", "");
# include "setRootCase.H"
......@@ -63,29 +215,64 @@ int main(int argc, char *argv[])
const word oldInstance = mesh.pointsInstance();
const polyBoundaryMesh& patches = mesh.boundaryMesh();
const faceZoneMesh& faceZones = mesh.faceZones();
// Faces to baffle
word setName(args.additionalArgs()[0]);
Pout<< "Reading faceSet from " << setName << nl << endl;
faceSet facesToSplit(mesh, setName);
// Make sure set is synchronised across couples
facesToSplit.sync(mesh);
Pout<< "Read " << facesToSplit.size() << " faces from " << setName
<< nl << endl;
// Patch to put them into
word patchName(args.additionalArgs()[1]);
label wantedPatchI = patches.findPatchID(patchName);
Pout<< "Using patch " << patchName << " at index " << wantedPatchI << endl;
// Patches to put baffles into
labelList newPatches(1);
if (wantedPatchI == -1)
word patchName(args.additionalArgs()[1]);
newPatches[0] = patches.findPatchID(patchName);
Pout<< "Using patch " << patchName
<< " at index " << newPatches[0] << endl;
if (newPatches[0] == -1)
{
FatalErrorIn(args.executable())
<< "Cannot find patch " << patchName << exit(FatalError);
<< "Cannot find patch " << patchName << endl
<< "Valid patches are " << patches.names() << exit(FatalError);
}
// Additional patches
if (args.options().found("additionalPatches"))
{
const wordList patchNames
(
IStringStream(args.options()["additionalPatches"])()
);
forAll(patchNames, i)
{
label patchI = patches.findPatchID(patchNames[i]);
Info<< "Using additional patch " << patchNames[i]
<< " at index " << patchI << endl;
if (patchI == -1)
{
FatalErrorIn(args.executable())
<< "Cannot find patch " << patchNames[i] << endl
<< "Valid patches are " << patches.names()
<< exit(FatalError);
}
newPatches.append(patchI);
}
}
bool overwrite = args.options().found("overwrite");
// Read objects in time directory
IOobjectList objects(mesh, runTime.timeName());
......@@ -128,107 +315,53 @@ int main(int argc, char *argv[])
polyTopoChange meshMod(mesh);
// Creating baffles:
// - coupled boundary faces : become the patch specified
// - non-coupled ,, : illegal
// - internal faces : converted into boundary faces.
// Do the actual changes
labelList newPatch(mesh.nFaces(), -1);
label nBaffled = 0;
PackedBoolList doneFace(mesh.nFaces());
forAllConstIter(faceSet, facesToSplit, iter)
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
{
label faceI = iter.key();
label patchI = patches.whichPatch(faceI);
if (patchI == -1)
if (facesToSplit.found(faceI))
{
newPatch[faceI] = wantedPatchI;
}
else
{
if (patches[patchI].coupled())
{
if (patchI != wantedPatchI)
{
newPatch[faceI] = wantedPatchI;
}
}
else
{
FatalErrorIn(args.executable())
<< "Can only create baffles from internal faces"
<< " or coupled boundary faces." << endl
<< "Face " << faceI << " is a boundary face on patch "
<< patches[patchI].name() << exit(FatalError);
}
createBaffles
(
mesh,
faceI,
-1, // oldPatchI,
newPatches,
doneFace,
meshMod
);
nBaffled++;
}
}
// If one side of a coupled boundary is marked for baffling, make sure to
// also do the other side.
syncTools::syncFaceList(mesh, newPatch, maxEqOp<label>(), false);
label nBaffled = 0;
forAll(newPatch, faceI)
forAll(patches, patchI)
{
if (newPatch[faceI] != -1)
{
const face& f = mesh.faces()[faceI];
label zoneID = faceZones.whichZone(faceI);
bool zoneFlip = false;
if (zoneID >= 0)
{
const faceZone& fZone = faceZones[zoneID];
zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
}
const polyPatch& pp = patches[patchI];
meshMod.setAction
(
polyModifyFace
(
f, // modified face
faceI, // label of face
mesh.faceOwner()[faceI], // owner
-1, // neighbour
false, // face flip
newPatch[faceI], // patch for face
false, // remove from zone
zoneID, // zone for face
zoneFlip // face flip in zone
)
);
forAll(pp, i)
{
label faceI = pp.start()+i;
if (mesh.isInternalFace(faceI))
if (facesToSplit.found(faceI))
{
meshMod.setAction
createBaffles
(
polyAddFace
(
f.reverseFace(), // modified face
mesh.faceNeighbour()[faceI],// owner
-1, // neighbour
-1, // masterPointID
-1, // masterEdgeID
faceI, // masterFaceID,
false, // face flip
newPatch[faceI], // patch for face
zoneID, // zone for face
zoneFlip // face flip in zone
)
mesh,
faceI,
patchI, // oldPatchI,
newPatches,
doneFace,
meshMod
);
nBaffled++;
}
nBaffled++;
}
}
Pout<< "Converted locally " << nBaffled
Info<< "Converted " << returnReduce(nBaffled, sumOp<label>())
<< " faces into boundary faces on patch " << patchName << nl << endl;
if (!overwrite)
......@@ -252,7 +385,7 @@ int main(int argc, char *argv[])
{
mesh.setInstance(oldInstance);
}
Pout<< "Writing mesh to " << runTime.timeName() << endl;
Info<< "Writing mesh to " << runTime.timeName() << endl;
mesh.write();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment