From 55cebb47ef264d10d8d88dd65a8bc1b83222514d Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Tue, 22 Jan 2019 09:44:18 +0100 Subject: [PATCH] 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 --- src/surfMesh/MeshedSurface/MeshedSurface.H | 2 +- .../MeshedSurfaceIOAllocator.C | 24 ++----- .../MeshedSurfaceIOAllocator.H | 31 ++------- .../MeshedSurfaceProxy/MeshedSurfaceProxy.H | 4 +- src/surfMesh/mergedSurf/mergedSurf.H | 2 +- src/surfMesh/meshedSurf/meshedSurf.H | 57 +++++++++++++-- src/surfMesh/meshedSurf/meshedSurfRef.H | 8 +-- src/surfMesh/surfMesh/surfMesh.C | 69 +++++++++++-------- src/surfMesh/surfMesh/surfMesh.H | 18 +++-- src/surfMesh/surfMesh/surfMeshClear.C | 4 +- src/surfMesh/surfMesh/surfMeshIO.C | 25 ++++--- 11 files changed, 141 insertions(+), 103 deletions(-) diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.H b/src/surfMesh/MeshedSurface/MeshedSurface.H index 4e470b6d9a7..d9fe402566d 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.H +++ b/src/surfMesh/MeshedSurface/MeshedSurface.H @@ -124,7 +124,7 @@ private: surfZoneList zones_; - // Private Member functions + // Private Member Functions //- Read/construct from Istream Istream& read(Istream& is); diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C index 2700593330e..5e51c35cbad 100644 --- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2010, 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2010, 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) ); } diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H index 6b7bfa9df55..fdbe53b74a4 100644 --- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2010, 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2010, 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(); diff --git a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H index 272027fdfcd..c200bac229c 100644 --- a/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H +++ b/src/surfMesh/MeshedSurfaceProxy/MeshedSurfaceProxy.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2009-2010, 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2010, 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() ); diff --git a/src/surfMesh/mergedSurf/mergedSurf.H b/src/surfMesh/mergedSurf/mergedSurf.H index 86886f9bc78..bb5e12f8b6f 100644 --- a/src/surfMesh/mergedSurf/mergedSurf.H +++ b/src/surfMesh/mergedSurf/mergedSurf.H @@ -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_; diff --git a/src/surfMesh/meshedSurf/meshedSurf.H b/src/surfMesh/meshedSurf/meshedSurf.H index 6a08bf99ffa..f5f2c531dfc 100644 --- a/src/surfMesh/meshedSurf/meshedSurf.H +++ b/src/surfMesh/meshedSurf/meshedSurf.H @@ -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 diff --git a/src/surfMesh/meshedSurf/meshedSurfRef.H b/src/surfMesh/meshedSurf/meshedSurfRef.H index f45e435f808..5ed5eba7908 100644 --- a/src/surfMesh/meshedSurf/meshedSurfRef.H +++ b/src/surfMesh/meshedSurf/meshedSurfRef.H @@ -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(); diff --git a/src/surfMesh/surfMesh/surfMesh.C b/src/surfMesh/surfMesh/surfMesh.C index 555d91ccfe6..6bfd870b8f3 100644 --- a/src/surfMesh/surfMesh/surfMesh.C +++ b/src/surfMesh/surfMesh/surfMesh.C @@ -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) diff --git a/src/surfMesh/surfMesh/surfMesh.H b/src/surfMesh/surfMesh/surfMesh.H index 2f056ede993..195117fbae5 100644 --- a/src/surfMesh/surfMesh/surfMesh.H +++ b/src/surfMesh/surfMesh/surfMesh.H @@ -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 ); diff --git a/src/surfMesh/surfMesh/surfMeshClear.C b/src/surfMesh/surfMesh/surfMeshClear.C index c76ecf6387c..96a088cf289 100644 --- a/src/surfMesh/surfMesh/surfMeshClear.C +++ b/src/surfMesh/surfMesh/surfMeshClear.C @@ -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(); } diff --git a/src/surfMesh/surfMesh/surfMeshIO.C b/src/surfMesh/surfMesh/surfMeshIO.C index 21e10e8c4de..62b2751b848 100644 --- a/src/surfMesh/surfMesh/surfMeshIO.C +++ b/src/surfMesh/surfMesh/surfMeshIO.C @@ -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()) { zonesChanged = true; break; @@ -142,12 +143,12 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() } } - zones.transfer(newZones); + surfZones_.transfer(newZones); if (zonesChanged) { WarningInFunction - << "unexpected consequences. Proceed with care." << endl; + << "Unexpected consequences. Proceed with care." << endl; return surfMesh::TOPO_PATCH_CHANGE; } @@ -155,7 +156,6 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate() { return surfMesh::TOPO_CHANGE; } - } else if (pointsInst != pointsInstance()) { @@ -198,7 +198,14 @@ bool Foam::surfMesh::writeObject const bool valid ) 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; } -- GitLab