OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Application
00026     foamToStarMesh
00027 
00028 Description
00029     Reads an OpenFOAM mesh and writes a pro-STAR (v4) bnd/cel/vrt format.
00030 
00031 Usage
00032     - foamToStarMesh [OPTION] \n
00033     Reads an OpenFOAM mesh and writes a pro-STAR (v4) bnd/cel/vrt format.
00034 
00035     @param -noBnd \n
00036     Suppress writing the @c .bnd file
00037 
00038     @param -scale <factor>\n
00039     Specify an alternative geometry scaling factor.
00040     The default is @b 1000 (scale @em [m] to @em [mm]).
00041 
00042     @param -surface \n
00043     Extract the surface of the volume mesh only.
00044     This can be useful, for example, for surface morphing in an external
00045     package.
00046 
00047     @param -tri \n
00048     Extract a triangulated surface.
00049     The @b -surface options is implicitly selected.
00050 
00051 
00052 Note
00053     The cellTable information available in the files
00054     @c constant/cellTable and @c constant/polyMesh/cellTableId
00055     will be used if available. Otherwise the cellZones are used when
00056     creating the cellTable information.
00057 
00058 See Also
00059     Foam::cellTable, Foam::meshWriter and Foam::meshWriters::STARCD
00060 
00061 \*---------------------------------------------------------------------------*/
00062 
00063 #include "argList.H"
00064 #include "timeSelector.H"
00065 #include "Time.H"
00066 #include "polyMesh.H"
00067 #include "STARCDMeshWriter.H"
00068 
00069 using namespace Foam;
00070 
00071 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00072 // Main program:
00073 
00074 int main(int argc, char *argv[])
00075 {
00076     argList::noParallel();
00077     timeSelector::addOptions();
00078 
00079     argList::validOptions.insert("scale", "scale");
00080     argList::validOptions.insert("noBnd", "");
00081     argList::validOptions.insert("tri", "");
00082     argList::validOptions.insert("surface", "");
00083 
00084 #   include "setRootCase.H"
00085 #   include "createTime.H"
00086 
00087     instantList timeDirs = timeSelector::select0(runTime, args);
00088 
00089     bool surfaceOnly = false;
00090     if (args.optionFound("surface") || args.optionFound("tri"))
00091     {
00092         surfaceOnly = true;
00093     }
00094 
00095     fileName exportName = meshWriter::defaultMeshName;
00096     if (surfaceOnly)
00097     {
00098         exportName = meshWriter::defaultSurfaceName;
00099     }
00100 
00101     if (args.optionFound("case"))
00102     {
00103         exportName += '-' + args.globalCaseName();
00104     }
00105 
00106     // default: rescale from [m] to [mm]
00107     scalar scaleFactor = 1000;
00108     if (args.optionReadIfPresent("scale", scaleFactor))
00109     {
00110         if (scaleFactor <= 0)
00111         {
00112             scaleFactor = 1;
00113         }
00114     }
00115 
00116 #   include "createPolyMesh.H"
00117 
00118 
00119     forAll(timeDirs, timeI)
00120     {
00121         runTime.setTime(timeDirs[timeI], timeI);
00122 
00123 #       include "getTimeIndex.H"
00124 
00125         polyMesh::readUpdateState state = mesh.readUpdate();
00126 
00127         if (!timeI || state != polyMesh::UNCHANGED)
00128         {
00129             meshWriters::STARCD writer(mesh, scaleFactor);
00130 
00131             if (args.optionFound("noBnd"))
00132             {
00133                 writer.noBoundary();
00134             }
00135 
00136             fileName meshName(exportName);
00137             if (state != polyMesh::UNCHANGED)
00138             {
00139                 meshName += '_' + runTime.timeName();
00140             }
00141 
00142             if (surfaceOnly)
00143             {
00144                 if (args.optionFound("tri"))
00145                 {
00146                     writer.writeSurface(meshName, true);
00147                 }
00148                 else
00149                 {
00150                     writer.writeSurface(meshName);
00151                 }
00152             }
00153             else
00154             {
00155                 writer.write(meshName);
00156             }
00157         }
00158 
00159         Info<< nl << endl;
00160     }
00161 
00162     Info<< "End\n" << endl;
00163 
00164     return 0;
00165 }
00166 
00167 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd