initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / conversion / foamToStarMesh / foamToStarMesh.C
blobb36ec777694b35d4a640212171062ad026020254
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Application
26     foamToStarMesh
28 Description
29     Reads an OpenFOAM mesh and writes a pro-STAR (v4) bnd/cel/vrt format.
31 Usage
32     - foamToStarMesh [OPTION] \n
33     Reads an OpenFOAM mesh and writes a pro-STAR (v4) bnd/cel/vrt format.
35     @param -noBnd \n
36     Suppress writing the @c .bnd file
38     @param -scale \<factor\>\n
39     Specify an alternative geometry scaling factor.
40     The default is @b 1000 (scale @em [m] to @em [mm]).
42     @param -surface \n
43     Extract the surface of the volume mesh only.
44     This can be useful, for example, for surface morphing in an external
45     package.
47     @param -tri \n
48     Extract a triangulated surface.
49     The @b -surface options is implicitly selected.
52 Note
53     The cellTable information available in the files
54     @c constant/cellTable and @c constant/polyMesh/cellTableId
55     will be used if available. Otherwise the cellZones are used when
56     creating the cellTable information.
58 See Also
59     Foam::cellTable, Foam::meshWriter and Foam::meshWriters::STARCD
61 \*---------------------------------------------------------------------------*/
63 #include "argList.H"
64 #include "timeSelector.H"
65 #include "Time.H"
66 #include "polyMesh.H"
67 #include "STARCDMeshWriter.H"
69 using namespace Foam;
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 // Main program:
74 int main(int argc, char *argv[])
76     argList::noParallel();
77     timeSelector::addOptions();
79     argList::validOptions.insert("scale", "scale");
80     argList::validOptions.insert("noBnd", "");
81     argList::validOptions.insert("tri", "");
82     argList::validOptions.insert("surface", "");
84 #   include "setRootCase.H"
85 #   include "createTime.H"
87     instantList timeDirs = timeSelector::select0(runTime, args);
89     bool surfaceOnly = false;
90     if (args.optionFound("surface") || args.optionFound("tri"))
91     {
92         surfaceOnly = true;
93     }
95     fileName exportName = meshWriter::defaultMeshName;
96     if (surfaceOnly)
97     {
98         exportName = meshWriter::defaultSurfaceName;
99     }
101     if (args.optionFound("case"))
102     {
103         exportName += '-' + args.globalCaseName();
104     }
106     // default: rescale from [m] to [mm]
107     scalar scaleFactor = 1000;
108     if (args.optionReadIfPresent("scale", scaleFactor))
109     {
110         if (scaleFactor <= 0)
111         {
112             scaleFactor = 1;
113         }
114     }
116 #   include "createPolyMesh.H"
119     forAll(timeDirs, timeI)
120     {
121         runTime.setTime(timeDirs[timeI], timeI);
123 #       include "getTimeIndex.H"
125         polyMesh::readUpdateState state = mesh.readUpdate();
127         if (!timeI || state != polyMesh::UNCHANGED)
128         {
129             meshWriters::STARCD writer(mesh, scaleFactor);
131             if (args.optionFound("noBnd"))
132             {
133                 writer.noBoundary();
134             }
136             fileName meshName(exportName);
137             if (state != polyMesh::UNCHANGED)
138             {
139                 meshName += '_' + runTime.timeName();
140             }
142             if (surfaceOnly)
143             {
144                 if (args.optionFound("tri"))
145                 {
146                     writer.writeSurface(meshName, true);
147                 }
148                 else
149                 {
150                     writer.writeSurface(meshName);
151                 }
152             }
153             else
154             {
155                 writer.write(meshName);
156             }
157         }
159         Info<< nl << endl;
160     }
162     Info<< "End\n" << endl;
164     return 0;
167 // ************************************************************************* //