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
29 A multi-block mesh generator.
31 Uses the block mesh description found in
32 @a constant/polyMesh/blockMeshDict
33 (or @a constant/\<region\>/polyMesh/blockMeshDict).
39 @param -blockTopology \n
40 Write the topology as a set of edges in OBJ format.
42 @param -region \<name\> \n
43 Specify an alternative mesh region.
45 @param -dict \<dictionary\> \n
46 Specify an alternative dictionary for the block mesh description.
48 \*---------------------------------------------------------------------------*/
51 #include "IOdictionary.H"
52 #include "IOPtrList.H"
54 #include "blockMesh.H"
55 #include "attachPolyTopoChanger.H"
56 #include "preservePatchTypes.H"
57 #include "emptyPolyPatch.H"
61 #include "OSspecific.H"
65 #include "slidingInterface.H"
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 int main(int argc, char *argv[])
74 argList::noParallel();
76 # include "addOptions.H"
77 # include "setRootCase.H"
78 # include "createTime.H"
79 # include "checkOptions.H"
83 word dictName("blockMeshDict");
84 fileName dictPath(runTime.constant());
86 if (args.options().found("region"))
88 // constant/<region>/polyMesh/blockMeshDict
89 regionName = args.options()["region"];
90 polyMeshDir = regionName/polyMesh::meshSubDir;
92 Info<< nl << "Generating mesh for region " << regionName << endl;
96 // constant/polyMesh/blockMeshDict
97 regionName = polyMesh::defaultRegion;
98 polyMeshDir = polyMesh::meshSubDir;
101 fileName dictLocal = polyMeshDir;
103 if (args.options().found("dict"))
105 wordList elems(fileName(args.options()["dict"]).components());
106 dictName = elems[elems.size()-1];
110 if (elems.size() == 1)
114 else if (elems.size() > 2)
116 dictLocal = fileName(SubList<word>(elems, elems.size()-2, 1));
132 if (!meshDictIo.headerOk())
134 FatalErrorIn(args.executable())
135 << "Cannot open mesh description file\n "
136 << meshDictIo.objectPath()
141 Info<< nl << "Creating block mesh from\n "
142 << meshDictIo.objectPath() << endl;
144 IOdictionary meshDict(meshDictIo);
146 blockMesh blocks(meshDict);
150 // Write mesh as edges.
152 fileName objMeshFile("blockTopology.obj");
154 OFstream str(runTime.path()/objMeshFile);
156 Info<< nl << "Dumping block structure as Lightwave obj format"
157 << " to " << objMeshFile << endl;
159 blocks.writeTopology(str);
162 // Write centres of blocks
164 fileName objCcFile("blockCentres.obj");
166 OFstream str(runTime.path()/objCcFile);
168 Info<< nl << "Dumping block centres as Lightwave obj format"
169 << " to " << objCcFile << endl;
171 const polyMesh& topo = blocks.topology();
173 const pointField& cellCentres = topo.cellCentres();
175 forAll(cellCentres, cellI)
177 //point cc = b.blockShape().centre(b.points());
178 const point& cc = cellCentres[cellI];
180 str << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl;
184 Info<< nl << "end" << endl;
191 Info<< nl << "Creating mesh from block mesh" << endl;
193 wordList patchNames = blocks.patchNames();
194 wordList patchTypes = blocks.patchTypes();
195 word defaultFacesName = "defaultFaces";
196 word defaultFacesType = emptyPolyPatch::typeName;
197 wordList patchPhysicalTypes = blocks.patchPhysicalTypes();
230 // Read in a list of dictionaries for the merge patch pairs
231 if (meshDict.found("mergePatchPairs"))
233 List<Pair<word> > mergePatchPairs
235 meshDict.lookup("mergePatchPairs")
238 #include "mergePatchPairs.H"
242 Info<< nl << "There are no merge patch pairs edges" << endl;
246 // Set any cellZones (note: cell labelling unaffected by above
249 label nZones = blocks.numZonedBlocks();
253 Info<< nl << "Adding cell zones" << endl;
255 // Map from zoneName to cellZone index
256 HashTable<label> zoneMap(nZones);
259 List<DynamicList<label> > zoneCells(nZones);
261 // Running cell counter
264 // Largest zone so far
267 forAll(blocks, blockI)
269 const block& b = blocks[blockI];
270 const labelListList& blockCells = b.cells();
271 const word& zoneName = b.blockDef().zoneName();
273 if (zoneName.size() > 0)
275 HashTable<label>::const_iterator iter = zoneMap.find(zoneName);
279 if (iter == zoneMap.end())
283 Info<< " " << zoneI << '\t' << zoneName << endl;
285 zoneMap.insert(zoneName, zoneI);
292 forAll(blockCells, i)
294 zoneCells[zoneI].append(cellI++);
299 cellI += b.cells().size();
304 List<cellZone*> cz(zoneMap.size());
306 Info<< nl << "Writing cell zones as cellSets" << endl;
308 forAllConstIter(HashTable<label>, zoneMap, iter)
310 label zoneI = iter();
312 cz[zoneI]= new cellZone
315 zoneCells[zoneI].shrink(),
320 // Write as cellSet for ease of processing
321 cellSet cset(mesh, iter.key(), zoneCells[zoneI].shrink());
325 mesh.pointZones().setSize(0);
326 mesh.faceZones().setSize(0);
327 mesh.cellZones().setSize(0);
328 mesh.addZones(List<pointZone*>(0), List<faceZone*>(0), cz);
331 // Set the precision of the points data to 10
332 IOstream::defaultPrecision(10);
334 Info << nl << "Writing polyMesh" << endl;
335 mesh.removeFiles(mesh.instance());
338 FatalErrorIn(args.executable())
339 << "Failed writing polyMesh."
343 Info<< nl << "end" << endl;
348 // ************************************************************************* //