FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

foamToStarMesh.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     foamToStarMesh
00026 
00027 Description
00028     Reads an OpenFOAM mesh and writes a pro-STAR (v4) bnd/cel/vrt format.
00029 
00030 Usage
00031     - foamToStarMesh [OPTION] \n
00032     Reads an OpenFOAM mesh and writes a pro-STAR (v4) bnd/cel/vrt format.
00033 
00034     @param -noBnd \n
00035     Suppress writing the @c .bnd file.
00036 
00037     @param -scale <factor>\n
00038     Specify an alternative geometry scaling factor.
00039     The default is @b 1000 (scale @em [m] to @em [mm]).
00040 
00041     @param -surface \n
00042     Extract the surface of the volume mesh only.
00043     This can be useful, for example, for surface morphing in an external
00044     package.
00045 
00046     @param -tri \n
00047     Extract a triangulated surface.
00048     The @b -surface options is implicitly selected.
00049 
00050     @param -case <dir> \n
00051     Case directory.
00052 
00053     @param -noZero \n
00054     Ignore time step 0.
00055 
00056     @param -constant \n
00057     Include the constant directory.
00058 
00059     @param -latestTime \n
00060     Only apply to the latest time step.
00061 
00062     @param -time <time>\n
00063     Apply only to specified time.
00064 
00065     @param -help \n
00066     Display help message.
00067 
00068     @param -doc \n
00069     Display Doxygen API documentation page for this application.
00070 
00071     @param -srcDoc \n
00072     Display Doxygen source documentation page for this application.
00073 
00074 Note
00075     The cellTable information available in the files
00076     @c constant/cellTable and @c constant/polyMesh/cellTableId
00077     will be used if available. Otherwise the cellZones are used when
00078     creating the cellTable information.
00079 
00080 See Also
00081     Foam::cellTable, Foam::meshWriter and Foam::meshWriters::STARCD
00082 
00083 \*---------------------------------------------------------------------------*/
00084 
00085 #include <OpenFOAM/argList.H>
00086 #include <OpenFOAM/timeSelector.H>
00087 #include <OpenFOAM/Time.H>
00088 #include <OpenFOAM/polyMesh.H>
00089 #include <conversion/STARCDMeshWriter.H>
00090 
00091 using namespace Foam;
00092 
00093 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00094 // Main program:
00095 
00096 int main(int argc, char *argv[])
00097 {
00098     argList::noParallel();
00099     timeSelector::addOptions();
00100 
00101     argList::validOptions.insert("scale", "scale");
00102     argList::validOptions.insert("noBnd", "");
00103     argList::validOptions.insert("tri", "");
00104     argList::validOptions.insert("surface", "");
00105 
00106 #   include <OpenFOAM/setRootCase.H>
00107 #   include <OpenFOAM/createTime.H>
00108 
00109     instantList timeDirs = timeSelector::select0(runTime, args);
00110 
00111     bool surfaceOnly = false;
00112     if (args.optionFound("surface") || args.optionFound("tri"))
00113     {
00114         surfaceOnly = true;
00115     }
00116 
00117     fileName exportName = meshWriter::defaultMeshName;
00118     if (surfaceOnly)
00119     {
00120         exportName = meshWriter::defaultSurfaceName;
00121     }
00122 
00123     if (args.optionFound("case"))
00124     {
00125         exportName += '-' + args.globalCaseName();
00126     }
00127 
00128     // default: rescale from [m] to [mm]
00129     scalar scaleFactor = 1000;
00130     if (args.optionReadIfPresent("scale", scaleFactor))
00131     {
00132         if (scaleFactor <= 0)
00133         {
00134             scaleFactor = 1;
00135         }
00136     }
00137 
00138 #   include <OpenFOAM/createPolyMesh.H>
00139 
00140 
00141     forAll(timeDirs, timeI)
00142     {
00143         runTime.setTime(timeDirs[timeI], timeI);
00144 
00145 #       include "getTimeIndex.H"
00146 
00147         polyMesh::readUpdateState state = mesh.readUpdate();
00148 
00149         if (!timeI || state != polyMesh::UNCHANGED)
00150         {
00151             meshWriters::STARCD writer(mesh, scaleFactor);
00152 
00153             if (args.optionFound("noBnd"))
00154             {
00155                 writer.noBoundary();
00156             }
00157 
00158             fileName meshName(exportName);
00159             if (state != polyMesh::UNCHANGED)
00160             {
00161                 meshName += '_' + runTime.timeName();
00162             }
00163 
00164             if (surfaceOnly)
00165             {
00166                 if (args.optionFound("tri"))
00167                 {
00168                     writer.writeSurface(meshName, true);
00169                 }
00170                 else
00171                 {
00172                     writer.writeSurface(meshName);
00173                 }
00174             }
00175             else
00176             {
00177                 writer.write(meshName);
00178             }
00179         }
00180 
00181         Info<< nl << endl;
00182     }
00183 
00184     Info<< "End\n" << endl;
00185 
00186     return 0;
00187 }
00188 
00189 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines