400 lines
12 KiB
C
400 lines
12 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
|
\\/ M anipulation |
|
|
-------------------------------------------------------------------------------
|
|
License
|
|
This file is part of OpenFOAM.
|
|
|
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
option) any later version.
|
|
|
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
Description
|
|
Makes internal faces into boundary faces. Does not duplicate points. Use
|
|
mergeOrSplitBaffles if you want this.
|
|
|
|
Note: if any coupled patch face is selected for baffling automatically
|
|
the opposite member is selected for baffling as well. Note that this
|
|
is the same as repatching. This was added only for convenience so
|
|
you don't have to filter coupled boundary out of your set.
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
#include "syncTools.H"
|
|
#include "argList.H"
|
|
#include "Time.H"
|
|
#include "faceSet.H"
|
|
#include "polyTopoChange.H"
|
|
#include "polyModifyFace.H"
|
|
#include "polyAddFace.H"
|
|
#include "ReadFields.H"
|
|
#include "volFields.H"
|
|
#include "surfaceFields.H"
|
|
|
|
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"
|
|
# include "createTime.H"
|
|
runTime.functionObjects().off();
|
|
# include "createMesh.H"
|
|
const word oldInstance = mesh.pointsInstance();
|
|
|
|
const polyBoundaryMesh& patches = mesh.boundaryMesh();
|
|
|
|
// 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;
|
|
|
|
|
|
// Patches to put baffles into
|
|
DynamicList<label> newPatches(1);
|
|
|
|
word patchName(args.additionalArgs()[1]);
|
|
newPatches.append(patches.findPatchID(patchName));
|
|
Pout<< "Using patch " << patchName
|
|
<< " 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
|
|
if (args.options().found("additionalPatches"))
|
|
{
|
|
const wordList patchNames
|
|
(
|
|
IStringStream(args.options()["additionalPatches"])()
|
|
);
|
|
|
|
newPatches.reserve(patchNames.size() + 1);
|
|
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());
|
|
|
|
// Read vol fields.
|
|
|
|
PtrList<volScalarField> vsFlds;
|
|
ReadFields(mesh, objects, vsFlds);
|
|
|
|
PtrList<volVectorField> vvFlds;
|
|
ReadFields(mesh, objects, vvFlds);
|
|
|
|
PtrList<volSphericalTensorField> vstFlds;
|
|
ReadFields(mesh, objects, vstFlds);
|
|
|
|
PtrList<volSymmTensorField> vsymtFlds;
|
|
ReadFields(mesh, objects, vsymtFlds);
|
|
|
|
PtrList<volTensorField> vtFlds;
|
|
ReadFields(mesh, objects, vtFlds);
|
|
|
|
// Read surface fields.
|
|
|
|
PtrList<surfaceScalarField> ssFlds;
|
|
ReadFields(mesh, objects, ssFlds);
|
|
|
|
PtrList<surfaceVectorField> svFlds;
|
|
ReadFields(mesh, objects, svFlds);
|
|
|
|
PtrList<surfaceSphericalTensorField> sstFlds;
|
|
ReadFields(mesh, objects, sstFlds);
|
|
|
|
PtrList<surfaceSymmTensorField> ssymtFlds;
|
|
ReadFields(mesh, objects, ssymtFlds);
|
|
|
|
PtrList<surfaceTensorField> stFlds;
|
|
ReadFields(mesh, objects, stFlds);
|
|
|
|
|
|
// Mesh change container
|
|
polyTopoChange meshMod(mesh);
|
|
|
|
|
|
// Do the actual changes
|
|
|
|
label nBaffled = 0;
|
|
PackedBoolList doneFace(mesh.nFaces());
|
|
|
|
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
|
|
{
|
|
if (facesToSplit.found(faceI))
|
|
{
|
|
createBaffles
|
|
(
|
|
mesh,
|
|
faceI,
|
|
-1, // oldPatchI,
|
|
newPatches,
|
|
doneFace,
|
|
meshMod
|
|
);
|
|
nBaffled++;
|
|
}
|
|
}
|
|
forAll(patches, patchI)
|
|
{
|
|
const polyPatch& pp = patches[patchI];
|
|
|
|
forAll(pp, i)
|
|
{
|
|
label faceI = pp.start()+i;
|
|
|
|
if (facesToSplit.found(faceI))
|
|
{
|
|
createBaffles
|
|
(
|
|
mesh,
|
|
faceI,
|
|
patchI, // oldPatchI,
|
|
newPatches,
|
|
doneFace,
|
|
meshMod
|
|
);
|
|
nBaffled++;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Info<< "Converted " << returnReduce(nBaffled, sumOp<label>())
|
|
<< " faces into boundary faces on patch " << patchName << nl << endl;
|
|
|
|
if (!overwrite)
|
|
{
|
|
runTime++;
|
|
}
|
|
|
|
// Change the mesh. Change points directly (no inflation).
|
|
autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
|
|
|
|
// Update fields
|
|
mesh.updateMesh(map);
|
|
|
|
// Move mesh (since morphing might not do this)
|
|
if (map().hasMotionPoints())
|
|
{
|
|
mesh.movePoints(map().preMotionPoints());
|
|
}
|
|
|
|
if (overwrite)
|
|
{
|
|
mesh.setInstance(oldInstance);
|
|
}
|
|
Info<< "Writing mesh to " << runTime.timeName() << endl;
|
|
|
|
mesh.write();
|
|
|
|
Info<< "End\n" << endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
// ************************************************************************* //
|