From 8d3e1061663aadb27fa2662969975ad222b1fe43 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 26 May 2017 08:15:49 +0200 Subject: [PATCH 01/20] STYLE: remove redundant size check --- src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C index 086f44ef8d..c535e5b0bf 100644 --- a/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C +++ b/src/OpenFOAM/meshes/Identifiers/patch/patchIdentifier.C @@ -82,7 +82,7 @@ Foam::patchIdentifier::~patchIdentifier() bool Foam::patchIdentifier::inGroup(const word& name) const { - return inGroups_.size() && findIndex(inGroups_, name) != -1; + return findIndex(inGroups_, name) != -1; } From 5efe22c2f0a2ea8d5ef005ac989faa35e27f6685 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 26 May 2017 09:10:48 +0200 Subject: [PATCH 02/20] ENH: align constructors of geometricSurfacePatch with surfZoneIdentifier - both classes are nearly identical and should be merged in the future. --- .../Identifiers/surface/surfZoneIdentifier.C | 35 ++--- .../Identifiers/surface/surfZoneIdentifier.H | 38 +++--- .../UnsortedMeshedSurface.C | 5 +- .../triSurface/interfaces/AC3D/readAC.C | 3 +- .../triSurface/interfaces/NAS/readNAS.C | 12 +- .../triSurface/interfaces/OBJ/readOBJ.C | 15 +-- .../triSurface/interfaces/TRI/readTRI.C | 2 +- .../triSurface/interfaces/VTK/readVTK.C | 12 +- .../patches/geometricSurfacePatch.C | 120 +++++++++++------- .../patches/geometricSurfacePatch.H | 64 +++++++--- src/surfMesh/triSurface/triSurface.C | 2 +- 11 files changed, 168 insertions(+), 140 deletions(-) diff --git a/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.C b/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.C index d9179f4274..33e933ba23 100644 --- a/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.C +++ b/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.C @@ -106,48 +106,39 @@ void Foam::surfZoneIdentifier::write(Ostream& os) const } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // -// needed for list output -bool Foam::surfZoneIdentifier::operator!= -( - const surfZoneIdentifier& rhs -) const -{ - return !(*this == rhs); -} - - -bool Foam::surfZoneIdentifier::operator== -( - const surfZoneIdentifier& rhs -) const +bool Foam::operator==(const surfZoneIdentifier& a, const surfZoneIdentifier& b) { return ( - (index() == rhs.index()) - && (name() == rhs.name()) - && (geometricType() == rhs.geometricType()) + (a.index() == b.index()) + && (a.name() == b.name()) + && (a.geometricType() == b.geometricType()) ); } +bool Foam::operator!=(const surfZoneIdentifier& a, const surfZoneIdentifier& b) +{ + return !(a == b); +} + + // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // Foam::Istream& Foam::operator>>(Istream& is, surfZoneIdentifier& obj) { is >> obj.name_ >> obj.geometricType_; - return is; } Foam::Ostream& Foam::operator<<(Ostream& os, const surfZoneIdentifier& obj) { - // newlines to separate, since that is what triSurface currently expects + // Newlines to separate, since that is what triSurface currently expects os << nl << obj.name_ << nl << obj.geometricType_; - - os.check("Ostream& operator<<(Ostream&, const surfZoneIdentifier&)"); + os.check(FUNCTION_NAME); return os; } diff --git a/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.H b/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.H index a084e0196a..26922f5aef 100644 --- a/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.H +++ b/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.H @@ -51,8 +51,8 @@ class dictionary; // Forward declaration of friend functions and operators class surfZoneIdentifier; -Istream& operator>>(Istream&, surfZoneIdentifier&); -Ostream& operator<<(Ostream&, const surfZoneIdentifier&); +Istream& operator>>(Istream& is, surfZoneIdentifier& p); +Ostream& operator<<(Ostream& os, const surfZoneIdentifier& p); /*---------------------------------------------------------------------------*\ Class surfZoneIdentifier Declaration @@ -94,21 +94,20 @@ public: const word& name, const label index, const word& geometricType = word::null - ); //- Construct from dictionary surfZoneIdentifier ( const word& name, - const dictionary&, + const dictionary& dict, const label index ); - //- Construct from another zone identifier, resetting the index + //- Copy construct from another zone identifier, resetting the index surfZoneIdentifier ( - const surfZoneIdentifier&, + const surfZoneIdentifier& p, const label index ); @@ -156,14 +155,8 @@ public: } - //- Write surfZoneIdentifier as a dictionary - void write(Ostream&) const; - - - // Member Operators - - bool operator!=(const surfZoneIdentifier&) const; - bool operator==(const surfZoneIdentifier&) const; + //- Write identifier as a dictionary + void write(Ostream& os) const; // Ostream Operator @@ -171,20 +164,29 @@ public: //- Read name/type. friend Istream& operator>> ( - Istream&, - surfZoneIdentifier& + Istream& is, + surfZoneIdentifier& ob ); //- Write name/type. friend Ostream& operator<< ( - Ostream&, - const surfZoneIdentifier& + Ostream& os, + const surfZoneIdentifier& obj ); }; +// Global Operators + +//- Compare zone indentifiers for equality +bool operator==(const surfZoneIdentifier& a, const surfZoneIdentifier& b); + +//- Compare zone indentifiers for inequality +bool operator!=(const surfZoneIdentifier& a, const surfZoneIdentifier& b); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C index 7ac9a3e598..c156793124 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C @@ -327,9 +327,8 @@ void Foam::UnsortedMeshedSurface::setOneZone() zoneName = "zone0"; } - // set single default zone - zoneToc_.setSize(1); - zoneToc_[0] = surfZoneIdentifier(zoneName, 0); + // Set single default zone + zoneToc_ = { surfZoneIdentifier(zoneName, 0) }; } diff --git a/src/surfMesh/triSurface/interfaces/AC3D/readAC.C b/src/surfMesh/triSurface/interfaces/AC3D/readAC.C index 8d300f08a1..f171287568 100644 --- a/src/surfMesh/triSurface/interfaces/AC3D/readAC.C +++ b/src/surfMesh/triSurface/interfaces/AC3D/readAC.C @@ -183,7 +183,7 @@ bool triSurface::readAC(const fileName& ACfileName) ); // Object global values - string patchName = string("patch") + name(patchi); + string patchName = string("patch") + Foam::name(patchi); label nVerts = 0; tensor rot(I); vector loc(0, 0, 0); @@ -319,7 +319,6 @@ bool triSurface::readAC(const fileName& ACfileName) patches[patchi] = geometricSurfacePatch ( - "empty", word(patchName), patchi ); diff --git a/src/surfMesh/triSurface/interfaces/NAS/readNAS.C b/src/surfMesh/triSurface/interfaces/NAS/readNAS.C index c98b11f08c..ae55c60ca3 100644 --- a/src/surfMesh/triSurface/interfaces/NAS/readNAS.C +++ b/src/surfMesh/triSurface/interfaces/NAS/readNAS.C @@ -372,16 +372,10 @@ bool triSurface::readNAS(const fileName& fName) // Convert groupToPatch to patchList. geometricSurfacePatchList patches(nPatches); - forAllConstIter(Map, groupToName, iter) + forAllConstIters(groupToName, iter) { - label patchi = groupToPatch[iter.key()]; - - patches[patchi] = geometricSurfacePatch - ( - "empty", - iter(), - patchi - ); + const label patchIdx = groupToPatch[iter.key()]; + patches[patchIdx] = geometricSurfacePatch(iter.object(), patchIdx); } Info<< "patches:" << patches << endl; diff --git a/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C b/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C index 907669961b..f13f1535bd 100644 --- a/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C +++ b/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C @@ -1,4 +1,3 @@ - /*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox @@ -172,19 +171,19 @@ bool Foam::triSurface::readOBJ(const fileName& OBJfileName) if (maxGroupID == 0) { - // Generate default patch - patches.setSize(1); - patches[0] = geometricSurfacePatch("empty", "patch0", 0); + // Add single (default) patch + patches = { geometricSurfacePatch("patch0", 0) }; } else { - forAllConstIter(HashTable