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
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 #include <OpenFOAM/argList.H>
00074 #include <OpenFOAM/Time.H>
00075 #include <OpenFOAM/IFstream.H>
00076 #include "hexBlock.H"
00077 #include <OpenFOAM/polyMesh.H>
00078 #include <OpenFOAM/wallPolyPatch.H>
00079 #include <OpenFOAM/symmetryPolyPatch.H>
00080 #include <OpenFOAM/preservePatchTypes.H>
00081 #include <OpenFOAM/cellShape.H>
00082 #include <OpenFOAM/cellModeller.H>
00083 #include <OpenFOAM/mergePoints.H>
00084
00085 using namespace Foam;
00086
00087
00088
00089
00090 int main(int argc, char *argv[])
00091 {
00092 argList::noParallel();
00093 argList::validArgs.append("PLOT3D geom file");
00094 argList::validOptions.insert("scale", "scale factor");
00095 argList::validOptions.insert("noBlank", "");
00096 argList::validOptions.insert("singleBlock", "");
00097 argList::validOptions.insert("2D", "thickness");
00098
00099 argList args(argc, argv);
00100
00101 if (!args.check())
00102 {
00103 FatalError.exit();
00104 }
00105
00106 scalar scaleFactor = 1.0;
00107 args.optionReadIfPresent("scale", scaleFactor);
00108
00109 bool readBlank = !args.optionFound("noBlank");
00110 bool singleBlock = args.optionFound("singleBlock");
00111 scalar twoDThickness = -1;
00112 if (args.optionReadIfPresent("2D", twoDThickness))
00113 {
00114 Info<< "Reading 2D case by extruding points by " << twoDThickness
00115 << " in z direction." << nl << endl;
00116 }
00117
00118
00119 # include <OpenFOAM/createTime.H>
00120
00121 IFstream plot3dFile(args.additionalArgs()[0]);
00122
00123
00124
00125
00126 label nblock;
00127
00128 if (singleBlock)
00129 {
00130 nblock = 1;
00131 }
00132 else
00133 {
00134 plot3dFile >> nblock;
00135 }
00136
00137 Info<< "Reading " << nblock << " blocks" << endl;
00138
00139 PtrList<hexBlock> blocks(nblock);
00140
00141 {
00142 label nx, ny, nz;
00143
00144 forAll (blocks, blockI)
00145 {
00146 if (twoDThickness > 0)
00147 {
00148
00149 plot3dFile >> nx >> ny;
00150 nz = 2;
00151 }
00152 else
00153 {
00154 plot3dFile >> nx >> ny >> nz;
00155 }
00156
00157 Info<< "block " << blockI << " nx:" << nx
00158 << " ny:" << ny << " nz:" << nz << endl;
00159
00160 blocks.set(blockI, new hexBlock(nx, ny, nz));
00161 }
00162 }
00163
00164 Info<< "Reading block points" << endl;
00165 label sumPoints(0);
00166 label nMeshCells(0);
00167
00168 forAll (blocks, blockI)
00169 {
00170 Info<< "block " << blockI << ":" << nl;
00171 blocks[blockI].readPoints(readBlank, twoDThickness, plot3dFile);
00172 sumPoints += blocks[blockI].nBlockPoints();
00173 nMeshCells += blocks[blockI].nBlockCells();
00174 Info<< nl;
00175 }
00176
00177 pointField points(sumPoints);
00178 labelList blockOffsets(blocks.size());
00179 sumPoints = 0;
00180 forAll (blocks, blockI)
00181 {
00182 const pointField& blockPoints = blocks[blockI].points();
00183 blockOffsets[blockI] = sumPoints;
00184 forAll (blockPoints, i)
00185 {
00186 points[sumPoints++] = blockPoints[i];
00187 }
00188 }
00189
00190
00191 labelList oldToNew;
00192 pointField newPoints;
00193
00194
00195 mergePoints
00196 (
00197 points,
00198 SMALL,
00199 false,
00200 oldToNew,
00201 newPoints
00202 );
00203
00204 Info<< "Merged points within " << SMALL << " distance. Merged from "
00205 << oldToNew.size() << " down to " << newPoints.size()
00206 << " points." << endl;
00207
00208
00209 if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
00210 {
00211 newPoints *= scaleFactor;
00212 }
00213
00214 Info<< "Creating cells" << endl;
00215
00216 cellShapeList cellShapes(nMeshCells);
00217
00218 const cellModel& hex = *(cellModeller::lookup("hex"));
00219
00220 label nCreatedCells = 0;
00221
00222 forAll (blocks, blockI)
00223 {
00224 labelListList curBlockCells = blocks[blockI].blockCells();
00225
00226 forAll (curBlockCells, blockCellI)
00227 {
00228 labelList cellPoints(curBlockCells[blockCellI].size());
00229
00230 forAll (cellPoints, pointI)
00231 {
00232 cellPoints[pointI] =
00233 oldToNew
00234 [
00235 curBlockCells[blockCellI][pointI]
00236 + blockOffsets[blockI]
00237 ];
00238 }
00239
00240
00241 cellShapes[nCreatedCells] = cellShape(hex, cellPoints, true);
00242
00243 nCreatedCells++;
00244 }
00245 }
00246
00247 Info<< "Creating boundary patches" << endl;
00248
00249 faceListList boundary(0);
00250 wordList patchNames(0);
00251 wordList patchTypes(0);
00252 word defaultFacesName = "defaultFaces";
00253 word defaultFacesType = wallPolyPatch::typeName;
00254 wordList patchPhysicalTypes(0);
00255
00256 polyMesh pShapeMesh
00257 (
00258 IOobject
00259 (
00260 polyMesh::defaultRegion,
00261 runTime.constant(),
00262 runTime
00263 ),
00264 xferMove(newPoints),
00265 cellShapes,
00266 boundary,
00267 patchNames,
00268 patchTypes,
00269 defaultFacesName,
00270 defaultFacesType,
00271 patchPhysicalTypes
00272 );
00273
00274
00275 IOstream::defaultPrecision(10);
00276
00277 Info<< "Writing polyMesh" << endl;
00278 pShapeMesh.write();
00279
00280 Info<< "End\n" << endl;
00281
00282 return 0;
00283 }
00284
00285
00286