Commit 68b2f503 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: unique_ptr instead of manual management

- conversion, sampling, surfMesh
parent 95f14621
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -89,8 +89,7 @@ bool Foam::ccm::base::close()
{
CCMIOCloseFile(nullptr, globalState_->root);
}
delete globalState_;
globalState_ = nullptr;
globalState_.reset(nullptr);
return true;
}
......
......@@ -41,6 +41,7 @@ SourceFiles
#ifndef ccmBase_H
#define ccmBase_H
#include <memory>
#include <string>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -50,8 +51,7 @@ namespace Foam
namespace ccm
{
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
// Forward Declarations
class ccmGlobalState;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -62,21 +62,12 @@ class ccmGlobalState;
class base
{
// Private Member Functions
//- No copy construct
base(const base&) = delete;
//- No copy assignment
void operator=(const base&) = delete;
protected:
// Protected Data
//- Maintain overall global states (error, root-node)
ccmGlobalState* globalState_;
std::unique_ptr<ccmGlobalState> globalState_;
// Protected Member Functions
......@@ -99,11 +90,18 @@ protected:
bool assertNoError(const std::string& msg) const;
//- No copy construct
base(const base&) = delete;
//- No copy assignment
void operator=(const base&) = delete;
public:
// Constructors
//- Construct null
//- Default construct. Initializes the global-state.
base();
......@@ -113,8 +111,6 @@ public:
// Member Functions
// Access
//- Explicitly close the file and terminate ccmio access.
// Return false if it was already closed.
bool close();
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -33,14 +33,14 @@ Description
#include "className.H"
#include "List.H"
// headers and definitions for using libccmio
// Headers and definitions for using libccmio
#include "libccmio/ccmio.h"
// low-level routines are also needed
// Low-level routines are also needed
#include "libccmio/ccmiocore.h"
#include "libccmio/ccmioutility.h"
// don't want these defines to leak through
// Do not allow these defines to leak through
#undef TRUE
#undef FALSE
......@@ -62,10 +62,7 @@ NamespaceName("ccm");
//- A C++ wrapper for the C struct
class ccmID
:
public CCMIOID
{};
class ccmID : public CCMIOID {};
//- A C++ wrapper for the C struct
class ccmNODE
......@@ -146,6 +143,7 @@ public:
class ccmMaps
{
public:
//- The cell map
ccmID cells;
......
......@@ -714,7 +714,6 @@ Foam::ccm::reader::reader(const fileName& file, const reader::options& opts)
Foam::ccm::reader::~reader()
{
close();
deleteDemandDrivenData(options_);
}
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -204,10 +204,10 @@ private:
static const char* cellTableOptstr[];
// Private data
// Private Data
//- Reader options
const options* options_;
const unique_ptr<options> options_;
//- Enumeration defining the status of a ccmio node
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,7 +30,6 @@ License
#include "demandDrivenData.H"
#include "ccmInternal.H" // include last to avoid any strange interactions
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// Name for the topology file reference
......@@ -377,8 +376,6 @@ Foam::ccm::writer::writer
Foam::ccm::writer::~writer()
{
close();
deleteDemandDrivenData(maps_);
}
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -132,7 +132,7 @@ class writer
// Member Data
//- MapIds for various components (cell, internalFaces, boundaries)
ccmMaps* maps_;
unique_ptr<ccmMaps> maps_;
//- mesh reference
const polyMesh& mesh_;
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -46,8 +47,8 @@ void Foam::meshReader::calcPointCells() const
label nPoints = points_.size();
pointCellsPtr_ = new labelListList(nPoints);
labelListList& ptCells = *pointCellsPtr_;
pointCellsPtr_.reset(new labelListList(nPoints));
auto& ptCells = *pointCellsPtr_;
forAll(ptCells, i)
{
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -31,7 +31,6 @@ License
#include "polyMesh.H"
#include "faceSet.H"
#include "emptyPolyPatch.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -147,7 +146,7 @@ void Foam::meshReader::clearExtraStorage()
boundaryIds_.clear();
baffleIds_.clear();
deleteDemandDrivenData(pointCellsPtr_);
pointCellsPtr_.reset(nullptr);
}
......@@ -190,12 +189,4 @@ Foam::meshReader::meshReader
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::meshReader::~meshReader()
{
deleteDemandDrivenData(pointCellsPtr_);
}
// ************************************************************************* //
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -117,12 +117,12 @@ protected:
private:
// Private data
// Private Data
//- Point-cell addressing. Used for topological analysis
// Warning. This point cell addressing list potentially contains
// duplicate cell entries. Use additional checking
mutable labelListList* pointCellsPtr_;
mutable unique_ptr<labelListList> pointCellsPtr_;
//- Association between two faces
List<labelPair> interfaces_;
......@@ -205,7 +205,7 @@ private:
protected:
// Protected member data
// Protected Data
//- Referenced filename
fileName geometryFile_;
......@@ -255,7 +255,7 @@ protected:
cellTable cellTable_;
// Protected member functions
// Protected Member Functions
//- Subclasses are required to supply this information
virtual bool readGeometry(const scalar scaleFactor = 1.0) = 0;
......@@ -276,7 +276,7 @@ public:
//- Destructor
virtual ~meshReader();
virtual ~meshReader() = 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.
......@@ -32,11 +33,8 @@ License
void Foam::meshToMesh0::calculateInverseDistanceWeights() const
{
if (debug)
{
InfoInFunction
<< "Calculating inverse distance weighting factors" << endl;
}
DebugInFunction
<< "Calculating inverse distance weighting factors" << nl;
if (inverseDistanceWeightsPtr_)
{
......@@ -46,10 +44,10 @@ void Foam::meshToMesh0::calculateInverseDistanceWeights() const
}
//- Initialise overlap volume to zero
V_ = 0.0;
V_ = 0;
inverseDistanceWeightsPtr_ = new scalarListList(toMesh_.nCells());
scalarListList& invDistCoeffs = *inverseDistanceWeightsPtr_;
inverseDistanceWeightsPtr_.reset(new scalarListList(toMesh_.nCells()));
auto& invDistCoeffs = *inverseDistanceWeightsPtr_;
// get reference to source mesh data
const labelListList& cc = fromMesh_.cellCells();
......@@ -134,11 +132,8 @@ void Foam::meshToMesh0::calculateInverseDistanceWeights() const
void Foam::meshToMesh0::calculateInverseVolumeWeights() const
{
if (debug)
{
InfoInFunction
<< "Calculating inverse volume weighting factors" << endl;
}
DebugInFunction
<< "Calculating inverse volume weighting factors" << endl;
if (inverseVolumeWeightsPtr_)
{
......@@ -148,10 +143,10 @@ void Foam::meshToMesh0::calculateInverseVolumeWeights() const
}
//- Initialise overlap volume to zero
V_ = 0.0;
V_ = 0;
inverseVolumeWeightsPtr_ = new scalarListList(toMesh_.nCells());
scalarListList& invVolCoeffs = *inverseVolumeWeightsPtr_;
inverseVolumeWeightsPtr_.reset(new scalarListList(toMesh_.nCells()));
auto& invVolCoeffs = *inverseVolumeWeightsPtr_;
const labelListList& cellToCell = cellToCellAddressing();
......@@ -197,11 +192,8 @@ void Foam::meshToMesh0::calculateInverseVolumeWeights() const
void Foam::meshToMesh0::calculateCellToCellAddressing() const
{
if (debug)
{
InfoInFunction
<< "Calculating cell to cell addressing" << endl;
}
DebugInFunction
<< "Calculating cell to cell addressing" << endl;
if (cellToCellAddressingPtr_)
{
......@@ -211,12 +203,12 @@ void Foam::meshToMesh0::calculateCellToCellAddressing() const
}
//- Initialise overlap volume to zero
V_ = 0.0;
V_ = 0;
tetOverlapVolume overlapEngine;
cellToCellAddressingPtr_ = new labelListList(toMesh_.nCells());
labelListList& cellToCell = *cellToCellAddressingPtr_;
cellToCellAddressingPtr_.reset(new labelListList(toMesh_.nCells()));
auto& cellToCell = *cellToCellAddressingPtr_;
forAll(cellToCell, iTo)
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -27,7 +28,6 @@ License
#include "meshToMesh0.H"
#include "processorFvPatch.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -57,7 +57,7 @@ Foam::meshToMesh0::meshToMesh0
inverseDistanceWeightsPtr_(nullptr),
inverseVolumeWeightsPtr_(nullptr),
cellToCellAddressingPtr_(nullptr),
V_(0.0)
V_(0)
{
forAll(fromMesh_.boundaryMesh(), patchi)
{
......@@ -125,7 +125,7 @@ Foam::meshToMesh0::meshToMesh0
inverseDistanceWeightsPtr_(nullptr),
inverseVolumeWeightsPtr_(nullptr),
cellToCellAddressingPtr_(nullptr),
V_(0.0)
V_(0)
{
// check whether both meshes have got the same number
// of boundary patches
......@@ -191,14 +191,4 @@ Foam::meshToMesh0::meshToMesh0
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::meshToMesh0::~meshToMesh0()
{
deleteDemandDrivenData(inverseDistanceWeightsPtr_);
deleteDemandDrivenData(inverseVolumeWeightsPtr_);
deleteDemandDrivenData(cellToCellAddressingPtr_);
}
// ************************************************************************* //
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -55,9 +55,8 @@ SourceFiles
namespace Foam
{
template<class Type>
class indexedOctree;
// Forward Declarations
template<class Type> class indexedOctree;
class treeDataCell;
/*---------------------------------------------------------------------------*\
......@@ -66,9 +65,9 @@ class treeDataCell;
class meshToMesh0
{
// Private data
// Private Data
// mesh references
// Mesh References
const fvMesh& fromMesh_;
const fvMesh& toMesh_;
......@@ -92,13 +91,13 @@ class meshToMesh0
labelListList boundaryAddressing_;
//- Inverse-distance interpolation weights
mutable scalarListList* inverseDistanceWeightsPtr_;
mutable unique_ptr<scalarListList> inverseDistanceWeightsPtr_;
//- Inverse-volume interpolation weights
mutable scalarListList* inverseVolumeWeightsPtr_;
mutable unique_ptr<scalarListList> inverseVolumeWeightsPtr_;
//- Cell to cell overlap addressing
mutable labelListList* cellToCellAddressingPtr_;
mutable unique_ptr<labelListList> cellToCellAddressingPtr_;
//- Overlap volume
mutable scalar V_;
......@@ -130,7 +129,7 @@ class meshToMesh0
const labelListList& cellToCellAddressing() const;
// Private static data members
// Private Static Data Members
//- Direct hit tolerance
static const scalar directHitTol;
......@@ -175,7 +174,7 @@ public:
//- Destructor
~meshToMesh0();
~meshToMesh0() = default;
//- Patch-field interpolation class
......
......@@ -27,7 +27,6 @@ License
#include "polySurface.H"
#include "globalMeshData.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......
......@@ -33,7 +33,6 @@ License
#include "Time.H"
#include "OSspecific.H"
#include "MeshedSurface.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......
......@@ -28,7 +28,6 @@ License
#include "surfMesh.H"
#include "globalMeshData.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......
......@@ -27,7 +27,6 @@ License
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "demandDrivenData.H"
#include "Time.H"
#include "surfZoneList.H"
#include "MeshedSurface.H"
......@@ -525,8 +524,8 @@ Foam::triSurface::~triSurface()
void Foam::triSurface::clearTopology()
{
ParentType::clearTopology();
deleteDemandDrivenData(sortedEdgeFacesPtr_);
deleteDemandDrivenData(edgeOwnerPtr_);
sortedEdgeFacesPtr_.reset(nullptr);
edgeOwnerPtr_.reset(nullptr);
}
......@@ -585,7 +584,7 @@ const Foam::labelList& Foam::triSurface::edgeOwner() const
void Foam::triSurface::movePoints(const pointField& pts)
{
// Remove all geometry dependent data
deleteDemandDrivenData(sortedEdgeFacesPtr_);
sortedEdgeFacesPtr_.reset(nullptr);
// Adapt for new point positions
ParentType::movePoints(pts);
......@@ -598,7 +597,7 @@ void Foam::triSurface::movePoints(const pointField& pts)
void Foam::triSurface::swapPoints(pointField& pts)
{
// Remove all geometry dependent data
deleteDemandDrivenData(sortedEdgeFacesPtr_);
sortedEdgeFacesPtr_.reset(nullptr);
// Adapt for new point positions
ParentType::movePoints(pts);
......
......@@ -106,11 +106,11 @@ class triSurface
// Demand driven private data.
//- Edge-face addressing (sorted)
mutable labelListList* sortedEdgeFacesPtr_;
mutable unique_ptr<labelListList> sortedEdgeFacesPtr_;
//- Label of face that 'owns' edge (i.e. e.vec() is righthanded walk
//- along face)
mutable labelList* edgeOwnerPtr_;
//- Label of face that 'owns' edge
//- i.e. e.vec() is righthanded walk along face
mutable unique_ptr<labelList> edgeOwnerPtr_;
// Private Member Functions
......
......@@ -47,8 +47,8 @@ void Foam::triSurface::calcSortedEdgeFaces() const
const labelListList& eFaces = edgeFaces();
sortedEdgeFacesPtr_ = new labelListList(eFaces.size());
labelListList& sortedEdgeFaces = *sortedEdgeFacesPtr_;
sortedEdgeFacesPtr_.reset(new labelListList(eFaces.size()));
auto& sortedEdgeFaces = *sortedEdgeFacesPtr_;
sortedEdgeFaces = PatchTools::sortedEdgeFaces(*this);
}
......@@ -63,9 +63,8 @@ void Foam::triSurface::calcEdgeOwner() const
<< abort(FatalError);
}
// create the owner list
edgeOwnerPtr_ = new labelList(nEdges());
labelList& edgeOwner = *edgeOwnerPtr_;
edgeOwnerPtr_.reset(new labelList(nEdges()));
auto& edgeOwner = *edgeOwnerPtr_;
forAll(edges(), edgeI)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment