Commit 0800e021 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: improved handling of zone allocation in surfMesh

- relocate zone IO from Detail::MeshedSurfaceIOAllocator into surfMesh
  directly to allow re-purposing of MeshedSurfaceIOAllocator

- provide meshedSurf::emptySurface zero-sized placeholder implementation

- add concrete implementation of meshedSurf::zoneIds() to simplify
  overloading
parent eaa3da72
......@@ -124,7 +124,7 @@ private:
surfZoneList zones_;
// Private Member functions
// Private Member Functions
//- Read/construct from Istream
Istream& read(Istream& is);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -32,39 +32,33 @@ License
Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
(
const IOobject& ioPoints,
const IOobject& ioFaces,
const IOobject& ioZones
const IOobject& ioFaces
)
:
points_(ioPoints),
faces_(ioFaces),
zones_(ioZones)
faces_(ioFaces)
{}
Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
(
const IOobject& ioPoints, const pointField& points,
const IOobject& ioFaces, const faceList& faces,
const IOobject& ioZones, const surfZoneList& zones
const IOobject& ioFaces, const faceList& faces
)
:
points_(ioPoints, points),
faces_(ioFaces, faces),
zones_(ioZones, zones)
faces_(ioFaces, faces)
{}
Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
(
const IOobject& ioPoints, pointField&& points,
const IOobject& ioFaces, faceList&& faces,
const IOobject& ioZones, surfZoneList&& zones
const IOobject& ioFaces, faceList&& faces
)
:
points_(ioPoints, std::move(points)),
faces_(ioFaces, std::move(faces)),
zones_(ioZones, std::move(zones))
faces_(ioFaces, std::move(faces))
{}
......@@ -85,7 +79,6 @@ void Foam::Detail::MeshedSurfaceIOAllocator::setInstance
{
points_.instance() = inst;
faces_.instance() = inst;
zones_.instance() = inst;
}
......@@ -96,7 +89,6 @@ void Foam::Detail::MeshedSurfaceIOAllocator::setWriteOption
{
points_.writeOpt() = wOpt;
faces_.writeOpt() = wOpt;
zones_.writeOpt() = wOpt;
}
......@@ -104,7 +96,6 @@ void Foam::Detail::MeshedSurfaceIOAllocator::clear()
{
points_.clear();
faces_.clear();
zones_.clear();
}
......@@ -120,7 +111,6 @@ bool Foam::Detail::MeshedSurfaceIOAllocator::writeObject
(
points_.writeObject(fmt, ver, cmp, valid)
&& faces_.writeObject(fmt, ver, cmp, valid)
&& zones_.writeObject(fmt, ver, cmp, valid)
);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -27,7 +27,7 @@ Class
Foam::Detail::MeshedSurfaceIOAllocator
Description
A helper class for storing points, faces and zones with IO capabilities.
A helper class for storing points and faces with IO capabilities.
SourceFiles
MeshedSurfaceIOAllocator.C
......@@ -39,7 +39,6 @@ SourceFiles
#include "pointIOField.H"
#include "faceIOList.H"
#include "surfZoneIOList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -62,9 +61,6 @@ class MeshedSurfaceIOAllocator
//- Faces
faceCompactIOList faces_;
//- Surface zones
surfZoneIOList zones_;
// Private Member Functions
......@@ -83,24 +79,21 @@ public:
MeshedSurfaceIOAllocator
(
const IOobject& ioPoints,
const IOobject& ioFaces,
const IOobject& ioZones
const IOobject& ioFaces
);
//- Construct from IOobjects, copying components
MeshedSurfaceIOAllocator
(
const IOobject& ioPoints, const pointField& points,
const IOobject& ioFaces, const faceList& faces,
const IOobject& ioZones, const surfZoneList& zones
const IOobject& ioFaces, const faceList& faces
);
//- Construct from IOobjects, moving components
MeshedSurfaceIOAllocator
(
const IOobject& ioPoints, pointField&& points,
const IOobject& ioFaces, faceList&& faces,
const IOobject& ioZones, surfZoneList&& zones
const IOobject& ioFaces, faceList&& faces
);
......@@ -133,12 +126,6 @@ public:
return faces_;
}
//- Non-const access to the zones
surfZoneIOList& storedIOZones()
{
return zones_;
}
//- Const access to the points
const pointIOField& storedIOPoints() const
{
......@@ -151,16 +138,10 @@ public:
return faces_;
}
//- Const access to the zones
const surfZoneIOList& storedIOZones() const
{
return zones_;
}
// Storage Management
//- Clear primitive data (points, faces and zones)
//- Clear primitive data (points, faces)
void clear();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -104,7 +104,7 @@ public:
const pointField& pointLst,
const UList<Face>& faceLst,
const UList<surfZone>& zoneLst = List<surfZone>(),
const labelUList& faceMap = Foam::emptyLabelList
const labelUList& faceMap = labelUList::null()
);
......
......@@ -123,7 +123,7 @@ public:
return faces_;
}
//- Const access to per-face zone/region information
//- Per-face zone/region information
virtual const labelList& zoneIds() const
{
return zones_;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -49,6 +49,10 @@ class meshedSurf
{
public:
// Forward declarations
class emptySurface;
// Constructors
//- Construct null
......@@ -59,19 +63,60 @@ public:
virtual ~meshedSurf() = default;
// Access Member Functions
// Member Functions
//- Const access to (global) points used for the surface
//- The points used for the surface
virtual const pointField& points() const = 0;
//- Const access to the surface faces
//- The faces used for the surface
virtual const faceList& faces() const = 0;
//- Const access to per-face zone/region information
virtual const labelList& zoneIds() const = 0;
//- Per-face zone/region information.
// Default is zero-sizes (ie, no zone information)
virtual const labelList& zoneIds() const
{
return labelList::null();
}
};
/*---------------------------------------------------------------------------*\
Class meshedSurf::emptySurface Declaration
\*---------------------------------------------------------------------------*/
//- A meshedSurf class with no faces, points or zoneId
class meshedSurf::emptySurface
:
public meshedSurf
{
public:
// Constructors
//- Construct null
emptySurface() = default;
//- Destructor
virtual ~emptySurface() = default;
// Member Functions
//- Zero-sized point field
virtual const pointField& points() const
{
return pointField::null();
}
//- Zero-sized face list
virtual const faceList& faces() const
{
return faceList::null();
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......
......@@ -62,7 +62,7 @@ public:
(
const pointField& pts,
const faceList& faces,
const labelList& ids = emptyLabelList
const labelList& ids = labelList::null()
)
:
points_(std::cref<pointField>(pts)),
......@@ -77,19 +77,19 @@ public:
// Member Functions
//- Const access to (global) points used for the surface
//- The points used for the surface
virtual const pointField& points() const
{
return points_.get();
}
//- Const access to the surface faces
//- The faces used for the surface
virtual const faceList& faces() const
{
return faces_.get();
}
//- Const access to per-face zone/region information
//- Per-face zone/region information.
virtual const labelList& zoneIds() const
{
return zoneIds_.get();
......
......@@ -48,10 +48,9 @@ Foam::word Foam::surfMesh::meshSubDir = "surfMesh";
// {
// word zoneName;
//
// surfZoneList& zones = Allocator::storedIOZones();
// if (zones.size())
// if (surfZones_.size())
// {
// zoneName = zones[0].name();
// zoneName = surfZones_[0].name();
// }
// if (zoneName.empty())
// {
......@@ -59,8 +58,8 @@ Foam::word Foam::surfMesh::meshSubDir = "surfMesh";
// }
//
// // Set single default zone
// zones.resize(1);
// zones[0] = surfZone
// surfZones_.resize(1);
// surfZones_[0] = surfZone
// (
// zoneName,
// nFaces(), // zone size
......@@ -100,18 +99,22 @@ Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
)
),
MeshReference(this->storedIOFaces(), this->storedIOPoints()),
surfZones_
(
IOobject
(
"surfZones",
time().findInstance(meshDir(), "surfZones"),
meshSubDir,
*this,
IOobject::MUST_READ,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
)
),
MeshReference(this->storedIOFaces(), this->storedIOPoints())
)
{}
......@@ -142,7 +145,12 @@ Foam::surfMesh::surfMesh
*this,
IOobject::NO_READ,
io.writeOpt()
),
)
),
MeshReference(this->storedIOFaces(), this->storedIOPoints()),
surfZones_
(
IOobject
(
"surfZones",
......@@ -152,8 +160,7 @@ Foam::surfMesh::surfMesh
IOobject::NO_READ,
io.writeOpt()
)
),
MeshReference(this->storedIOFaces(), this->storedIOPoints())
)
{
DebugInfo
<<"IOobject: " << io.path() << nl
......@@ -194,7 +201,12 @@ Foam::surfMesh::surfMesh
*this,
io.readOpt(),
io.writeOpt()
),
)
),
MeshReference(this->storedIOFaces(), this->storedIOPoints()),
surfZones_
(
IOobject
(
"surfZones",
......@@ -204,8 +216,7 @@ Foam::surfMesh::surfMesh
io.readOpt(),
io.writeOpt()
)
),
MeshReference(this->storedIOFaces(), this->storedIOPoints())
)
{
DebugInfo
<<"IOobject: " << io.path() << nl
......@@ -224,8 +235,7 @@ Foam::surfMesh::surfMesh
Foam::surfMesh::~surfMesh()
{
// clearOut();
// resetMotion();
clearOut(); // Clear addressing
}
......@@ -272,7 +282,7 @@ void Foam::surfMesh::copyContents
this->storedIOPoints() = surf.points();
this->storedIOFaces() = surf.surfFaces();
this->storedIOZones() = surf.surfZones();
surfZones_ = surf.surfZones();
this->updateRefs();
......@@ -291,9 +301,9 @@ void Foam::surfMesh::transfer
{
clearOut(); // Clear addressing
this->storedIOPoints().transfer(surf.storedPoints());
this->storedIOFaces().transfer(surf.storedFaces());
this->storedIOZones().transfer(surf.storedZones());
this->storedPoints().transfer(surf.storedPoints());
this->storedFaces().transfer(surf.storedFaces());
this->storedZones().transfer(surf.storedZones());
this->updateRefs();
......@@ -366,18 +376,17 @@ const Foam::faceList& Foam::surfMesh::faces() const
void Foam::surfMesh::checkZones()
{
// extra safety, ensure we have at some zones
// Extra safety, ensure we have at some zones
// and they cover all the faces - fix start silently
surfZoneList& zones = Allocator::storedIOZones();
if (zones.size() <= 1)
if (surfZones_.size() <= 1)
{
removeZones();
return;
}
label count = 0;
for (surfZone& zn : zones)
for (surfZone& zn : surfZones_)
{
zn.start() = count;
count += zn.size();
......@@ -390,7 +399,7 @@ void Foam::surfMesh::checkZones()
<< " ... extending final zone"
<< endl;
zones.last().size() += count - nFaces();
surfZones_.last().size() += count - nFaces();
}
else if (size() < count)
{
......@@ -404,15 +413,15 @@ void Foam::surfMesh::checkZones()
// Add boundary patches. Constructor helper
void Foam::surfMesh::addZones
(
const surfZoneList& srfZones,
const surfZoneList& zones,
const bool validate
)
{
surfZoneList& zones = Allocator::storedIOZones();
removeZones();
forAll(zones, zonei)
forAll(surfZones_, zonei)
{
zones[zonei] = surfZone(srfZones[zonei], zonei);
surfZones_[zonei] = surfZone(zones[zonei], zonei);
}
if (validate)
......
......@@ -43,6 +43,7 @@ SourceFiles
#include "MeshedSurfaceIOAllocator.H"
#include "PrimitivePatch.H"
#include "SubField.H"
#include "surfZoneIOList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -64,7 +65,7 @@ class surfMesh
{
public:
// Public data types
// Public Data Types
//- Enumeration defining the state of the mesh after a read update.
// Used for post-processing applications, where the mesh
......@@ -94,6 +95,12 @@ private:
MeshReference;
// Demand driven private data
//- The surface zones
surfZoneIOList surfZones_;
// Private Member Functions
//- No copy construct
......@@ -119,10 +126,10 @@ protected:
return Allocator::storedIOFaces();
}
//- Non-const access to the zones
//- Non-const access to the surface zones
surfZoneList& storedZones()
{
return Allocator::storedIOZones();
return surfZones_;
}
//- Update references to storedFaces
......@@ -236,10 +243,9 @@ public:
//- Return surface zones
virtual const surfZoneList& surfZones() const
{
return Allocator::storedIOZones();
return surfZones_;
}
//- Return face area vectors (normals)
inline const vectorField& Sf() const
{
......@@ -264,7 +270,7 @@ public:
//- Add surface zones, optionally validating the zone coverage
void addZones
(
const surfZoneList& srfZones,
const surfZoneList& zones,
bool validate = true
);
......
......@@ -36,7 +36,7 @@ void Foam::surfMesh::removeZones()
DebugInFunction << "Removing surface zones." << endl;
// Remove the surface zones
storedZones().clear();
surfZones_.clear();
clearOut();
}
......@@ -54,7 +54,7 @@ void Foam::surfMesh::clearGeom()
void Foam::surfMesh::clearAddressing()
{
DebugInFunction << "clearing topology" << endl;
DebugInFunction << "Clearing topology" << endl;
MeshReference::clearPatchMeshAddr();
}
......
......@@ -40,6 +40,7 @@ void Foam::surfMesh::setInstance
instance() = inst;
Allocator::setInstance(inst);
surfZones_.instance() = inst;
setWriteOption(wOpt);
}
......@@ -49,6 +50,7 @@ void Foam::surfMesh::setWriteOption(IOobject::writeOption wOpt)
{
writeOpt() = wOpt;
Allocator::setWriteOption(wOpt);
surfZones_.writeOpt() = wOpt;
}
......@@ -116,7 +118,7 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
facesInst,
meshSubDir,
*this,
IOobject::MUST_READ,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
......@@ -125,16 +127,15 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
// Check that zone types and names are unchanged
bool zonesChanged = false;
surfZoneList& zones = this->storedIOZones();
if (zones.size() != newZones.size())
if (surfZones_.size() != newZones.size())
{
zonesChanged = true;
}
else
{
forAll(zones, zoneI)
forAll(surfZones_, zoneI)
{
if (zones[zoneI].name() != newZones[zoneI].name())
if (surfZones_[zoneI].name() != newZones[zoneI].name())
{