mshToFoam.C
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 #include "argList.H"
00041 #include "Time.H"
00042 #include "polyMesh.H"
00043 #include "IFstream.H"
00044 #include "polyPatch.H"
00045 #include "ListOps.H"
00046 #include "cellModeller.H"
00047
00048 #include <fstream>
00049
00050 using namespace Foam;
00051
00052
00053
00054
00055
00056 int main(int argc, char *argv[])
00057 {
00058 argList::noParallel();
00059 argList::validArgs.append(".msh file");
00060 argList::validOptions.insert("hex", "");
00061
00062 # include "setRootCase.H"
00063 # include "createTime.H"
00064
00065 bool readHex = args.optionFound("hex");
00066
00067 fileName mshFile(args.additionalArgs()[0]);
00068 IFstream mshStream(mshFile);
00069
00070 label nCells;
00071 mshStream >> nCells;
00072
00073 if (readHex)
00074 {
00075 Info<< "Trying to read " << nCells << " hexes." << endl << endl;
00076 }
00077 else
00078 {
00079 Info<< "Trying to read " << nCells << " tets." << endl << endl;
00080 }
00081
00082 cellShapeList cells(nCells);
00083
00084 const cellModel& tet = *(cellModeller::lookup("tet"));
00085 const cellModel& hex = *(cellModeller::lookup("hex"));
00086
00087 labelList tetPoints(4);
00088 labelList hexPoints(8);
00089
00090 if (readHex)
00091 {
00092 for (label cellI = 0; cellI < nCells; cellI++)
00093 {
00094 for (label cp = 0; cp < 8; cp++)
00095 {
00096 mshStream >> hexPoints[cp];
00097 }
00098 cells[cellI] = cellShape(hex, hexPoints);
00099 }
00100 }
00101 else
00102 {
00103 for (label cellI = 0; cellI < nCells; cellI++)
00104 {
00105 for (label cp = 0; cp < 4; cp++)
00106 {
00107 mshStream >> tetPoints[cp];
00108 }
00109 cells[cellI] = cellShape(tet, tetPoints);
00110 }
00111 }
00112
00113
00114 label nPoints;
00115
00116 mshStream >> nPoints;
00117
00118 Info<< "Trying to read " << nPoints << " points." << endl << endl;
00119
00120 pointField points(nPoints);
00121
00122
00123 for (label pointI = 0; pointI < nPoints; pointI++)
00124 {
00125 scalar x, y, z;
00126
00127 mshStream >> x >> y >> z;
00128
00129 points[pointI] = point(x, y, z);
00130 }
00131
00132
00133 polyMesh mesh
00134 (
00135 IOobject
00136 (
00137 polyMesh::defaultRegion,
00138 runTime.constant(),
00139 runTime
00140 ),
00141 xferMove(points),
00142 cells,
00143 faceListList(0),
00144 wordList(0),
00145 wordList(0),
00146 "defaultFaces",
00147 polyPatch::typeName,
00148 wordList(0)
00149 );
00150
00151 Info<< "Writing mesh ..." << endl;
00152
00153 mesh.write();
00154
00155
00156 Info<< "End\n" << endl;
00157
00158 return 0;
00159 }
00160
00161
00162
Copyright © 2000-2009 OpenCFD Ltd