1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Plot3d mesh (ascii/formatted format) converter.
28 Work in progress! Handles ascii multiblock (and optionally singleBlock)
30 By default expects blanking. Use -noBlank if none.
31 Use -2D @a thickness if 2D.
33 Niklas Nordin has experienced a problem with lefthandedness of the blocks.
34 The code should detect this automatically - see hexBlock::readPoints but
35 if this goes wrong just set the blockHandedness_ variable to 'right'
38 \*---------------------------------------------------------------------------*/
45 #include "wallPolyPatch.H"
46 #include "symmetryPolyPatch.H"
47 #include "preservePatchTypes.H"
48 #include "cellShape.H"
49 #include "cellModeller.H"
50 #include "mergePoints.H"
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 int main(int argc, char *argv[])
59 argList::noParallel();
60 argList::validArgs.append("PLOT3D geom file");
61 argList::validOptions.insert("scale", "scale factor");
62 argList::validOptions.insert("noBlank", "");
63 argList::validOptions.insert("singleBlock", "");
64 argList::validOptions.insert("2D", "thickness");
66 argList args(argc, argv);
73 scalar scaleFactor = 1.0;
74 if (args.options().found("scale"))
76 scaleFactor = atof(args.options()["scale"].c_str());
79 bool readBlank = !args.options().found("noBlank");
80 bool singleBlock = args.options().found("singleBlock");
81 scalar twoDThicknes = -1;
82 if (args.options().found("2D"))
84 twoDThicknes = readScalar(IStringStream(args.options()["2D"])());
85 Info<< "Reading 2D case by extruding points by " << twoDThicknes
86 << " in z direction." << nl << endl;
90 # include "createTime.H"
92 IFstream plot3dFile(args.additionalArgs()[0]);
94 // Read the plot3d information using a fixed format reader.
95 // Comments in the file are in C++ style, so the stream parser will remove
96 // them with no intervention
105 plot3dFile >> nblock;
108 Info<< "Reading " << nblock << " blocks" << endl;
110 PtrList<hexBlock> blocks(nblock);
115 forAll (blocks, blockI)
117 if (twoDThicknes > 0)
119 // Fake second set of points (done in readPoints below)
120 plot3dFile >> nx >> ny;
125 plot3dFile >> nx >> ny >> nz;
128 Info<< "block " << blockI << " nx:" << nx
129 << " ny:" << ny << " nz:" << nz << endl;
131 blocks.set(blockI, new hexBlock(nx, ny, nz));
135 Info<< "Reading block points" << endl;
139 forAll (blocks, blockI)
141 Info<< "block " << blockI << ":" << nl;
142 blocks[blockI].readPoints(readBlank, twoDThicknes, plot3dFile);
143 sumPoints += blocks[blockI].nBlockPoints();
144 nMeshCells += blocks[blockI].nBlockCells();
148 pointField points(sumPoints);
149 labelList blockOffsets(blocks.size());
151 forAll (blocks, blockI)
153 const pointField& blockPoints = blocks[blockI].points();
154 blockOffsets[blockI] = sumPoints;
155 forAll (blockPoints, i)
157 points[sumPoints++] = blockPoints[i];
161 // From old to new master point
163 pointField newPoints;
175 Info<< "Merged points within " << SMALL << " distance. Merged from "
176 << oldToNew.size() << " down to " << newPoints.size()
177 << " points." << endl;
180 if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
182 newPoints *= scaleFactor;
185 Info<< "Creating cells" << endl;
187 cellShapeList cellShapes(nMeshCells);
189 const cellModel& hex = *(cellModeller::lookup("hex"));
191 label nCreatedCells = 0;
193 forAll (blocks, blockI)
195 labelListList curBlockCells = blocks[blockI].blockCells();
197 forAll (curBlockCells, blockCellI)
199 labelList cellPoints(curBlockCells[blockCellI].size());
201 forAll (cellPoints, pointI)
206 curBlockCells[blockCellI][pointI]
207 + blockOffsets[blockI]
211 // Do automatic collapse from hex.
212 cellShapes[nCreatedCells] = cellShape(hex, cellPoints, true);
218 Info<< "Creating boundary patches" << endl;
220 faceListList boundary(0);
221 wordList patchNames(0);
222 wordList patchTypes(0);
223 word defaultFacesName = "defaultFaces";
224 word defaultFacesType = wallPolyPatch::typeName;
225 wordList patchPhysicalTypes(0);
231 polyMesh::defaultRegion,
245 // Set the precision of the points data to 10
246 IOstream::defaultPrecision(10);
248 Info<< "Writing polyMesh" << endl;
251 Info<< "End\n" << endl;
257 // ************************************************************************* //