From 6aa8b82744c91c6e3571ac1c79ffbbd65a624068 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 1 Sep 2023 14:10:29 +0200 Subject: [PATCH] ENH: zone improvements - retain group information when copying zones - support construct empty (add details later) - improve consistency for zone and boundaryMesh construction - support front/back/both selection for faceZoneToCell STYLE: prefer faceZone patch() method instead of operator() STYLE: use std::unique_ptr instead of manual pointer management - for zones and core patch types. Easier data management, allows default destructors (for example) --- etc/caseDicts/annotated/topoSetSourcesDict | 6 +- .../Identifiers/patch/patchIdentifier.C | 31 +- .../Identifiers/patch/patchIdentifier.H | 19 +- .../meshes/Identifiers/zone/zoneIdentifier.C | 29 +- .../meshes/Identifiers/zone/zoneIdentifier.H | 19 +- .../meshes/polyMesh/mapPolyMesh/mapPolyMesh.C | 2 +- .../polyBoundaryMesh/polyBoundaryMesh.C | 41 +- .../polyBoundaryMesh/polyBoundaryMesh.H | 25 +- .../polyBoundaryMeshEntries.C | 28 +- .../polyBoundaryMeshEntries.H | 18 +- .../constraint/cyclic/cyclicPolyPatch.C | 28 +- .../constraint/cyclic/cyclicPolyPatch.H | 33 +- .../polyPatches/polyPatch/polyPatch.C | 20 +- .../polyPatches/polyPatch/polyPatch.H | 8 +- .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C | 120 ++++-- .../meshes/polyMesh/zones/ZoneMesh/ZoneMesh.H | 44 +- .../meshes/polyMesh/zones/cellZone/cellZone.C | 100 ++++- .../meshes/polyMesh/zones/cellZone/cellZone.H | 73 +++- .../meshes/polyMesh/zones/faceZone/faceZone.C | 387 +++++++++++------- .../meshes/polyMesh/zones/faceZone/faceZone.H | 188 ++++++--- .../polyMesh/zones/pointZone/pointZone.C | 100 ++++- .../polyMesh/zones/pointZone/pointZone.H | 70 +++- .../meshes/polyMesh/zones/zone/zone.C | 75 ++-- .../meshes/polyMesh/zones/zone/zone.H | 26 +- .../polyTopoChanger/polyTopoChanger.C | 15 +- .../faMesh/faBoundaryMesh/faBoundaryMesh.C | 58 ++- .../faMesh/faBoundaryMesh/faBoundaryMesh.H | 28 +- .../faBoundaryMesh/faBoundaryMeshEntries.C | 29 +- .../faBoundaryMesh/faBoundaryMeshEntries.H | 17 +- .../faMesh/faPatches/faPatch/faPatch.C | 23 +- .../faMesh/faPatches/faPatch/faPatch.H | 6 +- .../fvMesh/fvBoundaryMesh/fvBoundaryMesh.H | 23 +- src/meshTools/cellFeatures/cellFeatures.C | 11 +- src/meshTools/cellFeatures/cellFeatures.H | 8 +- src/meshTools/polyTopoChange/polyTopoChange.C | 4 +- .../faceZoneToCell/faceZoneToCell.C | 92 +++-- .../faceZoneToCell/faceZoneToCell.H | 18 +- src/surfMesh/surfZone/surfZoneIOList.C | 95 +++-- src/surfMesh/surfZone/surfZoneIOList.H | 13 +- .../cpuCabinet/system/topoSetDict.f1 | 15 +- .../pisoFoam/RAS/cavity/system/topoSetDict | 6 +- 41 files changed, 1322 insertions(+), 629 deletions(-) diff --git a/etc/caseDicts/annotated/topoSetSourcesDict b/etc/caseDicts/annotated/topoSetSourcesDict index 53a868b7f6..11e2608439 100644 --- a/etc/caseDicts/annotated/topoSetSourcesDict +++ b/etc/caseDicts/annotated/topoSetSourcesDict @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2306 | +| \\ / O peration | Version: v2312 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -71,14 +71,14 @@ cellSet_doc } - //- Cells on master or slave side of faceZone + //- Cells on front/back/both side of faceZone { source faceZoneToCell; zones (".*Zone"); // Names of faceZones, word or regex // or zone ".*Zone"; // Name of faceZone, word or regex - option master; // master/slave + option front; // front/back/both } diff --git a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C index e0c59d99dd..a76ade8c7d 100644 --- a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C +++ b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -81,14 +81,31 @@ Foam::patchIdentifier::patchIdentifier Foam::patchIdentifier::patchIdentifier ( const patchIdentifier& ident, - const label index + const label newIndex ) : - name_(ident.name_), - index_(index), - physicalType_(ident.physicalType_), - inGroups_(ident.inGroups_) -{} + patchIdentifier(ident) +{ + if (newIndex >= 0) + { + index_ = newIndex; + } +} + + +Foam::patchIdentifier::patchIdentifier +( + patchIdentifier&& ident, + const label newIndex +) +: + patchIdentifier(std::move(ident)) +{ + if (newIndex >= 0) + { + index_ = newIndex; + } +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H index e5e5ba43e6..f6796d603d 100644 --- a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H +++ b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.H @@ -90,16 +90,22 @@ public: //- Copy construct patchIdentifier(const patchIdentifier&) = default; + //- Move construct + patchIdentifier(patchIdentifier&&) = default; + //- Copy assignment patchIdentifier& operator=(const patchIdentifier&) = default; + //- Move assignment + patchIdentifier& operator=(patchIdentifier&&) = default; + //- Destructor virtual ~patchIdentifier() = default; // Constructors - //- Default construct. Uses name="", index=0 + //- Default construct: name="", index=0 patchIdentifier(); //- Construct from mandatory components @@ -122,11 +128,18 @@ public: const label index ); - //- Copy construct, resetting the index + //- Copy construct, resetting the index (if non-negative) patchIdentifier ( const patchIdentifier& ident, - const label index + const label newIndex + ); + + //- Move construct, resetting the index (if non-negative) + patchIdentifier + ( + patchIdentifier&& ident, + const label newIndex ); diff --git a/src/OpenFOAM/meshes/Identifiers/zone/zoneIdentifier.C b/src/OpenFOAM/meshes/Identifiers/zone/zoneIdentifier.C index c28b53f755..acfa9f6743 100644 --- a/src/OpenFOAM/meshes/Identifiers/zone/zoneIdentifier.C +++ b/src/OpenFOAM/meshes/Identifiers/zone/zoneIdentifier.C @@ -80,14 +80,31 @@ Foam::zoneIdentifier::zoneIdentifier Foam::zoneIdentifier::zoneIdentifier ( const zoneIdentifier& ident, - const label index + const label newIndex ) : - name_(ident.name_), - index_(index), - physicalType_(ident.physicalType_), - inGroups_(ident.inGroups_) -{} + zoneIdentifier(ident) +{ + if (newIndex >= 0) + { + index_ = newIndex; + } +} + + +Foam::zoneIdentifier::zoneIdentifier +( + zoneIdentifier&& ident, + const label newIndex +) +: + zoneIdentifier(std::move(ident)) +{ + if (newIndex >= 0) + { + index_ = newIndex; + } +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/Identifiers/zone/zoneIdentifier.H b/src/OpenFOAM/meshes/Identifiers/zone/zoneIdentifier.H index 19d9bdb662..9a6c943729 100644 --- a/src/OpenFOAM/meshes/Identifiers/zone/zoneIdentifier.H +++ b/src/OpenFOAM/meshes/Identifiers/zone/zoneIdentifier.H @@ -78,16 +78,22 @@ public: //- Copy construct zoneIdentifier(const zoneIdentifier&) = default; + //- Move construct + zoneIdentifier(zoneIdentifier&&) = default; + //- Copy assignment zoneIdentifier& operator=(const zoneIdentifier&) = default; + //- Move assignment + zoneIdentifier& operator=(zoneIdentifier&&) = default; + //- Destructor virtual ~zoneIdentifier() = default; // Constructors - //- Default construct. Uses name="", index=0 + //- Default construct: name="", index=0 zoneIdentifier(); //- Construct from mandatory components @@ -110,11 +116,18 @@ public: const label index ); - //- Copy construct, resetting the index + //- Copy construct, resetting the index (if non-negative) zoneIdentifier ( const zoneIdentifier& ident, - const label index + const label newIndex + ); + + //- Move construct, resetting the index (if non-negative) + zoneIdentifier + ( + zoneIdentifier&& ident, + const label newIndex ); diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C index 0bae7021c7..ee7694bb11 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapPolyMesh.C @@ -81,7 +81,7 @@ Foam::mapPolyMesh::mapPolyMesh(const polyMesh& mesh) forAll(faceZonePointMap_, zonei) { faceZonePointMap_[zonei] = - identity(mesh.faceZones()[zonei]().meshPoints().size()); + identity(mesh.faceZones()[zonei].patch().meshPoints().size()); } forAll(faceZoneFaceMap_, zonei) diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 29ffe6f3f1..531500637f 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -105,12 +105,12 @@ void Foam::polyBoundaryMesh::calcGroupIDs() const } -bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent) +bool Foam::polyBoundaryMesh::readContents(const bool allowOptionalRead) { if ( this->isReadRequired() - || (allowReadIfPresent && this->isReadOptional() && this->headerOk()) + || (allowOptionalRead && this->isReadOptional() && this->headerOk()) ) { // Warn for MUST_READ_IF_MODIFIED @@ -118,12 +118,11 @@ bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent) polyPatchList& patches = *this; - // Read polyPatchList + // Read entries Istream& is = readStream(typeName); - // Read patches as entries - PtrList patchEntries(is); - patches.resize(patchEntries.size()); + PtrList entries(is); + patches.resize_null(entries.size()); // Transcribe forAll(patches, patchi) @@ -133,8 +132,8 @@ bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent) patchi, polyPatch::New ( - patchEntries[patchi].keyword(), - patchEntries[patchi].dict(), + entries[patchi].keyword(), + entries[patchi].dict(), patchi, *this ) @@ -146,6 +145,7 @@ bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent) return true; } + // Nothing read return false; } @@ -162,10 +162,23 @@ Foam::polyBoundaryMesh::polyBoundaryMesh regIOobject(io), mesh_(mesh) { - readContents(false); // READ_IF_PRESENT allowed: False + readContents(false); // allowOptionalRead = false } +Foam::polyBoundaryMesh::polyBoundaryMesh +( + const IOobject& io, + const polyMesh& pm, + Foam::zero +) +: + polyPatchList(), + regIOobject(io), + mesh_(pm) +{} + + Foam::polyBoundaryMesh::polyBoundaryMesh ( const IOobject& io, @@ -183,20 +196,22 @@ Foam::polyBoundaryMesh::polyBoundaryMesh ( const IOobject& io, const polyMesh& pm, - const polyPatchList& ppl + const polyPatchList& list ) : polyPatchList(), regIOobject(io), mesh_(pm) { - if (!readContents(true)) // READ_IF_PRESENT allowed: True + if (!readContents(true)) // allowOptionalRead = true { + // Nothing read. Use supplied patches polyPatchList& patches = *this; - patches.resize(ppl.size()); + patches.resize(list.size()); + forAll(patches, patchi) { - patches.set(patchi, ppl[patchi].clone(*this)); + patches.set(patchi, list[patchi].clone(*this)); } } } diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index ab953dd029..625b2d7a3e 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -91,8 +91,9 @@ class polyBoundaryMesh //- Calculate group name to patch ids lookup void calcGroupIDs() const; - //- Read if IOobject flags set. Return true if read. - bool readContents(const bool allowReadIfPresent); + //- Return true if contents were read + //- (controlled by IOobject readOption flags). + bool readContents(const bool allowOptionalRead); public: @@ -114,15 +115,24 @@ public: // Constructors - //- Read constructor given IOobject and a polyMesh reference - // Note point pointers are unset, only used in copying meshes + //- Read construct given IOobject and a mesh reference. + //- It will only read for MUST_READ variants (not READ_IF_PRESENT). polyBoundaryMesh ( const IOobject& io, const polyMesh& mesh ); - //- Construct given size + //- Construct empty with IOobject properties and a mesh reference. + //- Does not read. + polyBoundaryMesh + ( + const IOobject& io, + const polyMesh& mesh, + Foam::zero + ); + + //- Construct with specified size. Does not read. polyBoundaryMesh ( const IOobject& io, @@ -130,12 +140,13 @@ public: const label size ); - //- Construct given polyPatchList + //- Read construct (mandatory, optional) based on IOobject properties + //- or use the fallback PtrList (with cloning). polyBoundaryMesh ( const IOobject& io, const polyMesh& mesh, - const polyPatchList& ppl + const polyPatchList& list ); diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.C index 05e419e4d5..a58a4ad684 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +27,7 @@ License \*---------------------------------------------------------------------------*/ #include "polyBoundaryMeshEntries.H" +#include "processorPolyPatch.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -36,4 +37,29 @@ namespace Foam } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::polyBoundaryMeshEntries::removeProcPatches() +{ + // Truncate at the first processor patch entry + PtrList& entries = *this; + + label nNonProcessor = entries.size(); + + forAll(entries, patchi) + { + const dictionary& dict = entries[patchi].dict(); + + const word pType = dict.get("type"); + if (pType == processorPolyPatch::typeName) + { + nNonProcessor = patchi; + break; + } + } + + entries.resize(nNonProcessor); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.H index aa2f97635a..671aa22958 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMeshEntries.H @@ -53,8 +53,8 @@ namespace Foam class polyBoundaryMeshEntries : - public regIOobject, - public PtrList + public PtrList, + public regIOobject { public: @@ -64,20 +64,28 @@ public: // Constructors + //- Read construct from IOobject explicit polyBoundaryMeshEntries(const IOobject& io) : - regIOobject(io), - PtrList() + regIOobject(io) { if (isReadRequired() || (isReadOptional() && headerOk())) { - readStream(typeName) >> *this; + // Read as entries + Istream& is = readStream(typeName); + + is >> *this; + close(); } } // Member Functions + //- Truncate at the first processor patch entry + void removeProcPatches(); + + //- The class is probably read-only bool writeData(Ostream&) const { NotImplemented; diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C index f42eb85f15..ea0bfbbc84 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,7 +30,6 @@ License #include "addToRunTimeSelectionTable.H" #include "polyBoundaryMesh.H" #include "polyMesh.H" -#include "demandDrivenData.H" #include "OFstream.H" #include "matchPoints.H" #include "edgeHashes.H" @@ -50,7 +49,7 @@ namespace Foam } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // Foam::label Foam::cyclicPolyPatch::findMaxArea ( @@ -813,10 +812,7 @@ Foam::cyclicPolyPatch::cyclicPolyPatch // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // Foam::cyclicPolyPatch::~cyclicPolyPatch() -{ - deleteDemandDrivenData(coupledPointsPtr_); - deleteDemandDrivenData(coupledEdgesPtr_); -} +{} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -1022,8 +1018,8 @@ void Foam::cyclicPolyPatch::initUpdateMesh(PstreamBuffers& pBufs) void Foam::cyclicPolyPatch::updateMesh(PstreamBuffers& pBufs) { polyPatch::updateMesh(pBufs); - deleteDemandDrivenData(coupledPointsPtr_); - deleteDemandDrivenData(coupledEdgesPtr_); + coupledPointsPtr_.reset(nullptr); + coupledEdgesPtr_.reset(nullptr); } @@ -1063,8 +1059,8 @@ const Foam::edgeList& Foam::cyclicPolyPatch::coupledPoints() const } } - coupledPointsPtr_ = new edgeList(nPoints()); - edgeList& connected = *coupledPointsPtr_; + coupledPointsPtr_.reset(new edgeList(nPoints())); + auto& connected = *coupledPointsPtr_; // Extract coupled points. label connectedI = 0; @@ -1153,8 +1149,8 @@ const Foam::edgeList& Foam::cyclicPolyPatch::coupledEdges() const const labelList& mp = meshPoints(); - coupledEdgesPtr_ = new edgeList(edgeMap.size()); - edgeList& coupledEdges = *coupledEdgesPtr_; + coupledEdgesPtr_.reset(new edgeList(edgeMap.size())); + auto& coupledEdges = *coupledEdgesPtr_; label coupleI = 0; forAll(neighbPatch, patchFacei) @@ -1275,10 +1271,10 @@ bool Foam::cyclicPolyPatch::order << " neighbour:" << neighbPatchName() << endl; } - faceMap.setSize(pp.size()); + faceMap.resize_nocopy(pp.size()); faceMap = -1; - rotation.setSize(pp.size()); + rotation.resize_nocopy(pp.size()); rotation = 0; if (transform() == NOORDERING) @@ -1434,7 +1430,7 @@ bool Foam::cyclicPolyPatch::order } } - ownerPatchPtr_.clear(); + ownerPatchPtr_.reset(nullptr); // Return false if no change necessary, true otherwise. diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H index 13302a8f46..19d0c9406e 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,8 +46,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef cyclicPolyPatch_H -#define cyclicPolyPatch_H +#ifndef Foam_cyclicPolyPatch_H +#define Foam_cyclicPolyPatch_H #include "coupledPolyPatch.H" #include "edgeList.H" @@ -68,7 +68,7 @@ class cyclicPolyPatch : public coupledPolyPatch { - // Private data + // Private Data //- Name of other half mutable word neighbPatchName_; @@ -93,16 +93,19 @@ class cyclicPolyPatch vector separationVector_; - //- List of edges formed from connected points. e[0] is the point on - // the first half of the patch, e[1] the corresponding point on the - // second half. - mutable edgeList* coupledPointsPtr_; + //- List of edges formed from connected points. + // From first half of the patch to the corresponding point + // on the second half. + mutable std::unique_ptr coupledPointsPtr_; - //- List of connected edges. e[0] is the edge on the first half of the - // patch, e[1] the corresponding edge on the second half. - mutable edgeList* coupledEdgesPtr_; + //- List of connected edges. + // From first half of the patch to the corresponding edge + // on the second half. + mutable std::unique_ptr coupledEdgesPtr_; //- Temporary storage of owner side patch during ordering. + // Saved as autoPtr instead of std::unique_ptr to allow + // extra nullptr checking mutable autoPtr ownerPatchPtr_; @@ -323,7 +326,7 @@ public: // Implicit Functions - //- Return number of new internal of this polyPatch faces + //- Return number of new internal of this polyPatch faces virtual void newInternalProcFaces ( label& newFaces, @@ -424,19 +427,19 @@ public: } //- Axis of rotation for rotational cyclics - const vector& rotationAxis() const + const vector& rotationAxis() const noexcept { return rotationAxis_; } //- Point on axis of rotation for rotational cyclics - const point& rotationCentre() const + const point& rotationCentre() const noexcept { return rotationCentre_; } //- Translation vector for translational cyclics - const vector& separationVector() const + const vector& separationVector() const noexcept { return separationVector_; } diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C index 7ad617d311..1a5e79754c 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C @@ -35,7 +35,6 @@ License #include "entry.H" #include "dictionary.H" #include "pointPatchField.H" -#include "demandDrivenData.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -260,7 +259,7 @@ Foam::polyPatch::polyPatch : polyPatch(p) { - faceCellsPtr_ = new labelList::subList(faceCells, faceCells.size()); + faceCellsPtr_.reset(new labelList::subList(faceCells, faceCells.size())); } @@ -374,9 +373,12 @@ const Foam::labelUList& Foam::polyPatch::faceCells() const { if (!faceCellsPtr_) { - faceCellsPtr_ = new labelList::subList + faceCellsPtr_.reset ( - patchSlice(boundaryMesh().mesh().faceOwner()) + new labelList::subList + ( + patchSlice(boundaryMesh().mesh().faceOwner()) + ) ); } @@ -388,7 +390,8 @@ const Foam::labelList& Foam::polyPatch::meshEdges() const { if (!mePtr_) { - mePtr_ = + mePtr_.reset + ( new labelList ( primitivePatch::meshEdges @@ -396,7 +399,8 @@ const Foam::labelList& Foam::polyPatch::meshEdges() const boundaryMesh().mesh().edges(), boundaryMesh().mesh().pointEdges() ) - ); + ) + ); } return *mePtr_; @@ -407,8 +411,8 @@ void Foam::polyPatch::clearAddressing() { primitivePatch::clearTopology(); primitivePatch::clearPatchMeshAddr(); - deleteDemandDrivenData(faceCellsPtr_); - deleteDemandDrivenData(mePtr_); + faceCellsPtr_.reset(nullptr); + mePtr_.reset(nullptr); } diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H index 42104698df..c676179197 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.H @@ -83,10 +83,10 @@ class polyPatch const polyBoundaryMesh& boundaryMesh_; //- Demand-driven: face-cell addressing - mutable labelList::subList* faceCellsPtr_; + mutable std::unique_ptr faceCellsPtr_; //- Demand-driven: global edge addressing - mutable labelList* mePtr_; + mutable std::unique_ptr mePtr_; protected: @@ -500,8 +500,8 @@ public: // Member Operators - //- Assignment - void operator=(const polyPatch&); + //- Copy assignment + void operator=(const polyPatch& p); // Ostream Operator diff --git a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C index ed35f4a341..622365e95d 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/ZoneMesh/ZoneMesh.C @@ -47,6 +47,22 @@ namespace Foam // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +template +Foam::label Foam::ZoneMesh::totalSize() const +{ + // Count number of objects in all zones + const PtrList& zones = *this; + + label total = 0; + for (const ZoneType& zn : zones) + { + total += zn.size(); + } + + return total; +} + + template void Foam::ZoneMesh::calcZoneMap() const { @@ -58,31 +74,22 @@ void Foam::ZoneMesh::calcZoneMap() const } else { - // Count number of objects in all zones - label nObjects = 0; - - const PtrList& zones = *this; - - for (const ZoneType& zn : zones) - { - nObjects += zn.size(); - } - - zoneMapPtr_.emplace(2*nObjects); - auto& zm = *zoneMapPtr_; + zoneMapPtr_.reset(new Map