ENH: relocate blockMesh polyMesh generation into library (for code reuse)

STYLE: adjust blockMesh advanced/non-advanced options

- make -merge-points "non-advanced" (for better exposure)
- make -write-obj "advanced" (-write-vtk is preferred)
This commit is contained in:
Mark Olesen
2020-10-05 12:30:41 +02:00
parent 179e4cbcf2
commit 8939a55653
7 changed files with 225 additions and 176 deletions

View File

@ -109,15 +109,23 @@ Foam::blockMesh::blockMesh
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::blockMesh::valid() const
bool Foam::blockMesh::valid() const noexcept
{
return bool(topologyPtr_);
}
void Foam::blockMesh::verbose(const bool on)
bool Foam::blockMesh::verbose() const noexcept
{
return verboseOutput;
}
bool Foam::blockMesh::verbose(const bool on) noexcept
{
bool old(verboseOutput);
verboseOutput = on;
return old;
}

View File

@ -226,10 +226,10 @@ public:
//- Construct from IOdictionary for given region
// Default is topological merging.
blockMesh
explicit blockMesh
(
const IOdictionary& dict,
const word& regionName,
const word& regionName = polyMesh::defaultRegion,
mergeStrategy strategy = mergeStrategy::DEFAULT_MERGE
);
@ -255,10 +255,10 @@ public:
}
//- True if the blockMesh topology exists
bool valid() const;
bool valid() const noexcept;
//- Reference to point field defining the blockMesh
// these points have not been scaled by scaleFactor
//- Reference to point field defining the blockMesh.
// These points are \b not scaled by scaleFactor
const pointField& vertices() const;
//- Return the blockMesh topology as a polyMesh
@ -279,8 +279,8 @@ public:
//- The scaling factor used to convert to metres
scalar scaleFactor() const;
//- The points for the entire mesh
// these points have been scaled by scaleFactor
//- The points for the entire mesh.
// These points \b are scaled by scaleFactor
const pointField& points() const;
//- Return cell shapes list
@ -299,16 +299,26 @@ public:
label numZonedBlocks() const;
// Edit
// Verbosity
//- Enable/disable verbose information about the progress
void verbose(const bool on=true);
//- Verbose information?
bool verbose() const noexcept;
//- Enable/disable verbose information about the progress
// \return old value
bool verbose(const bool on) noexcept;
// Write
// Mesh Generation
//- Writes edges of blockMesh in OBJ format.
void writeTopology(Ostream&) const;
//- Create polyMesh, with cell zones
autoPtr<polyMesh> mesh(const IOobject& io) const;
// Write
//- Writes edges of blockMesh in OBJ format.
void writeTopology(Ostream& os) const;
};

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,6 +28,7 @@ License
#include "blockMesh.H"
#include "cellModel.H"
#include "emptyPolyPatch.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -270,4 +271,129 @@ void Foam::blockMesh::createPatches() const
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::polyMesh>
Foam::blockMesh::mesh(const IOobject& io) const
{
const blockMesh& blkMesh = *this;
if (verboseOutput)
{
Info<< nl << "Creating polyMesh from blockMesh" << endl;
}
auto meshPtr = autoPtr<polyMesh>::New
(
io,
pointField(blkMesh.points()), // Copy, could we re-use space?
blkMesh.cells(),
blkMesh.patches(),
blkMesh.patchNames(),
blkMesh.patchDicts(),
"defaultFaces", // Default patch name
emptyPolyPatch::typeName // Default patch type
);
// Set any cellZones
const label nZones = blkMesh.numZonedBlocks();
if (nZones)
{
polyMesh& pmesh = *meshPtr;
if (verboseOutput)
{
Info<< "Adding cell zones" << endl;
}
// Map from zoneName to cellZone index
HashTable<label> zoneMap(2*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 : blkMesh)
{
const word& zoneName = b.zoneName();
const label nCellsInBlock = b.cells().size();
if (zoneName.size())
{
const auto iter = zoneMap.cfind(zoneName);
label zonei = freeZonei;
if (iter.found())
{
zonei = *iter;
}
else
{
zoneMap.insert(zoneName, zonei);
++freeZonei;
if (verboseOutput)
{
Info<< " " << zonei << '\t' << zoneName << endl;
}
}
// 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.val();
cz[zonei] = new cellZone
(
zoneName,
zoneCells[zonei].shrink(),
zonei,
pmesh.cellZones()
);
}
pmesh.pointZones().resize(0);
pmesh.faceZones().resize(0);
pmesh.cellZones().resize(0);
pmesh.addZones(List<pointZone*>(), List<faceZone*>(), cz);
}
// Merge patch pairs, cyclic must be done elsewhere
// - requires libdynamicMesh
return meshPtr;
}
// ************************************************************************* //