openfoam/applications/utilities/surface/surfaceRemoveBaffles/surfaceRemoveBaffles.C

173 lines
4.7 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
Strips any baffle parts of a surface. A baffle region is one which is
reached by walking from an open edge, and stopping when a multiply connected
edge is reached.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "triSurface.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validArgs.clear();
argList::validArgs.append("input surface file");
argList::validArgs.append("output surface file");
argList args(argc, argv);
fileName surfFileName(args.additionalArgs()[0]);
Info<< "Reading surface from " << surfFileName << endl;
fileName outFileName(args.additionalArgs()[1]);
fileName outFileBaseName = outFileName.lessExt();
word outExtension = outFileName.ext();
// Load surface
triSurface surf(surfFileName);
bool anyZoneRemoved = false;
label iterationNo = 0;
label iterationLimit = 10;
do
{
anyZoneRemoved = false;
labelList faceZone;
const labelListList& edFaces = surf.edgeFaces();
const labelListList& faceEds = surf.faceEdges();
boolList multipleEdges(edFaces.size(), false);
forAll(multipleEdges, i)
{
if (edFaces[i].size() > 2)
{
multipleEdges[i] = true;
}
}
label nZones = surf.markZones(multipleEdges, faceZone);
if (nZones < 2)
{
break;
}
boolList nonBaffle(faceZone.size(), true);
boolList baffle(faceZone.size(), true);
labelList pointMap;
labelList faceMap;
for (label z = 0; z < nZones; z++)
{
bool keepZone = true;
forAll(faceZone, f)
{
if (faceZone[f] == z)
{
forAll (faceEds[f], fe)
{
if (edFaces[faceEds[f][fe]].size() < 2)
{
keepZone = false;
anyZoneRemoved = true;
break;
}
}
}
if (!keepZone)
{
break;
}
}
forAll(faceZone, f)
{
if (faceZone[f] == z)
{
nonBaffle[f] = keepZone;
baffle[f] = !keepZone;
}
}
}
Info<< " Iteration " << iterationNo << endl;
triSurface baffleSurf = surf.subsetMesh(baffle, pointMap, faceMap);
if (baffleSurf.size())
{
fileName bafflePartFileName =
outFileBaseName
+ "_bafflePart_"
+ name(iterationNo)
+ "." + outExtension;
Info<< " Writing baffle part to " << bafflePartFileName << endl;
baffleSurf.write(bafflePartFileName);
}
surf = surf.subsetMesh(nonBaffle, pointMap, faceMap);
if (iterationNo == iterationLimit)
{
WarningIn("surfaceRemoveBaffles")
<< "Iteration limit of " << iterationLimit << "reached" << endl;
}
iterationNo++;
} while (anyZoneRemoved && iterationNo < iterationLimit);
Info<< "Writing new surface to " << outFileName << endl;
surf.write(outFileName);
Info << "End\n" << endl;
return 0;
}
// ************************************************************************* //