2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2014-06-01 11:15:18 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2018-05-29 07:35:20 +00:00
|
|
|
\\ / O peration | Version: 4.1
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2014-06-01 11:15:18 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2014-06-01 11:15:18 +00:00
|
|
|
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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2014-06-01 11:15:18 +00:00
|
|
|
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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2014-06-01 11:15:18 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Application
|
|
|
|
blockMesh
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
Description
|
|
|
|
A multi-block mesh generator.
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Uses the block mesh description found in
|
2014-05-28 11:49:49 +00:00
|
|
|
\a constant/polyMesh/blockMeshDict
|
|
|
|
(or \a constant/\<region\>/polyMesh/blockMeshDict).
|
2010-08-25 21:42:57 +00:00
|
|
|
|
|
|
|
Usage
|
|
|
|
|
|
|
|
- blockMesh [OPTION]
|
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
\param -blockTopology \n
|
2010-08-25 21:42:57 +00:00
|
|
|
Write the topology as a set of edges in OBJ format.
|
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
\param -region \<name\> \n
|
2010-08-25 21:42:57 +00:00
|
|
|
Specify an alternative mesh region.
|
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
\param -dict \<filename\> \n
|
|
|
|
Specify alternative dictionary for the block mesh description.
|
2010-08-25 21:42:57 +00:00
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
2014-06-02 16:05:03 +00:00
|
|
|
#include "objectRegistry.H"
|
2015-06-17 13:53:59 +00:00
|
|
|
#include "foamTime.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
#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();
|
2010-08-25 21:42:57 +00:00
|
|
|
argList::validOptions.insert("blockTopology", "");
|
|
|
|
argList::validOptions.insert("dict", "dictionary");
|
|
|
|
# include "addRegionOption.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
# include "setRootCase.H"
|
|
|
|
# include "createTime.H"
|
2010-08-25 21:42:57 +00:00
|
|
|
|
|
|
|
const word dictName("blockMeshDict");
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
word regionName;
|
|
|
|
fileName polyMeshDir;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (args.optionFound("region"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
// constant/<region>/polyMesh/blockMeshDict
|
|
|
|
regionName = args.option("region");
|
2010-05-12 13:27:55 +00:00
|
|
|
polyMeshDir = regionName/polyMesh::meshSubDir;
|
|
|
|
|
|
|
|
Info<< nl << "Generating mesh for region " << regionName << endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
// constant/polyMesh/blockMeshDict
|
|
|
|
regionName = polyMesh::defaultRegion;
|
2010-05-12 13:27:55 +00:00
|
|
|
polyMeshDir = polyMesh::meshSubDir;
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
autoPtr<IOobject> meshDictIoPtr;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (args.optionFound("dict"))
|
|
|
|
{
|
|
|
|
fileName dictPath(args.option("dict"));
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (!meshDictIoPtr->headerOk())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
2010-08-25 21:42:57 +00:00
|
|
|
<< "Cannot open mesh description file\n "
|
|
|
|
<< meshDictIoPtr->objectPath()
|
|
|
|
<< nl
|
2010-05-12 13:27:55 +00:00
|
|
|
<< exit(FatalError);
|
|
|
|
}
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
Info<< nl << "Creating block mesh from\n "
|
|
|
|
<< meshDictIoPtr->objectPath() << nl << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
blockMesh::verbose(true);
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
IOdictionary meshDict(meshDictIoPtr());
|
2014-05-28 11:49:49 +00:00
|
|
|
blockMesh blocks(meshDict, regionName);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (args.optionFound("blockTopology"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
Info<< nl << "Creating polyMesh from blockMesh" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
word defaultFacesName = "defaultFaces";
|
|
|
|
word defaultFacesType = emptyPolyPatch::typeName;
|
|
|
|
polyMesh mesh
|
|
|
|
(
|
|
|
|
IOobject
|
|
|
|
(
|
|
|
|
regionName,
|
|
|
|
runTime.constant(),
|
|
|
|
runTime
|
|
|
|
),
|
2014-05-28 11:49:49 +00:00
|
|
|
xferCopy(blocks.points()), // could we re-use space?
|
2010-05-12 13:27:55 +00:00
|
|
|
blocks.cells(),
|
|
|
|
blocks.patches(),
|
2014-05-28 11:49:49 +00:00
|
|
|
blocks.patchNames(),
|
|
|
|
blocks.patchDicts(),
|
2010-05-12 13:27:55 +00:00
|
|
|
defaultFacesName,
|
2014-05-28 11:49:49 +00:00
|
|
|
defaultFacesType
|
2010-05-12 13:27:55 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Read in a list of dictionaries for the merge patch pairs
|
2010-08-25 21:42:57 +00:00
|
|
|
if (meshDict.found("mergePatchPairs"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
List<Pair<word> > mergePatchPairs
|
|
|
|
(
|
2010-08-25 21:42:57 +00:00
|
|
|
meshDict.lookup("mergePatchPairs")
|
2010-05-12 13:27:55 +00:00
|
|
|
);
|
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
# include "mergePatchPairs.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-28 11:49:49 +00:00
|
|
|
Info<< nl << "There are no merge patch pairs edges" << endl;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
2019-02-01 12:36:12 +00:00
|
|
|
List<dynamicLabelList > zoneCells(nZones);
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (zoneName.size())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
cz[zoneI] = new cellZone
|
2010-05-12 13:27:55 +00:00
|
|
|
(
|
|
|
|
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
|
2014-05-28 11:49:49 +00:00
|
|
|
IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
Info<< nl << "Writing polyMesh" << endl;
|
2010-08-25 21:42:57 +00:00
|
|
|
mesh.removeFiles();
|
2010-05-12 13:27:55 +00:00
|
|
|
if (!mesh.write())
|
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "Failed writing polyMesh."
|
|
|
|
<< exit(FatalError);
|
|
|
|
}
|
|
|
|
|
2014-05-28 11:49:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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;
|
2010-08-25 21:42:57 +00:00
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|