From 7a200e81b4a1cade5c00d388fd64d9da3a8f486e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 15 Jan 2010 16:20:06 +0100 Subject: [PATCH] Add foamToSurface to dev repository. - Extracts the boundary faces of a polyMesh to a meshedSurface and writes in various possible formats. --- .../mesh/conversion/foamToSurface/Make/files | 3 + .../conversion/foamToSurface/Make/options | 5 + .../conversion/foamToSurface/foamToSurface.C | 129 ++++++++++++++++++ .../conversion/foamToSurface/getTimeIndex.H | 51 +++++++ 4 files changed, 188 insertions(+) create mode 100644 applications/utilities/mesh/conversion/foamToSurface/Make/files create mode 100644 applications/utilities/mesh/conversion/foamToSurface/Make/options create mode 100644 applications/utilities/mesh/conversion/foamToSurface/foamToSurface.C create mode 100644 applications/utilities/mesh/conversion/foamToSurface/getTimeIndex.H diff --git a/applications/utilities/mesh/conversion/foamToSurface/Make/files b/applications/utilities/mesh/conversion/foamToSurface/Make/files new file mode 100644 index 0000000000..a5dfd1e846 --- /dev/null +++ b/applications/utilities/mesh/conversion/foamToSurface/Make/files @@ -0,0 +1,3 @@ +foamToSurface.C + +EXE = $(FOAM_APPBIN)/foamToSurface diff --git a/applications/utilities/mesh/conversion/foamToSurface/Make/options b/applications/utilities/mesh/conversion/foamToSurface/Make/options new file mode 100644 index 0000000000..a504dd8617 --- /dev/null +++ b/applications/utilities/mesh/conversion/foamToSurface/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/surfMesh/lnInclude + +EXE_LIBS = \ + -lsurfMesh diff --git a/applications/utilities/mesh/conversion/foamToSurface/foamToSurface.C b/applications/utilities/mesh/conversion/foamToSurface/foamToSurface.C new file mode 100644 index 0000000000..f9a255c502 --- /dev/null +++ b/applications/utilities/mesh/conversion/foamToSurface/foamToSurface.C @@ -0,0 +1,129 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 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 + +Application + foamToSurface + +Description + Reads an OpenFOAM mesh and writes the boundaries in a surface format. + +Usage + - foamToSurface [OPTION] \n + Reads an OpenFOAM mesh and writes the boundaries in a surface format. + + @param -scale \\n + Specify an alternative geometry scaling factor. + Eg, use @b 1000 to scale @em [m] to @em [mm]. + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "timeSelector.H" +#include "Time.H" +#include "polyMesh.H" + +#include "MeshedSurfaces.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Main program: + +int main(int argc, char *argv[]) +{ + argList::noParallel(); + argList::validArgs.append("outputFile.ext"); + timeSelector::addOptions(); + + argList::addOption + ( + "scale", + "scale", + "specify geometry scaling factor" + ); + +# include "setRootCase.H" + + const stringList& params = args.additionalArgs(); + + scalar scaleFactor = 0; + args.optionReadIfPresent("scale", scaleFactor); + + fileName exportName(params[0]); + + fileName exportBase = exportName.lessExt(); + word exportExt = exportName.ext(); + + if (!meshedSurface::canWriteType(exportExt, true)) + { + return 1; + } + +# include "createTime.H" + instantList timeDirs = timeSelector::select0(runTime, args); +# include "createPolyMesh.H" + + forAll(timeDirs, timeI) + { + runTime.setTime(timeDirs[timeI], timeI); +# include "getTimeIndex.H" + + polyMesh::readUpdateState state = mesh.readUpdate(); + + if (timeI == 0 || state != polyMesh::UNCHANGED) + { + if (state == polyMesh::UNCHANGED) + { + exportName = exportBase + "." + exportExt; + } + else + { + exportName = + exportBase + '_' + runTime.timeName() + "." + exportExt; + } + + meshedSurface surf(mesh.boundaryMesh()); + surf.scalePoints(scaleFactor); + + Info<< "writing " << exportName; + if (scaleFactor <= 0) + { + Info<< " without scaling" << endl; + } + else + { + Info<< " with scaling " << scaleFactor << endl; + } + surf.write(exportName); + } + + Info<< nl << endl; + } + + Info<< "End\n" << endl; + + return 0; +} + +// ************************************************************************* // diff --git a/applications/utilities/mesh/conversion/foamToSurface/getTimeIndex.H b/applications/utilities/mesh/conversion/foamToSurface/getTimeIndex.H new file mode 100644 index 0000000000..85a92405dd --- /dev/null +++ b/applications/utilities/mesh/conversion/foamToSurface/getTimeIndex.H @@ -0,0 +1,51 @@ +// Read time index from */uniform/time, but treat 0 and constant specially + + word timeName = "0"; + + if + ( + runTime.timeName() != "constant" + && runTime.timeName() != "0" + ) + { + IOobject io + ( + "time", + runTime.timeName(), + "uniform", + runTime, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE, + false + ); + + if (io.headerOk()) + { + IOdictionary timeObject + ( + IOobject + ( + "time", + runTime.timeName(), + "uniform", + runTime, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ) + ); + + label index; + timeObject.lookup("index") >> index; + timeName = Foam::name(index); + } + else + { + timeName = runTime.timeName(); + // Info<< "skip ... missing entry " << io.objectPath() << endl; + // continue; + } + } + + Info<< "\nTime [" << timeName << "] = " << runTime.timeName() << nl; +