From 5130c7bcbc8557809f80c606287c87ff8027cc1c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 23 Sep 2022 11:33:30 +0200 Subject: [PATCH] STYLE: use polyPatchList instead of List in more places --- .../refinementLevel/refinementLevel.C | 12 +++-- .../snappyRefineMesh/snappyRefineMesh.C | 47 ++++++++++------- .../mesh/conversion/gmshToFoam/gmshToFoam.C | 21 ++++---- .../foamyMesh/foamyQuadMesh/foamyQuadMesh.C | 32 +++++++----- .../mesh/manipulation/autoPatch/autoPatch.C | 35 ++++++++----- .../manipulation/mergeMeshes/mergePolyMesh.C | 52 ++++++++++++------- .../manipulation/mirrorMesh/mirrorFvMesh.C | 22 ++++---- .../surface/surfaceToPatch/surfaceToPatch.C | 18 ++++--- src/conversion/ccm/reader/ccmReaderMesh.C | 32 ++++++++---- .../common/reader/createPolyBoundary.C | 22 ++++---- src/conversion/common/reader/meshReader.C | 4 +- src/conversion/common/reader/meshReader.H | 6 +-- src/conversion/fire/FIREMeshReader.C | 20 ++++--- src/conversion/polyDualMesh/polyDualMesh.C | 16 +++--- src/dynamicMesh/boundaryMesh/boundaryMesh.C | 42 +++++++++------ .../extrudePatchMesh/extrudePatchMesh.C | 46 ++++++++++------ .../extrudePatchMesh/extrudePatchMesh.H | 30 +++++++---- .../fvMeshDistribute/fvMeshDistribute.C | 16 +++--- .../attachPolyTopoChanger.C | 33 +++++++----- .../attachPolyTopoChanger.H | 12 ++--- .../repatchPolyTopoChanger.C | 14 ++++- .../repatchPolyTopoChanger.H | 15 +++--- .../hexCellFvMesh/hexCellFvMesh.C | 18 ++++--- .../singleCellFvMesh/singleCellFvMesh.C | 18 ++++--- .../thermalBaffleFvPatchScalarField.C | 25 +++++---- src/sampling/meshToMesh/meshToMesh.C | 18 ++++--- 26 files changed, 388 insertions(+), 238 deletions(-) diff --git a/applications/utilities/mesh/advanced/refinementLevel/refinementLevel.C b/applications/utilities/mesh/advanced/refinementLevel/refinementLevel.C index 8d6a3c3870..9d5c334970 100644 --- a/applications/utilities/mesh/advanced/refinementLevel/refinementLevel.C +++ b/applications/utilities/mesh/advanced/refinementLevel/refinementLevel.C @@ -226,14 +226,18 @@ int main(int argc, char *argv[]) // Add the boundary patches const polyBoundaryMesh& patches = mesh.boundaryMesh(); - List p(patches.size()); + polyPatchList newPatches(patches.size()); - forAll(p, patchi) + forAll(newPatches, patchi) { - p[patchi] = patches[patchi].clone(fMesh.boundaryMesh()).ptr(); + newPatches.set + ( + patchi, + patches[patchi].clone(fMesh.boundaryMesh()) + ); } - fMesh.addFvPatches(p); + fMesh.addFvPatches(newPatches); // Refinement level diff --git a/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C b/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C index e52f20f577..7d1db05860 100644 --- a/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C +++ b/applications/utilities/mesh/advanced/snappyRefineMesh/snappyRefineMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -205,34 +205,43 @@ label addPatch(polyMesh& mesh, const word& patchName) { const polyBoundaryMesh& patches = mesh.boundaryMesh(); - List newPatches(patches.size() + 1); + polyPatchList newPatches(patches.size() + 1); + + label nPatches = 0; // Add empty patch as 0th entry (Note: only since subsetMesh wants this) patchi = 0; - - newPatches[patchi] = - new emptyPolyPatch - ( - Foam::word(patchName), - 0, - mesh.nInternalFaces(), - patchi, - patches, - emptyPolyPatch::typeName - ); - - forAll(patches, i) { - const polyPatch& pp = patches[i]; + newPatches.set + ( + nPatches, + new emptyPolyPatch + ( + patchName, + 0, + mesh.nInternalFaces(), + nPatches, + patches, + emptyPolyPatch::typeName + ) + ); + ++nPatches; + } - newPatches[i+1] = + for (const polyPatch& pp : patches) + { + newPatches.set + ( + nPatches, pp.clone ( patches, - i+1, + nPatches, pp.size(), pp.start() - ).ptr(); + ) + ); + ++nPatches; } mesh.removeBoundary(); diff --git a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C index fec3b4bed8..77dc4d738e 100644 --- a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C +++ b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C @@ -1678,7 +1678,7 @@ int main(int argc, char *argv[]) label defaultPatchID = mesh.boundaryMesh().findPatchID(defaultFacesName); if (mesh.boundaryMesh()[defaultPatchID].size() == 0) { - List newPatchPtrList((mesh.boundaryMesh().size() - 1)); + polyPatchList newPatches((mesh.boundaryMesh().size() - 1)); label newPatchi = 0; forAll(mesh.boundaryMesh(), patchi) { @@ -1686,18 +1686,21 @@ int main(int argc, char *argv[]) { const polyPatch& patch = mesh.boundaryMesh()[patchi]; - newPatchPtrList[newPatchi] = patch.clone + newPatches.set ( - mesh.boundaryMesh(), newPatchi, - patch.size(), - patch.start() - ).ptr(); - - newPatchi++; + patch.clone + ( + mesh.boundaryMesh(), + newPatchi, + patch.size(), + patch.start() + ) + ); + ++newPatchi; } } - repatcher.changePatches(newPatchPtrList); + repatcher.changePatches(newPatches); } // Set the precision of the points data to 10 diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/foamyQuadMesh.C b/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/foamyQuadMesh.C index 919b812071..cc27297870 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/foamyQuadMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/foamyQuadMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2016 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -167,28 +167,32 @@ int main(int argc, char *argv[]) ); Info<< "Constructing patches." << endl; - List patches(poly2DMesh.patchNames().size()); - label countPatches = 0; + polyPatchList newPatches(poly2DMesh.patchNames().size()); + label nPatches = 0; - forAll(patches, patchi) + forAll(newPatches, patchi) { if (poly2DMesh.patchSizes()[patchi] != 0) { - patches[countPatches] = new polyPatch + newPatches.set ( - poly2DMesh.patchNames()[patchi], - poly2DMesh.patchSizes()[patchi], - poly2DMesh.patchStarts()[patchi], - countPatches, - pMesh.boundaryMesh(), - word::null + nPatches, + new polyPatch + ( + poly2DMesh.patchNames()[patchi], + poly2DMesh.patchSizes()[patchi], + poly2DMesh.patchStarts()[patchi], + nPatches, + pMesh.boundaryMesh(), + word::null + ) ); - countPatches++; + ++nPatches; } } - patches.setSize(countPatches); - pMesh.addPatches(patches); + newPatches.resize(nPatches); + pMesh.addPatches(newPatches); if (extrude) { diff --git a/applications/utilities/mesh/manipulation/autoPatch/autoPatch.C b/applications/utilities/mesh/manipulation/autoPatch/autoPatch.C index 248e327900..d9a3c2d438 100644 --- a/applications/utilities/mesh/manipulation/autoPatch/autoPatch.C +++ b/applications/utilities/mesh/manipulation/autoPatch/autoPatch.C @@ -191,7 +191,7 @@ int main(int argc, char *argv[]) const PtrList& patches = bMesh.patches(); // Create new list of patches with old ones first - List newPatchPtrList(patches.size()); + polyPatchList newPatches(patches.size()); newPatchi = 0; @@ -200,34 +200,41 @@ int main(int argc, char *argv[]) { const polyPatch& patch = mesh.boundaryMesh()[patchi]; - newPatchPtrList[newPatchi] = + newPatches.set + ( + newPatchi, patch.clone ( mesh.boundaryMesh(), newPatchi, patch.size(), patch.start() - ).ptr(); + ) + ); - newPatchi++; + ++newPatchi; } // Add new ones with empty size. for (label patchi = newPatchi; patchi < patches.size(); patchi++) { - const boundaryPatch& bp = patches[patchi]; + const word& patchName = patches[patchi].name(); - newPatchPtrList[newPatchi] = polyPatch::New + newPatches.set ( - polyPatch::typeName, - bp.name(), - 0, - mesh.nFaces(), newPatchi, - mesh.boundaryMesh() - ).ptr(); + polyPatch::New + ( + polyPatch::typeName, + patchName, + 0, + mesh.nFaces(), + newPatchi, + mesh.boundaryMesh() + ) + ); - newPatchi++; + ++newPatchi; } if (!overwrite) @@ -238,7 +245,7 @@ int main(int argc, char *argv[]) // Change patches repatchPolyTopoChanger polyMeshRepatcher(mesh); - polyMeshRepatcher.changePatches(newPatchPtrList); + polyMeshRepatcher.changePatches(newPatches); // Change face ordering diff --git a/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C b/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C index c0ad8a9ade..d5477c7a9e 100644 --- a/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C +++ b/applications/utilities/mesh/manipulation/mergeMeshes/mergePolyMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -136,46 +136,55 @@ void Foam::mergePolyMesh::sortProcessorPatches() const polyBoundaryMesh& oldPatches = boundaryMesh(); - DynamicList newPatches(oldPatches.size()); + polyPatchList newPatches(oldPatches.size()); labelList oldToSorted(oldPatches.size()); + label nPatches = 0; + forAll(oldPatches, patchi) { const polyPatch& pp = oldPatches[patchi]; if (!isA(pp)) { - oldToSorted[patchi] = newPatches.size(); - newPatches.append + newPatches.set ( + nPatches, pp.clone ( oldPatches, - oldToSorted[patchi], + nPatches, 0, nInternalFaces() - ).ptr() + ) ); + + oldToSorted[patchi] = nPatches; + ++nPatches; } } + forAll(oldPatches, patchi) { const polyPatch& pp = oldPatches[patchi]; if (isA(pp)) { - oldToSorted[patchi] = newPatches.size(); - newPatches.append + newPatches.set ( + nPatches, pp.clone ( oldPatches, oldToSorted[patchi], 0, nInternalFaces() - ).ptr() + ) ); + + oldToSorted[patchi] = nPatches; + ++nPatches; } } @@ -461,7 +470,7 @@ void Foam::mergePolyMesh::merge() { Info<< "Copying old patches" << endl; - List newPatches(patchNames_.size()); + polyPatchList newPatches(patchNames_.size()); const polyBoundaryMesh& oldPatches = boundaryMesh(); @@ -470,7 +479,11 @@ void Foam::mergePolyMesh::merge() for (patchi = 0; patchi < oldPatches.size(); patchi++) { - newPatches[patchi] = oldPatches[patchi].clone(oldPatches).ptr(); + newPatches.set + ( + patchi, + oldPatches[patchi].clone(oldPatches) + ); } Info<< "Adding new patches. " << endl; @@ -487,15 +500,18 @@ void Foam::mergePolyMesh::merge() dict.set("nFaces", 0); dict.set("startFace", endOfLastPatch); - newPatches[patchi] = + newPatches.set ( - polyPatch::New + patchi, ( - patchNames_[patchi], - dict, - patchi, - oldPatches - ).ptr() + polyPatch::New + ( + patchNames_[patchi], + dict, + patchi, + oldPatches + ) + ) ); } diff --git a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C index fdb650db9d..ac43973e75 100644 --- a/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C +++ b/applications/utilities/mesh/manipulation/mirrorMesh/mirrorFvMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2017-2018 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -404,20 +404,24 @@ Foam::mirrorFvMesh::mirrorFvMesh fvMesh& pMesh = mirrorMeshPtr_(); // Add the boundary patches - List p(newPatchSizes.size()); + polyPatchList newPatches(newPatchSizes.size()); - forAll(p, patchi) + forAll(newPatches, patchi) { - p[patchi] = boundaryMesh()[patchi].clone + newPatches.set ( - pMesh.boundaryMesh(), patchi, - newPatchSizes[patchi], - newPatchStarts[patchi] - ).ptr(); + boundaryMesh()[patchi].clone + ( + pMesh.boundaryMesh(), + patchi, + newPatchSizes[patchi], + newPatchStarts[patchi] + ) + ); } - pMesh.addPatches(p); + pMesh.addPatches(newPatches); } diff --git a/applications/utilities/surface/surfaceToPatch/surfaceToPatch.C b/applications/utilities/surface/surfaceToPatch/surfaceToPatch.C index d4d31c1ca7..bec02775ba 100644 --- a/applications/utilities/surface/surfaceToPatch/surfaceToPatch.C +++ b/applications/utilities/surface/surfaceToPatch/surfaceToPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -58,7 +58,7 @@ label addPatch(polyMesh& mesh, const word& patchName) { const polyBoundaryMesh& patches = mesh.boundaryMesh(); - List newPatches(patches.size() + 1); + polyPatchList newPatches(patches.size() + 1); patchi = 0; @@ -67,20 +67,25 @@ label addPatch(polyMesh& mesh, const word& patchName) { const polyPatch& pp = patches[i]; - newPatches[patchi] = + newPatches.set + ( + patchi, pp.clone ( patches, patchi, pp.size(), pp.start() - ).ptr(); + ) + ); patchi++; } // Add zero-sized patch - newPatches[patchi] = + newPatches.set + ( + patchi, new polyPatch ( patchName, @@ -89,7 +94,8 @@ label addPatch(polyMesh& mesh, const word& patchName) patchi, patches, polyPatch::typeName - ); + ) + ); mesh.removeBoundary(); mesh.addPatches(newPatches); diff --git a/src/conversion/ccm/reader/ccmReaderMesh.C b/src/conversion/ccm/reader/ccmReaderMesh.C index ca38f19d1f..db3087240e 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-2021 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -2420,7 +2420,7 @@ void Foam::ccm::reader::addPatches { // Create patches // use patch types to determine what Foam types to generate - List newPatches(origBndId_.size()); + polyPatchList newPatches(origBndId_.size()); label meshFaceI = nInternalFaces_; wordHashSet hashedNames(origBndId_.size()); @@ -2463,7 +2463,9 @@ void Foam::ccm::reader::addPatches if (patchType == "wall") { - newPatches[patchI] = + newPatches.set + ( + patchI, new wallPolyPatch ( patchName, @@ -2472,11 +2474,14 @@ void Foam::ccm::reader::addPatches patchI, mesh.boundaryMesh(), patchType - ); + ) + ); } else if (patchType == "symmetry") { - newPatches[patchI] = + newPatches.set + ( + patchI, new symmetryPolyPatch ( patchName, @@ -2485,12 +2490,15 @@ void Foam::ccm::reader::addPatches patchI, mesh.boundaryMesh(), patchType - ); + ) + ); } else if (patchType == "empty") { // Note: not ccm name, may have been introduced by us - newPatches[patchI] = + newPatches.set + ( + patchI, new emptyPolyPatch ( patchName, @@ -2499,13 +2507,16 @@ void Foam::ccm::reader::addPatches patchI, mesh.boundaryMesh(), patchType - ); + ) + ); } else { // All other ccm types become straight polyPatch: // 'inlet', 'outlet', 'pressure'. - newPatches[patchI] = + newPatches.set + ( + patchI, new polyPatch ( patchName, @@ -2514,7 +2525,8 @@ void Foam::ccm::reader::addPatches patchI, mesh.boundaryMesh(), patchType - ); + ) + ); } meshFaceI += patchSizes_[patchI]; diff --git a/src/conversion/common/reader/createPolyBoundary.C b/src/conversion/common/reader/createPolyBoundary.C index d85dfb987a..c127a47921 100644 --- a/src/conversion/common/reader/createPolyBoundary.C +++ b/src/conversion/common/reader/createPolyBoundary.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -377,7 +377,7 @@ void Foam::meshReader::createPolyBoundary() // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -Foam::List +Foam::polyPatchList Foam::meshReader::polyBoundaryPatches(const polyMesh& mesh) { label nUsed = 0, nEmpty = 0; @@ -416,7 +416,7 @@ Foam::meshReader::polyBoundaryPatches(const polyMesh& mesh) patchSizes_.setSize(nPatches); - List p(nPatches); + polyPatchList newPatches(nPatches); // All patch dictionaries PtrList patchDicts(patchNames_.size()); @@ -469,16 +469,20 @@ Foam::meshReader::polyBoundaryPatches(const polyMesh& mesh) forAll(patchStarts_, patchi) { - p[patchi] = polyPatch::New + newPatches.set ( - patchNames_[patchi], - patchDicts[patchi], patchi, - mesh.boundaryMesh() - ).ptr(); + polyPatch::New + ( + patchNames_[patchi], + patchDicts[patchi], + patchi, + mesh.boundaryMesh() + ) + ); } - return p; + return newPatches; } diff --git a/src/conversion/common/reader/meshReader.C b/src/conversion/common/reader/meshReader.C index c85759da13..16e5085814 100644 --- a/src/conversion/common/reader/meshReader.C +++ b/src/conversion/common/reader/meshReader.C @@ -109,8 +109,10 @@ Foam::autoPtr Foam::meshReader::mesh ); polyMesh& mesh = *meshPtr; + polyPatchList newPatches(polyBoundaryPatches(mesh)); + // Adding patches also checks the mesh - mesh.addPatches(polyBoundaryPatches(mesh)); + mesh.addPatches(newPatches); warnDuplicates("boundaries", mesh.boundaryMesh().names()); diff --git a/src/conversion/common/reader/meshReader.H b/src/conversion/common/reader/meshReader.H index d584a02b76..839f174755 100644 --- a/src/conversion/common/reader/meshReader.H +++ b/src/conversion/common/reader/meshReader.H @@ -49,8 +49,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef meshReader_H -#define meshReader_H +#ifndef Foam_meshReader_H +#define Foam_meshReader_H #include "polyMesh.H" #include "HashTable.H" @@ -179,7 +179,7 @@ private: void createPolyBoundary(); //- Add polyhedral boundary - List polyBoundaryPatches(const polyMesh&); + polyPatchList polyBoundaryPatches(const polyMesh&); //- Clear extra storage before creation of the mesh to remove // a memory peak diff --git a/src/conversion/fire/FIREMeshReader.C b/src/conversion/fire/FIREMeshReader.C index 8235561ebe..248261a852 100644 --- a/src/conversion/fire/FIREMeshReader.C +++ b/src/conversion/fire/FIREMeshReader.C @@ -342,8 +342,8 @@ void Foam::fileFormats::FIREMeshReader::reorganize() void Foam::fileFormats::FIREMeshReader::addPatches(polyMesh& mesh) const { - // create patches - List newPatches(patchSizes_.size()); + // Create patches + polyPatchList newPatches(patchSizes_.size()); label meshFaceI = nInternalFaces_; @@ -355,14 +355,18 @@ void Foam::fileFormats::FIREMeshReader::addPatches(polyMesh& mesh) const << endl; // don't know anything better - just make it a wall - newPatches[patchI] = new polyPatch + newPatches.set ( - patchNames_[patchI], - patchSizes_[patchI], - meshFaceI, patchI, - mesh.boundaryMesh(), - word::null + new polyPatch + ( + patchNames_[patchI], + patchSizes_[patchI], + meshFaceI, + patchI, + mesh.boundaryMesh(), + word::null + ) ); meshFaceI += patchSizes_[patchI]; diff --git a/src/conversion/polyDualMesh/polyDualMesh.C b/src/conversion/polyDualMesh/polyDualMesh.C index d7b3948f96..89b89bb7f7 100644 --- a/src/conversion/polyDualMesh/polyDualMesh.C +++ b/src/conversion/polyDualMesh/polyDualMesh.C @@ -1315,19 +1315,23 @@ void Foam::polyDualMesh::calcDual // Add patches. First add zero sized (since mesh still 0 size) - List dualPatches(patches.size()); + polyPatchList dualPatches(patches.size()); forAll(patches, patchi) { const polyPatch& pp = patches[patchi]; - dualPatches[patchi] = pp.clone + dualPatches.set ( - boundaryMesh(), patchi, - 0, //patchSizes[patchi], - 0 //patchStarts[patchi] - ).ptr(); + pp.clone + ( + boundaryMesh(), + patchi, + 0, //patchSizes[patchi], + 0 //patchStarts[patchi] + ) + ); } addPatches(dualPatches); diff --git a/src/dynamicMesh/boundaryMesh/boundaryMesh.C b/src/dynamicMesh/boundaryMesh/boundaryMesh.C index 78640758c7..d202475fbc 100644 --- a/src/dynamicMesh/boundaryMesh/boundaryMesh.C +++ b/src/dynamicMesh/boundaryMesh/boundaryMesh.C @@ -1149,7 +1149,7 @@ void Foam::boundaryMesh::patchify // zero faces (repatched later on). Exception is coupled patches which // keep their size. - List newPatchPtrList(nNewPatches); + polyPatchList newPatches(nNewPatches); label meshFacei = newMesh.nInternalFaces(); @@ -1174,15 +1174,19 @@ void Foam::boundaryMesh::patchify << " type:" << bp.physicalType() << endl; } - newPatchPtrList[newPatchi] = polyPatch::New + newPatches.set ( - bp.physicalType(), - bp.name(), - facesToBeDone, - meshFacei, newPatchi, - newMesh.boundaryMesh() - ).ptr(); + polyPatch::New + ( + bp.physicalType(), + bp.name(), + facesToBeDone, + meshFacei, + newPatchi, + newMesh.boundaryMesh() + ) + ); meshFacei += facesToBeDone; @@ -1200,13 +1204,17 @@ void Foam::boundaryMesh::patchify << oldPatch.name() << endl; } - newPatchPtrList[newPatchi] = oldPatch.clone + newPatches.set ( - newMesh.boundaryMesh(), newPatchi, - facesToBeDone, - meshFacei - ).ptr(); + oldPatch.clone + ( + newMesh.boundaryMesh(), + newPatchi, + facesToBeDone, + meshFacei + ) + ); meshFacei += facesToBeDone; @@ -1220,9 +1228,9 @@ void Foam::boundaryMesh::patchify { Pout<< "Patchify : new polyPatch list:" << endl; - forAll(newPatchPtrList, patchi) + forAll(newPatches, patchi) { - const polyPatch& newPatch = *newPatchPtrList[patchi]; + const polyPatch& newPatch = newPatches[patchi]; if (debug) { @@ -1237,13 +1245,13 @@ void Foam::boundaryMesh::patchify // Actually add new list of patches repatchPolyTopoChanger polyMeshRepatcher(newMesh); - polyMeshRepatcher.changePatches(newPatchPtrList); + polyMeshRepatcher.changePatches(newPatches); // Pass2: // Change patch type for face - if (newPatchPtrList.size()) + if (newPatches.size()) { List> patchFaces(nNewPatches); diff --git a/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.C b/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.C index 628acf544f..a0b06807e0 100644 --- a/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.C +++ b/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -77,7 +77,7 @@ Foam::extrudePatchMesh::extrudePatchMesh const fvPatch& p, const dictionary& dict, const word& regionName, - const List& regionPatches + polyPatchList& regionPatches ) : extrudePatchMesh(regionName, mesh, p, dict) @@ -86,6 +86,24 @@ Foam::extrudePatchMesh::extrudePatchMesh } +Foam::extrudePatchMesh::extrudePatchMesh +( + const fvMesh& mesh, + const fvPatch& p, + const dictionary& dict, + const word& regionName, + const List& regionPatches +) +: + extrudePatchMesh(regionName, mesh, p, dict) +{ + // Acquire ownership of the pointers + polyPatchList plist(const_cast&>(regionPatches)); + + extrudeMesh(plist); +} + + Foam::extrudePatchMesh::extrudePatchMesh ( const fvMesh& mesh, @@ -96,18 +114,10 @@ Foam::extrudePatchMesh::extrudePatchMesh : extrudePatchMesh(regionName, mesh, p, dict) { - List regionPatches(3); + polyPatchList regionPatches(3); + List dicts(regionPatches.size()); List patchNames(regionPatches.size()); List patchTypes(regionPatches.size()); - PtrList dicts(regionPatches.size()); - - forAll(dicts, patchi) - { - if (!dicts.set(patchi)) - { - dicts.set(patchi, new dictionary()); - } - } dicts[bottomPatchID] = dict_.subDict("bottomCoeffs"); dicts[sidePatchID] = dict_.subDict("sideCoeffs"); @@ -125,22 +135,26 @@ Foam::extrudePatchMesh::extrudePatchMesh patchDict.set("nFaces", 0); patchDict.set("startFace", 0); - regionPatches[patchi] = polyPatch::New + regionPatches.set + ( + patchi, + polyPatch::New ( patchNames[patchi], patchDict, patchi, mesh.boundaryMesh() - ).ptr(); + ) + ); } extrudeMesh(regionPatches); } -void Foam::extrudePatchMesh::extrudeMesh(const List& regionPatches) +void Foam::extrudePatchMesh::extrudeMesh(polyPatchList& regionPatches) { - if (this->boundaryMesh().size() == 0) + if (this->boundaryMesh().empty()) { const bool columnCells = dict_.get("columnCells"); diff --git a/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.H b/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.H index 72040e91d2..5e9130095f 100644 --- a/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.H +++ b/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.H @@ -70,12 +70,11 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef extrudePatchMesh_H -#define extrudePatchMesh_H +#ifndef Foam_extrudePatchMesh_H +#define Foam_extrudePatchMesh_H #include "extrudeModel.H" #include "autoPtr.H" - #include "fvMesh.H" #include "Time.H" @@ -97,12 +96,12 @@ class extrudePatchMesh { // Private Data - //- Enumeration of patch IDs + //- Enumeration of patch IDs. Must be 0,1,2,... enum patchID { - bottomPatchID, - topPatchID, - sidePatchID + bottomPatchID = 0, + topPatchID = 1, + sidePatchID = 2 }; //- Const reference to the patch from which this mesh is extruded @@ -115,7 +114,7 @@ class extrudePatchMesh // Private Member Functions //- Extrude mesh using polyPatches - void extrudeMesh(const List& regionPatches); + void extrudeMesh(polyPatchList& regionPatches); //- Construct from mesh, patch and dictionary without patches. // Only used internally @@ -145,14 +144,25 @@ public: ); //- Construct from mesh, patch, dictionary and new mesh - // polyPatch information + //- polyPatch information extrudePatchMesh ( const fvMesh& mesh, const fvPatch& p, const dictionary& dict, const word& regionName, - const List& polyPatches + polyPatchList& regionPatches + ); + + //- Construct from mesh, patch, dictionary and new mesh + //- polyPatch information + extrudePatchMesh + ( + const fvMesh& mesh, + const fvPatch& p, + const dictionary& dict, + const word& regionName, + const List& regionPatches ); diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index 26d5582ac7..8ce423e64f 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -1796,17 +1796,21 @@ Foam::autoPtr Foam::fvMeshDistribute::receiveMesh ); fvMesh& domainMesh = *domainMeshPtr; - List patches(patchEntries.size()); + polyPatchList patches(patchEntries.size()); forAll(patchEntries, patchi) { - patches[patchi] = polyPatch::New + patches.set ( - patchEntries[patchi].keyword(), - patchEntries[patchi].dict(), patchi, - domainMesh.boundaryMesh() - ).ptr(); + polyPatch::New + ( + patchEntries[patchi].keyword(), + patchEntries[patchi].dict(), + patchi, + domainMesh.boundaryMesh() + ) + ); } // Add patches; no parallel comms domainMesh.addFvPatches(patches, false); diff --git a/src/dynamicMesh/polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.C b/src/dynamicMesh/polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.C index e30ae87a59..a88b03e5d5 100644 --- a/src/dynamicMesh/polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.C +++ b/src/dynamicMesh/polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -80,34 +81,40 @@ void Foam::attachPolyTopoChanger::attach(const bool removeEmptyPatches) // Re-do the boundary patches, removing the ones with zero size const polyBoundaryMesh& oldPatches = mesh_.boundaryMesh(); - List newPatches(oldPatches.size()); + polyPatchList newPatches(oldPatches.size()); label nNewPatches = 0; forAll(oldPatches, patchi) { - if (oldPatches[patchi].size()) - { - newPatches[nNewPatches] = oldPatches[patchi].clone - ( - mesh_.boundaryMesh(), - nNewPatches, - oldPatches[patchi].size(), - oldPatches[patchi].start() - ).ptr(); + const word& patchName = oldPatches[patchi].name(); - nNewPatches++; + if (returnReduceOr(oldPatches[patchi].size())) + { + newPatches.set + ( + nNewPatches, + oldPatches[patchi].clone + ( + mesh_.boundaryMesh(), + nNewPatches, + oldPatches[patchi].size(), + oldPatches[patchi].start() + ) + ); + + ++nNewPatches; } else { if (debug) { Pout<< "Removing zero-sized patch " << patchi - << " named " << oldPatches[patchi].name() << endl; + << " named " << patchName << endl; } } } - newPatches.setSize(nNewPatches); + newPatches.resize(nNewPatches); mesh_.removeBoundary(); mesh_.addPatches(newPatches); diff --git a/src/dynamicMesh/polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.H b/src/dynamicMesh/polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.H index cab5d79ae0..b8f3428761 100644 --- a/src/dynamicMesh/polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.H +++ b/src/dynamicMesh/polyTopoChange/attachPolyTopoChanger/attachPolyTopoChanger.H @@ -46,8 +46,8 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef attachPolyTopoChanger_H -#define attachPolyTopoChanger_H +#ifndef Foam_attachPolyTopoChanger_H +#define Foam_attachPolyTopoChanger_H #include "polyTopoChanger.H" @@ -57,16 +57,16 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class attachPolyTopoChanger Declaration + Class attachPolyTopoChanger Declaration \*---------------------------------------------------------------------------*/ class attachPolyTopoChanger : public polyTopoChanger { - // Private data +public: - // Private Member Functions + // Generated Methods //- No copy construct attachPolyTopoChanger(const attachPolyTopoChanger&) = delete; @@ -75,8 +75,6 @@ class attachPolyTopoChanger void operator=(const attachPolyTopoChanger&) = delete; -public: - // Constructors //- Read constructor from IOobject and a polyMesh diff --git a/src/dynamicMesh/polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.C b/src/dynamicMesh/polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.C index ebece44115..f4b66a2323 100644 --- a/src/dynamicMesh/polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.C +++ b/src/dynamicMesh/polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.C @@ -60,7 +60,7 @@ Foam::repatchPolyTopoChanger::repatchPolyTopoChanger(polyMesh& mesh) void Foam::repatchPolyTopoChanger::changePatches ( - const List& patches + polyPatchList& patches ) { if (meshModPtr_) @@ -76,6 +76,18 @@ void Foam::repatchPolyTopoChanger::changePatches } +void Foam::repatchPolyTopoChanger::changePatches +( + const List& patches +) +{ + // Acquire ownership of the pointers + polyPatchList plist(const_cast&>(patches)); + + changePatches(plist); +} + + void Foam::repatchPolyTopoChanger::changePatchID ( const label faceID, diff --git a/src/dynamicMesh/polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.H b/src/dynamicMesh/polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.H index 14c7f0c591..3cfb98670f 100644 --- a/src/dynamicMesh/polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.H +++ b/src/dynamicMesh/polyTopoChange/repatchPolyTopoChanger/repatchPolyTopoChanger.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,8 +37,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef repatchPolyTopoChanger_H -#define repatchPolyTopoChanger_H +#ifndef Foam_repatchPolyTopoChanger_H +#define Foam_repatchPolyTopoChanger_H #include "polyMesh.H" #include "polyTopoChange.H" @@ -60,7 +60,7 @@ class repatchPolyTopoChanger polyMesh& mesh_; //- Topological change to accumulated all mesh changes - unique_ptr meshModPtr_; + std::unique_ptr meshModPtr_; // Private Member Functions @@ -89,11 +89,14 @@ public: // Member Functions + //- Change patches. + void changePatches(polyPatchList& patches); + //- Change patches. void changePatches(const List& patches); - //- Change patch ID for a boundary face. Note: patchID should be in new - // numbering. + //- Change patch ID for a boundary face. + //- Note: patchID should be in new numbering. void changePatchID ( const label faceID, diff --git a/src/finiteVolume/fvMesh/simplifiedFvMesh/hexCellFvMesh/hexCellFvMesh.C b/src/finiteVolume/fvMesh/simplifiedFvMesh/hexCellFvMesh/hexCellFvMesh.C index a00628e88a..d796dec0c7 100644 --- a/src/finiteVolume/fvMesh/simplifiedFvMesh/hexCellFvMesh/hexCellFvMesh.C +++ b/src/finiteVolume/fvMesh/simplifiedFvMesh/hexCellFvMesh/hexCellFvMesh.C @@ -83,16 +83,20 @@ Foam::simplifiedMeshes::hexCellFvMesh::hexCellFvMesh labelList() ) { - List patches(1); + polyPatchList patches(1); - patches[0] = new emptyPolyPatch + patches.set ( - "boundary", - 6, 0, - 0, - boundaryMesh(), - emptyPolyPatch::typeName + new emptyPolyPatch + ( + "boundary", + 6, + 0, + 0, + boundaryMesh(), + emptyPolyPatch::typeName + ) ); addFvPatches(patches); diff --git a/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C b/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C index f3b975a44a..05a74ef6bd 100644 --- a/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C +++ b/src/finiteVolume/fvMesh/singleCellFvMesh/singleCellFvMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -258,16 +258,20 @@ void Foam::singleCellFvMesh::agglomerateMesh pointField boundaryPoints(mesh.points(), pointMap_); // Add patches (on still zero sized mesh) - List newPatches(oldPatches.size()); + polyPatchList newPatches(oldPatches.size()); forAll(oldPatches, patchi) { - newPatches[patchi] = oldPatches[patchi].clone + newPatches.set ( - boundaryMesh(), patchi, - 0, - 0 - ).ptr(); + oldPatches[patchi].clone + ( + boundaryMesh(), + patchi, + 0, + 0 + ) + ); } addFvPatches(newPatches); diff --git a/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C b/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C index 9d38d83a7a..be475dc138 100644 --- a/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C +++ b/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C @@ -143,10 +143,10 @@ void thermalBaffleFvPatchScalarField::createPatchMesh() const word regionName(dict_.get("region")); - List regionPatches(3); + polyPatchList regionPatches(3); + List dicts(regionPatches.size()); List patchNames(regionPatches.size()); List patchTypes(regionPatches.size()); - List dicts(regionPatches.size()); patchNames[bottomPatchID] = word("bottom"); patchNames[sidePatchID] = word("side"); @@ -172,8 +172,7 @@ void thermalBaffleFvPatchScalarField::createPatchMesh() patchTypes[sidePatchID] = polyPatch::typeName; } - const mappedPatchBase& mpp = - refCast(patch().patch(), dict_); + const auto& mpp = refCast(patch().patch(), dict_); const word coupleGroup(mpp.coupleGroup()); @@ -202,18 +201,22 @@ void thermalBaffleFvPatchScalarField::createPatchMesh() forAll(regionPatches, patchi) { - dictionary& patchDict = dicts[patchi]; + dictionary& patchDict = dicts[patchi]; patchDict.set("nFaces", 0); patchDict.set("startFace", 0); - regionPatches[patchi] = polyPatch::New + regionPatches.set ( - patchTypes[patchi], - patchNames[patchi], - dicts[patchi], patchi, - thisMesh.boundaryMesh() - ).ptr(); + polyPatch::New + ( + patchTypes[patchi], + patchNames[patchi], + dicts[patchi], + patchi, + thisMesh.boundaryMesh() + ) + ); } extrudeMeshPtr_.reset diff --git a/src/sampling/meshToMesh/meshToMesh.C b/src/sampling/meshToMesh/meshToMesh.C index 64612a4cbe..0383009453 100644 --- a/src/sampling/meshToMesh/meshToMesh.C +++ b/src/sampling/meshToMesh/meshToMesh.C @@ -495,15 +495,19 @@ void Foam::meshToMesh::calculate(const word& methodName, const bool normalise) ); // create some dummy patch info - List patches(1); - patches[0] = new polyPatch + polyPatchList patches(1); + patches.set ( - "defaultFaces", - newTgt.nBoundaryFaces(), - newTgt.nInternalFaces(), 0, - newTgt.boundaryMesh(), - word::null + new polyPatch + ( + "defaultFaces", + newTgt.nBoundaryFaces(), + newTgt.nInternalFaces(), + 0, + newTgt.boundaryMesh(), + word::null + ) ); newTgt.addPatches(patches);