From 52b6c49b4fa9f6b95cfd091d4a4c5d90ba5ef608 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sat, 12 Nov 2016 23:42:17 +0100 Subject: [PATCH] ENH: provide xfer methods for the meshed surface components. - the surfMesh classes where originally designed with limited (protected) access to the underlying components. This is to avoid unintentional direct changes, since these can quickly lead to inconsistencies with the topology addressing etc. However, if we wish to efficiently adjust surfaces, it is useful to modify the components directly. The compromise is to provide 'xfer' methods: - xferFaces() - xferPoints() - xferZones() These transfer the contents to an Xfer container for reuse, while also resetting the topology addressing. To apply the changes, the reset() method is used. --- src/surfMesh/MeshedSurface/MeshedSurface.C | 54 ++++++++++++++++--- src/surfMesh/MeshedSurface/MeshedSurface.H | 15 ++++++ .../MeshedSurfaceIOAllocator.H | 2 +- .../UnsortedMeshedSurface.C | 8 +++ .../UnsortedMeshedSurface.H | 3 ++ src/surfMesh/surfMesh/surfMesh.C | 24 ++++++++- src/surfMesh/surfMesh/surfMesh.H | 9 ++++ .../triSurface/interfaces/VTK/readVTK.C | 2 +- src/triSurface/triSurface/triSurface.H | 6 +-- 9 files changed, 110 insertions(+), 13 deletions(-) diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.C b/src/surfMesh/MeshedSurface/MeshedSurface.C index 79be6bfac4..a51428f8b4 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.C +++ b/src/surfMesh/MeshedSurface/MeshedSurface.C @@ -532,6 +532,16 @@ void Foam::MeshedSurface::scalePoints(const scalar scaleFactor) } +template +void Foam::MeshedSurface::reset +( + const Xfer>& surf +) +{ + transfer(surf()); +} + + template void Foam::MeshedSurface::reset ( @@ -1112,12 +1122,11 @@ void Foam::MeshedSurface::transfer MeshedSurface& surf ) { - reset - ( - xferMove(surf.storedPoints()), - xferMove(surf.storedFaces()), - xferMove(surf.storedZones()) - ); + ParentType::clearOut(); + + this->storedPoints().transfer(surf.storedPoints()); + this->storedFaces().transfer(surf.storedFaces()); + this->storedZones().transfer(surf.storedZones()); surf.clear(); } @@ -1167,12 +1176,43 @@ void Foam::MeshedSurface::transfer template -Foam::Xfer> Foam::MeshedSurface::xfer() +Foam::Xfer> +Foam::MeshedSurface::xfer() { return xferMove(*this); } +template +Foam::Xfer> +Foam::MeshedSurface::xferFaces() +{ + // Topology changed because of transfer + ParentType::clearOut(); + + return this->storedFaces().xfer(); +} + + +template +Foam::Xfer> +Foam::MeshedSurface::xferPoints() +{ + // Topology changed because of transfer + ParentType::clearOut(); + + return this->storedPoints().xfer(); +} + + +template +Foam::Xfer +Foam::MeshedSurface::xferZones() +{ + return this->storedZones().xfer(); +} + + // Read from file, determine format from extension template bool Foam::MeshedSurface::read(const fileName& name) diff --git a/src/surfMesh/MeshedSurface/MeshedSurface.H b/src/surfMesh/MeshedSurface/MeshedSurface.H index 3922edf29e..513a813597 100644 --- a/src/surfMesh/MeshedSurface/MeshedSurface.H +++ b/src/surfMesh/MeshedSurface/MeshedSurface.H @@ -405,6 +405,12 @@ public: //- Scale points. A non-positive factor is ignored virtual void scalePoints(const scalar); + //- Reset by transferring contents of the argument and annul it + virtual void reset + ( + const Xfer>& + ); + //- Reset primitive data (points, faces and zones) // Note, optimized to avoid overwriting data (with Xfer::null) virtual void reset @@ -476,6 +482,15 @@ public: //- Transfer contents to the Xfer container Xfer> xfer(); + //- Transfer stored faces to an Xfer container + Xfer> xferFaces(); + + //- Transfer stored points to an Xfer container + Xfer> xferPoints(); + + //- Transfer stored zones to an Xfer container + Xfer xferZones(); + // Read diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H index 190b081ce5..6c8aa07e2a 100644 --- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H @@ -152,7 +152,7 @@ public: //- Clear primitive data (points, faces and zones) void clear(); - //- Reset primitive data (points, faces and zones) + //- Reset primitive data (faces and zones) // Note, optimized to avoid overwriting data (with Xfer::null) void resetFaces ( diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C index d427454e4a..e3975c6b8b 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C @@ -722,6 +722,14 @@ Foam::UnsortedMeshedSurface::xfer() } +template +Foam::Xfer +Foam::UnsortedMeshedSurface::xferZoneIds() +{ + return this->storedZoneIds().xfer(); +} + + // Read from file, determine format from extension template bool Foam::UnsortedMeshedSurface::read(const fileName& name) diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H index 9be2e3151d..e038e92711 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.H @@ -366,6 +366,9 @@ public: //- Transfer contents to the Xfer container Xfer> xfer(); + //- Transfer stored zoneIds to an Xfer container + Xfer xferZoneIds(); + // Read diff --git a/src/surfMesh/surfMesh/surfMesh.C b/src/surfMesh/surfMesh/surfMesh.C index 20042257c8..c7eef6b72b 100644 --- a/src/surfMesh/surfMesh/surfMesh.C +++ b/src/surfMesh/surfMesh/surfMesh.C @@ -272,6 +272,27 @@ void Foam::surfMesh::resetPrimitives } +void Foam::surfMesh::resetPrimitives +( + const Xfer>& points, + const Xfer& faces, + const Xfer& zones, + const bool validate +) +{ + // Clear addressing. + clearOut(); + + Allocator::reset(points, faces, zones); + this->updateRefs(); + + if (validate) + { + checkZones(); + } +} + + void Foam::surfMesh::transfer ( MeshedSurface& surf @@ -288,7 +309,8 @@ void Foam::surfMesh::transfer } -Foam::Xfer> Foam::surfMesh::xfer() +Foam::Xfer> +Foam::surfMesh::xfer() { Xfer> xf; diff --git a/src/surfMesh/surfMesh/surfMesh.H b/src/surfMesh/surfMesh/surfMesh.H index f936d3f46d..64e7c0239a 100644 --- a/src/surfMesh/surfMesh/surfMesh.H +++ b/src/surfMesh/surfMesh/surfMesh.H @@ -277,6 +277,15 @@ public: const bool validate = true ); + //- Reset mesh primitive data. + void resetPrimitives + ( + const Xfer>& points, + const Xfer& faces, + const Xfer& zones, + const bool validate = true + ); + //- Transfer the contents of the argument and annul the argument void transfer(MeshedSurface&); diff --git a/src/triSurface/triSurface/interfaces/VTK/readVTK.C b/src/triSurface/triSurface/interfaces/VTK/readVTK.C index a28570164b..b413641102 100644 --- a/src/triSurface/triSurface/interfaces/VTK/readVTK.C +++ b/src/triSurface/triSurface/interfaces/VTK/readVTK.C @@ -94,7 +94,7 @@ bool Foam::triSurface::readVTK(const fileName& fName) ( tris.xfer(), patches, - xferCopy>(surf.points()) + surf.xferPoints() ); return true; diff --git a/src/triSurface/triSurface/triSurface.H b/src/triSurface/triSurface/triSurface.H index 0383c14a2b..cfa253fbb3 100644 --- a/src/triSurface/triSurface/triSurface.H +++ b/src/triSurface/triSurface/triSurface.H @@ -270,7 +270,7 @@ public: const bool reuse ); - //- Construct from triangles, patches, points. + //- Construct by transferring (triangles, points) components. triSurface ( const Xfer>&, @@ -278,7 +278,7 @@ public: const Xfer>& ); - //- Construct from triangles, points. Set patchnames to default. + //- Construct from triangles, points. Set patch names to default. triSurface(const List&, const pointField&); //- Construct from triangles, points. Set region to 0 and default @@ -299,7 +299,7 @@ public: //- Destructor - ~triSurface(); + virtual ~triSurface(); void clearOut();