mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
createBaffles with faceZone
This commit is contained in:
@ -43,16 +43,89 @@ Description
|
|||||||
#include "ReadFields.H"
|
#include "ReadFields.H"
|
||||||
#include "volFields.H"
|
#include "volFields.H"
|
||||||
#include "surfaceFields.H"
|
#include "surfaceFields.H"
|
||||||
|
#include "ZoneIDs.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void modifyOrAddFace
|
||||||
|
(
|
||||||
|
polyTopoChange& meshMod,
|
||||||
|
const face& f,
|
||||||
|
const label faceI,
|
||||||
|
const label own,
|
||||||
|
const bool flipFaceFlux,
|
||||||
|
const label newPatchI,
|
||||||
|
const label zoneID,
|
||||||
|
const bool zoneFlip,
|
||||||
|
|
||||||
|
PackedBoolList& modifiedFace
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!modifiedFace[faceI])
|
||||||
|
{
|
||||||
|
// First usage of face. Modify.
|
||||||
|
meshMod.setAction
|
||||||
|
(
|
||||||
|
polyModifyFace
|
||||||
|
(
|
||||||
|
f, // modified face
|
||||||
|
faceI, // label of face
|
||||||
|
own, // owner
|
||||||
|
-1, // neighbour
|
||||||
|
flipFaceFlux, // face flip
|
||||||
|
newPatchI, // patch for face
|
||||||
|
false, // remove from zone
|
||||||
|
zoneID, // zone for face
|
||||||
|
zoneFlip // face flip in zone
|
||||||
|
)
|
||||||
|
);
|
||||||
|
modifiedFace[faceI] = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Second or more usage of face. Add.
|
||||||
|
meshMod.setAction
|
||||||
|
(
|
||||||
|
polyAddFace
|
||||||
|
(
|
||||||
|
f, // modified face
|
||||||
|
own, // owner
|
||||||
|
-1, // neighbour
|
||||||
|
-1, // master point
|
||||||
|
-1, // master edge
|
||||||
|
faceI, // master face
|
||||||
|
flipFaceFlux, // face flip
|
||||||
|
newPatchI, // patch for face
|
||||||
|
zoneID, // zone for face
|
||||||
|
zoneFlip // face flip in zone
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
label findPatchID(const polyMesh& mesh, const word& name)
|
||||||
|
{
|
||||||
|
label patchI = mesh.boundaryMesh().findPatchID(name);
|
||||||
|
|
||||||
|
if (patchI == -1)
|
||||||
|
{
|
||||||
|
FatalErrorIn("findPatchID(const polyMesh&, const word&)")
|
||||||
|
<< "Cannot find patch " << name << endl
|
||||||
|
<< "Valid patches are " << mesh.boundaryMesh().names()
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
return patchI;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Main program:
|
// Main program:
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
argList::validArgs.append("set");
|
argList::validArgs.append("faceZone");
|
||||||
argList::validArgs.append("patch");
|
argList::validArgs.append("patch");
|
||||||
argList::validOptions.insert("additionalPatches", "(patch2 .. patchN)");
|
argList::validOptions.insert("additionalPatches", "(patch2 .. patchN)");
|
||||||
argList::validOptions.insert("overwrite", "");
|
argList::validOptions.insert("overwrite", "");
|
||||||
@ -67,30 +140,28 @@ int main(int argc, char *argv[])
|
|||||||
const faceZoneMesh& faceZones = mesh.faceZones();
|
const faceZoneMesh& faceZones = mesh.faceZones();
|
||||||
|
|
||||||
// Faces to baffle
|
// Faces to baffle
|
||||||
word setName(args.additionalArgs()[0]);
|
faceZoneID zoneID(args.additionalArgs()[0], faceZones);
|
||||||
Info<< "Reading faceSet from " << setName << nl << endl;
|
|
||||||
faceSet facesToSplit(mesh, setName);
|
|
||||||
// Make sure set is synchronised across couples
|
|
||||||
facesToSplit.sync(mesh);
|
|
||||||
Info<< "Read " << returnReduce(facesToSplit.size(), sumOp<label>())
|
|
||||||
<< " faces from " << setName << nl << endl;
|
|
||||||
|
|
||||||
|
Info<< "Converting faces on zone " << zoneID.name()
|
||||||
|
<< " into baffles." << nl << endl;
|
||||||
|
|
||||||
|
const faceZone& fZone = faceZones[zoneID.index()];
|
||||||
|
|
||||||
|
Info<< "Found " << returnReduce(fZone.size(), sumOp<label>())
|
||||||
|
<< " faces on zone " << zoneID.name() << nl << endl;
|
||||||
|
|
||||||
|
// Make sure patches and zoneFaces are synchronised across couples
|
||||||
|
patches.checkParallelSync(true);
|
||||||
|
fZone.checkParallelSync(true);
|
||||||
|
|
||||||
// Patches to put baffles into
|
// Patches to put baffles into
|
||||||
DynamicList<label> newPatches(1);
|
DynamicList<label> newPatches(1);
|
||||||
|
|
||||||
word patchName(args.additionalArgs()[1]);
|
word patchName(args.additionalArgs()[1]);
|
||||||
newPatches.append(patches.findPatchID(patchName));
|
newPatches.append(findPatchID(mesh, patchName));
|
||||||
Pout<< "Using patch " << patchName
|
Info<< "Using patch " << patchName
|
||||||
<< " at index " << newPatches[0] << endl;
|
<< " at index " << newPatches[0] << endl;
|
||||||
|
|
||||||
if (newPatches[0] == -1)
|
|
||||||
{
|
|
||||||
FatalErrorIn(args.executable())
|
|
||||||
<< "Cannot find patch " << patchName << endl
|
|
||||||
<< "Valid patches are " << patches.names() << exit(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Additional patches
|
// Additional patches
|
||||||
if (args.optionFound("additionalPatches"))
|
if (args.optionFound("additionalPatches"))
|
||||||
@ -103,19 +174,9 @@ int main(int argc, char *argv[])
|
|||||||
newPatches.reserve(patchNames.size() + 1);
|
newPatches.reserve(patchNames.size() + 1);
|
||||||
forAll(patchNames, i)
|
forAll(patchNames, i)
|
||||||
{
|
{
|
||||||
label patchI = patches.findPatchID(patchNames[i]);
|
newPatches.append(findPatchID(mesh, patchNames[i]));
|
||||||
Info<< "Using additional patch " << patchNames[i]
|
Info<< "Using additional patch " << patchNames[i]
|
||||||
<< " at index " << patchI << endl;
|
<< " at index " << newPatches[newPatches.size()-1] << endl;
|
||||||
|
|
||||||
if (patchI == -1)
|
|
||||||
{
|
|
||||||
FatalErrorIn(args.executable())
|
|
||||||
<< "Cannot find patch " << patchNames[i] << endl
|
|
||||||
<< "Valid patches are " << patches.names()
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
newPatches.append(patchI);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,111 +227,112 @@ int main(int argc, char *argv[])
|
|||||||
polyTopoChange meshMod(mesh);
|
polyTopoChange meshMod(mesh);
|
||||||
|
|
||||||
|
|
||||||
// Do the actual changes
|
// Do the actual changes. Note:
|
||||||
// Note order in which faces are modified/added is so they end up correctly
|
// - loop in incrementing face order (not necessary if faceZone ordered).
|
||||||
// for cyclic patches (original faces first and then reversed faces)
|
// Preserves any existing ordering on patch faces.
|
||||||
// since otherwise it will have trouble matching baffles.
|
// - two passes, do non-flip faces first and flip faces second. This
|
||||||
|
// guarantees that when e.g. creating a cyclic all faces from one
|
||||||
|
// side come first and faces from the other side next.
|
||||||
|
|
||||||
label nBaffled = 0;
|
PackedBoolList modifiedFace(mesh.nFaces());
|
||||||
|
|
||||||
forAll(newPatches, i)
|
forAll(newPatches, i)
|
||||||
{
|
{
|
||||||
label newPatchI = newPatches[i];
|
label newPatchI = newPatches[i];
|
||||||
|
|
||||||
|
// Pass 1. Do selected side of zone
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
|
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
|
||||||
{
|
{
|
||||||
if (facesToSplit.found(faceI))
|
label zoneFaceI = fZone.whichFace(faceI);
|
||||||
{
|
|
||||||
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)];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 0)
|
if (zoneFaceI != -1)
|
||||||
{
|
{
|
||||||
// First usage of face. Modify.
|
if (!fZone.flipMap()[zoneFaceI])
|
||||||
meshMod.setAction
|
{
|
||||||
|
// Use owner side of face
|
||||||
|
modifyOrAddFace
|
||||||
(
|
(
|
||||||
polyModifyFace
|
meshMod,
|
||||||
(
|
mesh.faces()[faceI], // modified face
|
||||||
f, // modified face
|
|
||||||
faceI, // label of face
|
faceI, // label of face
|
||||||
mesh.faceOwner()[faceI], // owner
|
mesh.faceOwner()[faceI],// owner
|
||||||
-1, // neighbour
|
|
||||||
false, // face flip
|
false, // face flip
|
||||||
newPatchI, // patch for face
|
newPatchI, // patch for face
|
||||||
false, // remove from zone
|
zoneID.index(), // zone for face
|
||||||
zoneID, // zone for face
|
false, // face flip in zone
|
||||||
zoneFlip // face flip in zone
|
modifiedFace // modify or add status
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Second or more usage of face. Add.
|
// Use neighbour side of face
|
||||||
meshMod.setAction
|
modifyOrAddFace
|
||||||
(
|
(
|
||||||
polyAddFace
|
meshMod,
|
||||||
(
|
mesh.faces()[faceI].reverseFace(), // modified face
|
||||||
f, // modified face
|
faceI, // label of face
|
||||||
mesh.faceOwner()[faceI], // owner
|
mesh.faceNeighbour()[faceI],// owner
|
||||||
-1, // neighbour
|
|
||||||
-1, // master point
|
|
||||||
-1, // master edge
|
|
||||||
faceI, // master face
|
|
||||||
false, // face flip
|
|
||||||
newPatchI, // patch for face
|
|
||||||
zoneID, // zone for face
|
|
||||||
zoneFlip // face flip in zone
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
nBaffled++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the reversed face.
|
|
||||||
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
|
|
||||||
{
|
|
||||||
if (facesToSplit.found(faceI))
|
|
||||||
{
|
|
||||||
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 = mesh.faceNeighbour()[faceI];
|
|
||||||
|
|
||||||
meshMod.setAction
|
|
||||||
(
|
|
||||||
polyAddFace
|
|
||||||
(
|
|
||||||
f.reverseFace(), // modified face
|
|
||||||
nei, // owner
|
|
||||||
-1, // neighbour
|
|
||||||
-1, // masterPointID
|
|
||||||
-1, // masterEdgeID
|
|
||||||
faceI, // masterFaceID,
|
|
||||||
true, // face flip
|
true, // face flip
|
||||||
newPatchI, // patch for face
|
newPatchI, // patch for face
|
||||||
zoneID, // zone for face
|
zoneID.index(), // zone for face
|
||||||
zoneFlip // face flip in zone
|
true, // face flip in zone
|
||||||
)
|
modifiedFace // modify or add status
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nBaffled++;
|
|
||||||
|
// Pass 2. Do other side of zone
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
|
||||||
|
{
|
||||||
|
label zoneFaceI = fZone.whichFace(faceI);
|
||||||
|
|
||||||
|
if (zoneFaceI != -1)
|
||||||
|
{
|
||||||
|
if (!fZone.flipMap()[zoneFaceI])
|
||||||
|
{
|
||||||
|
// Use neighbour side of face
|
||||||
|
modifyOrAddFace
|
||||||
|
(
|
||||||
|
meshMod,
|
||||||
|
mesh.faces()[faceI].reverseFace(), // modified face
|
||||||
|
faceI, // label of face
|
||||||
|
mesh.faceNeighbour()[faceI], // owner
|
||||||
|
true, // face flip
|
||||||
|
newPatchI, // patch for face
|
||||||
|
zoneID.index(), // zone for face
|
||||||
|
true, // face flip in zone
|
||||||
|
modifiedFace // modify or add
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Use owner side of face
|
||||||
|
modifyOrAddFace
|
||||||
|
(
|
||||||
|
meshMod,
|
||||||
|
mesh.faces()[faceI], // modified face
|
||||||
|
faceI, // label of face
|
||||||
|
mesh.faceOwner()[faceI],// owner
|
||||||
|
false, // face flip
|
||||||
|
newPatchI, // patch for face
|
||||||
|
zoneID.index(), // zone for face
|
||||||
|
false, // face flip in zone
|
||||||
|
modifiedFace // modify or add status
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Modify any boundary faces
|
// Modify any boundary faces
|
||||||
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
forAll(patches, patchI)
|
forAll(patches, patchI)
|
||||||
{
|
{
|
||||||
const polyPatch& pp = patches[patchI];
|
const polyPatch& pp = patches[patchI];
|
||||||
@ -286,66 +348,30 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
label faceI = pp.start()+i;
|
label faceI = pp.start()+i;
|
||||||
|
|
||||||
if (facesToSplit.found(faceI))
|
label zoneFaceI = fZone.whichFace(faceI);
|
||||||
{
|
|
||||||
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)];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 0)
|
if (zoneFaceI != -1)
|
||||||
{
|
{
|
||||||
// First usage of face. Modify.
|
modifyOrAddFace
|
||||||
meshMod.setAction
|
|
||||||
(
|
(
|
||||||
polyModifyFace
|
meshMod,
|
||||||
(
|
mesh.faces()[faceI], // modified face
|
||||||
f, // modified face
|
|
||||||
faceI, // label of face
|
faceI, // label of face
|
||||||
mesh.faceOwner()[faceI],// owner
|
mesh.faceOwner()[faceI], // owner
|
||||||
-1, // neighbour
|
|
||||||
false, // face flip
|
false, // face flip
|
||||||
newPatchI, // patch for face
|
newPatchI, // patch for face
|
||||||
false, // remove from zone
|
zoneID.index(), // zone for face
|
||||||
zoneID, // zone for face
|
fZone.flipMap()[zoneFaceI], // face flip in zone
|
||||||
zoneFlip // face flip in zone
|
modifiedFace // modify or add status
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
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
|
|
||||||
newPatchI, // patch for face
|
|
||||||
zoneID, // zone for face
|
|
||||||
zoneFlip // face flip in zone
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
nBaffled++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Info<< "Converted " << returnReduce(nBaffled, sumOp<label>())
|
Info<< "Converted " << returnReduce(modifiedFace.count(), sumOp<label>())
|
||||||
<< " faces into boundary faces on patch " << patchName << nl << endl;
|
<< " faces into boundary faces on patch " << patchName << nl << endl;
|
||||||
|
|
||||||
if (!overwrite)
|
if (!overwrite)
|
||||||
|
|||||||
@ -1,24 +1,23 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Source tutorial run functions
|
||||||
|
. $WM_PROJECT_DIR/bin/tools/RunFunctions
|
||||||
|
|
||||||
|
application="porousExplicitSourceReactingParcelFoam"
|
||||||
|
|
||||||
# create mesh
|
# create mesh
|
||||||
blockMesh >& log.blockMesh
|
runApplication blockMesh
|
||||||
|
|
||||||
# create sets - 1
|
# create sets
|
||||||
setSet -batch system/sets.setSet >& log.setSet1
|
setSet -batch system/sets.setSet >& log.setSet1
|
||||||
|
|
||||||
# create the first cyclic - lhs of porous zone
|
|
||||||
createBaffles cycLeft cycLeft -overwrite >& log.createBaffles1
|
|
||||||
|
|
||||||
# create sets - 2 (ordering changed after createBaffles)
|
|
||||||
setSet -batch system/sets.setSet >& log.setSet2
|
|
||||||
|
|
||||||
# create the second cyclic - rhs of porous zone
|
|
||||||
createBaffles cycRight cycRight -overwrite >& log.createBaffles2
|
|
||||||
|
|
||||||
# create sets - 3 (ordering changed after createBaffles)
|
|
||||||
setSet -batch system/sets.setSet >& log.setSet3
|
|
||||||
|
|
||||||
# convert sets to zones
|
# convert sets to zones
|
||||||
setsToZones -noFlipMap >& log.setsToZones
|
setsToZones -noFlipMap >& log.setsToZones
|
||||||
|
|
||||||
|
# create the first cyclic - lhs of porous zone
|
||||||
|
createBaffles cycLeft cycLeft -overwrite >& log.createBaffles1
|
||||||
|
|
||||||
|
# create the second cyclic - rhs of porous zone
|
||||||
|
createBaffles cycRight cycRight -overwrite >& log.createBaffles2
|
||||||
|
|
||||||
|
runApplication $application
|
||||||
|
|||||||
Reference in New Issue
Block a user