/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.0
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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 3 of the License, or (at your
option) any later version.
foam-extend 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 foam-extend. If not, see .
Description
Extracts triSurface from a polyMesh. Triangulates all boundary faces.
Region numbers on triangles are the patch numbers of the polyMesh.
Optionally only triangulates named patches.
If run in parallel the processor patches get filtered out by default and
the mesh gets merged. (based on vertex position, not topology, so might go
wrong!).
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "objectRegistry.H"
#include "foamTime.H"
#include "polyMesh.H"
#include "triSurface.H"
#include "triSurfaceTools.H"
#include "processorPolyPatch.H"
#include "ListListOps.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::validArgs.append("output file");
# include "addRegionOption.H"
argList::validOptions.insert("excludeProcPatches", "");
argList::validOptions.insert("patches", "(patch0 .. patchN)");
# include "setRootCase.H"
# include "createTime.H"
fileName outFileName(runTime.path()/args.additionalArgs()[0]);
Info<< "Extracting triSurface from boundaryMesh ..."
<< endl << endl;
Pout<< "Reading mesh from time " << runTime.value() << endl;
# include "createNamedPolyMesh.H"
bool includeProcPatches =
!(
args.optionFound("excludeProcPatches")
|| Pstream::parRun()
);
// Create local surface from:
// - explicitly named patches only (-patches option)
// - all patches (default in sequential mode)
// - all non-processor patches (default in parallel mode)
// - all non-processor patches (sequential mode, -excludeProcPatches option)
// Construct table of patches to include.
const polyBoundaryMesh& bMesh = mesh.boundaryMesh();
labelHashSet includePatches(bMesh.size());
if (args.optionFound("patches"))
{
wordList patchNames(args.optionLookup("patches")());
forAll(patchNames, patchNameI)
{
const word& patchName = patchNames[patchNameI];
label patchI = bMesh.findPatchID(patchName);
if (patchI == -1)
{
FatalErrorIn(args.executable()) << "No such patch "
<< patchName << endl << "Patches are " << bMesh.names()
<< exit(FatalError);
}
includePatches.insert(patchI);
}
}
else
{
forAll(bMesh, patchI)
{
const polyPatch& patch = bMesh[patchI];
if (includeProcPatches || !isA(patch))
{
includePatches.insert(patchI);
}
else
{
Pout<< patch.name() << " : skipped since processorPatch"
<< endl;
}
}
}
triSurface localSurface
(
triSurfaceTools::triangulate
(
mesh.boundaryMesh(),
includePatches
)
);
if (!Pstream::parRun())
{
Info<< "Writing surface to " << outFileName << endl;
localSurface.write(outFileName);
}
else
{
// Write local surface
fileName localPath = runTime.path()/runTime.caseName() + ".ftr";
Pout<< "Writing local surface to " << localPath << endl;
localSurface.write(localPath);
Info<< endl;
// Gather all points on master
List gatheredPoints(Pstream::nProcs());
gatheredPoints[Pstream::myProcNo()] = localSurface.points();
Pstream::gatherList(gatheredPoints);
// Gather all localSurface patches
List gatheredPatches(Pstream::nProcs());
gatheredPatches[Pstream::myProcNo()] = localSurface.patches();
Pstream::gatherList(gatheredPatches);
// Gather all faces
List > gatheredFaces(Pstream::nProcs());
gatheredFaces[Pstream::myProcNo()] = localSurface;
Pstream::gatherList(gatheredFaces);
if (Pstream::master())
{
// On master combine all points
pointField allPoints =
ListListOps::combine
(
gatheredPoints,
accessOp()
);
// Count number of patches.
label nPatches = 0;
forAll(gatheredPatches, procI)
{
nPatches += gatheredPatches[procI].size();
}
// Count number of faces.
label nFaces = 0;
forAll(gatheredFaces, procI)
{
nFaces += gatheredFaces[procI].size();
}
// Loop over all processors and
// - construct mapping from local to global patches
// - relabel faces (both points and regions)
label newPatchI = 0;
// Name to new patchI
HashTable