fvMesh: added move constructor and disallowed construction

This support efficient return of fvMesh from functions which generate region
meshes without allowing risky copy construction.
This commit is contained in:
Henry Weller
2022-11-06 17:16:25 +00:00
parent 1258c02558
commit 94152725a8
12 changed files with 131 additions and 34 deletions

View File

@ -201,7 +201,7 @@ int main(int argc, char *argv[])
}
else if (action == 1 || action == 2)
{
// Mesh changing engine.
// Mesh topo-change engine.
polyTopoChange meshMod(mesh);
if (action == 1)
@ -290,16 +290,13 @@ int main(int argc, char *argv[])
Info<< nl<< "-- Mesh : moving:" << mesh.moving()
<< " topoChanged:" << mesh.topoChanged()
<< " changing:" << mesh.changing()
<< endl;
Info<< "Writing fields" << nl << endl;
runTime.write();
// Check mesh volume conservation
if (mesh.moving())
{

View File

@ -118,8 +118,11 @@ public:
const label nIoObjects = 128
);
//- Move constructor
objectRegistry(objectRegistry&&) = default;
//- Disallow default bitwise copy construction
objectRegistry(const objectRegistry&);
objectRegistry(const objectRegistry&) = delete;
//- Destructor

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,15 +53,6 @@ class data
:
public IOdictionary
{
// Private Member Functions
//- Disallow default bitwise copy construction
data(const data&) = delete;
//- Disallow default bitwise assignment
void operator=(const data&) = delete;
public:
//- Type information
@ -72,6 +63,15 @@ public:
//- Construct for objectRegistry
data(const objectRegistry& obr);
//- Move constructor
data(data&&) = default;
//- Disallow default bitwise copy construction
data(const data&) = delete;
//- Disallow default bitwise assignment
void operator=(const data&) = delete;
};

View File

@ -83,12 +83,6 @@ class polyBoundaryMesh
//- Calculate the geometry for the patches (transformation tensors etc.)
void calcGeometry();
//- Disallow default bitwise copy construction
polyBoundaryMesh(const polyBoundaryMesh&);
//- Disallow default bitwise assignment
void operator=(const polyBoundaryMesh&);
public:
@ -126,6 +120,12 @@ public:
const polyPatchList&
);
//- Move constructor
polyBoundaryMesh(polyBoundaryMesh&&) = default;
//- Disallow default bitwise copy construction
polyBoundaryMesh(const polyBoundaryMesh&) = delete;
//- Destructor
~polyBoundaryMesh();
@ -266,6 +266,9 @@ public:
//- Return reference to polyPatch by name.
polyPatch& operator[](const word&);
//- Disallow default bitwise assignment
void operator=(const polyBoundaryMesh&) = delete;
// Ostream operator

View File

@ -668,6 +668,35 @@ Foam::polyMesh::polyMesh
}
Foam::polyMesh::polyMesh(polyMesh&& mesh)
:
objectRegistry(move(mesh)),
primitiveMesh(move(mesh)),
points_(move(mesh.points_)),
faces_(move(mesh.faces_)),
owner_(move(mesh.owner_)),
neighbour_(move(mesh.neighbour_)),
clearedPrimitives_(mesh.clearedPrimitives_),
boundary_(move(mesh.boundary_)),
bounds_(move(mesh.bounds_)),
comm_(mesh.comm_),
geometricD_(mesh.geometricD_),
solutionD_(mesh.solutionD_),
tetBasePtIsPtr_(move(mesh.tetBasePtIsPtr_)),
cellTreePtr_(move(mesh.cellTreePtr_)),
pointZones_(move(mesh.pointZones_)),
faceZones_(move(mesh.faceZones_)),
cellZones_(move(mesh.cellZones_)),
globalMeshDataPtr_(move(mesh.globalMeshDataPtr_)),
curMotionTimeIndex_(mesh.curMotionTimeIndex_),
oldPointsPtr_(move(mesh.oldPointsPtr_)),
oldCellCentresPtr_(move(mesh.oldCellCentresPtr_)),
storeOldCellCentres_(mesh.storeOldCellCentres_),
moving_(mesh.moving_),
topoChanged_(mesh.topoChanged_)
{}
void Foam::polyMesh::resetPrimitives
(
pointField&& points,

View File

@ -388,8 +388,11 @@ public:
const bool syncPar = true
);
//- Move constructor
polyMesh(polyMesh&&);
//- Disallow default bitwise copy construction
polyMesh(const polyMesh&);
polyMesh(const polyMesh&) = delete;
//- Destructor
@ -528,13 +531,14 @@ public:
return moving_;
}
//- Has the mesh topology changed
//- Has the mesh topology changed this time-step
bool topoChanged() const
{
return topoChanged_;
}
//- Is mesh changing (topology changing and/or moving)
//- Is mesh changing
// Moving or mesh topology changed this time-step)
bool changing() const
{
return moving() || topoChanged();

View File

@ -811,8 +811,7 @@ Foam::polyMesh::polyMesh
oldPointsPtr_(nullptr),
oldCellCentresPtr_(nullptr),
storeOldCellCentres_(false),
moving_(false),
topoChanged_(false)
moving_(false)
{
if (debug)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -79,9 +79,6 @@ class MeshZones
//- Read if IOobject flags set. Return true if read.
bool read();
//- Disallow default bitwise copy construction
MeshZones(const MeshZones&);
//- Disallow default bitwise assignment
void operator=(const MeshZones<ZoneType, MeshType>&);
@ -117,6 +114,12 @@ public:
const PtrList<ZoneType>&
);
//- Move constructor
MeshZones(MeshZones&&) = default;
//- Disallow default bitwise copy construction
MeshZones(const MeshZones&) = delete;
//- Destructor
~MeshZones();

View File

@ -443,8 +443,11 @@ public:
const label nCells
);
//- Move constructor
primitiveMesh(primitiveMesh&&) = default;
//- Disallow default bitwise copy construction
primitiveMesh(const primitiveMesh&);
primitiveMesh(const primitiveMesh&) = delete;
//- Destructor

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -85,8 +85,11 @@ public:
//- Construct from polyBoundaryMesh
fvBoundaryMesh(const fvMesh&, const polyBoundaryMesh&);
//- Move constructor
fvBoundaryMesh(fvBoundaryMesh&&) = default;
//- Disallow default bitwise copy construction
fvBoundaryMesh(const fvBoundaryMesh&);
fvBoundaryMesh(const fvBoundaryMesh&) = delete;
// Member Functions

View File

@ -580,6 +580,47 @@ Foam::fvMesh::fvMesh
}
Foam::fvMesh::fvMesh(fvMesh&& mesh)
:
polyMesh(Foam::move(mesh)),
surfaceInterpolation(Foam::move(mesh)),
data(static_cast<const objectRegistry&>(*this)),
boundary_(Foam::move(mesh.boundary_)),
stitcher_(Foam::move(mesh.stitcher_)),
topoChanger_(Foam::move(mesh.topoChanger_)),
distributor_(Foam::move(mesh.distributor_)),
mover_(Foam::move(mesh.mover_)),
lduPtr_(Foam::move(mesh.lduPtr_)),
polyFacesBfPtr_(Foam::move(mesh.polyFacesBfPtr_)),
polyBFaceOffsetsPtr_(Foam::move(mesh.polyBFaceOffsetsPtr_)),
polyBFaceOffsetPatchesPtr_(Foam::move(mesh.polyBFaceOffsetPatchesPtr_)),
polyBFaceOffsetPatchFacesPtr_
(
Foam::move(mesh.polyBFaceOffsetPatchFacesPtr_)
),
polyBFacePatchesPtr_(Foam::move(mesh.polyBFacePatchesPtr_)),
polyBFacePatchFacesPtr_(Foam::move(mesh.polyBFacePatchFacesPtr_)),
curTimeIndex_(mesh.curTimeIndex_),
VPtr_(Foam::move(mesh.VPtr_)),
V0Ptr_(Foam::move(mesh.V0Ptr_)),
V00Ptr_(Foam::move(mesh.V00Ptr_)),
SfSlicePtr_(Foam::move(mesh.SfSlicePtr_)),
SfPtr_(Foam::move(mesh.SfPtr_)),
magSfSlicePtr_(Foam::move(mesh.magSfSlicePtr_)),
magSfPtr_(Foam::move(mesh.magSfPtr_)),
CSlicePtr_(Foam::move(mesh.CSlicePtr_)),
CPtr_(Foam::move(mesh.CPtr_)),
CfSlicePtr_(Foam::move(mesh.CfSlicePtr_)),
CfPtr_(Foam::move(mesh.CfPtr_)),
phiPtr_(Foam::move(mesh.phiPtr_))
{
if (debug)
{
Pout<< FUNCTION_NAME << "Moving fvMesh" << endl;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fvMesh::~fvMesh()
@ -590,6 +631,12 @@ Foam::fvMesh::~fvMesh()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fvMesh::topoChanging() const
{
return topoChanger_->dynamic();
}
bool Foam::fvMesh::dynamic() const
{
return topoChanger_->dynamic() || mover_->dynamic();

View File

@ -370,8 +370,11 @@ public:
const bool syncPar = true
);
//- Move constructor
fvMesh(fvMesh&&);
//- Disallow default bitwise copy construction
fvMesh(const fvMesh&);
fvMesh(const fvMesh&) = delete;
//- Destructor
@ -532,6 +535,9 @@ public:
// Edit
//- Does the mesh topology change?
bool topoChanging() const;
//- Is this mesh dynamic?
bool dynamic() const;