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
This commit is contained in:
Mark Olesen
2019-01-22 09:44:18 +01:00
parent b9e801ce91
commit 55cebb47ef
11 changed files with 142 additions and 104 deletions

View File

@ -124,7 +124,7 @@ private:
surfZoneList zones_; surfZoneList zones_;
// Private Member functions // Private Member Functions
//- Read/construct from Istream //- Read/construct from Istream
Istream& read(Istream& is); Istream& read(Istream& is);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2009-2010, 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2009-2010, 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -32,39 +32,33 @@ License
Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
( (
const IOobject& ioPoints, const IOobject& ioPoints,
const IOobject& ioFaces, const IOobject& ioFaces
const IOobject& ioZones
) )
: :
points_(ioPoints), points_(ioPoints),
faces_(ioFaces), faces_(ioFaces)
zones_(ioZones)
{} {}
Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
( (
const IOobject& ioPoints, const pointField& points, const IOobject& ioPoints, const pointField& points,
const IOobject& ioFaces, const faceList& faces, const IOobject& ioFaces, const faceList& faces
const IOobject& ioZones, const surfZoneList& zones
) )
: :
points_(ioPoints, points), points_(ioPoints, points),
faces_(ioFaces, faces), faces_(ioFaces, faces)
zones_(ioZones, zones)
{} {}
Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator Foam::Detail::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
( (
const IOobject& ioPoints, pointField&& points, const IOobject& ioPoints, pointField&& points,
const IOobject& ioFaces, faceList&& faces, const IOobject& ioFaces, faceList&& faces
const IOobject& ioZones, surfZoneList&& zones
) )
: :
points_(ioPoints, std::move(points)), points_(ioPoints, std::move(points)),
faces_(ioFaces, std::move(faces)), faces_(ioFaces, std::move(faces))
zones_(ioZones, std::move(zones))
{} {}
@ -85,7 +79,6 @@ void Foam::Detail::MeshedSurfaceIOAllocator::setInstance
{ {
points_.instance() = inst; points_.instance() = inst;
faces_.instance() = inst; faces_.instance() = inst;
zones_.instance() = inst;
} }
@ -96,7 +89,6 @@ void Foam::Detail::MeshedSurfaceIOAllocator::setWriteOption
{ {
points_.writeOpt() = wOpt; points_.writeOpt() = wOpt;
faces_.writeOpt() = wOpt; faces_.writeOpt() = wOpt;
zones_.writeOpt() = wOpt;
} }
@ -104,7 +96,6 @@ void Foam::Detail::MeshedSurfaceIOAllocator::clear()
{ {
points_.clear(); points_.clear();
faces_.clear(); faces_.clear();
zones_.clear();
} }
@ -120,7 +111,6 @@ bool Foam::Detail::MeshedSurfaceIOAllocator::writeObject
( (
points_.writeObject(fmt, ver, cmp, valid) points_.writeObject(fmt, ver, cmp, valid)
&& faces_.writeObject(fmt, ver, cmp, valid) && faces_.writeObject(fmt, ver, cmp, valid)
&& zones_.writeObject(fmt, ver, cmp, valid)
); );
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2009-2010, 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2009-2010, 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -27,7 +27,7 @@ Class
Foam::Detail::MeshedSurfaceIOAllocator Foam::Detail::MeshedSurfaceIOAllocator
Description 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 SourceFiles
MeshedSurfaceIOAllocator.C MeshedSurfaceIOAllocator.C
@ -39,7 +39,6 @@ SourceFiles
#include "pointIOField.H" #include "pointIOField.H"
#include "faceIOList.H" #include "faceIOList.H"
#include "surfZoneIOList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -62,9 +61,6 @@ class MeshedSurfaceIOAllocator
//- Faces //- Faces
faceCompactIOList faces_; faceCompactIOList faces_;
//- Surface zones
surfZoneIOList zones_;
// Private Member Functions // Private Member Functions
@ -83,24 +79,21 @@ public:
MeshedSurfaceIOAllocator MeshedSurfaceIOAllocator
( (
const IOobject& ioPoints, const IOobject& ioPoints,
const IOobject& ioFaces, const IOobject& ioFaces
const IOobject& ioZones
); );
//- Construct from IOobjects, copying components //- Construct from IOobjects, copying components
MeshedSurfaceIOAllocator MeshedSurfaceIOAllocator
( (
const IOobject& ioPoints, const pointField& points, const IOobject& ioPoints, const pointField& points,
const IOobject& ioFaces, const faceList& faces, const IOobject& ioFaces, const faceList& faces
const IOobject& ioZones, const surfZoneList& zones
); );
//- Construct from IOobjects, moving components //- Construct from IOobjects, moving components
MeshedSurfaceIOAllocator MeshedSurfaceIOAllocator
( (
const IOobject& ioPoints, pointField&& points, const IOobject& ioPoints, pointField&& points,
const IOobject& ioFaces, faceList&& faces, const IOobject& ioFaces, faceList&& faces
const IOobject& ioZones, surfZoneList&& zones
); );
@ -133,12 +126,6 @@ public:
return faces_; return faces_;
} }
//- Non-const access to the zones
surfZoneIOList& storedIOZones()
{
return zones_;
}
//- Const access to the points //- Const access to the points
const pointIOField& storedIOPoints() const const pointIOField& storedIOPoints() const
{ {
@ -151,16 +138,10 @@ public:
return faces_; return faces_;
} }
//- Const access to the zones
const surfZoneIOList& storedIOZones() const
{
return zones_;
}
// Storage Management // Storage Management
//- Clear primitive data (points, faces and zones) //- Clear primitive data (points, faces)
void clear(); void clear();

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2009-2010, 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2009-2010, 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -104,7 +104,7 @@ public:
const pointField& pointLst, const pointField& pointLst,
const UList<Face>& faceLst, const UList<Face>& faceLst,
const UList<surfZone>& zoneLst = List<surfZone>(), const UList<surfZone>& zoneLst = List<surfZone>(),
const labelUList& faceMap = Foam::emptyLabelList const labelUList& faceMap = labelUList::null()
); );

View File

@ -123,7 +123,7 @@ public:
return faces_; return faces_;
} }
//- Const access to per-face zone/region information //- Per-face zone/region information
virtual const labelList& zoneIds() const virtual const labelList& zoneIds() const
{ {
return zones_; return zones_;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -49,6 +49,10 @@ class meshedSurf
{ {
public: public:
// Forward declarations
class emptySurface;
// Constructors // Constructors
//- Construct null //- Construct null
@ -59,19 +63,60 @@ public:
virtual ~meshedSurf() = default; 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; virtual const pointField& points() const = 0;
//- Const access to the surface faces //- The faces used for the surface
virtual const faceList& faces() const = 0; virtual const faceList& faces() const = 0;
//- Const access to per-face zone/region information //- Per-face zone/region information.
virtual const labelList& zoneIds() const = 0; // 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 } // End namespace Foam

View File

@ -62,7 +62,7 @@ public:
( (
const pointField& pts, const pointField& pts,
const faceList& faces, const faceList& faces,
const labelList& ids = emptyLabelList const labelList& ids = labelList::null()
) )
: :
points_(std::cref<pointField>(pts)), points_(std::cref<pointField>(pts)),
@ -77,19 +77,19 @@ public:
// Member Functions // Member Functions
//- Const access to (global) points used for the surface //- The points used for the surface
virtual const pointField& points() const virtual const pointField& points() const
{ {
return points_.get(); return points_.get();
} }
//- Const access to the surface faces //- The faces used for the surface
virtual const faceList& faces() const virtual const faceList& faces() const
{ {
return faces_.get(); return faces_.get();
} }
//- Const access to per-face zone/region information //- Per-face zone/region information.
virtual const labelList& zoneIds() const virtual const labelList& zoneIds() const
{ {
return zoneIds_.get(); return zoneIds_.get();

View File

@ -48,10 +48,9 @@ Foam::word Foam::surfMesh::meshSubDir = "surfMesh";
// { // {
// word zoneName; // word zoneName;
// //
// surfZoneList& zones = Allocator::storedIOZones(); // if (surfZones_.size())
// if (zones.size())
// { // {
// zoneName = zones[0].name(); // zoneName = surfZones_[0].name();
// } // }
// if (zoneName.empty()) // if (zoneName.empty())
// { // {
@ -59,8 +58,8 @@ Foam::word Foam::surfMesh::meshSubDir = "surfMesh";
// } // }
// //
// // Set single default zone // // Set single default zone
// zones.resize(1); // surfZones_.resize(1);
// zones[0] = surfZone // surfZones_[0] = surfZone
// ( // (
// zoneName, // zoneName,
// nFaces(), // zone size // nFaces(), // zone size
@ -100,18 +99,22 @@ Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
*this, *this,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
)
), ),
MeshReference(this->storedIOFaces(), this->storedIOPoints()),
surfZones_
(
IOobject IOobject
( (
"surfZones", "surfZones",
time().findInstance(meshDir(), "surfZones"), time().findInstance(meshDir(), "surfZones"),
meshSubDir, meshSubDir,
*this, *this,
IOobject::MUST_READ, IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE IOobject::NO_WRITE
) )
), )
MeshReference(this->storedIOFaces(), this->storedIOPoints())
{} {}
@ -142,7 +145,12 @@ Foam::surfMesh::surfMesh
*this, *this,
IOobject::NO_READ, IOobject::NO_READ,
io.writeOpt() io.writeOpt()
)
), ),
MeshReference(this->storedIOFaces(), this->storedIOPoints()),
surfZones_
(
IOobject IOobject
( (
"surfZones", "surfZones",
@ -152,8 +160,7 @@ Foam::surfMesh::surfMesh
IOobject::NO_READ, IOobject::NO_READ,
io.writeOpt() io.writeOpt()
) )
), )
MeshReference(this->storedIOFaces(), this->storedIOPoints())
{ {
DebugInfo DebugInfo
<<"IOobject: " << io.path() << nl <<"IOobject: " << io.path() << nl
@ -194,7 +201,12 @@ Foam::surfMesh::surfMesh
*this, *this,
io.readOpt(), io.readOpt(),
io.writeOpt() io.writeOpt()
)
), ),
MeshReference(this->storedIOFaces(), this->storedIOPoints()),
surfZones_
(
IOobject IOobject
( (
"surfZones", "surfZones",
@ -204,8 +216,7 @@ Foam::surfMesh::surfMesh
io.readOpt(), io.readOpt(),
io.writeOpt() io.writeOpt()
) )
), )
MeshReference(this->storedIOFaces(), this->storedIOPoints())
{ {
DebugInfo DebugInfo
<<"IOobject: " << io.path() << nl <<"IOobject: " << io.path() << nl
@ -224,8 +235,7 @@ Foam::surfMesh::surfMesh
Foam::surfMesh::~surfMesh() Foam::surfMesh::~surfMesh()
{ {
// clearOut(); clearOut(); // Clear addressing
// resetMotion();
} }
@ -272,7 +282,7 @@ void Foam::surfMesh::copyContents
this->storedIOPoints() = surf.points(); this->storedIOPoints() = surf.points();
this->storedIOFaces() = surf.surfFaces(); this->storedIOFaces() = surf.surfFaces();
this->storedIOZones() = surf.surfZones(); surfZones_ = surf.surfZones();
this->updateRefs(); this->updateRefs();
@ -291,9 +301,9 @@ void Foam::surfMesh::transfer
{ {
clearOut(); // Clear addressing clearOut(); // Clear addressing
this->storedIOPoints().transfer(surf.storedPoints()); this->storedPoints().transfer(surf.storedPoints());
this->storedIOFaces().transfer(surf.storedFaces()); this->storedFaces().transfer(surf.storedFaces());
this->storedIOZones().transfer(surf.storedZones()); this->storedZones().transfer(surf.storedZones());
this->updateRefs(); this->updateRefs();
@ -366,18 +376,17 @@ const Foam::faceList& Foam::surfMesh::faces() const
void Foam::surfMesh::checkZones() 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 // and they cover all the faces - fix start silently
surfZoneList& zones = Allocator::storedIOZones();
if (zones.size() <= 1) if (surfZones_.size() <= 1)
{ {
removeZones(); removeZones();
return; return;
} }
label count = 0; label count = 0;
for (surfZone& zn : zones) for (surfZone& zn : surfZones_)
{ {
zn.start() = count; zn.start() = count;
count += zn.size(); count += zn.size();
@ -390,7 +399,7 @@ void Foam::surfMesh::checkZones()
<< " ... extending final zone" << " ... extending final zone"
<< endl; << endl;
zones.last().size() += count - nFaces(); surfZones_.last().size() += count - nFaces();
} }
else if (size() < count) else if (size() < count)
{ {
@ -404,15 +413,15 @@ void Foam::surfMesh::checkZones()
// Add boundary patches. Constructor helper // Add boundary patches. Constructor helper
void Foam::surfMesh::addZones void Foam::surfMesh::addZones
( (
const surfZoneList& srfZones, const surfZoneList& zones,
const bool validate 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) if (validate)

View File

@ -43,6 +43,7 @@ SourceFiles
#include "MeshedSurfaceIOAllocator.H" #include "MeshedSurfaceIOAllocator.H"
#include "PrimitivePatch.H" #include "PrimitivePatch.H"
#include "SubField.H" #include "SubField.H"
#include "surfZoneIOList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -64,7 +65,7 @@ class surfMesh
{ {
public: public:
// Public data types // Public Data Types
//- Enumeration defining the state of the mesh after a read update. //- Enumeration defining the state of the mesh after a read update.
// Used for post-processing applications, where the mesh // Used for post-processing applications, where the mesh
@ -94,6 +95,12 @@ private:
MeshReference; MeshReference;
// Demand driven private data
//- The surface zones
surfZoneIOList surfZones_;
// Private Member Functions // Private Member Functions
//- No copy construct //- No copy construct
@ -119,10 +126,10 @@ protected:
return Allocator::storedIOFaces(); return Allocator::storedIOFaces();
} }
//- Non-const access to the zones //- Non-const access to the surface zones
surfZoneList& storedZones() surfZoneList& storedZones()
{ {
return Allocator::storedIOZones(); return surfZones_;
} }
//- Update references to storedFaces //- Update references to storedFaces
@ -236,10 +243,9 @@ public:
//- Return surface zones //- Return surface zones
virtual const surfZoneList& surfZones() const virtual const surfZoneList& surfZones() const
{ {
return Allocator::storedIOZones(); return surfZones_;
} }
//- Return face area vectors (normals) //- Return face area vectors (normals)
inline const vectorField& Sf() const inline const vectorField& Sf() const
{ {
@ -264,7 +270,7 @@ public:
//- Add surface zones, optionally validating the zone coverage //- Add surface zones, optionally validating the zone coverage
void addZones void addZones
( (
const surfZoneList& srfZones, const surfZoneList& zones,
bool validate = true bool validate = true
); );

View File

@ -36,7 +36,7 @@ void Foam::surfMesh::removeZones()
DebugInFunction << "Removing surface zones." << endl; DebugInFunction << "Removing surface zones." << endl;
// Remove the surface zones // Remove the surface zones
storedZones().clear(); surfZones_.clear();
clearOut(); clearOut();
} }
@ -54,7 +54,7 @@ void Foam::surfMesh::clearGeom()
void Foam::surfMesh::clearAddressing() void Foam::surfMesh::clearAddressing()
{ {
DebugInFunction << "clearing topology" << endl; DebugInFunction << "Clearing topology" << endl;
MeshReference::clearPatchMeshAddr(); MeshReference::clearPatchMeshAddr();
} }

View File

@ -40,6 +40,7 @@ void Foam::surfMesh::setInstance
instance() = inst; instance() = inst;
Allocator::setInstance(inst); Allocator::setInstance(inst);
surfZones_.instance() = inst;
setWriteOption(wOpt); setWriteOption(wOpt);
} }
@ -49,6 +50,7 @@ void Foam::surfMesh::setWriteOption(IOobject::writeOption wOpt)
{ {
writeOpt() = wOpt; writeOpt() = wOpt;
Allocator::setWriteOption(wOpt); Allocator::setWriteOption(wOpt);
surfZones_.writeOpt() = wOpt;
} }
@ -116,7 +118,7 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
facesInst, facesInst,
meshSubDir, meshSubDir,
*this, *this,
IOobject::MUST_READ, IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
) )
@ -125,16 +127,15 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
// Check that zone types and names are unchanged // Check that zone types and names are unchanged
bool zonesChanged = false; bool zonesChanged = false;
surfZoneList& zones = this->storedIOZones(); if (surfZones_.size() != newZones.size())
if (zones.size() != newZones.size())
{ {
zonesChanged = true; zonesChanged = true;
} }
else else
{ {
forAll(zones, zoneI) forAll(surfZones_, zoneI)
{ {
if (zones[zoneI].name() != newZones[zoneI].name()) if (surfZones_[zoneI].name() != newZones[zoneI].name())
{ {
zonesChanged = true; zonesChanged = true;
break; break;
@ -142,12 +143,12 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
} }
} }
zones.transfer(newZones); surfZones_.transfer(newZones);
if (zonesChanged) if (zonesChanged)
{ {
WarningInFunction WarningInFunction
<< "unexpected consequences. Proceed with care." << endl; << "Unexpected consequences. Proceed with care." << endl;
return surfMesh::TOPO_PATCH_CHANGE; return surfMesh::TOPO_PATCH_CHANGE;
} }
@ -155,7 +156,6 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
{ {
return surfMesh::TOPO_CHANGE; return surfMesh::TOPO_CHANGE;
} }
} }
else if (pointsInst != pointsInstance()) else if (pointsInst != pointsInstance())
{ {
@ -198,7 +198,14 @@ bool Foam::surfMesh::writeObject
const bool valid const bool valid
) const ) const
{ {
return Allocator::writeObject(fmt, ver, cmp, valid); bool ok = Allocator::writeObject(fmt, ver, cmp, valid);
if (ok)
{
surfZones_.writeObject(fmt, ver, cmp, valid);
}
return ok;
} }