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

mshToFoam.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     mshToFoam
00026 
00027 Description
00028     Converts .msh file generated by the Adventure system.
00029 
00030 Note
00031     The .msh format does not contain any boundary information. It is
00032     purely a description of the internal mesh.
00033 
00034     Can read both linear-tet format (i.e. 4 verts per tet) and linear-hex
00035     format (8 verts per hex) (if provided with the -hex option)
00036 
00037     Will bomb out if not supplied with the correct option for the
00038     file format
00039 
00040     Not extensively tested.
00041 
00042 Usage
00043 
00044     - mshToFoam [OPTIONS] <.msh file>
00045 
00046     @param <.msh file> \n
00047     @todo Detailed description of argument.
00048 
00049     @param -hex \n
00050     Read hex cells.
00051 
00052     @param -help \n
00053     Display help message.
00054 
00055     @param -doc \n
00056     Display Doxygen API documentation page for this application.
00057 
00058     @param -srcDoc \n
00059     Display Doxygen source documentation page for this application.
00060 
00061 \*---------------------------------------------------------------------------*/
00062 
00063 #include <OpenFOAM/argList.H>
00064 #include <OpenFOAM/Time.H>
00065 #include <OpenFOAM/polyMesh.H>
00066 #include <OpenFOAM/IFstream.H>
00067 #include <OpenFOAM/polyPatch.H>
00068 #include <OpenFOAM/ListOps.H>
00069 #include <OpenFOAM/cellModeller.H>
00070 
00071 #include <fstream>
00072 
00073 using namespace Foam;
00074 
00075 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00076 
00077 // Main program:
00078 
00079 int main(int argc, char *argv[])
00080 {
00081     argList::noParallel();
00082     argList::validArgs.append(".msh file");
00083     argList::validOptions.insert("hex", "");
00084 
00085 #   include <OpenFOAM/setRootCase.H>
00086 #   include <OpenFOAM/createTime.H>
00087 
00088     bool readHex = args.optionFound("hex");
00089 
00090     fileName mshFile(args.additionalArgs()[0]);
00091     IFstream mshStream(mshFile);
00092 
00093     label nCells;
00094     mshStream >> nCells;
00095 
00096     if (readHex)
00097     {
00098         Info<< "Trying to read " << nCells << " hexes." << endl << endl;
00099     }
00100     else
00101     {
00102         Info<< "Trying to read " << nCells << " tets." << endl << endl;
00103     }
00104 
00105     cellShapeList cells(nCells);
00106 
00107     const cellModel& tet = *(cellModeller::lookup("tet"));
00108     const cellModel& hex = *(cellModeller::lookup("hex"));
00109 
00110     labelList tetPoints(4);
00111     labelList hexPoints(8);
00112 
00113     if (readHex)
00114     {
00115         for (label cellI = 0; cellI < nCells; cellI++)
00116         {
00117             for (label cp = 0; cp < 8; cp++)
00118             {
00119                 mshStream >> hexPoints[cp];
00120             }
00121             cells[cellI] = cellShape(hex, hexPoints);
00122         }
00123     }
00124     else
00125     {
00126         for (label cellI = 0; cellI < nCells; cellI++)
00127         {
00128             for (label cp = 0; cp < 4; cp++)
00129             {
00130                 mshStream >> tetPoints[cp];
00131             }
00132             cells[cellI] = cellShape(tet, tetPoints);
00133         }
00134     }
00135 
00136 
00137     label nPoints;
00138 
00139     mshStream >> nPoints;
00140 
00141     Info<< "Trying to read " << nPoints << " points." << endl << endl;
00142 
00143     pointField points(nPoints);
00144 
00145 
00146     for (label pointI = 0; pointI < nPoints; pointI++)
00147     {
00148         scalar x, y, z;
00149 
00150         mshStream >> x >> y >> z;
00151 
00152         points[pointI] = point(x, y, z);
00153     }
00154 
00155 
00156     polyMesh mesh
00157     (
00158         IOobject
00159         (
00160             polyMesh::defaultRegion,
00161             runTime.constant(),
00162             runTime
00163         ),
00164         xferMove(points),
00165         cells,
00166         faceListList(0),
00167         wordList(0),
00168         wordList(0),
00169         "defaultFaces",
00170         polyPatch::typeName,
00171         wordList(0)
00172     );
00173 
00174     Info<< "Writing mesh ..." << endl;
00175 
00176     mesh.write();
00177 
00178 
00179     Info<< "End\n" << endl;
00180 
00181     return 0;
00182 }
00183 
00184 
00185 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines