From 8756791b005c2408ff64a7c11683e9a885b50e0c Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Mon, 4 May 2020 16:19:03 +0200 Subject: [PATCH] ENH: use topological merge as default for blockMesh (closes #1589) - faster and fewer issues with high aspect ratio cells. - `blockMesh -merge-geometric` for old behaviour --- .../generation/PDRblockMesh/PDRblockMesh.C | 5 ++- .../mesh/generation/blockMesh/blockMesh.C | 29 ++++++++++++--- src/mesh/blockMesh/Make/files | 4 +-- src/mesh/blockMesh/blockMesh/blockMesh.C | 25 ++++++++----- src/mesh/blockMesh/blockMesh/blockMesh.H | 36 ++++++++++++++----- ...eshMerge.C => blockMeshMergeGeometrical.C} | 3 +- ...ergeFast.C => blockMeshMergeTopological.C} | 4 +-- 7 files changed, 79 insertions(+), 27 deletions(-) rename src/mesh/blockMesh/blockMesh/{blockMeshMerge.C => blockMeshMergeGeometrical.C} (99%) rename src/mesh/blockMesh/blockMesh/{blockMeshMergeFast.C => blockMeshMergeTopological.C} (99%) diff --git a/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C b/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C index 20efaae0d24..8f040f93d2a 100644 --- a/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C +++ b/applications/utilities/mesh/generation/PDRblockMesh/PDRblockMesh.C @@ -111,6 +111,9 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" + // Remove old files, unless disabled + const bool removeOldFiles = !args.found("noClean"); + // Instance for resulting mesh bool useTime = false; word meshInstance(runTime.constant()); @@ -159,7 +162,7 @@ int main(int argc, char *argv[]) runTime.setTime(instant(meshInstance), 0); } - if (!args.found("noClean")) + if (removeOldFiles) { const fileName polyMeshPath ( diff --git a/applications/utilities/mesh/generation/blockMesh/blockMesh.C b/applications/utilities/mesh/generation/blockMesh/blockMesh.C index 02a59d6c13d..431f7000ef5 100644 --- a/applications/utilities/mesh/generation/blockMesh/blockMesh.C +++ b/applications/utilities/mesh/generation/blockMesh/blockMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,6 +46,9 @@ Usage - \par -blockTopology Write the topology as a set of edges in OBJ format and exit. + - \par -merge-geometric + Use geometric instead of topological merging + - \par -region \<name\> Specify alternative mesh region. @@ -118,6 +121,13 @@ int main(int argc, char *argv[]) "Write block edges and centres as obj files and exit" ); argList::addBoolOption + ( + "merge-geometric", + "Use geometric (point) merging instead of topological merging " + "(slower, fails with high-aspect cells. default for 1912 and earlier)", + true // mark as an advanced option + ); + argList::addBoolOption ( "noClean", "Do not remove any existing polyMesh/ directory or files" @@ -144,7 +154,18 @@ int main(int argc, char *argv[]) #include "setRootCase.H" #include "createTime.H" - word regionName = polyMesh::defaultRegion; + // Remove old files, unless disabled + const bool removeOldFiles = !args.found("noClean"); + + // Topological merge, unless otherwise specified + blockMesh::mergeStrategy strategy(blockMesh::TOPOLOGICAL); + + if (args.found("merge-geometric")) + { + strategy = blockMesh::GEOMETRIC; + } + + word regionName(polyMesh::defaultRegion); word regionPath; // Check if the region is specified otherwise mesh the default region @@ -183,7 +204,7 @@ int main(int argc, char *argv[]) // Locate appropriate blockMeshDict #include "findBlockMeshDict.H" - blockMesh blocks(meshDict, regionName); + blockMesh blocks(meshDict, regionName, strategy); if (!blocks.valid()) { @@ -243,7 +264,7 @@ int main(int argc, char *argv[]) runTime.setTime(instant(meshInstance), 0); } - if (!args.found("noClean")) + if (removeOldFiles) { const fileName polyMeshPath ( diff --git a/src/mesh/blockMesh/Make/files b/src/mesh/blockMesh/Make/files index 8193f56e1a1..2f88d0e1e3a 100644 --- a/src/mesh/blockMesh/Make/files +++ b/src/mesh/blockMesh/Make/files @@ -34,8 +34,8 @@ blockMesh/blockMesh.C blockMesh/blockMeshCreate.C blockMesh/blockMeshTopology.C blockMesh/blockMeshCheck.C -blockMesh/blockMeshMerge.C -blockMesh/blockMeshMergeFast.C +blockMesh/blockMeshMergeGeometrical.C +blockMesh/blockMeshMergeTopological.C blockMeshTools/blockMeshTools.C diff --git a/src/mesh/blockMesh/blockMesh/blockMesh.C b/src/mesh/blockMesh/blockMesh/blockMesh.C index cc2f51a64e8..0b52d4daa83 100644 --- a/src/mesh/blockMesh/blockMesh/blockMesh.C +++ b/src/mesh/blockMesh/blockMesh/blockMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,13 +39,18 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::blockMesh::blockMesh(const IOdictionary& dict, const word& regionName) +Foam::blockMesh::blockMesh +( + const IOdictionary& dict, + const word& regionName, + const mergeStrategy strategy +) : meshDict_(dict), - verboseOutput(meshDict_.lookupOrDefault("verbose", true)), + verboseOutput(meshDict_.getOrDefault("verbose", true)), checkFaceCorrespondence_ ( - meshDict_.lookupOrDefault("checkFaceCorrespondence", true) + meshDict_.getOrDefault("checkFaceCorrespondence", true) ), geometry_ ( @@ -63,7 +68,7 @@ Foam::blockMesh::blockMesh(const IOdictionary& dict, const word& regionName) : dictionary(), true ), - scaleFactor_(1.0), + scaleFactor_(1), blockVertices_ ( meshDict_.lookup("vertices"), @@ -72,13 +77,17 @@ Foam::blockMesh::blockMesh(const IOdictionary& dict, const word& regionName) vertices_(Foam::vertices(blockVertices_)), topologyPtr_(createTopology(meshDict_, regionName)) { - if (meshDict_.lookupOrDefault("fastMerge", false)) + // TODO - extend with Enum + + bool useTopoMerge = (strategy == mergeStrategy::TOPOLOGICAL); + + if (meshDict_.getOrDefault("fastMerge", useTopoMerge)) { - calcMergeInfoFast(); + calcTopologicalMerge(); } else { - calcMergeInfo(); + calcGeometricalMerge(); } } diff --git a/src/mesh/blockMesh/blockMesh/blockMesh.H b/src/mesh/blockMesh/blockMesh/blockMesh.H index 0f6747d6ff3..d89bbf95a26 100644 --- a/src/mesh/blockMesh/blockMesh/blockMesh.H +++ b/src/mesh/blockMesh/blockMesh/blockMesh.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,7 +66,7 @@ class blockMesh : public blockList { - // Private data + // Private Data //- Reference to mesh dictionary const IOdictionary& meshDict_; @@ -155,11 +155,13 @@ class blockMesh void check(const polyMesh& bm, const dictionary& dict) const; - //- Determine the merge info and the final number of cells/points - void calcMergeInfo(); + //- Determine merge info and final number of cells/points + //- based on point distances + void calcGeometricalMerge(); - //- Determine the merge info and the final number of cells/points - void calcMergeInfoFast(); + //- Determine merge info and final number of cells/points + //- based on block topology + void calcTopologicalMerge(); faceList createPatchFaces(const polyPatch& patchTopologyFaces) const; @@ -177,15 +179,31 @@ class blockMesh public: - // Static data members + // Data Types + + //- The block merging strategy + enum mergeStrategy + { + TOPOLOGICAL, //!< Merge using block topology + GEOMETRIC //!< Merge using point geometry + }; + + + // Static Data Members ClassName("blockMesh"); // Constructors - //- Construct from IOdictionary - blockMesh(const IOdictionary& dict, const word& regionName); + //- Construct from IOdictionary for given region + // Default is topological merging. + blockMesh + ( + const IOdictionary& dict, + const word& regionName, + const mergeStrategy strategy = TOPOLOGICAL + ); //- Destructor diff --git a/src/mesh/blockMesh/blockMesh/blockMeshMerge.C b/src/mesh/blockMesh/blockMesh/blockMeshMergeGeometrical.C similarity index 99% rename from src/mesh/blockMesh/blockMesh/blockMeshMerge.C rename to src/mesh/blockMesh/blockMesh/blockMeshMergeGeometrical.C index 87771f846ca..c5936f7bf07 100644 --- a/src/mesh/blockMesh/blockMesh/blockMeshMerge.C +++ b/src/mesh/blockMesh/blockMesh/blockMeshMergeGeometrical.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,7 +30,7 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::blockMesh::calcMergeInfo() +void Foam::blockMesh::calcGeometricalMerge() { const blockList& blocks = *this; diff --git a/src/mesh/blockMesh/blockMesh/blockMeshMergeFast.C b/src/mesh/blockMesh/blockMesh/blockMeshMergeTopological.C similarity index 99% rename from src/mesh/blockMesh/blockMesh/blockMeshMergeFast.C rename to src/mesh/blockMesh/blockMesh/blockMeshMergeTopological.C index 15d23219bf8..42a0c80354a 100644 --- a/src/mesh/blockMesh/blockMesh/blockMeshMergeFast.C +++ b/src/mesh/blockMesh/blockMesh/blockMeshMergeTopological.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -301,7 +301,7 @@ inline label facePointN // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::blockMesh::calcMergeInfoFast() +void Foam::blockMesh::calcTopologicalMerge() { // Generate the static face-face map genFaceFaceRotMap(); -- GitLab