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
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #include <OpenFOAM/Time.H>
00062 #include <OpenFOAM/IOdictionary.H>
00063 #include <OpenFOAM/IOPtrList.H>
00064
00065 #include "blockMesh.H"
00066 #include <dynamicMesh/attachPolyTopoChanger.H>
00067 #include <OpenFOAM/preservePatchTypes.H>
00068 #include <OpenFOAM/emptyPolyPatch.H>
00069 #include <meshTools/cellSet.H>
00070
00071 #include <OpenFOAM/argList.H>
00072 #include <OpenFOAM/OSspecific.H>
00073 #include <OpenFOAM/OFstream.H>
00074
00075 #include <OpenFOAM/Pair.H>
00076 #include <dynamicMesh/slidingInterface.H>
00077
00078 using namespace Foam;
00079
00080
00081
00082
00083 int main(int argc, char *argv[])
00084 {
00085 argList::noParallel();
00086 argList::validOptions.insert("blockTopology", "");
00087 argList::validOptions.insert("dict", "dictionary");
00088 # include <OpenFOAM/addRegionOption.H>
00089 # include <OpenFOAM/setRootCase.H>
00090 # include <OpenFOAM/createTime.H>
00091
00092 const word dictName("blockMeshDict");
00093
00094 word regionName;
00095 fileName polyMeshDir;
00096
00097 if (args.optionFound("region"))
00098 {
00099
00100 regionName = args.option("region");
00101 polyMeshDir = regionName/polyMesh::meshSubDir;
00102
00103 Info<< nl << "Generating mesh for region " << regionName << endl;
00104 }
00105 else
00106 {
00107
00108 regionName = polyMesh::defaultRegion;
00109 polyMeshDir = polyMesh::meshSubDir;
00110 }
00111
00112 autoPtr<IOobject> meshDictIoPtr;
00113
00114 if (args.optionFound("dict"))
00115 {
00116 fileName dictPath(args.option("dict"));
00117
00118 meshDictIoPtr.set
00119 (
00120 new IOobject
00121 (
00122 (
00123 isDir(dictPath)
00124 ? dictPath/dictName
00125 : dictPath
00126 ),
00127 runTime,
00128 IOobject::MUST_READ,
00129 IOobject::NO_WRITE,
00130 false
00131 )
00132 );
00133 }
00134 else
00135 {
00136 meshDictIoPtr.set
00137 (
00138 new IOobject
00139 (
00140 dictName,
00141 runTime.constant(),
00142 polyMeshDir,
00143 runTime,
00144 IOobject::MUST_READ,
00145 IOobject::NO_WRITE,
00146 false
00147 )
00148 );
00149 }
00150
00151 if (!meshDictIoPtr->headerOk())
00152 {
00153 FatalErrorIn(args.executable())
00154 << "Cannot open mesh description file\n "
00155 << meshDictIoPtr->objectPath()
00156 << nl
00157 << exit(FatalError);
00158 }
00159
00160 Info<< nl << "Creating block mesh from\n "
00161 << meshDictIoPtr->objectPath() << nl << endl;
00162
00163 IOdictionary meshDict(meshDictIoPtr());
00164 blockMesh blocks(meshDict);
00165
00166
00167 if (args.optionFound("blockTopology"))
00168 {
00169
00170 {
00171 fileName objMeshFile("blockTopology.obj");
00172
00173 OFstream str(runTime.path()/objMeshFile);
00174
00175 Info<< nl << "Dumping block structure as Lightwave obj format"
00176 << " to " << objMeshFile << endl;
00177
00178 blocks.writeTopology(str);
00179 }
00180
00181
00182 {
00183 fileName objCcFile("blockCentres.obj");
00184
00185 OFstream str(runTime.path()/objCcFile);
00186
00187 Info<< nl << "Dumping block centres as Lightwave obj format"
00188 << " to " << objCcFile << endl;
00189
00190 const polyMesh& topo = blocks.topology();
00191
00192 const pointField& cellCentres = topo.cellCentres();
00193
00194 forAll(cellCentres, cellI)
00195 {
00196
00197 const point& cc = cellCentres[cellI];
00198
00199 str << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl;
00200 }
00201 }
00202
00203 Info<< nl << "end" << endl;
00204
00205 return 0;
00206 }
00207
00208
00209
00210 Info<< nl << "Creating mesh from block mesh" << endl;
00211
00212 wordList patchNames = blocks.patchNames();
00213 wordList patchTypes = blocks.patchTypes();
00214 word defaultFacesName = "defaultFaces";
00215 word defaultFacesType = emptyPolyPatch::typeName;
00216 wordList patchPhysicalTypes = blocks.patchPhysicalTypes();
00217
00218 preservePatchTypes
00219 (
00220 runTime,
00221 runTime.constant(),
00222 polyMeshDir,
00223 patchNames,
00224 patchTypes,
00225 defaultFacesName,
00226 defaultFacesType,
00227 patchPhysicalTypes
00228 );
00229
00230 polyMesh mesh
00231 (
00232 IOobject
00233 (
00234 regionName,
00235 runTime.constant(),
00236 runTime
00237 ),
00238 xferCopy(blocks.points()),
00239 blocks.cells(),
00240 blocks.patches(),
00241 patchNames,
00242 patchTypes,
00243 defaultFacesName,
00244 defaultFacesType,
00245 patchPhysicalTypes
00246 );
00247
00248
00249
00250 if (meshDict.found("mergePatchPairs"))
00251 {
00252 List<Pair<word> > mergePatchPairs
00253 (
00254 meshDict.lookup("mergePatchPairs")
00255 );
00256
00257 # include "mergePatchPairs.H"
00258 }
00259 else
00260 {
00261 Info<< nl << "There are no merge patch pairs edges" << endl;
00262 }
00263
00264
00265
00266
00267
00268 label nZones = blocks.numZonedBlocks();
00269
00270 if (nZones > 0)
00271 {
00272 Info<< nl << "Adding cell zones" << endl;
00273
00274
00275 HashTable<label> zoneMap(nZones);
00276
00277
00278 List<DynamicList<label> > zoneCells(nZones);
00279
00280
00281 label cellI = 0;
00282
00283
00284 label freeZoneI = 0;
00285
00286 forAll(blocks, blockI)
00287 {
00288 const block& b = blocks[blockI];
00289 const labelListList& blockCells = b.cells();
00290 const word& zoneName = b.blockDef().zoneName();
00291
00292 if (zoneName.size())
00293 {
00294 HashTable<label>::const_iterator iter = zoneMap.find(zoneName);
00295
00296 label zoneI;
00297
00298 if (iter == zoneMap.end())
00299 {
00300 zoneI = freeZoneI++;
00301
00302 Info<< " " << zoneI << '\t' << zoneName << endl;
00303
00304 zoneMap.insert(zoneName, zoneI);
00305 }
00306 else
00307 {
00308 zoneI = iter();
00309 }
00310
00311 forAll(blockCells, i)
00312 {
00313 zoneCells[zoneI].append(cellI++);
00314 }
00315 }
00316 else
00317 {
00318 cellI += b.cells().size();
00319 }
00320 }
00321
00322
00323 List<cellZone*> cz(zoneMap.size());
00324
00325 Info<< nl << "Writing cell zones as cellSets" << endl;
00326
00327 forAllConstIter(HashTable<label>, zoneMap, iter)
00328 {
00329 label zoneI = iter();
00330
00331 cz[zoneI] = new cellZone
00332 (
00333 iter.key(),
00334 zoneCells[zoneI].shrink(),
00335 zoneI,
00336 mesh.cellZones()
00337 );
00338
00339
00340 cellSet cset(mesh, iter.key(), zoneCells[zoneI].shrink());
00341 cset.write();
00342 }
00343
00344 mesh.pointZones().setSize(0);
00345 mesh.faceZones().setSize(0);
00346 mesh.cellZones().setSize(0);
00347 mesh.addZones(List<pointZone*>(0), List<faceZone*>(0), cz);
00348 }
00349
00350
00351 IOstream::defaultPrecision(10);
00352
00353 Info << nl << "Writing polyMesh" << endl;
00354 mesh.removeFiles();
00355 if (!mesh.write())
00356 {
00357 FatalErrorIn(args.executable())
00358 << "Failed writing polyMesh."
00359 << exit(FatalError);
00360 }
00361
00362 Info<< nl << "End" << endl;
00363
00364 return 0;
00365 }
00366
00367
00368