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