diff --git a/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.C b/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.C index d9179f42748bb4b1763183e056ec596c2e556896..33e933ba23028f7a2466095f7012da0c71c82df3 100644 --- a/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.C +++ b/src/OpenFOAM/meshes/Identifiers/surface/surfZoneIdentifier.C @@ -106,29 +106,22 @@ void Foam::surfZoneIdentifier::write(Ostream& os) const } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // -// needed for list output -bool Foam::surfZoneIdentifier::operator!= -( - const surfZoneIdentifier& rhs -) const +bool Foam::operator==(const surfZoneIdentifier& a, const surfZoneIdentifier& b) { - return !(*this == rhs); + return + ( + (a.index() == b.index()) + && (a.name() == b.name()) + && (a.geometricType() == b.geometricType()) + ); } -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()) - ); + return !(a == b); } @@ -137,17 +130,15 @@ bool Foam::surfZoneIdentifier::operator== 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 a084e0196a3145d550df311ef9f9cc38d4e8fb08..26922f5aef8b54203d18411cbda4fbea72915ea1 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 7ac9a3e598c536a08433fe787aff92370aaeb6af..c1567931240a9f261ab8e0d049df0bc18b862d74 100644 --- a/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C +++ b/src/surfMesh/UnsortedMeshedSurface/UnsortedMeshedSurface.C @@ -327,9 +327,8 @@ void Foam::UnsortedMeshedSurface<Face>::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 8d300f08a1ac5ff2549c48655deb79a023504b39..f17128756885fe36e7dc0fab3939355d78e2f689 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 c98b11f08c05fcad586dff2ca36f4056f47ed802..ae55c60ca37df322cf937145351b660c19b096dd 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<word>, 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 907669961b6042bc35a1e5fe5a200a610acb356c..f13f1535bd29deb3c7c2f6815f3be7afc9f543a1 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<label>, groupToPatch, iter) + forAllConstIters(groupToPatch, iter) { - patches[iter()] = geometricSurfacePatch + const label patchIdx = iter.object(); + + patches[patchIdx] = geometricSurfacePatch ( - "empty", iter.key(), - iter() + patchIdx ); } } diff --git a/src/surfMesh/triSurface/interfaces/TRI/readTRI.C b/src/surfMesh/triSurface/interfaces/TRI/readTRI.C index f11ddcfd5ef3c898333accf756348159f4cb0eab..841ab10692d7f19f7791773180f017bba128fbf2 100644 --- a/src/surfMesh/triSurface/interfaces/TRI/readTRI.C +++ b/src/surfMesh/triSurface/interfaces/TRI/readTRI.C @@ -163,7 +163,7 @@ bool Foam::triSurface::readTRI(const fileName& TRIfileName) forAll(names, nameI) { patches_[nameI].name() = names[nameI]; - patches_[nameI].geometricType() = "empty"; + patches_[nameI].geometricType() = geometricSurfacePatch::emptyType; } return true; diff --git a/src/surfMesh/triSurface/interfaces/VTK/readVTK.C b/src/surfMesh/triSurface/interfaces/VTK/readVTK.C index b413641102d4754d23cda88562680cecce0221cb..d19b38e96c7d61705fe2c83091b65abda6f2493b 100644 --- a/src/surfMesh/triSurface/interfaces/VTK/readVTK.C +++ b/src/surfMesh/triSurface/interfaces/VTK/readVTK.C @@ -67,13 +67,13 @@ bool Foam::triSurface::readVTK(const fileName& fName) patches[zoneI] = geometricSurfacePatch ( - zone.geometricType().size() ? zone.geometricType() : "empty", regionName, - zoneI + zoneI, + zone.geometricType() ); // Set triangle regions - for (label i = zone.start(); i < zone.start()+zone.size(); i++) + for (label i = zone.start(); i < zone.start()+zone.size(); ++i) { tris[i].region() = zoneI; } @@ -81,11 +81,9 @@ bool Foam::triSurface::readVTK(const fileName& fName) } else { - // Add single patch - patches.setSize(1); - patches[0] = geometricSurfacePatch("empty", "patch0", 0); - + // Add single (default) patch // Triangle regions already set to 0 + patches = { geometricSurfacePatch("patch0", 0) }; } diff --git a/src/surfMesh/triSurface/patches/geometricSurfacePatch.C b/src/surfMesh/triSurface/patches/geometricSurfacePatch.C index 6bfd83e14c77407b669b35112ea265e5dcc527ff..45c3191b35df63422372eccfa4f0f67e5a31e39e 100644 --- a/src/surfMesh/triSurface/patches/geometricSurfacePatch.C +++ b/src/surfMesh/triSurface/patches/geometricSurfacePatch.C @@ -26,28 +26,54 @@ License #include "geometricSurfacePatch.H" #include "dictionary.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { +defineTypeNameAndDebug(geometricSurfacePatch, 0); +} -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // +const Foam::word Foam::geometricSurfacePatch::emptyType = "empty"; -defineTypeNameAndDebug(geometricSurfacePatch, 0); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Construct null -geometricSurfacePatch::geometricSurfacePatch() +Foam::geometricSurfacePatch::geometricSurfacePatch() : - geometricType_("empty"), + geometricType_(emptyType), name_("patch"), index_(0) {} -// Construct from components -geometricSurfacePatch::geometricSurfacePatch +Foam::geometricSurfacePatch::geometricSurfacePatch(const label index) +: + geometricType_(emptyType), + name_("patch"), + index_(index) +{} + + +Foam::geometricSurfacePatch::geometricSurfacePatch +( + const word& name, + const label index, + const word& geometricType +) +: + geometricType_(geometricType), + name_(name), + index_(index) + +{ + if (geometricType_.empty()) + { + geometricType_ = emptyType; + } +} + + +Foam::geometricSurfacePatch::geometricSurfacePatch ( const word& geometricType, const word& name, @@ -61,13 +87,16 @@ geometricSurfacePatch::geometricSurfacePatch { if (geometricType_.empty()) { - geometricType_ = "empty"; + geometricType_ = emptyType; } } -// Construct from Istream -geometricSurfacePatch::geometricSurfacePatch(Istream& is, const label index) +Foam::geometricSurfacePatch::geometricSurfacePatch +( + Istream& is, + const label index +) : geometricType_(is), name_(is), @@ -75,89 +104,82 @@ geometricSurfacePatch::geometricSurfacePatch(Istream& is, const label index) { if (geometricType_.empty()) { - geometricType_ = "empty"; + geometricType_ = emptyType; } } -// Construct from dictionary -geometricSurfacePatch::geometricSurfacePatch +Foam::geometricSurfacePatch::geometricSurfacePatch ( const word& name, const dictionary& dict, const label index ) : - geometricType_(dict.lookup("geometricType")), + geometricType_(emptyType), name_(name), index_(index) { - if (geometricType_.empty()) - { - geometricType_ = "empty"; - } + dict.readIfPresent("geometricType", geometricType_); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -// Write -void geometricSurfacePatch::write(Ostream& os) const +void Foam::geometricSurfacePatch::write(Ostream& os) const { os << nl << name_ << nl << geometricType_; } -void geometricSurfacePatch::writeDict(Ostream& os) const +void Foam::geometricSurfacePatch::writeDict(Ostream& os) const { - os << " geometricType " << geometricType_ << ';' << nl; + os.writeEntry("geometricType", geometricType_); } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // -bool Foam::geometricSurfacePatch::operator!=(const geometricSurfacePatch& p) - const +bool Foam::operator== +( + const geometricSurfacePatch& a, + const geometricSurfacePatch& b +) { - return !(*this == p); + return + ( + (a.geometricType() == b.geometricType()) + && (a.name() == b.name()) + ); } -bool Foam::geometricSurfacePatch::operator==(const geometricSurfacePatch& p) - const +bool Foam::operator!= +( + const geometricSurfacePatch& a, + const geometricSurfacePatch& b +) { - return - ( - (geometricType() == p.geometricType()) - && (name() == p.name()) - ); + return !(a == b); } // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // -Istream& operator>>(Istream& is, geometricSurfacePatch& gp) +Foam::Istream& Foam::operator>>(Istream& is, geometricSurfacePatch& p) { - is >> gp.name_ >> gp.geometricType_; - + is >> p.name_ >> p.geometricType_; return is; } -Ostream& operator<<(Ostream& os, const geometricSurfacePatch& gp) +Foam::Ostream& Foam::operator<<(Ostream& os, const geometricSurfacePatch& p) { - gp.write(os); - os.check - ( - "Ostream& operator<<(Ostream& f, const geometricSurfacePatch& gp)" - ); + p.write(os); + os.check(FUNCTION_NAME); return os; } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/src/surfMesh/triSurface/patches/geometricSurfacePatch.H b/src/surfMesh/triSurface/patches/geometricSurfacePatch.H index 3a54b71975b7e6d0e94b4cb472a1ece77f006762..3adfe452d7a4d77e9870040ab2d63abdc7db4318 100644 --- a/src/surfMesh/triSurface/patches/geometricSurfacePatch.H +++ b/src/surfMesh/triSurface/patches/geometricSurfacePatch.H @@ -47,8 +47,14 @@ namespace Foam class dictionary; +// Forward declaration of friend functions and operators +class geometricSurfacePatch; + +Istream& operator>>(Istream& is, geometricSurfacePatch& p); +Ostream& operator<<(Ostream& os, const geometricSurfacePatch& p); + /*---------------------------------------------------------------------------*\ - Class geometricSurfacePatch Declaration + Class geometricSurfacePatch Declaration \*---------------------------------------------------------------------------*/ class geometricSurfacePatch @@ -66,6 +72,12 @@ class geometricSurfacePatch public: + // Public data + + //- The name for an 'empty' type + static const word emptyType; + + //- Runtime type information ClassName("geometricSurfacePatch"); @@ -75,6 +87,17 @@ public: //- Construct null geometricSurfacePatch(); + //- Construct null with specified index + explicit geometricSurfacePatch(const label index); + + //- Construct from components + geometricSurfacePatch + ( + const word& name, + const label index, + const word& geometricType = word::null + ); + //- Construct from components geometricSurfacePatch ( @@ -83,9 +106,6 @@ public: const label index ); - //- Construct from Istream - geometricSurfacePatch(Istream&, const label index); - //- Construct from dictionary geometricSurfacePatch ( @@ -94,6 +114,9 @@ public: const label index ); + //- Construct from Istream + geometricSurfacePatch(Istream& is, const label index); + // Member Functions @@ -109,50 +132,51 @@ public: return name_; } - //- Return the type of the patch + //- Return the geometric type of the patch const word& geometricType() const { return geometricType_; } - //- Return the type of the patch + //- Return the geometric type of the patch for modification word& geometricType() { return geometricType_; } - //- Return the index of this patch in the boundaryMesh + //- Return the index of this patch in the surface mesh label index() const { return index_; } - //- Return the index of this patch in the boundaryMesh + //- Return the index of this patch in the surface mesh for modification label& index() { return index_; } //- Write - void write(Ostream&) const; + void write(Ostream& os) const; //- Write dictionary - void writeDict(Ostream&) const; + void writeDict(Ostream& os) const; - // Member Operators + // Ostream Operator - bool operator!=(const geometricSurfacePatch&) const; + friend Istream& operator>>(Istream& is, geometricSurfacePatch& p); + friend Ostream& operator<<(Ostream& os, const geometricSurfacePatch& p); +}; - //- compare. - bool operator==(const geometricSurfacePatch&) const; +// Global Operators - // Ostream Operator +//- Compare patches for equality +bool operator==(const geometricSurfacePatch& a, const geometricSurfacePatch& b); - friend Ostream& operator<<(Ostream&, const geometricSurfacePatch&); - friend Istream& operator>>(Istream&, geometricSurfacePatch&); -}; +//- Compare patches for inequality +bool operator!=(const geometricSurfacePatch& a, const geometricSurfacePatch& b); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/surfMesh/triSurface/triSurface.C b/src/surfMesh/triSurface/triSurface.C index d1ff1919c58515a85e360f933aa521c0fb7b4191..7590bba3a81cce0cdd2fd44b4e6e3344d297a2ed 100644 --- a/src/surfMesh/triSurface/triSurface.C +++ b/src/surfMesh/triSurface/triSurface.C @@ -623,7 +623,7 @@ Foam::triSurface::calcPatches(labelList& faceMap) const } else { - newPatch.geometricType() = "empty"; + newPatch.geometricType() = geometricSurfacePatch::emptyType; } startFacei += newPatch.size();