FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

blockMeshApp.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     blockMesh
00026 
00027 Description
00028     A multi-block mesh generator.
00029 
00030     Uses the block mesh description found in
00031     @a constant/polyMesh/blockMeshDict
00032     (or @a constant/<region>/polyMesh/blockMeshDict).
00033 
00034 Usage
00035 
00036     - blockMesh [OPTION]
00037 
00038     @param -blockTopology \n
00039     Write the topology as a set of edges in OBJ format.
00040 
00041     @param -region <name> \n
00042     Specify an alternative mesh region.
00043 
00044     @param -dict <dictionary> \n
00045     Specify an alternative dictionary for the block mesh description.
00046 
00047     @param -case <dir> \n
00048     Case directory.
00049 
00050     @param -help \n
00051     Display help message.
00052 
00053     @param -doc \n
00054     Display Doxygen API documentation page for this application.
00055 
00056     @param -srcDoc \n
00057     Display Doxygen source documentation page for this application.
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 // Main program:
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         // constant/<region>/polyMesh/blockMeshDict
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         // constant/polyMesh/blockMeshDict
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         // Write mesh as edges.
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         // Write centres of blocks
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                 //point cc = b.blockShape().centre(b.points());
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()),           // could we re-use space?
00239         blocks.cells(),
00240         blocks.patches(),
00241         patchNames,
00242         patchTypes,
00243         defaultFacesName,
00244         defaultFacesType,
00245         patchPhysicalTypes
00246     );
00247 
00248 
00249     // Read in a list of dictionaries for the merge patch pairs
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     // Set any cellZones (note: cell labelling unaffected by above
00266     // mergePatchPairs)
00267 
00268     label nZones = blocks.numZonedBlocks();
00269 
00270     if (nZones > 0)
00271     {
00272         Info<< nl << "Adding cell zones" << endl;
00273 
00274         // Map from zoneName to cellZone index
00275         HashTable<label> zoneMap(nZones);
00276 
00277         // Cells per zone.
00278         List<DynamicList<label> > zoneCells(nZones);
00279 
00280         // Running cell counter
00281         label cellI = 0;
00282 
00283         // Largest zone so far
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             // Write as cellSet for ease of processing
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     // Set the precision of the points data to 10
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 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines