From f0be8679f66e0b25e9877e8921ecd2160802b68e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 16 Jan 2020 13:24:23 +0100 Subject: [PATCH] ENH: provide defaultName() static method for patches, zones - consistent way of writing "patch" + Foam::name(id) etc. --- .../mesh/conversion/ansysToFoam/ansysToFoam.L | 4 ++-- .../mesh/conversion/gmshToFoam/gmshToFoam.C | 3 ++- .../netgenNeutralToFoam/netgenNeutralToFoam.C | 3 ++- .../conversion/tetgenToFoam/tetgenToFoam.C | 8 +++---- .../createBoxTurb/createBlockMesh.H | 6 +++--- .../searchableSurfaceModifier/cut.C | 2 +- .../surfaceSplitByPatch/surfaceSplitByPatch.C | 5 +++-- .../Identifiers/patch/patchIdentifier.H | 14 +++++++++++++ .../surface/geometricSurfacePatch.H | 14 +++++++++++++ .../Identifiers/surface/surfZoneIdentifier.H | 14 +++++++++++++ src/conversion/ccm/reader/ccmReaderMesh.C | 4 ++-- src/dynamicMesh/boundaryMesh/boundaryMesh.C | 4 ++-- src/fileFormats/stl/STLReader.C | 13 ++++++------ .../trackingInverseDistance/voxelMeshSearch.C | 4 ++-- .../sampledTriSurfaceMesh.C | 12 +++++++---- .../surface/triSurfaceMesh/discreteSurface.C | 21 +++++++------------ .../MeshedSurface/MeshedSurfaceZones.C | 4 ++-- .../UnsortedMeshedSurface.C | 6 +++--- .../surfaceFormats/ac3d/AC3DsurfaceFormat.C | 4 ++-- .../surfaceFormats/gts/GTSsurfaceFormat.C | 10 ++++----- .../surfaceFormats/nas/NASsurfaceFormat.C | 4 ++-- .../surfaceFormats/obj/OBJsurfaceFormat.C | 2 +- .../surfaceFormats/vtk/VTKsurfaceFormat.C | 4 ++-- src/surfMesh/triSurface/triSurface.C | 2 +- 24 files changed, 105 insertions(+), 62 deletions(-) diff --git a/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L b/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L index 8f097f17b7..33e06e70a8 100644 --- a/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L +++ b/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L @@ -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. @@ -521,7 +521,7 @@ int main(int argc, char *argv[]) } boundary[patchi] = patchFaces; - patchNames[patchi] = "patch" + Foam::name(patchi + 1); + patchNames[patchi] = polyPatch::defaultName(patchi + 1); } diff --git a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C index 40e4a9c9cb..02a17f4235 100644 --- a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C +++ b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -1465,7 +1466,7 @@ int main(int argc, char *argv[]) physicalNames.lookup ( patchToPhys[patchi], - "patch" + Foam::name(patchi) // default name + polyPatch::defaultName(patchi) ); Info<< "Patch " << patchi << " gets name " diff --git a/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C b/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C index 724979c6cc..cbae422f00 100644 --- a/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C +++ b/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -263,7 +264,7 @@ int main(int argc, char *argv[]) forAll(patchNames, patchi) { - patchNames[patchi] = word("patch") + name(patchi); + patchNames[patchi] = polyPatch::defaultName(patchi); } wordList patchTypes(nPatches, polyPatch::typeName); diff --git a/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C b/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C index d70a2d4a74..55ac13b40c 100644 --- a/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C +++ b/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2019 OpenCFD Ltd. + Copyright (C) 2015-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -483,8 +483,8 @@ int main(int argc, char *argv[]) forAllConstIters(regionToPatch, iter) { - Info<< " region:" << iter.key() << '\t' << "patch:" - << iter() << endl; + Info<< " region:" << iter.key() + << '\t' << "patch:" << iter.val() << nl; } Info<< endl; @@ -495,7 +495,7 @@ int main(int argc, char *argv[]) forAll(patchNames, patchi) { - patchNames[patchi] = "patch" + Foam::name(patchi); + patchNames[patchi] = polyPatch::defaultName(patchi); } wordList patchTypes(nPatches, polyPatch::typeName); diff --git a/applications/utilities/preProcessing/createBoxTurb/createBlockMesh.H b/applications/utilities/preProcessing/createBoxTurb/createBlockMesh.H index e85661a40d..3e22ad2f1f 100644 --- a/applications/utilities/preProcessing/createBoxTurb/createBlockMesh.H +++ b/applications/utilities/preProcessing/createBoxTurb/createBlockMesh.H @@ -58,7 +58,7 @@ Info<< "Creating patch dictionaries" << endl; wordList patchNames(boundary.size()); forAll(patchNames, patchi) { - patchNames[patchi] = "patch" + Foam::name(patchi); + patchNames[patchi] = polyPatch::defaultName(patchi); } PtrList boundaryDicts(boundary.size()); @@ -69,11 +69,11 @@ forAll(boundaryDicts, patchi) word nbrPatchName; if (patchi % 2 == 0) { - nbrPatchName = "patch" + Foam::name(patchi + 1); + nbrPatchName = polyPatch::defaultName(patchi + 1); } else { - nbrPatchName = "patch" + Foam::name(patchi - 1); + nbrPatchName = polyPatch::defaultName(patchi - 1); } patchDict.add("type", cyclicPolyPatch::typeName); diff --git a/applications/utilities/surface/surfacePatch/searchableSurfaceModifier/cut.C b/applications/utilities/surface/surfacePatch/searchableSurfaceModifier/cut.C index e90c555508..73d630018f 100644 --- a/applications/utilities/surface/surfacePatch/searchableSurfaceModifier/cut.C +++ b/applications/utilities/surface/surfacePatch/searchableSurfaceModifier/cut.C @@ -78,7 +78,7 @@ void Foam::searchableSurfaceModifiers::cut::triangulate { patches[patchi] = geometricSurfacePatch ( - "patch" + Foam::name(patchi), + geometricSurfacePatch::defaultName(patchi), patchi ); } diff --git a/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C b/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C index 081c3e198d..f49d334e5b 100644 --- a/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C +++ b/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -72,11 +73,11 @@ int main(int argc, char *argv[]) { const geometricSurfacePatch& pp = patches[patchi]; - word patchName = pp.name(); + word patchName(pp.name()); if (patchName.empty()) { - patchName = "patch" + Foam::name(patchi); + patchName = geometricSurfacePatch::defaultName(patchi); } fileName outFile(surfBase + '_' + patchName + '.' + extension); diff --git a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H index 57244522fa..e34a456f7d 100644 --- a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H +++ b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H @@ -70,6 +70,20 @@ class patchIdentifier public: + // Static Member Functions + + //- Default patch name: "patch" or "patchN" + static word defaultName(const label n = -1) + { + return + ( + n < 0 + ? word("patch", false) + : word("patch" + std::to_string(n), false) + ); + } + + // Generated Methods //- Copy construct diff --git a/src/OpenFOAM/meshes/Identifiers/surface/geometricSurfacePatch.H b/src/OpenFOAM/meshes/Identifiers/surface/geometricSurfacePatch.H index 9d466c3e3c..773807b468 100644 --- a/src/OpenFOAM/meshes/Identifiers/surface/geometricSurfacePatch.H +++ b/src/OpenFOAM/meshes/Identifiers/surface/geometricSurfacePatch.H @@ -71,6 +71,20 @@ public: static constexpr const char* const emptyType = "empty"; + // Static Member Functions + + //- Default patch name: "patch" or "patchN" + static word defaultName(const label n = -1) + { + return + ( + n < 0 + ? word("patch", false) + : word("patch" + std::to_string(n), false) + ); + } + + // Public Classes //- Helper to convert identifier types as an operation diff --git a/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.H b/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.H index f28a6290b1..670d164f4a 100644 --- a/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.H +++ b/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.H @@ -78,6 +78,20 @@ public: static constexpr const char* const emptyType = "empty"; + // Static Member Functions + + //- Default zone name: "zone" or "zoneN" + static word defaultName(const label n = -1) + { + return + ( + n < 0 + ? word("zone", false) + : word("zone" + std::to_string(n), false) + ); + } + + // Generated Methods //- Copy construct diff --git a/src/conversion/ccm/reader/ccmReaderMesh.C b/src/conversion/ccm/reader/ccmReaderMesh.C index 60120270fb..7eeb2b1537 100644 --- a/src/conversion/ccm/reader/ccmReaderMesh.C +++ b/src/conversion/ccm/reader/ccmReaderMesh.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2019 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -2419,7 +2419,7 @@ void Foam::ccm::reader::addPatches // provide some fallback values forAll(newPatches, patchI) { - const word fallbackName("patch" + Foam::name(patchI)); + const word fallbackName(polyPatch::defaultName(patchI)); word patchName; word patchType; diff --git a/src/dynamicMesh/boundaryMesh/boundaryMesh.C b/src/dynamicMesh/boundaryMesh/boundaryMesh.C index 7439f40732..99da7db453 100644 --- a/src/dynamicMesh/boundaryMesh/boundaryMesh.C +++ b/src/dynamicMesh/boundaryMesh/boundaryMesh.C @@ -680,11 +680,11 @@ void Foam::boundaryMesh::readTriSurface(const fileName& fName) patchi, new boundaryPatch ( - "patch" + name(patchi), + geometricSurfacePatch::defaultName(patchi), patchi, 0, 0, - "empty" + geometricSurfacePatch::emptyType ) ); } diff --git a/src/fileFormats/stl/STLReader.C b/src/fileFormats/stl/STLReader.C index cf39ad788b..2d7f75418e 100644 --- a/src/fileFormats/stl/STLReader.C +++ b/src/fileFormats/stl/STLReader.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2017 OpenCFD Ltd. + Copyright (C) 2016-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -128,15 +128,14 @@ bool Foam::fileFormats::STLReader::readBINARY // interpret STL attribute as a zone const label origId = stlTri.attrib(); - Map