Commit 841b6553 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: use unique_ptr for resource handling in dynamicMesh

ENH: defaulting for destructors where possible

STYLE: clear() instead of setSize(0) for plain Lists

STYLE: use bool operator instead of valid()/empty() for autoPtr tests
parent 2c3425ac
......@@ -33,7 +33,6 @@ License
#include "primitiveMesh.H"
#include "polyTopoChange.H"
#include "addToRunTimeSelectionTable.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -222,13 +221,12 @@ void Foam::attachDetach::checkDefinition()
void Foam::attachDetach::clearAddressing() const
{
deleteDemandDrivenData(pointMatchMapPtr_);
pointMatchMapPtr_.reset(nullptr);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::attachDetach::attachDetach
(
const word& name,
......@@ -256,7 +254,6 @@ Foam::attachDetach::attachDetach
}
// Construct from components
Foam::attachDetach::attachDetach
(
const word& name,
......@@ -292,26 +289,11 @@ Foam::attachDetach::attachDetach
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::attachDetach::~attachDetach()
{
clearAddressing();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::attachDetach::setAttach() const
{
if (!attached())
{
trigger_ = true;
}
else
{
trigger_ = false;
}
trigger_ = (!attached());
return trigger_;
}
......@@ -319,14 +301,7 @@ bool Foam::attachDetach::setAttach() const
bool Foam::attachDetach::setDetach() const
{
if (attached())
{
trigger_ = true;
}
else
{
trigger_ = false;
}
trigger_ = (attached());
return trigger_;
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -63,7 +64,7 @@ class attachDetach
:
public polyMeshModifier
{
// Data types
// Data Types
//- State of the modifier
enum modifierState
......@@ -74,7 +75,7 @@ class attachDetach
};
// Private data
// Private Data
//- Master face zone ID
faceZoneID faceZoneID_;
......@@ -103,8 +104,8 @@ class attachDetach
// Private addressing data. Created on topology change
//- Map of matching points
mutable Map<label>* pointMatchMapPtr_;
//- Map of matching points
mutable unique_ptr<Map<label>> pointMatchMapPtr_;
// Private Member Functions
......@@ -174,7 +175,7 @@ public:
//- Destructor
virtual ~attachDetach();
virtual ~attachDetach() = default;
// Member Functions
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -89,8 +90,8 @@ void Foam::attachDetach::calcPointMatchMap() const
const faceList& masterLocalFaces = masterPatch.localFaces();
const faceList& slaveLocalFaces = reverseSlavePatch.localFaces();
pointMatchMapPtr_ = new Map<label>(2*slaveMeshPoints.size());
Map<label>& removedPointMap = *pointMatchMapPtr_;
pointMatchMapPtr_.reset(new Map<label>(2*slaveMeshPoints.size()));
auto& removedPointMap = *pointMatchMapPtr_;
forAll(masterLocalFaces, facei)
{
......
......@@ -43,14 +43,14 @@ License
namespace Foam
{
defineTypeNameAndDebug(boundaryMesh, 0);
defineTypeNameAndDebug(boundaryMesh, 0);
}
// Normal along which to divide faces into categories (used in getNearest)
const vector boundaryMesh::splitNormal_(3, 2, 1);
const Foam::vector Foam::boundaryMesh::splitNormal_(3, 2, 1);
// Distance to face tolerance for getNearest
const scalar boundaryMesh::distanceTol_ = 1e-2;
}
const Foam::scalar Foam::boundaryMesh::distanceTol_ = 1e-2;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -437,7 +437,6 @@ void Foam::boundaryMesh::markZone
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Null constructor
Foam::boundaryMesh::boundaryMesh()
:
meshPtr_(nullptr),
......@@ -452,27 +451,14 @@ Foam::boundaryMesh::boundaryMesh()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::boundaryMesh::~boundaryMesh()
{
clearOut();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::boundaryMesh::clearOut()
{
if (meshPtr_)
{
delete meshPtr_;
meshPtr_ = nullptr;
}
meshPtr_.reset(nullptr);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::boundaryMesh::read(const polyMesh& mesh)
{
patches_.clear();
......@@ -544,8 +530,10 @@ void Foam::boundaryMesh::read(const polyMesh& mesh)
// Store in local(compact) addressing
clearOut();
meshPtr_ = new bMesh(globalPatch.localFaces(), globalPatch.localPoints());
meshPtr_.reset
(
new bMesh(globalPatch.localFaces(), globalPatch.localPoints())
);
if (debug & 2)
{
......@@ -586,16 +574,15 @@ void Foam::boundaryMesh::read(const polyMesh& mesh)
}
// Clear edge storage
featurePoints_.setSize(0);
featureEdges_.setSize(0);
featurePoints_.clear();
featureEdges_.clear();
featureToEdge_.setSize(0);
edgeToFeature_.setSize(meshPtr_->nEdges());
featureToEdge_.clear();
edgeToFeature_.resize(meshPtr_->nEdges());
edgeToFeature_ = -1;
featureSegments_.setSize(0);
extraEdges_.setSize(0);
featureSegments_.clear();
extraEdges_.clear();
}
......@@ -752,19 +739,18 @@ void Foam::boundaryMesh::readTriSurface(const fileName& fName)
clearOut();
// Store compact.
meshPtr_ = new bMesh(bFaces, surf.localPoints());
meshPtr_.reset(new bMesh(bFaces, surf.localPoints()));
// Clear edge storage
featurePoints_.setSize(0);
featureEdges_.setSize(0);
featurePoints_.clear();
featureEdges_.clear();
featureToEdge_.setSize(0);
edgeToFeature_.setSize(meshPtr_->nEdges());
featureToEdge_.clear();
edgeToFeature_.resize(meshPtr_->nEdges());
edgeToFeature_ = -1;
featureSegments_.setSize(0);
extraEdges_.setSize(0);
featureSegments_.clear();
extraEdges_.clear();
}
......@@ -1813,7 +1799,8 @@ void Foam::boundaryMesh::changeFaces
}
// Reconstruct 'mesh' from new faces and (copy of) existing points.
bMesh* newMeshPtr_ = new bMesh(newFaces, mesh().points());
unique_ptr<bMesh> newMeshPtr(new bMesh(newFaces, mesh().points()));
// Reset meshFace_ to new ordering.
meshFace_.transfer(newMeshFace);
......@@ -1823,7 +1810,7 @@ void Foam::boundaryMesh::changeFaces
clearOut();
// And insert new 'mesh'.
meshPtr_ = newMeshPtr_;
meshPtr_ = std::move(newMeshPtr);
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -76,7 +77,7 @@ class boundaryMesh
// Private Data
//- All boundary mesh data. Reconstructed every time faces are repatched
bMesh* meshPtr_;
unique_ptr<bMesh> meshPtr_;
//- Patches. Reconstructed every time faces are repatched.
PtrList<boundaryPatch> patches_;
......@@ -189,12 +190,12 @@ public:
// Constructors
//- Construct null
//- Default construct
boundaryMesh();
//- Destructor
~boundaryMesh();
~boundaryMesh() = default;
void clearOut();
......@@ -208,8 +209,8 @@ public:
if (!meshPtr_)
{
FatalErrorInFunction
<< "No mesh available. Probably mesh not yet"
<< " read." << abort(FatalError);
<< "No mesh available. Probably mesh not yet read\n"
<< abort(FatalError);
}
return *meshPtr_;
}
......
......@@ -50,7 +50,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class mapPolyMesh;
class polyTopoChange;
class globalMeshData;
......@@ -61,7 +61,7 @@ class globalMeshData;
class createShellMesh
{
// Private data
// Private Data
//- Reference to patch to extrude
const primitiveFacePatch& patch_;
......@@ -113,7 +113,7 @@ public:
// Constructors
//- Construct from mesh.
//- Construct from face patch
createShellMesh
(
const primitiveFacePatch& patch,
......@@ -124,7 +124,6 @@ public:
// Member Functions
// Access
//- From region cell to patch face. Consecutively added so
......
......@@ -51,7 +51,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class IOobject;
class faceCoupleInfo;
class IOobjectList;
......@@ -68,7 +68,6 @@ class fvMeshAdder
:
public polyMeshAdder
{
private:
// Private Member Functions
......
......@@ -1650,7 +1650,6 @@ Foam::autoPtr<Foam::fvMesh> Foam::fvMeshDistribute::receiveMesh
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::fvMeshDistribute::fvMeshDistribute(fvMesh& mesh, const scalar mergeTol)
:
mesh_(mesh),
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -63,7 +63,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class mapAddedPolyMesh;
class mapDistributePolyMesh;
......
......@@ -68,7 +68,7 @@ Foam::word Foam::fvMeshSubset::exposedPatchName("oldInternalFaces");
bool Foam::fvMeshSubset::checkCellSubset() const
{
if (fvMeshSubsetPtr_.empty())
if (!fvMeshSubsetPtr_)
{
FatalErrorInFunction
<< "setCellSubset()" << nl
......@@ -87,9 +87,8 @@ void Foam::fvMeshSubset::calcFaceFlipMap() const
const labelList& subToBaseFace = faceMap();
const labelList& subToBaseCell = cellMap();
faceFlipMapPtr_.clear();
faceFlipMapPtr_.reset(new labelList(subToBaseFace.size()));
labelList& faceFlipMap = *faceFlipMapPtr_;
auto& faceFlipMap = *faceFlipMapPtr_;
// Only exposed internal faces might be flipped (since we don't do
// any cell renumbering, just compacting)
......@@ -546,8 +545,8 @@ Foam::fvMeshSubset::fvMeshSubset
void Foam::fvMeshSubset::clear()
{
fvMeshSubsetPtr_.clear();
faceFlipMapPtr_.clear();
fvMeshSubsetPtr_.reset(nullptr);
faceFlipMapPtr_.reset(nullptr);
pointMap_.clear();
faceMap_.clear();
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd.
Copyright (C) 2018-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -35,13 +35,13 @@ inline const Foam::fvMesh& Foam::fvMeshSubset::baseMesh() const
inline const Foam::fvMesh& Foam::fvMeshSubset::mesh() const
{
return fvMeshSubsetPtr_.valid() ? *fvMeshSubsetPtr_ : baseMesh_;
return fvMeshSubsetPtr_ ? *fvMeshSubsetPtr_ : baseMesh_;
}
inline bool Foam::fvMeshSubset::hasSubMesh() const
{
return fvMeshSubsetPtr_.valid();
return bool(fvMeshSubsetPtr_);
}
......@@ -79,7 +79,7 @@ inline const Foam::labelList& Foam::fvMeshSubset::faceMap() const
inline const Foam::labelList& Foam::fvMeshSubset::faceFlipMap() const
{
if (!faceFlipMapPtr_.valid())
if (!faceFlipMapPtr_)
{
calcFaceFlipMap();
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -49,9 +49,6 @@ SourceFiles
namespace Foam
{
// Forward declarations
class Time;
/*---------------------------------------------------------------------------*\
Class fvMeshSubsetProxy Declaration
\*---------------------------------------------------------------------------*/
......@@ -60,6 +57,8 @@ class fvMeshSubsetProxy
{
public:
// Data Types
//- Internal bookkeeping for subset type
enum subsetType
{
......
......@@ -33,7 +33,6 @@ License
#include "primitiveMesh.H"
#include "polyTopoChange.H"
#include "addToRunTimeSelectionTable.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -96,38 +95,10 @@ void Foam::layerAdditionRemoval::checkDefinition()
}
Foam::scalar Foam::layerAdditionRemoval::readOldThickness
(
const dictionary& dict
)
{
return dict.lookupOrDefault("oldLayerThickness", -1.0);
}
void Foam::layerAdditionRemoval::clearAddressing() const
{
if (pointsPairingPtr_)
{
if (debug)
{
Pout<< "layerAdditionRemoval::clearAddressing()" << nl
<< " clearing pointsPairingPtr_" << endl;
}
deleteDemandDrivenData(pointsPairingPtr_);
}
if (facesPairingPtr_)
{
if (debug)
{
Pout<< "layerAdditionRemoval::clearAddressing()" << nl
<< " clearing facesPairingPtr_" << endl;
}
deleteDemandDrivenData(facesPairingPtr_);
}
pointsPairingPtr_.reset(nullptr);
facesPairingPtr_.reset(nullptr);
}
......@@ -171,8 +142,8 @@ Foam::layerAdditionRemoval::layerAdditionRemoval
faceZoneID_(dict.lookup("faceZoneName"), ptc.mesh().faceZones()),
minLayerThickness_(dict.get<scalar>("minLayerThickness")),
maxLayerThickness_(dict.get<scalar>("maxLayerThickness")),
thicknessFromVolume_(dict.lookupOrDefault("thicknessFromVolume", true)),
oldLayerThickness_(readOldThickness(dict)),
thicknessFromVolume_(dict.getOrDefault("thicknessFromVolume", true)),
oldLayerThickness_(dict.getOrDefault<scalar>("oldLayerThickness", -1.0)),
pointsPairingPtr_(nullptr),
facesPairingPtr_(nullptr),
triggerRemoval_(-1),
......@@ -182,14 +153,6 @@ Foam::layerAdditionRemoval::layerAdditionRemoval
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::layerAdditionRemoval::~layerAdditionRemoval()
{
clearAddressing();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::layerAdditionRemoval::changeTopology() const
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -56,7 +57,7 @@ class layerAdditionRemoval
:
public polyMeshModifier
{
// Private data
// Private Data
//- Master face zone ID
faceZoneID faceZoneID_;
......@@ -76,10 +77,10 @@ class layerAdditionRemoval
mutable scalar oldLayerThickness_;
//- Point pairing
mutable labelList* pointsPairingPtr_;
mutable unique_ptr<labelList> pointsPairingPtr_;
//- Face pairing
mutable labelList* facesPairingPtr_;
mutable unique_ptr<labelList> facesPairingPtr_;
//- Layer removal trigger time index
mutable label triggerRemoval_;
......@@ -100,7 +101,7 @@ class layerAdditionRemoval
void checkDefinition();
// Topological changes
// Topological Changes
//- Check for valid layer
bool validCollapse() const;
......@@ -127,13 +128,7 @@ class layerAdditionRemoval
void clearAddressing() const;
// Helpers
//- Optionally read old thickness
static scalar readOldThickness(const dictionary&);
// Static data members
// Static Data Members
//- Thickness insertion fraction for the pre-motion
static const scalar addDelta_;
......@@ -174,7 +169,7 @@ public:
//- Destructor
virtual ~layerAdditionRemoval();
virtual ~layerAdditionRemoval() = default;
// Member Functions
......