ENH: avoid blockMesh removal of files for special cases (issue #963)

- do not remove if the dictionary failed to load.
- do not remove if -blockTopology was used.
This commit is contained in:
Mark Olesen
2018-08-03 14:30:41 +02:00
parent 88e5334a9f
commit 319e09e32f
11 changed files with 409 additions and 366 deletions

View File

@ -28,8 +28,7 @@ Group
grpMeshConversionUtilities grpMeshConversionUtilities
Description Description
For mesh debugging: writes mesh as three separate OBJ files which can For mesh debugging: writes mesh as three separate OBJ files.
be viewed with e.g. javaview.
meshPoints_XXX.obj : all points and edges as lines. meshPoints_XXX.obj : all points and edges as lines.
meshFaceCentres_XXX.obj : all face centres. meshFaceCentres_XXX.obj : all face centres.
@ -61,6 +60,7 @@ void writeOBJ(const point& pt, Ostream& os)
os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl; os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
} }
// All edges of mesh // All edges of mesh
void writePoints(const polyMesh& mesh, const fileName& timeName) void writePoints(const polyMesh& mesh, const fileName& timeName)
{ {

View File

@ -0,0 +1,87 @@
// Set any cellZones
// Note cell labelling unaffected by previous mergePatchPairs
{
const label nZones = blocks.numZonedBlocks();
if (nZones)
{
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;
for (const block& b : blocks)
{
const word& zoneName = b.zoneName();
const label nCellsInBlock = b.cells().size();
if (zoneName.size())
{
const auto iter = zoneMap.cfind(zoneName);
label zonei;
if (iter.found())
{
zonei = *iter;
}
else
{
zonei = freeZoneI++;
Info<< " " << zonei << '\t' << zoneName << endl;
zoneMap.insert(zoneName, zonei);
}
// Fill with cell ids
zoneCells[zonei].reserve
(
zoneCells[zonei].size() + nCellsInBlock
);
const label endOfFill = celli + nCellsInBlock;
for (; celli < endOfFill; ++celli)
{
zoneCells[zonei].append(celli);
}
}
else
{
celli += nCellsInBlock;
}
}
List<cellZone*> cz(zoneMap.size());
forAllConstIters(zoneMap, iter)
{
const word& zoneName = iter.key();
const label zonei = iter.object();
cz[zonei] = new cellZone
(
zoneName,
zoneCells[zonei].shrink(),
zonei,
mesh.cellZones()
);
}
mesh.pointZones().resize(0);
mesh.faceZones().resize(0);
mesh.cellZones().resize(0);
mesh.addZones(List<pointZone*>(), List<faceZone*>(), cz);
}
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -41,17 +41,20 @@ Usage
Options: Options:
- \par -blockTopology - \par -blockTopology
Write the topology as a set of edges in OBJ format. Write the topology as a set of edges in OBJ format and exit.
- \par -region \<name\> - \par -region \<name\>
Specify an alternative mesh region. Specify alternative mesh region.
- \par -dict \<filename\> - \par -dict \<filename\>
Specify alternative dictionary for the block mesh description. Alternative dictionary for the block mesh description.
- \par -sets - \par -sets
Write cellZones as cellSets too (for processing purposes) Write cellZones as cellSets too (for processing purposes)
- \par -noClean
Do not remove any existing polyMesh/ directory or files
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "Time.H" #include "Time.H"
@ -78,58 +81,55 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::addNote
(
"Block mesh generator.\n"
" The ordering of vertex and face labels within a block as shown "
"below.\n"
" For the local vertex numbering in the sequence 0 to 7:\n"
" Faces 0, 1 (x-direction) are left, right.\n"
" Faces 2, 3 (y-direction) are front, back.\n"
" Faces 4, 5 (z-direction) are bottom, top.\n"
"\n"
" 7 ---- 6\n"
" f5 |\\ |\\ f3\n"
" | | 4 ---- 5 \\\n"
" | 3 |--- 2 | \\\n"
" | \\| \\| f2\n"
" f4 0 ---- 1\n"
" Y Z\n"
" \\ | f0 ------ f1\n"
" \\|\n"
" O--- X\n"
);
argList::noParallel(); argList::noParallel();
argList::addBoolOption argList::addBoolOption
( (
"blockTopology", "blockTopology",
"Write block edges and centres as .obj files" "Write block edges and centres as obj files and exit"
); );
argList::addBoolOption argList::addBoolOption
( (
"noClean", "noClean",
"Keep the existing files in the polyMesh" "Do not remove any existing polyMesh/ directory or files"
); );
argList::addOption argList::addOption
( (
"dict", "dict",
"file", "file",
"Specify alternative dictionary for the blockMesh description" "Alternative dictionary for the blockMesh description"
); );
argList::addBoolOption argList::addBoolOption
( (
"sets", "sets",
"Write cellZones as cellSets too (for processing purposes)" "Write cellZones as cellSets too (for processing purposes)"
); );
argList::addNote
(
"Block description\n"
"\n"
" For a given block, the correspondence between the ordering of\n"
" vertex labels and face labels is shown below.\n"
" For vertex numbering in the sequence 0 to 7 (block, centre):\n"
" faces 0 (f0) and 1 are left and right, respectively;\n"
" faces 2 and 3 are front and back; \n"
" and faces 4 and 5 are bottom and top::\n"
"\n"
" 7 ---- 6\n"
" f5 |\\ |\\ f3\n"
" | | 4 ---- 5 \\\n"
" | 3 |--- 2 | \\\n"
" | \\| \\| f2\n"
" f4 0 ---- 1\n"
"\n"
" Z f0 ----- f1\n"
" | Y\n"
" | /\n"
" O --- X\n"
);
#include "addRegionOption.H" #include "addRegionOption.H"
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"
const word dictName("blockMeshDict");
word regionName; word regionName;
word regionPath; word regionPath;
@ -140,47 +140,59 @@ int main(int argc, char *argv[])
regionPath = regionName; regionPath = regionName;
} }
// Search for the appropriate blockMesh dictionary....
fileName dictPath; // Locate appropriate blockMeshDict
#include "findBlockMeshDict.H"
// Check if the dictionary is specified on the command-line blockMesh blocks(meshDict, regionName);
if (args.readIfPresent("dict", dictPath))
if (!blocks.valid())
{ {
if (isDir(dictPath)) // Could/should be Fatal?
WarningIn(args.executable())
<< "Did not generate any blocks. Stopping." << nl << endl;
return 1;
}
if (args.found("blockTopology"))
{
Info<< nl;
// Write mesh as edges.
{ {
dictPath /= dictName; OFstream os(runTime.path()/"blockTopology.obj");
}
}
// Check if dictionary is present in the constant directory
else if
(
exists
(
runTime.path()/runTime.constant()
/regionPath/polyMesh::meshSubDir/dictName
)
)
{
dictPath =
runTime.constant()
/regionPath/polyMesh::meshSubDir/dictName;
// Warn that constant/polyMesh/blockMesh was selected instead of Info<< "Writing block structure as obj format: "
// system/blockMesh << os.name().name() << endl;
WarningIn(args[0])
<< "Using the old blockMeshDict location: " blocks.writeTopology(os);
<< dictPath << nl }
<< " instead of the default location: "
<< runTime.system()/regionPath/dictName << nl // Write centres of blocks
<< endl; {
} OFstream os(runTime.path()/"blockCentres.obj");
// Otherwise assume the dictionary is present in the system directory
else Info<< "Writing block centres as obj format: "
{ << os.name().name() << endl;
dictPath = runTime.system()/regionPath/dictName;
const polyMesh& topo = blocks.topology();
for (const point& cc : topo.cellCentres())
{
os << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl;
}
}
Info<< "\nEnd\n" << endl;
return 0;
} }
if (!args.found("noClean")) if (!args.found("noClean"))
{ {
fileName polyMeshPath fileName polyMeshPath
@ -205,74 +217,12 @@ int main(int argc, char *argv[])
} }
} }
IOobject meshDictIO
(
dictPath,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
if (!meshDictIO.typeHeaderOk<IOdictionary>(true))
{
FatalErrorInFunction
<< meshDictIO.objectPath()
<< nl
<< exit(FatalError);
}
Info<< "Creating block mesh from\n "
<< meshDictIO.objectPath() << endl;
IOdictionary meshDict(meshDictIO);
blockMesh blocks(meshDict, regionName);
if (args.found("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();
for (const point& cc : cellCentres)
{
//point cc = b.blockShape().centre(b.points());
str << "v " << cc.x() << ' ' << cc.y() << ' ' << cc.z() << nl;
}
}
Info<< nl << "end" << endl;
return 0;
}
Info<< nl << "Creating polyMesh from blockMesh" << endl; Info<< nl << "Creating polyMesh from blockMesh" << endl;
word defaultFacesName = "defaultFaces"; word defaultFacesName = "defaultFaces";
word defaultFacesType = emptyPolyPatch::typeName; word defaultFacesType = emptyPolyPatch::typeName;
polyMesh mesh polyMesh mesh
( (
IOobject IOobject
@ -290,97 +240,12 @@ int main(int argc, char *argv[])
defaultFacesType 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" // Handle merging of patch pairs. Dictionary entry "mergePatchPairs"
} #include "mergePatchPairs.H"
else
{
Info<< nl << "There are no merge patch pairs edges" << endl;
}
// Set any cellZones
// Set any cellZones (note: cell labelling unaffected by above #include "addCellZones.H"
// mergePatchPairs)
const 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 List<FixedList<label, 8>> blockCells = b.cells();
const word& zoneName = b.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());
forAllConstIter(HashTable<label>, zoneMap, iter)
{
label zoneI = iter();
cz[zoneI] = new cellZone
(
iter.key(),
zoneCells[zoneI].shrink(),
zoneI,
mesh.cellZones()
);
}
mesh.pointZones().setSize(0);
mesh.faceZones().setSize(0);
mesh.cellZones().setSize(0);
mesh.addZones(List<pointZone*>(0), List<faceZone*>(0), cz);
}
// Detect any cyclic patches and force re-ordering of the faces // Detect any cyclic patches and force re-ordering of the faces
@ -413,6 +278,7 @@ int main(int argc, char *argv[])
Info<< nl << "Writing polyMesh with " Info<< nl << "Writing polyMesh with "
<< mesh.cellZones().size() << " cellZones"; << mesh.cellZones().size() << " cellZones";
if (args.found("sets") && !mesh.cellZones().empty()) if (args.found("sets") && !mesh.cellZones().empty())
{ {
Info<< " (written as cellSets too)"; Info<< " (written as cellSets too)";
@ -429,9 +295,8 @@ int main(int argc, char *argv[])
if (args.found("sets")) if (args.found("sets"))
{ {
forAll(mesh.cellZones(), zonei) for (const cellZone& cz : mesh.cellZones())
{ {
const cellZone& cz = mesh.cellZones()[zonei];
cellSet(mesh, cz.name(), cz).write(); cellSet(mesh, cz.name(), cz).write();
} }
} }
@ -453,11 +318,9 @@ int main(int argc, char *argv[])
<< "Patches" << nl << "Patches" << nl
<< "----------------" << nl; << "----------------" << nl;
forAll(patches, patchi) for (const polyPatch& p : patches)
{ {
const polyPatch& p = patches[patchi]; Info<< " " << "patch " << p.index()
Info<< " " << "patch " << patchi
<< " (start: " << p.start() << " (start: " << p.start()
<< " size: " << p.size() << " size: " << p.size()
<< ") name: " << p.name() << ") name: " << p.name()

View File

@ -0,0 +1,72 @@
// Search for the appropriate blockMesh dictionary....
const word dictName("blockMeshDict");
autoPtr<IOdictionary> meshDictPtr;
{
fileName dictPath;
if (args.readIfPresent("dict", dictPath))
{
// Dictionary specified on the command-line ...
if (isDir(dictPath))
{
dictPath /= dictName;
}
}
else if
(
exists
(
runTime.path()/runTime.constant()
/regionPath/polyMesh::meshSubDir/dictName
)
)
{
// Dictionary present constant polyMesh directory (old-style)
dictPath =
runTime.constant()
/regionPath/polyMesh::meshSubDir/dictName;
// Warn that constant/polyMesh/blockMeshDict was used
// instead of system/blockMeshDict
WarningIn(args.executable())
<< "Using the old blockMeshDict location: "
<< dictPath << nl
<< " instead of the default location: "
<< runTime.system()/regionPath/dictName << nl
<< endl;
}
else
{
// Assume dictionary is to be found in the system directory
dictPath = runTime.system()/regionPath/dictName;
}
IOobject meshDictIO
(
dictPath,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
if (!meshDictIO.typeHeaderOk<IOdictionary>(true))
{
FatalErrorInFunction
<< meshDictIO.objectPath() << nl
<< exit(FatalError);
}
Info<< "Creating block mesh from\n "
<< meshDictIO.objectPath() << endl;
meshDictPtr = autoPtr<IOdictionary>::New(meshDictIO);
}
const IOdictionary& meshDict = *meshDictPtr;

View File

@ -1,104 +1,118 @@
if (mergePatchPairs.size()) // Handle merging of patch pairs
{
List<Pair<word>> mergePatchPairs;
// Read in a list of dictionaries for the merge patch pairs
if
(
meshDict.readIfPresent("mergePatchPairs", mergePatchPairs)
&& mergePatchPairs.size()
)
{
Info<< "Creating merge patch pairs" << nl << endl;
// Create and add point and face zones and mesh modifiers
List<pointZone*> pz(mergePatchPairs.size());
List<faceZone*> fz(3*mergePatchPairs.size());
List<cellZone*> cz(0);
forAll(mergePatchPairs, pairI)
{ {
Info<< "Creating merge patch pairs" << nl << endl; const word mergeName
(
mergePatchPairs[pairI].first()
+ mergePatchPairs[pairI].second()
+ name(pairI)
);
// Create and add point and face zones and mesh modifiers // An empty zone for cut points
List<pointZone*> pz(mergePatchPairs.size()); pz[pairI] = new pointZone
List<faceZone*> fz(3*mergePatchPairs.size()); (
List<cellZone*> cz(0); mergeName + "CutPointZone",
0,
mesh.pointZones()
);
forAll(mergePatchPairs, pairI) // Master patch
{ const word masterPatchName(mergePatchPairs[pairI].first());
const word mergeName const polyPatch& masterPatch =
( mesh.boundaryMesh()[masterPatchName];
mergePatchPairs[pairI].first()
+ mergePatchPairs[pairI].second() fz[3*pairI] = new faceZone
+ name(pairI) (
); mergeName + "MasterZone",
identity(masterPatch.size(), masterPatch.start()),
// An empty zone for cut points false, // none are flipped
pz[pairI] = new pointZone 0,
( mesh.faceZones()
mergeName + "CutPointZone", );
0,
mesh.pointZones() // Slave patch
); const word slavePatchName(mergePatchPairs[pairI].second());
const polyPatch& slavePatch =
// Master patch mesh.boundaryMesh()[slavePatchName];
const word masterPatchName(mergePatchPairs[pairI].first());
const polyPatch& masterPatch = fz[3*pairI + 1] = new faceZone
mesh.boundaryMesh()[masterPatchName]; (
mergeName + "SlaveZone",
fz[3*pairI] = new faceZone identity(slavePatch.size(), slavePatch.start()),
( false, // none are flipped
mergeName + "MasterZone", 1,
identity(masterPatch.size(), masterPatch.start()), mesh.faceZones()
false, // none are flipped );
0,
mesh.faceZones() // An empty zone for cut faces
); fz[3*pairI + 2] = new faceZone
(
// Slave patch mergeName + "CutFaceZone",
const word slavePatchName(mergePatchPairs[pairI].second()); 2,
const polyPatch& slavePatch = mesh.faceZones()
mesh.boundaryMesh()[slavePatchName]; );
} // end of all merge pairs
fz[3*pairI + 1] = new faceZone
( Info<< "Adding point and face zones" << endl;
mergeName + "SlaveZone", mesh.addZones(pz, fz, cz);
identity(slavePatch.size(), slavePatch.start()),
false, // none are flipped
1, Info<< "Creating attachPolyTopoChanger" << endl;
mesh.faceZones() attachPolyTopoChanger polyMeshAttacher(mesh);
); polyMeshAttacher.setSize(mergePatchPairs.size());
// An empty zone for cut faces forAll(mergePatchPairs, pairI)
fz[3*pairI + 2] = new faceZone {
( const word mergeName
mergeName + "CutFaceZone", (
2, mergePatchPairs[pairI].first()
mesh.faceZones() + mergePatchPairs[pairI].second()
); + name(pairI)
} // end of all merge pairs );
Info<< "Adding point and face zones" << endl; // Add the sliding interface mesh modifier
mesh.addZones(pz, fz, cz); polyMeshAttacher.set
(
pairI,
Info<< "Creating attachPolyTopoChanger" << endl; new slidingInterface
attachPolyTopoChanger polyMeshAttacher(mesh);
polyMeshAttacher.setSize(mergePatchPairs.size());
forAll(mergePatchPairs, pairI)
{
const word mergeName
(
mergePatchPairs[pairI].first()
+ mergePatchPairs[pairI].second()
+ name(pairI)
);
// Add the sliding interface mesh modifier
polyMeshAttacher.set
( (
"couple" + name(pairI),
pairI, pairI,
new slidingInterface polyMeshAttacher,
( mergeName + "MasterZone",
"couple" + name(pairI), mergeName + "SlaveZone",
pairI, mergeName + "CutPointZone",
polyMeshAttacher, mergeName + "CutFaceZone",
mergeName + "MasterZone", mergePatchPairs[pairI].first(),
mergeName + "SlaveZone", mergePatchPairs[pairI].second(),
mergeName + "CutPointZone", slidingInterface::INTEGRAL, // always integral
mergeName + "CutFaceZone", false,
mergePatchPairs[pairI].first(), intersection::VISIBLE
mergePatchPairs[pairI].second(), )
slidingInterface::INTEGRAL, // always integral );
false,
intersection::VISIBLE
)
);
}
polyMeshAttacher.attach(true);
} }
polyMeshAttacher.attach(true);
}
else
{
Info<< nl << "There are no merge patch pairs" << endl;
}
}

View File

@ -677,6 +677,11 @@ void writeMesh
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::addNote
(
"Automatic split hex mesher. Refines and snaps to surface"
);
#include "addRegionOption.H" #include "addRegionOption.H"
#include "addOverwriteOption.H" #include "addOverwriteOption.H"
argList::addBoolOption argList::addBoolOption

View File

@ -82,8 +82,7 @@ void dumpPoints(const triSurface& surf, const labelList& borderPoint)
{ {
fileName fName("borderPoints.obj"); fileName fName("borderPoints.obj");
Info<< "Dumping borderPoints as Lightwave .obj file to " << fName Info<< "Dumping borderPoints as obj file: " << fName << endl;
<< "\nThis can be visualized with e.g. javaview (www.javaview.de)\n\n";
OFstream os(fName); OFstream os(fName);
@ -103,8 +102,7 @@ void dumpEdges(const triSurface& surf, const boolList& borderEdge)
{ {
fileName fName("borderEdges.obj"); fileName fName("borderEdges.obj");
Info<< "Dumping borderEdges as Lightwave .obj file to " << fName Info<< "Dumping borderEdges as obj file: " << fName << endl;
<< "\nThis can be visualized with e.g. javaview (www.javaview.de)\n\n";
OFstream os(fName); OFstream os(fName);
@ -129,7 +127,7 @@ void dumpFaces
const Map<label>& connectedFaces const Map<label>& connectedFaces
) )
{ {
Info<< "Dumping connectedFaces as .obj file to " << fName << nl; Info<< "Dumping connectedFaces as obj file: " << fName << endl;
OFstream os(fName); OFstream os(fName);

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -80,16 +80,14 @@ Foam::blockMesh::blockMesh(const IOdictionary& dict, const word& regionName)
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::blockMesh::~blockMesh() bool Foam::blockMesh::valid() const
{ {
delete topologyPtr_; return topologyPtr_.valid();
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::blockMesh::verbose(const bool on) void Foam::blockMesh::verbose(const bool on)
{ {
verboseOutput = on; verboseOutput = on;
@ -191,17 +189,19 @@ Foam::wordList Foam::blockMesh::patchNames() const
Foam::label Foam::blockMesh::numZonedBlocks() const Foam::label Foam::blockMesh::numZonedBlocks() const
{ {
label num = 0; const blockList& blocks = *this;
forAll(*this, blocki) label count = 0;
for (const block& blk : blocks)
{ {
if (operator[](blocki).zoneName().size()) if (blk.zoneName().size())
{ {
num++; ++count;
} }
} }
return num; return count;
} }
@ -209,19 +209,15 @@ void Foam::blockMesh::writeTopology(Ostream& os) const
{ {
const pointField& pts = topology().points(); const pointField& pts = topology().points();
forAll(pts, pI) for (const point& pt : pts)
{ {
const point& pt = pts[pI];
os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
} }
const edgeList& edges = topology().edges(); const edgeList& edges = topology().edges();
forAll(edges, eI) for (const edge& e : edges)
{ {
const edge& e = edges[eI];
os << "l " << e.start() + 1 << ' ' << e.end() + 1 << endl; os << "l " << e.start() + 1 << ' ' << e.end() + 1 << endl;
} }
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -93,8 +93,9 @@ class blockMesh
blockFaceList faces_; blockFaceList faces_;
//- The blocks themselves (the topology) as a polyMesh //- The blocks themselves (the topology) as a polyMesh
polyMesh* topologyPtr_; autoPtr<polyMesh> topologyPtr_;
//- The sum of all cells in each block
label nPoints_; label nPoints_;
//- The sum of all cells in each block //- The sum of all cells in each block
@ -143,9 +144,13 @@ class blockMesh
void createCellShapes(cellShapeList& tmpBlockCells); void createCellShapes(cellShapeList& tmpBlockCells);
polyMesh* createTopology(const IOdictionary&, const word& regionName); autoPtr<polyMesh> createTopology
(
const IOdictionary& dict,
const word& regionName
);
void check(const polyMesh&, const dictionary&) const; void check(const polyMesh& bm, const dictionary& dict) const;
//- Determine the merge info and the final number of cells/points //- Determine the merge info and the final number of cells/points
void calcMergeInfo(); void calcMergeInfo();
@ -159,9 +164,13 @@ class blockMesh
void createCells() const; void createCells() const;
void createPatches() const; void createPatches() const;
//- As copy (not implemented)
//- No copy construct
blockMesh(const blockMesh&) = delete; blockMesh(const blockMesh&) = delete;
//- No copy assignment
void operator=(const blockMesh&) = delete;
public: public:
@ -173,11 +182,11 @@ public:
// Constructors // Constructors
//- Construct from IOdictionary //- Construct from IOdictionary
blockMesh(const IOdictionary&, const word& regionName); blockMesh(const IOdictionary& dict, const word& regionName);
//- Destructor //- Destructor
~blockMesh(); ~blockMesh() = default;
// Member Functions // Member Functions
@ -196,6 +205,9 @@ public:
return geometry_; return geometry_;
} }
//- True if the blockMesh topology exists
bool valid() const;
//- Reference to point field defining the blockMesh //- Reference to point field defining the blockMesh
// these points have not been scaled by scaleFactor // these points have not been scaled by scaleFactor
const pointField& vertices() const; const pointField& vertices() const;

View File

@ -336,7 +336,7 @@ void Foam::blockMesh::createCellShapes
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::polyMesh* Foam::blockMesh::createTopology Foam::autoPtr<Foam::polyMesh> Foam::blockMesh::createTopology
( (
const IOdictionary& meshDescription, const IOdictionary& meshDescription,
const word& regionName const word& regionName
@ -428,8 +428,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
} }
autoPtr<polyMesh> blockMeshPtr;
polyMesh* blockMeshPtr = nullptr;
// Create the patches // Create the patches
@ -511,7 +510,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
} }
} }
blockMeshPtr = new polyMesh blockMeshPtr = autoPtr<polyMesh>::New
( (
IOobject IOobject
( (
@ -550,7 +549,7 @@ Foam::polyMesh* Foam::blockMesh::createTopology
cellShapeList tmpBlockCells(blocks.size()); cellShapeList tmpBlockCells(blocks.size());
createCellShapes(tmpBlockCells); createCellShapes(tmpBlockCells);
blockMeshPtr = new polyMesh blockMeshPtr = autoPtr<polyMesh>::New
( (
IOobject IOobject
( (

View File

@ -1296,10 +1296,7 @@ Foam::Map<Foam::label> Foam::surfaceFeatures::nearestSamples
// Dump to obj file // Dump to obj file
// //
Pout<< endl Pout<< "Dumping nearest surface feature points to nearestSamples.obj"
<< "Dumping nearest surface feature points to nearestSamples.obj"
<< endl
<< "View this Lightwave-OBJ file with e.g. javaview" << endl
<< endl; << endl;
OFstream objStream("nearestSamples.obj"); OFstream objStream("nearestSamples.obj");
@ -1423,8 +1420,8 @@ Foam::Map<Foam::label> Foam::surfaceFeatures::nearestSamples
{ {
// Dump to obj file // Dump to obj file
Pout<< "Dumping nearest surface edges to nearestEdges.obj\n" Pout<< "Dumping nearest surface edges to nearestEdges.obj"
<< "View this Lightwave-OBJ file with e.g. javaview\n" << endl; << endl;
OFstream objStream("nearestEdges.obj"); OFstream objStream("nearestEdges.obj");
@ -1577,8 +1574,8 @@ Foam::Map<Foam::pointIndexHit> Foam::surfaceFeatures::nearestEdges
{ {
// Dump to obj file // Dump to obj file
Pout<< "Dumping nearest surface feature edges to nearestEdges.obj\n" Pout<< "Dumping nearest surface feature edges to nearestEdges.obj"
<< "View this Lightwave-OBJ file with e.g. javaview\n" << endl; << endl;
OFstream objStream("nearestEdges.obj"); OFstream objStream("nearestEdges.obj");