From 47232ccf664cf0ed7010ceea853d4d6381eaa78d Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Tue, 27 Feb 2024 13:40:27 +0000 Subject: [PATCH] ENH: finiteArea: replace raw pointers with unique_ptr --- .../distributed/faMeshDistributor.C | 8 +- .../distributed/faMeshDistributor.H | 2 +- .../distributed/faMeshDistributorTemplates.C | 4 +- src/finiteArea/faMesh/faMesh.C | 135 +++------- src/finiteArea/faMesh/faMesh.H | 29 +-- .../faMesh/faMeshDemandDrivenData.C | 231 +++++++++--------- .../faMesh/faMeshMapper/faAreaMapper.C | 45 ++-- .../faMesh/faMeshMapper/faAreaMapper.H | 13 +- .../faMesh/faMeshMapper/faEdgeMapper.C | 7 +- .../faMesh/faMeshMapper/faEdgeMapper.H | 2 +- .../faMesh/faMeshMapper/faPatchMapper.C | 7 +- .../faMesh/faMeshMapper/faPatchMapper.H | 2 +- src/finiteArea/faMesh/faMeshTopology.C | 11 +- .../faMesh/faPatches/faPatch/faPatch.C | 26 +- .../leastSquaresFaVectors.C | 21 +- .../leastSquaresFaVectors.H | 6 +- .../edgeInterpolation/edgeInterpolation.C | 88 +++---- .../edgeInterpolation/edgeInterpolation.H | 24 +- 18 files changed, 257 insertions(+), 404 deletions(-) diff --git a/src/finiteArea/distributed/faMeshDistributor.C b/src/finiteArea/distributed/faMeshDistributor.C index 9ee084fd94..a3b8841d1e 100644 --- a/src/finiteArea/distributed/faMeshDistributor.C +++ b/src/finiteArea/distributed/faMeshDistributor.C @@ -84,10 +84,10 @@ void Foam::faMeshDistributor::createInternalEdgeMap() const const auto& faEdgeMap = distMap_.faceMap(); // Copy full map - internalEdgeMap_.reset(new mapDistributeBase(faEdgeMap)); + internalEdgeMapPtr_ = std::make_unique(faEdgeMap); // Retain internal edges - internalEdgeMap_->compactRemoteData + internalEdgeMapPtr_->compactRemoteData ( bitSet(tgtMesh_.nInternalEdges(), true), UPstream::msgType(), @@ -200,8 +200,6 @@ Foam::faMeshDistributor::faMeshDistributor srcMesh_(srcMesh), tgtMesh_(tgtMesh), distMap_(distMap), - internalEdgeMap_(), - patchEdgeMaps_(), dummyHandler_(fileOperation::null()), writeHandler_(dummyHandler_), isWriteProc_(isWriteProc) @@ -221,8 +219,6 @@ Foam::faMeshDistributor::faMeshDistributor srcMesh_(srcMesh), tgtMesh_(tgtMesh), distMap_(distMap), - internalEdgeMap_(), - patchEdgeMaps_(), dummyHandler_(nullptr), writeHandler_(writeHandler), isWriteProc_(Switch::INVALID) diff --git a/src/finiteArea/distributed/faMeshDistributor.H b/src/finiteArea/distributed/faMeshDistributor.H index 05f40ab9cc..632d617308 100644 --- a/src/finiteArea/distributed/faMeshDistributor.H +++ b/src/finiteArea/distributed/faMeshDistributor.H @@ -73,7 +73,7 @@ class faMeshDistributor const mapDistributePolyMesh& distMap_; //- Internal edge mapper - mutable std::unique_ptr internalEdgeMap_; + mutable std::unique_ptr internalEdgeMapPtr_; //- Patch edge mappers mutable PtrList patchEdgeMaps_; diff --git a/src/finiteArea/distributed/faMeshDistributorTemplates.C b/src/finiteArea/distributed/faMeshDistributorTemplates.C index 9215cc3b2b..8df66fe2ab 100644 --- a/src/finiteArea/distributed/faMeshDistributorTemplates.C +++ b/src/finiteArea/distributed/faMeshDistributorTemplates.C @@ -154,7 +154,7 @@ Foam::faMeshDistributor::distributeField const GeometricField& fld ) const { - if (!internalEdgeMap_) + if (!internalEdgeMapPtr_) { createInternalEdgeMap(); } @@ -165,7 +165,7 @@ Foam::faMeshDistributor::distributeField const distributedFieldMapper mapper ( labelUList::null(), - *(internalEdgeMap_) + *(internalEdgeMapPtr_) ); DimensionedField internalField diff --git a/src/finiteArea/faMesh/faMesh.C b/src/finiteArea/faMesh/faMesh.C index cfb9e1608c..49c518363d 100644 --- a/src/finiteArea/faMesh/faMesh.C +++ b/src/finiteArea/faMesh/faMesh.C @@ -169,14 +169,12 @@ void Foam::faMesh::checkBoundaryEdgeLabelRange void Foam::faMesh::initPatch() const { - patchPtr_.reset + patchPtr_ = std::make_unique ( - new uindirectPrimitivePatch - ( - UIndirectList(mesh().faces(), faceLabels_), - mesh().points() - ) + UIndirectList(mesh().faces(), faceLabels_), + mesh().points() ); + // Could set some basic primitive data here... // nEdges_ = patchPtr_->nEdges(); // nInternalEdges_ = patchPtr_->nInternalEdges(); @@ -253,17 +251,17 @@ void Foam::faMesh::clearGeomNotAreas() const polyPatchFacesPtr_.reset(nullptr); polyPatchIdsPtr_.reset(nullptr); bndConnectPtr_.reset(nullptr); - deleteDemandDrivenData(SPtr_); - deleteDemandDrivenData(patchStartsPtr_); - deleteDemandDrivenData(LePtr_); - deleteDemandDrivenData(magLePtr_); - deleteDemandDrivenData(faceCentresPtr_); - deleteDemandDrivenData(edgeCentresPtr_); - deleteDemandDrivenData(faceAreaNormalsPtr_); - deleteDemandDrivenData(edgeAreaNormalsPtr_); + SPtr_.reset(nullptr); + patchStartsPtr_.reset(nullptr); + LePtr_.reset(nullptr); + magLePtr_.reset(nullptr); + faceCentresPtr_.reset(nullptr); + edgeCentresPtr_.reset(nullptr); + faceAreaNormalsPtr_.reset(nullptr); + edgeAreaNormalsPtr_.reset(nullptr); pointAreaNormalsPtr_.reset(nullptr); - deleteDemandDrivenData(faceCurvaturesPtr_); - deleteDemandDrivenData(edgeTransformTensorsPtr_); + faceCurvaturesPtr_.reset(nullptr); + edgeTransformTensorsPtr_.reset(nullptr); } @@ -272,9 +270,9 @@ void Foam::faMesh::clearGeom() const DebugInFunction << "Clearing geometry" << endl; clearGeomNotAreas(); - deleteDemandDrivenData(S0Ptr_); - deleteDemandDrivenData(S00Ptr_); - deleteDemandDrivenData(correctPatchPointNormalsPtr_); + S0Ptr_.reset(nullptr); + S00Ptr_.reset(nullptr); + correctPatchPointNormalsPtr_.reset(nullptr); } @@ -282,7 +280,7 @@ void Foam::faMesh::clearAddressing() const { DebugInFunction << "Clearing addressing" << endl; - deleteDemandDrivenData(lduPtr_); + lduPtr_.reset(nullptr); } @@ -402,33 +400,7 @@ Foam::faMesh::faMesh *this ), comm_(UPstream::worldComm), - curTimeIndex_(time().timeIndex()), - - patchPtr_(nullptr), - polyPatchFacesPtr_(nullptr), - polyPatchIdsPtr_(nullptr), - bndConnectPtr_(nullptr), - lduPtr_(nullptr), - - SPtr_(nullptr), - S0Ptr_(nullptr), - S00Ptr_(nullptr), - patchStartsPtr_(nullptr), - LePtr_(nullptr), - magLePtr_(nullptr), - faceCentresPtr_(nullptr), - edgeCentresPtr_(nullptr), - faceAreaNormalsPtr_(nullptr), - edgeAreaNormalsPtr_(nullptr), - pointAreaNormalsPtr_(nullptr), - faceCurvaturesPtr_(nullptr), - edgeTransformTensorsPtr_(nullptr), - correctPatchPointNormalsPtr_(nullptr), - globalMeshDataPtr_(nullptr), - - haloMapPtr_(nullptr), - haloFaceCentresPtr_(nullptr), - haloFaceNormalsPtr_(nullptr) + curTimeIndex_(time().timeIndex()) { DebugInFunction << "Creating from IOobject" << endl; @@ -459,7 +431,7 @@ Foam::faMesh::faMesh rio.resetHeader("S0"); if (returnReduceOr(rio.typeHeaderOk(false))) { - S0Ptr_ = new DimensionedField + S0Ptr_ = std::make_unique> ( rio, *this, @@ -524,33 +496,7 @@ Foam::faMesh::faMesh label(0) ), comm_(UPstream::worldComm), - curTimeIndex_(time().timeIndex()), - - patchPtr_(nullptr), - polyPatchFacesPtr_(nullptr), - polyPatchIdsPtr_(nullptr), - bndConnectPtr_(nullptr), - lduPtr_(nullptr), - - SPtr_(nullptr), - S0Ptr_(nullptr), - S00Ptr_(nullptr), - patchStartsPtr_(nullptr), - LePtr_(nullptr), - magLePtr_(nullptr), - faceCentresPtr_(nullptr), - edgeCentresPtr_(nullptr), - faceAreaNormalsPtr_(nullptr), - edgeAreaNormalsPtr_(nullptr), - pointAreaNormalsPtr_(nullptr), - faceCurvaturesPtr_(nullptr), - edgeTransformTensorsPtr_(nullptr), - correctPatchPointNormalsPtr_(nullptr), - globalMeshDataPtr_(nullptr), - - haloMapPtr_(nullptr), - haloFaceCentresPtr_(nullptr), - haloFaceNormalsPtr_(nullptr) + curTimeIndex_(time().timeIndex()) { // Not yet much for primitive mesh data possible... nPoints_ = 0; @@ -609,33 +555,7 @@ Foam::faMesh::faMesh label(0) ), comm_(UPstream::worldComm), - curTimeIndex_(time().timeIndex()), - - patchPtr_(nullptr), - polyPatchFacesPtr_(nullptr), - polyPatchIdsPtr_(nullptr), - bndConnectPtr_(nullptr), - lduPtr_(nullptr), - - SPtr_(nullptr), - S0Ptr_(nullptr), - S00Ptr_(nullptr), - patchStartsPtr_(nullptr), - LePtr_(nullptr), - magLePtr_(nullptr), - faceCentresPtr_(nullptr), - edgeCentresPtr_(nullptr), - faceAreaNormalsPtr_(nullptr), - edgeAreaNormalsPtr_(nullptr), - pointAreaNormalsPtr_(nullptr), - faceCurvaturesPtr_(nullptr), - edgeTransformTensorsPtr_(nullptr), - correctPatchPointNormalsPtr_(nullptr), - globalMeshDataPtr_(nullptr), - - haloMapPtr_(nullptr), - haloFaceCentresPtr_(nullptr), - haloFaceNormalsPtr_(nullptr) + curTimeIndex_(time().timeIndex()) { // Not yet much for primitive mesh data possible... nPoints_ = 0; @@ -732,7 +652,7 @@ Foam::faMesh::faMesh rio.resetHeader("S0"); if (returnReduceOr(rio.typeHeaderOk(false))) { - S0Ptr_ = new DimensionedField + S0Ptr_ = std::make_unique> ( rio, *this, @@ -948,7 +868,7 @@ Foam::faMesh::S00() const { if (!S00Ptr_) { - S00Ptr_ = new DimensionedField + S00Ptr_ = std::make_unique> ( IOobject ( @@ -994,7 +914,7 @@ const Foam::vectorField& Foam::faMesh::pointAreaNormals() const { if (!pointAreaNormalsPtr_) { - pointAreaNormalsPtr_.reset(new vectorField(nPoints())); + pointAreaNormalsPtr_ = std::make_unique(nPoints()); calcPointAreaNormals(*pointAreaNormalsPtr_); @@ -1082,7 +1002,7 @@ bool Foam::faMesh::movePoints() { DebugInfo<< "Creating old cell volumes." << endl; - S0Ptr_ = new DimensionedField + S0Ptr_ = std::make_unique> ( IOobject ( @@ -1140,7 +1060,8 @@ Foam::boolList& Foam::faMesh::correctPatchPointNormals() const { if (!correctPatchPointNormalsPtr_) { - correctPatchPointNormalsPtr_ = new boolList(boundary().size(), false); + correctPatchPointNormalsPtr_ = + std::make_unique(boundary().size(), false); } return *correctPatchPointNormalsPtr_; diff --git a/src/finiteArea/faMesh/faMesh.H b/src/finiteArea/faMesh/faMesh.H index f587973530..34e1352250 100644 --- a/src/finiteArea/faMesh/faMesh.H +++ b/src/finiteArea/faMesh/faMesh.H @@ -261,52 +261,53 @@ class faMesh mutable std::unique_ptr> bndConnectPtr_; //- Ldu addressing data - mutable faMeshLduAddressing* lduPtr_; + mutable std::unique_ptr lduPtr_; // Geometric Data //- Face areas - mutable DimensionedField* SPtr_; + mutable std::unique_ptr> SPtr_; //- Face areas old time level - mutable DimensionedField* S0Ptr_; + mutable std::unique_ptr> S0Ptr_; //- Face areas old-old time level - mutable DimensionedField* S00Ptr_; + mutable std::unique_ptr> S00Ptr_; //- Patch starts in the edge list - mutable labelList* patchStartsPtr_; + mutable std::unique_ptr patchStartsPtr_; //- Edge length vectors - mutable edgeVectorField* LePtr_; + mutable std::unique_ptr LePtr_; //- Mag edge length vectors - mutable edgeScalarField* magLePtr_; + mutable std::unique_ptr magLePtr_; //- Face centres - mutable areaVectorField* faceCentresPtr_; + mutable std::unique_ptr faceCentresPtr_; //- Edge centres - mutable edgeVectorField* edgeCentresPtr_; + mutable std::unique_ptr edgeCentresPtr_; //- Face area normals - mutable areaVectorField* faceAreaNormalsPtr_; + mutable std::unique_ptr faceAreaNormalsPtr_; //- Edge area normals - mutable edgeVectorField* edgeAreaNormalsPtr_; + mutable std::unique_ptr edgeAreaNormalsPtr_; //- Point area normals mutable std::unique_ptr pointAreaNormalsPtr_; //- Face curvatures - mutable areaScalarField* faceCurvaturesPtr_; + mutable std::unique_ptr faceCurvaturesPtr_; //- Edge transformation tensors - mutable FieldField* edgeTransformTensorsPtr_; + mutable std::unique_ptr> + edgeTransformTensorsPtr_; //- Whether point normals must be corrected for a patch - mutable boolList* correctPatchPointNormalsPtr_; + mutable std::unique_ptr correctPatchPointNormalsPtr_; // Other mesh-related data diff --git a/src/finiteArea/faMesh/faMeshDemandDrivenData.C b/src/finiteArea/faMesh/faMeshDemandDrivenData.C index 3f94292886..49b60d4018 100644 --- a/src/finiteArea/faMesh/faMeshDemandDrivenData.C +++ b/src/finiteArea/faMesh/faMeshDemandDrivenData.C @@ -222,7 +222,7 @@ void Foam::faMesh::calcLduAddressing() const << abort(FatalError); } - lduPtr_ = new faMeshLduAddressing(*this); + lduPtr_ = std::make_unique(*this); } @@ -238,7 +238,7 @@ void Foam::faMesh::calcPatchStarts() const << abort(FatalError); } - patchStartsPtr_ = new labelList(boundary().patchStarts()); + patchStartsPtr_ = std::make_unique(boundary().patchStarts()); } @@ -254,9 +254,9 @@ void Foam::faMesh::calcWhichPatchFaces() const const polyBoundaryMesh& pbm = mesh().boundaryMesh(); - polyPatchFacesPtr_.reset + polyPatchFacesPtr_ = std::make_unique> ( - new List(pbm.whichPatchFace(faceLabels_)) + pbm.whichPatchFace(faceLabels_) ); labelHashSet ids; @@ -278,7 +278,7 @@ void Foam::faMesh::calcWhichPatchFaces() const this->comm() ); - polyPatchIdsPtr_.reset(new labelList(ids.sortedToc())); + polyPatchIdsPtr_ = std::make_unique(ids.sortedToc()); } @@ -675,23 +675,22 @@ void Foam::faMesh::calcLe() const << abort(FatalError); } - LePtr_ = - new edgeVectorField + LePtr_ = std::make_unique + ( + IOobject ( - IOobject - ( - "Le", - mesh().pointsInstance(), - faMesh::meshSubDir, - faMesh::thisDb(), - IOobject::NO_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ), - *this, - dimLength - // -> calculatedType() - ); + "Le", + mesh().pointsInstance(), + faMesh::meshSubDir, + faMesh::thisDb(), + IOobject::NO_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ), + *this, + dimLength + // -> calculatedType() + ); edgeVectorField& Le = *LePtr_; // Need face centres @@ -773,23 +772,21 @@ void Foam::faMesh::calcMagLe() const << abort(FatalError); } - magLePtr_ = - new edgeScalarField + magLePtr_ = std::make_unique + ( + IOobject ( - IOobject - ( - "magLe", - mesh().pointsInstance(), - faMesh::meshSubDir, - faMesh::thisDb(), - IOobject::NO_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ), - *this, - dimLength - ); - + "magLe", + mesh().pointsInstance(), + faMesh::meshSubDir, + faMesh::thisDb(), + IOobject::NO_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ), + *this, + dimLength + ); edgeScalarField& magLe = *magLePtr_; const pointField& localPoints = points(); @@ -849,24 +846,22 @@ void Foam::faMesh::calcFaceCentres() const << abort(FatalError); } - faceCentresPtr_ = - new areaVectorField + faceCentresPtr_ = std::make_unique + ( + IOobject ( - IOobject - ( - "centres", - mesh().pointsInstance(), - faMesh::meshSubDir, - faMesh::thisDb(), - IOobject::NO_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ), - *this, - dimLength - // -> calculatedType() - ); - + "centres", + mesh().pointsInstance(), + faMesh::meshSubDir, + faMesh::thisDb(), + IOobject::NO_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ), + *this, + dimLength + // -> calculatedType() + ); areaVectorField& centres = *faceCentresPtr_; // Need local points @@ -931,24 +926,22 @@ void Foam::faMesh::calcEdgeCentres() const << abort(FatalError); } - edgeCentresPtr_ = - new edgeVectorField + edgeCentresPtr_ = std::make_unique + ( + IOobject ( - IOobject - ( - "edgeCentres", - mesh().pointsInstance(), - faMesh::meshSubDir, - faMesh::thisDb(), - IOobject::NO_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ), - *this, - dimLength - // -> calculatedType() - ); - + "edgeCentres", + mesh().pointsInstance(), + faMesh::meshSubDir, + faMesh::thisDb(), + IOobject::NO_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ), + *this, + dimLength + // -> calculatedType() + ); edgeVectorField& centres = *edgeCentresPtr_; // Need local points @@ -996,7 +989,7 @@ void Foam::faMesh::calcS() const << abort(FatalError); } - SPtr_ = new DimensionedField + SPtr_ = std::make_unique> ( IOobject ( @@ -1068,23 +1061,21 @@ void Foam::faMesh::calcFaceAreaNormals() const << abort(FatalError); } - faceAreaNormalsPtr_ = - new areaVectorField + faceAreaNormalsPtr_ = std::make_unique + ( + IOobject ( - IOobject - ( - "faceAreaNormals", - mesh().pointsInstance(), - faMesh::meshSubDir, - faMesh::thisDb(), - IOobject::NO_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ), - *this, - dimless - ); - + "faceAreaNormals", + mesh().pointsInstance(), + faMesh::meshSubDir, + faMesh::thisDb(), + IOobject::NO_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ), + *this, + dimless + ); areaVectorField& faceNormals = *faceAreaNormalsPtr_; const pointField& localPoints = points(); @@ -1149,23 +1140,22 @@ void Foam::faMesh::calcEdgeAreaNormals() const << abort(FatalError); } - edgeAreaNormalsPtr_ = - new edgeVectorField + edgeAreaNormalsPtr_ = std::make_unique + ( + IOobject ( - IOobject - ( - "edgeAreaNormals", - mesh().pointsInstance(), - faMesh::meshSubDir, - faMesh::thisDb(), - IOobject::NO_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ), - *this, - dimless - // -> calculatedType() - ); + "edgeAreaNormals", + mesh().pointsInstance(), + faMesh::meshSubDir, + faMesh::thisDb(), + IOobject::NO_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ), + *this, + dimless + // -> calculatedType() + ); edgeVectorField& edgeAreaNormals = *edgeAreaNormalsPtr_; @@ -1279,23 +1269,21 @@ void Foam::faMesh::calcFaceCurvatures() const << abort(FatalError); } - faceCurvaturesPtr_ = - new areaScalarField + faceCurvaturesPtr_ = std::make_unique + ( + IOobject ( - IOobject - ( - "faceCurvatures", - mesh().pointsInstance(), - faMesh::meshSubDir, - faMesh::thisDb(), - IOobject::NO_READ, - IOobject::NO_WRITE, - IOobject::NO_REGISTER - ), - *this, - dimless/dimLength - ); - + "faceCurvatures", + mesh().pointsInstance(), + faMesh::meshSubDir, + faMesh::thisDb(), + IOobject::NO_READ, + IOobject::NO_WRITE, + IOobject::NO_REGISTER + ), + *this, + dimless/dimLength + ); areaScalarField& faceCurvatures = *faceCurvaturesPtr_; @@ -1321,7 +1309,8 @@ void Foam::faMesh::calcEdgeTransformTensors() const << abort(FatalError); } - edgeTransformTensorsPtr_ = new FieldField(nEdges_); + edgeTransformTensorsPtr_ = + std::make_unique>(nEdges_); auto& edgeTransformTensors = *edgeTransformTensorsPtr_; // Initialize all transformation tensors diff --git a/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C b/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C index e079de2bab..f575d1a6e8 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C +++ b/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.C @@ -61,10 +61,18 @@ void Foam::faAreaMapper::calcAddressing() const // Prepare a list of new face labels and (preliminary) addressing // Note: dimensioned to number of boundary faces of polyMesh - newFaceLabelsPtr_ = new labelList(mesh_.mesh().nBoundaryFaces(), -1); - labelList& newFaceLabels = *newFaceLabelsPtr_; + newFaceLabelsPtr_ = std::make_unique + ( + mesh_.mesh().nBoundaryFaces(), + -1 + ); + auto& newFaceLabels = *newFaceLabelsPtr_; - newFaceLabelsMapPtr_ = new labelList(mesh_.mesh().nBoundaryFaces(), -1); + newFaceLabelsMapPtr_ = std::make_unique + ( + mesh_.mesh().nBoundaryFaces(), + -1 + ); labelList& newFaceLabelsMap = *newFaceLabelsMapPtr_; label nNewFaces = 0; @@ -94,7 +102,7 @@ void Foam::faAreaMapper::calcAddressing() const // Direct mapping: no further faces to add. Resize list newFaceLabels.setSize(nNewFaces); - directAddrPtr_ = new labelList(newFaceLabels.size()); + directAddrPtr_ = std::make_unique(newFaceLabels.size()); labelList& addr = *directAddrPtr_; // Adjust for creation of a boundary face from an internal face @@ -114,10 +122,13 @@ void Foam::faAreaMapper::calcAddressing() const { // There are further faces to add. Prepare interpolation addressing // and weights to full size - interpolationAddrPtr_ = new labelListList(newFaceLabels.size()); + interpolationAddrPtr_ = std::make_unique + ( + newFaceLabels.size() + ); labelListList& addr = *interpolationAddrPtr_; - weightsPtr_ = new scalarListList(newFaceLabels.size()); + weightsPtr_ = std::make_unique(newFaceLabels.size()); scalarListList& w = *weightsPtr_; // Insert single addressing and weights @@ -256,20 +267,20 @@ void Foam::faAreaMapper::calcAddressing() const // Inserted objects cannot appear in the new faMesh as they have no master // HJ, 10/Aug/2011 - insertedObjectLabelsPtr_ = new labelList(0); + insertedObjectLabelsPtr_ = std::make_unique(); } void Foam::faAreaMapper::clearOut() { - deleteDemandDrivenData(newFaceLabelsPtr_); - deleteDemandDrivenData(newFaceLabelsMapPtr_); + newFaceLabelsPtr_.reset(nullptr); + newFaceLabelsMapPtr_.reset(nullptr); - deleteDemandDrivenData(directAddrPtr_); - deleteDemandDrivenData(interpolationAddrPtr_); - deleteDemandDrivenData(weightsPtr_); + directAddrPtr_.reset(nullptr); + interpolationAddrPtr_.reset(nullptr); + weightsPtr_.reset(nullptr); - deleteDemandDrivenData(insertedObjectLabelsPtr_); + insertedObjectLabelsPtr_.reset(nullptr); hasUnmapped_ = false; } @@ -286,13 +297,7 @@ Foam::faAreaMapper::faAreaMapper mpm_(mpm), direct_(false), hasUnmapped_(false), - sizeBeforeMapping_(mesh.nFaces()), - newFaceLabelsPtr_(nullptr), - newFaceLabelsMapPtr_(nullptr), - directAddrPtr_(nullptr), - interpolationAddrPtr_(nullptr), - weightsPtr_(nullptr), - insertedObjectLabelsPtr_(nullptr) + sizeBeforeMapping_(mesh.nFaces()) { // Check for possibility of direct mapping if diff --git a/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H b/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H index 7569df58f7..9a75decf95 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H +++ b/src/finiteArea/faMesh/faMeshMapper/faAreaMapper.H @@ -77,23 +77,23 @@ class faAreaMapper label sizeBeforeMapping_; //- New face labels after mapping - mutable labelList* newFaceLabelsPtr_; + mutable std::unique_ptr newFaceLabelsPtr_; //- New face labels after mapping - mutable labelList* newFaceLabelsMapPtr_; + mutable std::unique_ptr newFaceLabelsMapPtr_; //- Direct addressing (only one form of addressing is used) - mutable labelList* directAddrPtr_; + mutable std::unique_ptr directAddrPtr_; //- Interpolated addressing (only one form of addressing is used) - mutable labelListList* interpolationAddrPtr_; + mutable std::unique_ptr interpolationAddrPtr_; //- Interpolation weights - mutable scalarListList* weightsPtr_; + mutable std::unique_ptr weightsPtr_; //- Inserted faces - mutable labelList* insertedObjectLabelsPtr_; + mutable std::unique_ptr insertedObjectLabelsPtr_; // Private Member Functions @@ -127,7 +127,6 @@ public: //- Destructor virtual ~faAreaMapper(); - // Member Functions //- Return new face labels diff --git a/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C b/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C index 582faf239a..2dffd9ed7b 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C +++ b/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.C @@ -43,13 +43,13 @@ void Foam::faEdgeMapper::calcAddressing() const hasUnmapped_ = false; // Dummy mapping: take value from edge 0 - directAddrPtr_ = new labelList(size(), Zero); + directAddrPtr_ = std::make_unique(size(), Foam::zero{}); } void Foam::faEdgeMapper::clearOut() { - deleteDemandDrivenData(directAddrPtr_); + directAddrPtr_.reset(nullptr); hasUnmapped_ = false; } @@ -64,8 +64,7 @@ Foam::faEdgeMapper::faEdgeMapper : mesh_(mesh), sizeBeforeMapping_(mesh.nInternalEdges()), - hasUnmapped_(false), - directAddrPtr_(nullptr) + hasUnmapped_(false) {} diff --git a/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H b/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H index 620795a0e8..05f0cd0fda 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H +++ b/src/finiteArea/faMesh/faMeshMapper/faEdgeMapper.H @@ -74,7 +74,7 @@ class faEdgeMapper mutable bool hasUnmapped_; //- Direct addressing - mutable labelList* directAddrPtr_; + mutable std::unique_ptr directAddrPtr_; // Private Member Functions diff --git a/src/finiteArea/faMesh/faMeshMapper/faPatchMapper.C b/src/finiteArea/faMesh/faMeshMapper/faPatchMapper.C index b54faafc13..69aa3177f6 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faPatchMapper.C +++ b/src/finiteArea/faMesh/faMeshMapper/faPatchMapper.C @@ -43,7 +43,7 @@ void Foam::faPatchMapper::calcAddressing() const // Compatibility change HJ, 12/Aug/2017 hasUnmapped_ = false; - directAddrPtr_ = new labelList(patch_.size(), Zero); + directAddrPtr_ = std::make_unique(patch_.size(), Foam::zero{}); labelList& addr = *directAddrPtr_; // Make a map of old edgeFaces, giving edge index in patch given the new @@ -86,7 +86,7 @@ void Foam::faPatchMapper::calcAddressing() const void Foam::faPatchMapper::clearOut() { - deleteDemandDrivenData(directAddrPtr_); + directAddrPtr_.reset(nullptr); hasUnmapped_ = false; } @@ -103,8 +103,7 @@ Foam::faPatchMapper::faPatchMapper mpm_(mpm), sizeBeforeMapping_(patch.size()), oldEdgeFaces_(patch.edgeFaces()), - hasUnmapped_(false), - directAddrPtr_(nullptr) + hasUnmapped_(false) {} diff --git a/src/finiteArea/faMesh/faMeshMapper/faPatchMapper.H b/src/finiteArea/faMesh/faMeshMapper/faPatchMapper.H index 8672301bd8..b27bd6874d 100644 --- a/src/finiteArea/faMesh/faMeshMapper/faPatchMapper.H +++ b/src/finiteArea/faMesh/faMeshMapper/faPatchMapper.H @@ -83,7 +83,7 @@ class faPatchMapper mutable bool hasUnmapped_; //- Direct addressing - mutable labelList* directAddrPtr_; + mutable std::unique_ptr directAddrPtr_; // Private Member Functions diff --git a/src/finiteArea/faMesh/faMeshTopology.C b/src/finiteArea/faMesh/faMeshTopology.C index 9c85727b5a..c9dbb6b130 100644 --- a/src/finiteArea/faMesh/faMeshTopology.C +++ b/src/finiteArea/faMesh/faMeshTopology.C @@ -849,9 +849,10 @@ void Foam::faMesh::setBoundaryConnections << abort(FatalError); } - bndConnectPtr_.reset + bndConnectPtr_ = std::make_unique> ( - new List(nBoundaryEdges, labelPair(-1,-1)) + nBoundaryEdges, + labelPair(-1,-1) ); auto& bndConnect = *bndConnectPtr_; @@ -989,7 +990,7 @@ const Foam::faMeshBoundaryHalo& Foam::faMesh::boundaryHaloMap() const { if (!haloMapPtr_) { - haloMapPtr_.reset(new faMeshBoundaryHalo(*this)); + haloMapPtr_ = std::make_unique(*this); } return *haloMapPtr_; @@ -1022,8 +1023,8 @@ void Foam::faMesh::calcHaloFaceGeometry() const const labelList& inputFaceIds = halo.inputMeshFaces(); - haloFaceCentresPtr_.reset(new pointField); - haloFaceNormalsPtr_.reset(new vectorField); + haloFaceCentresPtr_ = std::make_unique(); + haloFaceNormalsPtr_ = std::make_unique(); auto& centres = *haloFaceCentresPtr_; auto& normals = *haloFaceNormalsPtr_; diff --git a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C index 39c1627d59..1f0248689a 100644 --- a/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C +++ b/src/finiteArea/faMesh/faPatches/faPatch/faPatch.C @@ -105,10 +105,7 @@ Foam::faPatch::faPatch patchIdentifier(name, index), labelList(edgeLabels), nbrPolyPatchId_(nbrPolyPatchi), - boundaryMesh_(bm), - edgeFacesPtr_(nullptr), - pointLabelsPtr_(nullptr), - pointEdgesPtr_(nullptr) + boundaryMesh_(bm) { if (constraintType(patchType)) { @@ -129,10 +126,7 @@ Foam::faPatch::faPatch patchIdentifier(name, dict, index), labelList(dict.get("edgeLabels")), nbrPolyPatchId_(dict.get