1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 Plot3d mesh (ascii/formatted format) converter.
27 Work in progress! Handles ascii multiblock (and optionally singleBlock)
29 By default expects blanking. Use -noBlank if none.
30 Use -2D \a thickness if 2D.
32 Niklas Nordin has experienced a problem with lefthandedness of the blocks.
33 The code should detect this automatically - see hexBlock::readPoints but
34 if this goes wrong just set the blockHandedness_ variable to 'right'
37 \*---------------------------------------------------------------------------*/
44 #include "wallPolyPatch.H"
45 #include "symmetryPolyPatch.H"
46 #include "cellShape.H"
47 #include "cellModeller.H"
48 #include "mergePoints.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 int main(int argc, char *argv[])
57 argList::noParallel();
58 argList::validArgs.append("PLOT3D geom file");
63 "geometry scaling factor - default is 1"
65 argList::addBoolOption
70 argList::addBoolOption
73 "input is a single block"
79 "use when converting a 2-D geometry"
82 argList args(argc, argv);
89 const scalar scaleFactor = args.optionLookupOrDefault("scale", 1.0);
91 bool readBlank = !args.optionFound("noBlank");
92 bool singleBlock = args.optionFound("singleBlock");
93 scalar twoDThickness = -1;
94 if (args.optionReadIfPresent("2D", twoDThickness))
96 Info<< "Reading 2D case by extruding points by " << twoDThickness
97 << " in z direction." << nl << endl;
101 # include "createTime.H"
103 IFstream plot3dFile(args[1]);
105 // Read the plot3d information using a fixed format reader.
106 // Comments in the file are in C++ style, so the stream parser will remove
107 // them with no intervention
116 plot3dFile >> nblock;
119 Info<< "Reading " << nblock << " blocks" << endl;
121 PtrList<hexBlock> blocks(nblock);
126 forAll(blocks, blockI)
128 if (twoDThickness > 0)
130 // Fake second set of points (done in readPoints below)
131 plot3dFile >> nx >> ny;
136 plot3dFile >> nx >> ny >> nz;
139 Info<< "block " << blockI << " nx:" << nx
140 << " ny:" << ny << " nz:" << nz << endl;
142 blocks.set(blockI, new hexBlock(nx, ny, nz));
146 Info<< "Reading block points" << endl;
150 forAll(blocks, blockI)
152 Info<< "block " << blockI << ":" << nl;
153 blocks[blockI].readPoints(readBlank, twoDThickness, plot3dFile);
154 sumPoints += blocks[blockI].nBlockPoints();
155 nMeshCells += blocks[blockI].nBlockCells();
159 pointField points(sumPoints);
160 labelList blockOffsets(blocks.size());
162 forAll(blocks, blockI)
164 const pointField& blockPoints = blocks[blockI].points();
165 blockOffsets[blockI] = sumPoints;
166 forAll(blockPoints, i)
168 points[sumPoints++] = blockPoints[i];
172 // From old to new master point
174 pointField newPoints;
186 Info<< "Merged points within " << SMALL << " distance. Merged from "
187 << oldToNew.size() << " down to " << newPoints.size()
188 << " points." << endl;
191 if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
193 newPoints *= scaleFactor;
196 Info<< "Creating cells" << endl;
198 cellShapeList cellShapes(nMeshCells);
200 const cellModel& hex = *(cellModeller::lookup("hex"));
202 label nCreatedCells = 0;
204 forAll(blocks, blockI)
206 labelListList curBlockCells = blocks[blockI].blockCells();
208 forAll(curBlockCells, blockCellI)
210 labelList cellPoints(curBlockCells[blockCellI].size());
212 forAll(cellPoints, pointI)
217 curBlockCells[blockCellI][pointI]
218 + blockOffsets[blockI]
222 // Do automatic collapse from hex.
223 cellShapes[nCreatedCells] = cellShape(hex, cellPoints, true);
229 Info<< "Creating boundary patches" << endl;
231 faceListList boundary(0);
232 wordList patchNames(0);
233 wordList patchTypes(0);
234 word defaultFacesName = "defaultFaces";
235 word defaultFacesType = wallPolyPatch::typeName;
236 wordList patchPhysicalTypes(0);
242 polyMesh::defaultRegion,
256 // Set the precision of the points data to 10
257 IOstream::defaultPrecision(10);
259 Info<< "Writing polyMesh" << endl;
262 Info<< "End\n" << endl;
268 // ************************************************************************* //