Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
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
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