1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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/>.
25 Converts .msh file generated by the Adventure system.
27 Note: the .msh format does not contain any boundary information. It is
28 purely a description of the internal mesh.
30 Can read both linear-tet format (i.e. 4 verts per tet) and linear-hex
31 format (8 verts per hex) (if provided with the -hex (at your option)
32 (Note: will bomb out if not supplied with the correct option for the
35 Not extensively tested.
37 \*---------------------------------------------------------------------------*/
43 #include "polyPatch.H"
45 #include "cellModeller.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 int main(int argc, char *argv[])
57 argList::noParallel();
58 argList::validArgs.append(".msh file");
59 argList::addBoolOption
62 "treat input as containing hex instead of tet cells"
65 # include "setRootCase.H"
66 # include "createTime.H"
68 const bool readHex = args.optionFound("hex");
69 IFstream mshStream(args[1]);
76 Info<< "Trying to read " << nCells << " hexes." << nl << endl;
80 Info<< "Trying to read " << nCells << " tets." << nl << endl;
83 cellShapeList cells(nCells);
85 const cellModel& tet = *(cellModeller::lookup("tet"));
86 const cellModel& hex = *(cellModeller::lookup("hex"));
88 labelList tetPoints(4);
89 labelList hexPoints(8);
93 for (label cellI = 0; cellI < nCells; cellI++)
95 for (label cp = 0; cp < 8; cp++)
97 mshStream >> hexPoints[cp];
99 cells[cellI] = cellShape(hex, hexPoints);
104 for (label cellI = 0; cellI < nCells; cellI++)
106 for (label cp = 0; cp < 4; cp++)
108 mshStream >> tetPoints[cp];
110 cells[cellI] = cellShape(tet, tetPoints);
117 mshStream >> nPoints;
119 Info<< "Trying to read " << nPoints << " points." << endl << endl;
121 pointField points(nPoints);
124 for (label pointI = 0; pointI < nPoints; pointI++)
128 mshStream >> x >> y >> z;
130 points[pointI] = point(x, y, z);
138 polyMesh::defaultRegion,
152 Info<< "Writing mesh ..." << endl;
157 Info<< "End\n" << endl;
163 // ************************************************************************* //