This repository has been archived on 2023-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
foam-extend4.1-coherent-io/applications/utilities/mesh/generation/blockMesh/blockMeshApp.C
Bernhard F.W. Gschaider a72b12ce8f This solves a compilation problem in Clang 3.5 where the class Time is
not completely instantiated in objectRegistry (see error message
below)

By including objectRegistry.H before Time.H the class Tiem gets
completely defined before objectRegistry.

The original Time.H could be omitted (as it is already included in
objectRegistry.H )

In file included from blockMeshApp.C:49:
In file included from /Users/bgschaid/OpenFOAM/foam-extend-3.1/src/foam/lnInclude/Time.H:42:
In file included from /Users/bgschaid/OpenFOAM/foam-extend-3.1/src/foam/lnInclude/objectRegistry.H:235:
/Users/bgschaid/OpenFOAM/foam-extend-3.1/src/foam/lnInclude/objectRegistryTemplates.C:94:25: error: 'const Foam::Time' is an incomplete type
        if (&parent_ != dynamic_cast<const objectRegistry*>(&time_))
                        ^                                   ~~~~~~
/Users/bgschaid/OpenFOAM/foam-extend-3.1/src/foam/lnInclude/IOobject.H:78:7: note: forward declaration of 'Foam::Time'
class Time;
      ^
In file included from blockMeshApp.C:49:
2014-06-02 18:05:03 +02:00

379 lines
9.7 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration |
\\ / A nd | For copyright notice see file Copyright
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Application
blockMesh
Description
A multi-block mesh generator.
Uses the block mesh description found in
\a constant/polyMesh/blockMeshDict
(or \a constant/\<region\>/polyMesh/blockMeshDict).
Usage
- blockMesh [OPTION]
\param -blockTopology \n
Write the topology as a set of edges in OBJ format.
\param -region \<name\> \n
Specify an alternative mesh region.
\param -dict \<filename\> \n
Specify alternative dictionary for the block mesh description.
\*---------------------------------------------------------------------------*/
#include "objectRegistry.H"
#include "Time.H"
#include "IOdictionary.H"
#include "IOPtrList.H"
#include "blockMesh.H"
#include "preservePatchTypes.H"
#include "emptyPolyPatch.H"
#include "cellSet.H"
#include "argList.H"
#include "OSspecific.H"
#include "OFstream.H"
#include "Pair.H"
#include "mapPolyMesh.H"
#include "polyTopoChanger.H"
#include "slidingInterface.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validOptions.insert("blockTopology", "");
argList::validOptions.insert("dict", "dictionary");
# include "addRegionOption.H"
# include "setRootCase.H"
# include "createTime.H"
const word dictName("blockMeshDict");
word regionName;
fileName polyMeshDir;
if (args.optionFound("region"))
{
// constant/<region>/polyMesh/blockMeshDict
regionName = args.option("region");
polyMeshDir = regionName/polyMesh::meshSubDir;
Info<< nl << "Generating mesh for region " << regionName << endl;
}
else
{
// constant/polyMesh/blockMeshDict
regionName = polyMesh::defaultRegion;
polyMeshDir = polyMesh::meshSubDir;
}
autoPtr<IOobject> meshDictIoPtr;
if (args.optionFound("dict"))
{
fileName dictPath(args.option("dict"));
meshDictIoPtr.set
(
new IOobject
(
(
isDir(dictPath)
? dictPath/dictName
: dictPath
),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
}
else
{
meshDictIoPtr.set
(
new IOobject
(
dictName,
runTime.constant(),
polyMeshDir,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
}
if (!meshDictIoPtr->headerOk())
{
FatalErrorIn(args.executable())
<< "Cannot open mesh description file\n "
<< meshDictIoPtr->objectPath()
<< nl
<< exit(FatalError);
}
Info<< nl << "Creating block mesh from\n "
<< meshDictIoPtr->objectPath() << nl << endl;
blockMesh::verbose(true);
IOdictionary meshDict(meshDictIoPtr());
blockMesh blocks(meshDict, regionName);
if (args.optionFound("blockTopology"))
{
// Write mesh as edges.
{
fileName objMeshFile("blockTopology.obj");
OFstream str(runTime.path()/objMeshFile);
Info<< nl << "Dumping block structure as Lightwave obj format"
<< " to " << objMeshFile << endl;
blocks.writeTopology(str);
}
// Write centres of blocks
{
fileName objCcFile("blockCentres.obj");
OFstream str(runTime.path()/objCcFile);
Info<< nl << "Dumping block centres as Lightwave obj format"
<< " to " << objCcFile << endl;
const polyMesh& topo = blocks.topology();
const pointField& cellCentres = topo.cellCentres();
forAll(cellCentres, cellI)
{
//point cc = b.blockShape().centre(b.points());
const point& cc = cellCentres[cellI];
str << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl;
}
}
Info<< nl << "end" << endl;
return 0;
}
Info<< nl << "Creating polyMesh from blockMesh" << endl;
word defaultFacesName = "defaultFaces";
word defaultFacesType = emptyPolyPatch::typeName;
polyMesh mesh
(
IOobject
(
regionName,
runTime.constant(),
runTime
),
xferCopy(blocks.points()), // could we re-use space?
blocks.cells(),
blocks.patches(),
blocks.patchNames(),
blocks.patchDicts(),
defaultFacesName,
defaultFacesType
);
// Read in a list of dictionaries for the merge patch pairs
if (meshDict.found("mergePatchPairs"))
{
List<Pair<word> > mergePatchPairs
(
meshDict.lookup("mergePatchPairs")
);
# include "mergePatchPairs.H"
}
else
{
Info<< nl << "There are no merge patch pairs edges" << endl;
}
// Set any cellZones (note: cell labelling unaffected by above
// mergePatchPairs)
label nZones = blocks.numZonedBlocks();
if (nZones > 0)
{
Info<< nl << "Adding cell zones" << endl;
// Map from zoneName to cellZone index
HashTable<label> zoneMap(nZones);
// Cells per zone.
List<DynamicList<label> > zoneCells(nZones);
// Running cell counter
label cellI = 0;
// Largest zone so far
label freeZoneI = 0;
forAll(blocks, blockI)
{
const block& b = blocks[blockI];
const labelListList& blockCells = b.cells();
const word& zoneName = b.blockDef().zoneName();
if (zoneName.size())
{
HashTable<label>::const_iterator iter = zoneMap.find(zoneName);
label zoneI;
if (iter == zoneMap.end())
{
zoneI = freeZoneI++;
Info<< " " << zoneI << '\t' << zoneName << endl;
zoneMap.insert(zoneName, zoneI);
}
else
{
zoneI = iter();
}
forAll(blockCells, i)
{
zoneCells[zoneI].append(cellI++);
}
}
else
{
cellI += b.cells().size();
}
}
List<cellZone*> cz(zoneMap.size());
Info<< nl << "Writing cell zones as cellSets" << endl;
forAllConstIter(HashTable<label>, zoneMap, iter)
{
label zoneI = iter();
cz[zoneI] = new cellZone
(
iter.key(),
zoneCells[zoneI].shrink(),
zoneI,
mesh.cellZones()
);
// Write as cellSet for ease of processing
cellSet cset
(
mesh,
iter.key(),
labelHashSet(zoneCells[zoneI].shrink())
);
cset.write();
}
mesh.pointZones().setSize(0);
mesh.faceZones().setSize(0);
mesh.cellZones().setSize(0);
mesh.addZones(List<pointZone*>(0), List<faceZone*>(0), cz);
}
// Set the precision of the points data to 10
IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
Info<< nl << "Writing polyMesh" << endl;
mesh.removeFiles();
if (!mesh.write())
{
FatalErrorIn(args.executable())
<< "Failed writing polyMesh."
<< exit(FatalError);
}
//
// write some information
//
{
const polyPatchList& patches = mesh.boundaryMesh();
Info<< "----------------" << nl
<< "Mesh Information" << nl
<< "----------------" << nl
<< " " << "boundingBox: " << boundBox(mesh.points()) << nl
<< " " << "nPoints: " << mesh.nPoints() << nl
<< " " << "nCells: " << mesh.nCells() << nl
<< " " << "nFaces: " << mesh.nFaces() << nl
<< " " << "nInternalFaces: " << mesh.nInternalFaces() << nl;
Info<< "----------------" << nl
<< "Patches" << nl
<< "----------------" << nl;
forAll(patches, patchI)
{
const polyPatch& p = patches[patchI];
Info<< " " << "patch " << patchI
<< " (start: " << p.start()
<< " size: " << p.size()
<< ") name: " << p.name()
<< nl;
}
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //