From ae14a1ef31bd1276367610fa20c2143faa4a5ea2 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 2 Apr 2020 11:23:14 +0200 Subject: [PATCH] COMP: correct the internal reference types for surfMesh - had a PrimitivePatch with SubField, but now use const pointField&. There is no derivation path from a pointIOField to SubField<point>, so a const reference makes more sense. --- .../MeshedSurfaceIOAllocator.H | 16 ++--- src/surfMesh/surfMesh/surfMesh.C | 62 ++++++------------- src/surfMesh/surfMesh/surfMesh.H | 33 ++++------ 3 files changed, 38 insertions(+), 73 deletions(-) diff --git a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H index 5980bd766e1..041cae40c7c 100644 --- a/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H +++ b/src/surfMesh/MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.H @@ -146,14 +146,14 @@ public: void clear(); - // Writing - - //- Write using stream options - virtual bool writeObject - ( - IOstreamOption streamOpt, - const bool valid - ) const; + // Writing + + //- Write using stream options + virtual bool writeObject + ( + IOstreamOption streamOpt, + const bool valid + ) const; }; diff --git a/src/surfMesh/surfMesh/surfMesh.C b/src/surfMesh/surfMesh/surfMesh.C index 04d3bc22713..e41911fefe5 100644 --- a/src/surfMesh/surfMesh/surfMesh.C +++ b/src/surfMesh/surfMesh/surfMesh.C @@ -59,18 +59,24 @@ Foam::word Foam::surfMesh::meshSubDir = "surfMesh"; // zoneName = "zone0"; // } // -// // Set single default zone +// // Set single default zone with nFaces // surfZones_.resize(1); -// surfZones_[0] = surfZone -// ( -// zoneName, -// nFaces(), // zone size -// 0, // zone start -// 0 // zone index -// ); +// surfZones_[0] = surfZone(zoneName, nFaces()); // } +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +void Foam::surfMesh::updateRefs() +{ + // Synchronize UList reference to the faces + static_cast<MeshReference&>(*this).shallowCopy + ( + this->storedFaces() + ); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::surfMesh::surfMesh(const IOobject& io) @@ -288,37 +294,6 @@ Foam::surfMesh::~surfMesh() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::surfMesh::updatePointsRef() -{ - // Assign the reference to the points (quite ugly) - // points() are returned as Field but are actually stored as SubField - reinterpret_cast<typename MeshReference::PointFieldType&> - ( - const_cast<Field<point>&>(MeshReference::points()) - ).shallowCopy - ( - this->storedPoints() - ); -} - - -void Foam::surfMesh::updateFacesRef() -{ - // Assign the reference to the faces (UList) - static_cast<MeshReference&>(*this).shallowCopy - ( - this->storedFaces() - ); -} - - -void Foam::surfMesh::updateRefs() -{ - this->updatePointsRef(); - this->updateFacesRef(); -} - - void Foam::surfMesh::copySurface ( const pointField& points, @@ -431,6 +406,9 @@ void Foam::surfMesh::transfer Foam::autoPtr<Foam::MeshedSurface<Foam::face>> Foam::surfMesh::releaseGeom() { + clearOut(); // Clear addressing + clearFields(); + // Start with an empty geometry auto aptr = autoPtr<MeshedSurface<face>>::New(); @@ -440,8 +418,6 @@ Foam::surfMesh::releaseGeom() aptr->storedZones().transfer(this->storedZones()); this->updateRefs(); // This may not be needed... - clearOut(); // Clear addressing. - clearFields(); return aptr; } @@ -577,7 +553,7 @@ void Foam::surfMesh::write void Foam::surfMesh::write ( const fileName& name, - const word& ext, + const word& fileType, IOstreamOption streamOpt, const dictionary& options ) const @@ -587,7 +563,7 @@ void Foam::surfMesh::write this->points(), this->faces(), this->surfZones() - ).write(name, ext, streamOpt, options); + ).write(name, fileType, streamOpt, options); } diff --git a/src/surfMesh/surfMesh/surfMesh.H b/src/surfMesh/surfMesh/surfMesh.H index 88efef81adc..dd3582fb616 100644 --- a/src/surfMesh/surfMesh/surfMesh.H +++ b/src/surfMesh/surfMesh/surfMesh.H @@ -28,7 +28,8 @@ Class Foam::surfMesh Description - A surface mesh consisting of general polygon faces. + A surface mesh consisting of general polygon faces that has + IO capabilities and a registry for storing fields. SourceFiles surfMesh.C @@ -43,9 +44,7 @@ SourceFiles #include "surfaceRegistry.H" #include "MeshedSurfaceIOAllocator.H" #include "PrimitivePatch.H" -#include "SubField.H" #include "surfZoneIOList.H" - #include "surfFieldsFwd.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -66,7 +65,7 @@ class surfMesh : public surfaceRegistry, private Detail::MeshedSurfaceIOAllocator, - public PrimitivePatch<face, ::Foam::UList, ::Foam::SubField<point>, point> + public PrimitivePatch<face, UList, const pointField&, point> { public: @@ -88,16 +87,12 @@ private: // Private Typedefs + //- Memory and IO management typedef Detail::MeshedSurfaceIOAllocator Allocator; - typedef PrimitivePatch - < - face, - ::Foam::UList, - ::Foam::SubField<point>, - point - > - MeshReference; + //- Internal mesh storage type + typedef PrimitivePatch<face, UList, const pointField&, point> + MeshReference; // Private Data @@ -137,14 +132,8 @@ protected: return surfZones_; } - //- Update references to storedFaces - virtual void updateFacesRef(); - - //- Update references to storedPoints - virtual void updatePointsRef(); - - //- Update references to storedPoints/storedFaces - virtual void updateRefs(); + //- Update point/face references + void updateRefs(); public: @@ -365,12 +354,12 @@ public: const dictionary& options = dictionary::null ) const; - //- Write to file, choosing writer given extension. + //- Write to file, choosing writer for given fileType. // Uses MeshedSurfaceProxy for writing. void write ( const fileName& name, - const word& ext, + const word& fileType, IOstreamOption streamOpt = IOstreamOption(), const dictionary& options = dictionary::null ) const; -- GitLab