BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / utilities / mesh / conversion / foamToSurface / foamToSurface.C
blobe95fc1efb54efc6c636463d76ef87be6694683c3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 Application
25     foamToSurface
27 Description
28     Reads an OpenFOAM mesh and writes the boundaries in a surface format.
30 Usage
31     - foamToSurface [OPTION] \n
32     Reads an OpenFOAM mesh and writes the boundaries in a surface format.
34     \param -scale \<factor\>\n
35     Specify an alternative geometry scaling factor.
36     Eg, use \b 1000 to scale \em [m] to \em [mm].
38     \param -tri \n
39     Triangulate surface.
41 \*---------------------------------------------------------------------------*/
43 #include "argList.H"
44 #include "timeSelector.H"
45 #include "Time.H"
46 #include "polyMesh.H"
48 #include "MeshedSurfaces.H"
50 using namespace Foam;
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 // Main program:
55 int main(int argc, char *argv[])
57     argList::noParallel();
58     argList::validArgs.append("outputFile.ext");
59     timeSelector::addOptions();
61     argList::addOption
62     (
63         "scale",
64         "factor",
65         "geometry scaling factor - default is 1"
66     );
67     argList::addBoolOption
68     (
69         "tri",
70         "triangulate surface"
71     );
73 #   include "setRootCase.H"
75     fileName exportName = args[1];
77     scalar scaleFactor = 0;
78     args.optionReadIfPresent<scalar>("scale", scaleFactor);
79     const bool doTriangulate = args.optionFound("tri");
81     fileName exportBase = exportName.lessExt();
82     word exportExt = exportName.ext();
84     if (!meshedSurface::canWriteType(exportExt, true))
85     {
86         return 1;
87     }
89 #   include "createTime.H"
90     instantList timeDirs = timeSelector::select0(runTime, args);
91 #   include "createPolyMesh.H"
93     forAll(timeDirs, timeI)
94     {
95         runTime.setTime(timeDirs[timeI], timeI);
96 #       include "getTimeIndex.H"
98         polyMesh::readUpdateState state = mesh.readUpdate();
100         if (timeI == 0 || state != polyMesh::UNCHANGED)
101         {
102             if (state == polyMesh::UNCHANGED)
103             {
104                 exportName = exportBase + "." + exportExt;
105             }
106             else
107             {
108                 exportName =
109                     exportBase + '_' + runTime.timeName() + "." + exportExt;
110             }
112             meshedSurface surf(mesh.boundaryMesh());
113             surf.scalePoints(scaleFactor);
115             Info<< "writing " << exportName;
116             if (doTriangulate)
117             {
118                 Info<< " triangulated";
119                 surf.triangulate();
120             }
122             if (scaleFactor <= 0)
123             {
124                 Info<< " without scaling" << endl;
125             }
126             else
127             {
128                 Info<< " with scaling " << scaleFactor << endl;
129             }
130             surf.write(exportName);
131         }
133         Info<< nl << endl;
134     }
136     Info<< "End\n" << endl;
138     return 0;
141 // ************************************************************************* //