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

@ -1,87 +1 @@
// 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.val();
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);
}
}
#warning File removed - left for old dependency check only

View File

@ -77,7 +77,6 @@ Usage
#include "foamVtkInternalMeshWriter.H"
#include "attachPolyTopoChanger.H"
#include "polyTopoChange.H"
#include "emptyPolyPatch.H"
#include "cyclicPolyPatch.H"
#include "cellSet.H"
@ -85,7 +84,7 @@ Usage
#include "OSspecific.H"
#include "OFstream.H"
#include "Pair.H"
#include "wordPair.H"
#include "slidingInterface.H"
using namespace Foam;
@ -122,7 +121,8 @@ int main(int argc, char *argv[])
argList::addBoolOption
(
"write-obj",
"Write block edges and centres as obj files and exit"
"Write block edges and centres as obj files and exit",
true // (old) mark as advanced option. -write-vtk is preferred
);
argList::addOptionCompat("write-obj", {"blockTopology", 1912});
@ -135,9 +135,9 @@ int main(int argc, char *argv[])
argList::addBoolOption
(
"merge-points",
"Geometric (point) merging instead of topological merging "
"(slower, fails with high-aspect cells. default for 1912 and earlier)",
true // mark as an advanced option
"Geometric point merging instead of topological merging"
" [default for 1912 and earlier]."
// NOTE: " Slower, fails with high-aspect cells."
);
argList::addBoolOption
(
@ -164,6 +164,9 @@ int main(int argc, char *argv[])
// Remove old files, unless disabled
const bool removeOldFiles = !args.found("noClean");
// Write cellSets
const bool writeCellSets = args.found("sets");
// Default merge (topology), unless otherwise specified
blockMesh::mergeStrategy strategy(blockMesh::DEFAULT_MERGE);
@ -329,56 +332,22 @@ int main(int argc, char *argv[])
}
Info<< nl << "Creating polyMesh from blockMesh" << endl;
// Ensure we get information messages, even if turned off in dictionary
blocks.verbose(true);
polyMesh mesh
(
IOobject
autoPtr<polyMesh> meshPtr =
blocks.mesh
(
regionName,
meshInstance,
runTime
),
pointField(blocks.points()), // Copy, could we re-use space?
blocks.cells(),
blocks.patches(),
blocks.patchNames(),
blocks.patchDicts(),
"defaultFaces", // Default patch name
emptyPolyPatch::typeName // Default patch type
);
IOobject(regionName, meshInstance, runTime)
);
polyMesh& mesh = *meshPtr;
// Handle merging of patch pairs. Dictionary entry "mergePatchPairs"
// Merge patch pairs (dictionary entry "mergePatchPairs")
#include "mergePatchPairs.H"
// Set any cellZones
#include "addCellZones.H"
// Detect any cyclic patches and force re-ordering of the faces
{
bool hasCyclic = false;
for (const polyPatch& pp : mesh.boundaryMesh())
{
if (isA<cyclicPolyPatch>(pp))
{
hasCyclic = true;
break;
}
}
if (hasCyclic)
{
Info<< nl << "Detected cyclic patches; ordering boundary faces"
<< endl;
const word oldInstance = mesh.instance();
polyTopoChange meshMod(mesh);
meshMod.changeMesh(mesh, false);
mesh.setInstance(oldInstance);
}
}
// Handle cyclic patches
#include "handleCyclicPatches.H"
// Set the precision of the points data to 10
IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
@ -386,7 +355,7 @@ int main(int argc, char *argv[])
Info<< nl << "Writing polyMesh with "
<< mesh.cellZones().size() << " cellZones";
if (args.found("sets") && !mesh.cellZones().empty())
if (writeCellSets && !mesh.cellZones().empty())
{
Info<< " (written as cellSets too)";
}
@ -400,7 +369,7 @@ int main(int argc, char *argv[])
<< exit(FatalError);
}
if (args.found("sets"))
if (writeCellSets)
{
for (const cellZone& cz : mesh.cellZones())
{

View File

@ -0,0 +1,22 @@
// Detect any cyclic patches and force re-ordering of the faces
{
bool hasCyclic = false;
for (const polyPatch& pp : mesh.boundaryMesh())
{
if (isA<cyclicPolyPatch>(pp))
{
hasCyclic = true;
break;
}
}
if (hasCyclic)
{
Info<< nl << "Detected cyclic patches; ordering boundary faces" << endl;
const word oldInstance = mesh.instance();
polyTopoChange meshMod(mesh);
meshMod.changeMesh(mesh, false);
mesh.setInstance(oldInstance);
}
}

View File

@ -1,6 +1,6 @@
// Handle merging of patch pairs
{
List<Pair<word>> mergePatchPairs;
wordPairList mergePatchPairs;
// Read in a list of dictionaries for the merge patch pairs
if
@ -14,19 +14,19 @@
// 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);
List<cellZone*> cz;
forAll(mergePatchPairs, pairI)
forAll(mergePatchPairs, pairi)
{
const word mergeName
(
mergePatchPairs[pairI].first()
+ mergePatchPairs[pairI].second()
+ name(pairI)
mergePatchPairs[pairi].first()
+ mergePatchPairs[pairi].second()
+ name(pairi)
);
// An empty zone for cut points
pz[pairI] = new pointZone
pz[pairi] = new pointZone
(
mergeName + "CutPointZone",
0,
@ -34,11 +34,11 @@
);
// Master patch
const word masterPatchName(mergePatchPairs[pairI].first());
const word masterPatchName(mergePatchPairs[pairi].first());
const polyPatch& masterPatch =
mesh.boundaryMesh()[masterPatchName];
fz[3*pairI] = new faceZone
fz[3*pairi] = new faceZone
(
mergeName + "MasterZone",
identity(masterPatch.size(), masterPatch.start()),
@ -48,11 +48,11 @@
);
// Slave patch
const word slavePatchName(mergePatchPairs[pairI].second());
const word slavePatchName(mergePatchPairs[pairi].second());
const polyPatch& slavePatch =
mesh.boundaryMesh()[slavePatchName];
fz[3*pairI + 1] = new faceZone
fz[3*pairi + 1] = new faceZone
(
mergeName + "SlaveZone",
identity(slavePatch.size(), slavePatch.start()),
@ -62,7 +62,7 @@
);
// An empty zone for cut faces
fz[3*pairI + 2] = new faceZone
fz[3*pairi + 2] = new faceZone
(
mergeName + "CutFaceZone",
2,
@ -78,30 +78,30 @@
attachPolyTopoChanger polyMeshAttacher(mesh);
polyMeshAttacher.setSize(mergePatchPairs.size());
forAll(mergePatchPairs, pairI)
forAll(mergePatchPairs, pairi)
{
const word mergeName
(
mergePatchPairs[pairI].first()
+ mergePatchPairs[pairI].second()
+ name(pairI)
mergePatchPairs[pairi].first()
+ mergePatchPairs[pairi].second()
+ name(pairi)
);
// Add the sliding interface mesh modifier
polyMeshAttacher.set
(
pairI,
pairi,
new slidingInterface
(
"couple" + name(pairI),
pairI,
"couple" + name(pairi),
pairi,
polyMeshAttacher,
mergeName + "MasterZone",
mergeName + "SlaveZone",
mergeName + "CutPointZone",
mergeName + "CutFaceZone",
mergePatchPairs[pairI].first(),
mergePatchPairs[pairI].second(),
mergePatchPairs[pairi].first(),
mergePatchPairs[pairi].second(),
slidingInterface::INTEGRAL, // always integral
false,
intersection::VISIBLE