1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 \*---------------------------------------------------------------------------*/
40 #include "objectRegistry.H"
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 args.optionReadIfPresent("scale", scaleFactor);
76 bool readBlank = !args.optionFound("noBlank");
77 bool singleBlock = args.optionFound("singleBlock");
78 scalar twoDThickness = -1;
79 if (args.optionReadIfPresent("2D", twoDThickness))
81 Info<< "Reading 2D case by extruding points by " << twoDThickness
82 << " in z direction." << nl << endl;
86 # include "createTime.H"
88 IFstream plot3dFile(args.additionalArgs()[0]);
90 // Read the plot3d information using a fixed format reader.
91 // Comments in the file are in C++ style, so the stream parser will remove
92 // them with no intervention
101 plot3dFile >> nblock;
104 Info<< "Reading " << nblock << " blocks" << endl;
106 PtrList<hexBlock> blocks(nblock);
111 forAll (blocks, blockI)
113 if (twoDThickness > 0)
115 // Fake second set of points (done in readPoints below)
116 plot3dFile >> nx >> ny;
121 plot3dFile >> nx >> ny >> nz;
124 Info<< "block " << blockI << " nx:" << nx
125 << " ny:" << ny << " nz:" << nz << endl;
127 blocks.set(blockI, new hexBlock(nx, ny, nz));
131 Info<< "Reading block points" << endl;
135 forAll (blocks, blockI)
137 Info<< "block " << blockI << ":" << nl;
138 blocks[blockI].readPoints(readBlank, twoDThickness, plot3dFile);
139 sumPoints += blocks[blockI].nBlockPoints();
140 nMeshCells += blocks[blockI].nBlockCells();
144 pointField points(sumPoints);
145 labelList blockOffsets(blocks.size());
147 forAll (blocks, blockI)
149 const pointField& blockPoints = blocks[blockI].points();
150 blockOffsets[blockI] = sumPoints;
151 forAll (blockPoints, i)
153 points[sumPoints++] = blockPoints[i];
157 // From old to new master point
159 pointField newPoints;
171 Info<< "Merged points within " << SMALL << " distance. Merged from "
172 << oldToNew.size() << " down to " << newPoints.size()
173 << " points." << endl;
176 if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
178 newPoints *= scaleFactor;
181 Info<< "Creating cells" << endl;
183 cellShapeList cellShapes(nMeshCells);
185 const cellModel& hex = *(cellModeller::lookup("hex"));
187 label nCreatedCells = 0;
189 forAll (blocks, blockI)
191 labelListList curBlockCells = blocks[blockI].blockCells();
193 forAll (curBlockCells, blockCellI)
195 labelList cellPoints(curBlockCells[blockCellI].size());
197 forAll (cellPoints, pointI)
202 curBlockCells[blockCellI][pointI]
203 + blockOffsets[blockI]
207 // Do automatic collapse from hex.
208 cellShapes[nCreatedCells] = cellShape(hex, cellPoints, true);
214 Info<< "Creating boundary patches" << endl;
216 faceListList boundary(0);
217 wordList patchNames(0);
218 wordList patchTypes(0);
219 word defaultFacesName = "defaultFaces";
220 word defaultFacesType = wallPolyPatch::typeName;
221 wordList patchPhysicalTypes(0);
227 polyMesh::defaultRegion,
241 // Set the precision of the points data to 10
242 IOstream::defaultPrecision(10);
244 Info<< "Writing polyMesh" << endl;
247 Info<< "End\n" << endl;
253 // ************************************************************************* //