ENH: align constructors of geometricSurfacePatch with surfZoneIdentifier

- both classes are nearly identical and should be merged in the future.
This commit is contained in:
Mark Olesen
2017-05-26 09:10:48 +02:00
parent 8d3e106166
commit 5efe22c2f0
11 changed files with 168 additions and 140 deletions

View File

@ -106,48 +106,39 @@ void Foam::surfZoneIdentifier::write(Ostream& os) const
} }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
// needed for list output bool Foam::operator==(const surfZoneIdentifier& a, const surfZoneIdentifier& b)
bool Foam::surfZoneIdentifier::operator!=
(
const surfZoneIdentifier& rhs
) const
{
return !(*this == rhs);
}
bool Foam::surfZoneIdentifier::operator==
(
const surfZoneIdentifier& rhs
) const
{ {
return return
( (
(index() == rhs.index()) (a.index() == b.index())
&& (name() == rhs.name()) && (a.name() == b.name())
&& (geometricType() == rhs.geometricType()) && (a.geometricType() == b.geometricType())
); );
} }
bool Foam::operator!=(const surfZoneIdentifier& a, const surfZoneIdentifier& b)
{
return !(a == b);
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, surfZoneIdentifier& obj) Foam::Istream& Foam::operator>>(Istream& is, surfZoneIdentifier& obj)
{ {
is >> obj.name_ >> obj.geometricType_; is >> obj.name_ >> obj.geometricType_;
return is; return is;
} }
Foam::Ostream& Foam::operator<<(Ostream& os, const surfZoneIdentifier& obj) 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 << nl << obj.name_ << nl << obj.geometricType_;
os.check(FUNCTION_NAME);
os.check("Ostream& operator<<(Ostream&, const surfZoneIdentifier&)");
return os; return os;
} }

View File

@ -51,8 +51,8 @@ class dictionary;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class surfZoneIdentifier; class surfZoneIdentifier;
Istream& operator>>(Istream&, surfZoneIdentifier&); Istream& operator>>(Istream& is, surfZoneIdentifier& p);
Ostream& operator<<(Ostream&, const surfZoneIdentifier&); Ostream& operator<<(Ostream& os, const surfZoneIdentifier& p);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class surfZoneIdentifier Declaration Class surfZoneIdentifier Declaration
@ -94,21 +94,20 @@ public:
const word& name, const word& name,
const label index, const label index,
const word& geometricType = word::null const word& geometricType = word::null
); );
//- Construct from dictionary //- Construct from dictionary
surfZoneIdentifier surfZoneIdentifier
( (
const word& name, const word& name,
const dictionary&, const dictionary& dict,
const label index const label index
); );
//- Construct from another zone identifier, resetting the index //- Copy construct from another zone identifier, resetting the index
surfZoneIdentifier surfZoneIdentifier
( (
const surfZoneIdentifier&, const surfZoneIdentifier& p,
const label index const label index
); );
@ -156,14 +155,8 @@ public:
} }
//- Write surfZoneIdentifier as a dictionary //- Write identifier as a dictionary
void write(Ostream&) const; void write(Ostream& os) const;
// Member Operators
bool operator!=(const surfZoneIdentifier&) const;
bool operator==(const surfZoneIdentifier&) const;
// Ostream Operator // Ostream Operator
@ -171,20 +164,29 @@ public:
//- Read name/type. //- Read name/type.
friend Istream& operator>> friend Istream& operator>>
( (
Istream&, Istream& is,
surfZoneIdentifier& surfZoneIdentifier& ob
); );
//- Write name/type. //- Write name/type.
friend Ostream& operator<< friend Ostream& operator<<
( (
Ostream&, Ostream& os,
const surfZoneIdentifier& 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 } // End namespace Foam

View File

@ -327,9 +327,8 @@ void Foam::UnsortedMeshedSurface<Face>::setOneZone()
zoneName = "zone0"; zoneName = "zone0";
} }
// set single default zone // Set single default zone
zoneToc_.setSize(1); zoneToc_ = { surfZoneIdentifier(zoneName, 0) };
zoneToc_[0] = surfZoneIdentifier(zoneName, 0);
} }

View File

@ -183,7 +183,7 @@ bool triSurface::readAC(const fileName& ACfileName)
); );
// Object global values // Object global values
string patchName = string("patch") + name(patchi); string patchName = string("patch") + Foam::name(patchi);
label nVerts = 0; label nVerts = 0;
tensor rot(I); tensor rot(I);
vector loc(0, 0, 0); vector loc(0, 0, 0);
@ -319,7 +319,6 @@ bool triSurface::readAC(const fileName& ACfileName)
patches[patchi] = patches[patchi] =
geometricSurfacePatch geometricSurfacePatch
( (
"empty",
word(patchName), word(patchName),
patchi patchi
); );

View File

@ -372,16 +372,10 @@ bool triSurface::readNAS(const fileName& fName)
// Convert groupToPatch to patchList. // Convert groupToPatch to patchList.
geometricSurfacePatchList patches(nPatches); geometricSurfacePatchList patches(nPatches);
forAllConstIter(Map<word>, groupToName, iter) forAllConstIters(groupToName, iter)
{ {
label patchi = groupToPatch[iter.key()]; const label patchIdx = groupToPatch[iter.key()];
patches[patchIdx] = geometricSurfacePatch(iter.object(), patchIdx);
patches[patchi] = geometricSurfacePatch
(
"empty",
iter(),
patchi
);
} }
Info<< "patches:" << patches << endl; Info<< "patches:" << patches << endl;

View File

@ -1,4 +1,3 @@
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
@ -172,19 +171,19 @@ bool Foam::triSurface::readOBJ(const fileName& OBJfileName)
if (maxGroupID == 0) if (maxGroupID == 0)
{ {
// Generate default patch // Add single (default) patch
patches.setSize(1); patches = { geometricSurfacePatch("patch0", 0) };
patches[0] = geometricSurfacePatch("empty", "patch0", 0);
} }
else else
{ {
forAllConstIter(HashTable<label>, groupToPatch, iter) forAllConstIters(groupToPatch, iter)
{ {
patches[iter()] = geometricSurfacePatch const label patchIdx = iter.object();
patches[patchIdx] = geometricSurfacePatch
( (
"empty",
iter.key(), iter.key(),
iter() patchIdx
); );
} }
} }

View File

@ -163,7 +163,7 @@ bool Foam::triSurface::readTRI(const fileName& TRIfileName)
forAll(names, nameI) forAll(names, nameI)
{ {
patches_[nameI].name() = names[nameI]; patches_[nameI].name() = names[nameI];
patches_[nameI].geometricType() = "empty"; patches_[nameI].geometricType() = geometricSurfacePatch::emptyType;
} }
return true; return true;

View File

@ -67,13 +67,13 @@ bool Foam::triSurface::readVTK(const fileName& fName)
patches[zoneI] = geometricSurfacePatch patches[zoneI] = geometricSurfacePatch
( (
zone.geometricType().size() ? zone.geometricType() : "empty",
regionName, regionName,
zoneI zoneI,
zone.geometricType()
); );
// Set triangle regions // 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; tris[i].region() = zoneI;
} }
@ -81,11 +81,9 @@ bool Foam::triSurface::readVTK(const fileName& fName)
} }
else else
{ {
// Add single patch // Add single (default) patch
patches.setSize(1);
patches[0] = geometricSurfacePatch("empty", "patch0", 0);
// Triangle regions already set to 0 // Triangle regions already set to 0
patches = { geometricSurfacePatch("patch0", 0) };
} }

View File

@ -26,28 +26,54 @@ License
#include "geometricSurfacePatch.H" #include "geometricSurfacePatch.H"
#include "dictionary.H" #include "dictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(geometricSurfacePatch, 0); defineTypeNameAndDebug(geometricSurfacePatch, 0);
}
const Foam::word Foam::geometricSurfacePatch::emptyType = "empty";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct null Foam::geometricSurfacePatch::geometricSurfacePatch()
geometricSurfacePatch::geometricSurfacePatch()
: :
geometricType_("empty"), geometricType_(emptyType),
name_("patch"), name_("patch"),
index_(0) index_(0)
{} {}
// Construct from components Foam::geometricSurfacePatch::geometricSurfacePatch(const label index)
geometricSurfacePatch::geometricSurfacePatch :
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& geometricType,
const word& name, const word& name,
@ -61,13 +87,16 @@ geometricSurfacePatch::geometricSurfacePatch
{ {
if (geometricType_.empty()) if (geometricType_.empty())
{ {
geometricType_ = "empty"; geometricType_ = emptyType;
} }
} }
// Construct from Istream Foam::geometricSurfacePatch::geometricSurfacePatch
geometricSurfacePatch::geometricSurfacePatch(Istream& is, const label index) (
Istream& is,
const label index
)
: :
geometricType_(is), geometricType_(is),
name_(is), name_(is),
@ -75,89 +104,82 @@ geometricSurfacePatch::geometricSurfacePatch(Istream& is, const label index)
{ {
if (geometricType_.empty()) if (geometricType_.empty())
{ {
geometricType_ = "empty"; geometricType_ = emptyType;
} }
} }
// Construct from dictionary Foam::geometricSurfacePatch::geometricSurfacePatch
geometricSurfacePatch::geometricSurfacePatch
( (
const word& name, const word& name,
const dictionary& dict, const dictionary& dict,
const label index const label index
) )
: :
geometricType_(dict.lookup("geometricType")), geometricType_(emptyType),
name_(name), name_(name),
index_(index) index_(index)
{ {
if (geometricType_.empty()) dict.readIfPresent("geometricType", geometricType_);
{
geometricType_ = "empty";
}
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Write void Foam::geometricSurfacePatch::write(Ostream& os) const
void geometricSurfacePatch::write(Ostream& os) const
{ {
os << nl << name_ os << nl << name_
<< nl << geometricType_; << 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) bool Foam::operator==
const (
{ const geometricSurfacePatch& a,
return !(*this == p); const geometricSurfacePatch& b
} )
bool Foam::geometricSurfacePatch::operator==(const geometricSurfacePatch& p)
const
{ {
return return
( (
(geometricType() == p.geometricType()) (a.geometricType() == b.geometricType())
&& (name() == p.name()) && (a.name() == b.name())
); );
} }
bool Foam::operator!=
(
const geometricSurfacePatch& a,
const geometricSurfacePatch& b
)
{
return !(a == b);
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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; return is;
} }
Ostream& operator<<(Ostream& os, const geometricSurfacePatch& gp) Foam::Ostream& Foam::operator<<(Ostream& os, const geometricSurfacePatch& p)
{ {
gp.write(os); p.write(os);
os.check os.check(FUNCTION_NAME);
(
"Ostream& operator<<(Ostream& f, const geometricSurfacePatch& gp)"
);
return os; return os;
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -47,8 +47,14 @@ namespace Foam
class dictionary; 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 class geometricSurfacePatch
@ -66,6 +72,12 @@ class geometricSurfacePatch
public: public:
// Public data
//- The name for an 'empty' type
static const word emptyType;
//- Runtime type information //- Runtime type information
ClassName("geometricSurfacePatch"); ClassName("geometricSurfacePatch");
@ -75,6 +87,17 @@ public:
//- Construct null //- Construct null
geometricSurfacePatch(); 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 //- Construct from components
geometricSurfacePatch geometricSurfacePatch
( (
@ -83,9 +106,6 @@ public:
const label index const label index
); );
//- Construct from Istream
geometricSurfacePatch(Istream&, const label index);
//- Construct from dictionary //- Construct from dictionary
geometricSurfacePatch geometricSurfacePatch
( (
@ -94,6 +114,9 @@ public:
const label index const label index
); );
//- Construct from Istream
geometricSurfacePatch(Istream& is, const label index);
// Member Functions // Member Functions
@ -109,52 +132,53 @@ public:
return name_; return name_;
} }
//- Return the type of the patch //- Return the geometric type of the patch
const word& geometricType() const const word& geometricType() const
{ {
return geometricType_; return geometricType_;
} }
//- Return the type of the patch //- Return the geometric type of the patch for modification
word& geometricType() word& geometricType()
{ {
return 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 label index() const
{ {
return index_; 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() label& index()
{ {
return index_; return index_;
} }
//- Write //- Write
void write(Ostream&) const; void write(Ostream& os) const;
//- Write dictionary //- Write dictionary
void writeDict(Ostream&) const; void writeDict(Ostream& os) const;
// Member Operators
bool operator!=(const geometricSurfacePatch&) const;
//- compare.
bool operator==(const geometricSurfacePatch&) const;
// Ostream Operator // Ostream Operator
friend Ostream& operator<<(Ostream&, const geometricSurfacePatch&); friend Istream& operator>>(Istream& is, geometricSurfacePatch& p);
friend Istream& operator>>(Istream&, geometricSurfacePatch&); friend Ostream& operator<<(Ostream& os, const geometricSurfacePatch& p);
}; };
// Global Operators
//- Compare patches for equality
bool operator==(const geometricSurfacePatch& a, const geometricSurfacePatch& b);
//- Compare patches for inequality
bool operator!=(const geometricSurfacePatch& a, const geometricSurfacePatch& b);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -623,7 +623,7 @@ Foam::triSurface::calcPatches(labelList& faceMap) const
} }
else else
{ {
newPatch.geometricType() = "empty"; newPatch.geometricType() = geometricSurfacePatch::emptyType;
} }
startFacei += newPatch.size(); startFacei += newPatch.size();