ENH: provide defaultName() static method for patches, zones

- consistent way of writing "patch" + Foam::name(id) etc.
This commit is contained in:
Mark Olesen
2020-01-16 13:24:23 +01:00
parent 2a98c4e665
commit f0be8679f6
24 changed files with 105 additions and 62 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -521,7 +521,7 @@ int main(int argc, char *argv[])
} }
boundary[patchi] = patchFaces; boundary[patchi] = patchFaces;
patchNames[patchi] = "patch" + Foam::name(patchi + 1); patchNames[patchi] = polyPatch::defaultName(patchi + 1);
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -1465,7 +1466,7 @@ int main(int argc, char *argv[])
physicalNames.lookup physicalNames.lookup
( (
patchToPhys[patchi], patchToPhys[patchi],
"patch" + Foam::name(patchi) // default name polyPatch::defaultName(patchi)
); );
Info<< "Patch " << patchi << " gets name " Info<< "Patch " << patchi << " gets name "

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -263,7 +264,7 @@ int main(int argc, char *argv[])
forAll(patchNames, patchi) forAll(patchNames, patchi)
{ {
patchNames[patchi] = word("patch") + name(patchi); patchNames[patchi] = polyPatch::defaultName(patchi);
} }
wordList patchTypes(nPatches, polyPatch::typeName); wordList patchTypes(nPatches, polyPatch::typeName);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -483,8 +483,8 @@ int main(int argc, char *argv[])
forAllConstIters(regionToPatch, iter) forAllConstIters(regionToPatch, iter)
{ {
Info<< " region:" << iter.key() << '\t' << "patch:" Info<< " region:" << iter.key()
<< iter() << endl; << '\t' << "patch:" << iter.val() << nl;
} }
Info<< endl; Info<< endl;
@ -495,7 +495,7 @@ int main(int argc, char *argv[])
forAll(patchNames, patchi) forAll(patchNames, patchi)
{ {
patchNames[patchi] = "patch" + Foam::name(patchi); patchNames[patchi] = polyPatch::defaultName(patchi);
} }
wordList patchTypes(nPatches, polyPatch::typeName); wordList patchTypes(nPatches, polyPatch::typeName);

View File

@ -58,7 +58,7 @@ Info<< "Creating patch dictionaries" << endl;
wordList patchNames(boundary.size()); wordList patchNames(boundary.size());
forAll(patchNames, patchi) forAll(patchNames, patchi)
{ {
patchNames[patchi] = "patch" + Foam::name(patchi); patchNames[patchi] = polyPatch::defaultName(patchi);
} }
PtrList<dictionary> boundaryDicts(boundary.size()); PtrList<dictionary> boundaryDicts(boundary.size());
@ -69,11 +69,11 @@ forAll(boundaryDicts, patchi)
word nbrPatchName; word nbrPatchName;
if (patchi % 2 == 0) if (patchi % 2 == 0)
{ {
nbrPatchName = "patch" + Foam::name(patchi + 1); nbrPatchName = polyPatch::defaultName(patchi + 1);
} }
else else
{ {
nbrPatchName = "patch" + Foam::name(patchi - 1); nbrPatchName = polyPatch::defaultName(patchi - 1);
} }
patchDict.add("type", cyclicPolyPatch::typeName); patchDict.add("type", cyclicPolyPatch::typeName);

View File

@ -78,7 +78,7 @@ void Foam::searchableSurfaceModifiers::cut::triangulate
{ {
patches[patchi] = geometricSurfacePatch patches[patchi] = geometricSurfacePatch
( (
"patch" + Foam::name(patchi), geometricSurfacePatch::defaultName(patchi),
patchi patchi
); );
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -72,11 +73,11 @@ int main(int argc, char *argv[])
{ {
const geometricSurfacePatch& pp = patches[patchi]; const geometricSurfacePatch& pp = patches[patchi];
word patchName = pp.name(); word patchName(pp.name());
if (patchName.empty()) if (patchName.empty())
{ {
patchName = "patch" + Foam::name(patchi); patchName = geometricSurfacePatch::defaultName(patchi);
} }
fileName outFile(surfBase + '_' + patchName + '.' + extension); fileName outFile(surfBase + '_' + patchName + '.' + extension);

View File

@ -70,6 +70,20 @@ class patchIdentifier
public: public:
// Static Member Functions
//- Default patch name: "patch" or "patchN"
static word defaultName(const label n = -1)
{
return
(
n < 0
? word("patch", false)
: word("patch" + std::to_string(n), false)
);
}
// Generated Methods // Generated Methods
//- Copy construct //- Copy construct

View File

@ -71,6 +71,20 @@ public:
static constexpr const char* const emptyType = "empty"; static constexpr const char* const emptyType = "empty";
// Static Member Functions
//- Default patch name: "patch" or "patchN"
static word defaultName(const label n = -1)
{
return
(
n < 0
? word("patch", false)
: word("patch" + std::to_string(n), false)
);
}
// Public Classes // Public Classes
//- Helper to convert identifier types as an operation //- Helper to convert identifier types as an operation

View File

@ -78,6 +78,20 @@ public:
static constexpr const char* const emptyType = "empty"; static constexpr const char* const emptyType = "empty";
// Static Member Functions
//- Default zone name: "zone" or "zoneN"
static word defaultName(const label n = -1)
{
return
(
n < 0
? word("zone", false)
: word("zone" + std::to_string(n), false)
);
}
// Generated Methods // Generated Methods
//- Copy construct //- Copy construct

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -2419,7 +2419,7 @@ void Foam::ccm::reader::addPatches
// provide some fallback values // provide some fallback values
forAll(newPatches, patchI) forAll(newPatches, patchI)
{ {
const word fallbackName("patch" + Foam::name(patchI)); const word fallbackName(polyPatch::defaultName(patchI));
word patchName; word patchName;
word patchType; word patchType;

View File

@ -680,11 +680,11 @@ void Foam::boundaryMesh::readTriSurface(const fileName& fName)
patchi, patchi,
new boundaryPatch new boundaryPatch
( (
"patch" + name(patchi), geometricSurfacePatch::defaultName(patchi),
patchi, patchi,
0, 0,
0, 0,
"empty" geometricSurfacePatch::emptyType
) )
); );
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -128,15 +128,14 @@ bool Foam::fileFormats::STLReader::readBINARY
// interpret STL attribute as a zone // interpret STL attribute as a zone
const label origId = stlTri.attrib(); const label origId = stlTri.attrib();
Map<label>::const_iterator fnd = lookup.find(origId); auto fnd = lookup.cfind(origId);
if (fnd != lookup.end()) if (fnd.found())
{ {
if (zoneI != fnd()) if (zoneI != *fnd)
{ {
// group appeared out of order sorted_ = false; // Group appeared out of order
sorted_ = false;
} }
zoneI = fnd(); zoneI = *fnd;
} }
else else
{ {

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd. Copyright (C) 2017-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -542,7 +542,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::voxelMeshSearch::makeMesh
wordList patchNames(boundary.size()); wordList patchNames(boundary.size());
forAll(patchNames, patchi) forAll(patchNames, patchi)
{ {
patchNames[patchi] = "patch" + Foam::name(patchi); patchNames[patchi] = polyPatch::defaultName(patchi);
} }
PtrList<dictionary> boundaryDicts(boundary.size()); PtrList<dictionary> boundaryDicts(boundary.size());

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -313,7 +313,7 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher)
patchi, patchi,
( (
patches[patchi].name().empty() patches[patchi].name().empty()
? word::printf("patch%d", patchi) ? geometricSurfacePatch::defaultName(patchi)
: patches[patchi].name() : patches[patchi].name()
) )
); );
@ -343,7 +343,11 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher)
{ {
// This shouldn't happen // This shouldn't happen
zoneSizes.insert(regionid, 1); zoneSizes.insert(regionid, 1);
zoneNames.set(regionid, word::printf("patch%d", regionid)); zoneNames.set
(
regionid,
geometricSurfacePatch::defaultName(regionid)
);
} }
// Store new faces compact // Store new faces compact
@ -388,7 +392,7 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher)
} }
if (name.empty()) if (name.empty())
{ {
name = word::printf("patch%d", regionid); name = geometricSurfacePatch::defaultName(regionid);
} }
zoneLst[zoneI] = surfZone zoneLst[zoneI] = surfZone

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -307,7 +307,7 @@ bool Foam::discreteSurface::update(const meshSearch& meshSearcher)
patchi, patchi,
( (
patches[patchi].name().empty() patches[patchi].name().empty()
? word::printf("patch%d", patchi) ? geometricSurfacePatch::defaultName(patchi)
: patches[patchi].name() : patches[patchi].name()
) )
); );
@ -328,10 +328,10 @@ bool Foam::discreteSurface::update(const meshSearch& meshSearcher)
const triSurface::FaceType& f = s[facei]; const triSurface::FaceType& f = s[facei];
const label regionid = f.region(); const label regionid = f.region();
Map<label>::iterator fnd = zoneSizes.find(regionid); auto fnd = zoneSizes.find(regionid);
if (fnd != zoneSizes.end()) if (fnd.found())
{ {
fnd()++; ++(*fnd);
} }
else else
{ {
@ -340,7 +340,7 @@ bool Foam::discreteSurface::update(const meshSearch& meshSearcher)
zoneNames.set zoneNames.set
( (
regionid, regionid,
word::printf("patch%d", regionid) geometricSurfacePatch::defaultName(regionid)
); );
} }
@ -380,15 +380,10 @@ bool Foam::discreteSurface::update(const meshSearch& meshSearcher)
// No negative regionids, so Map<label> sorts properly // No negative regionids, so Map<label> sorts properly
const label regionid = iter.key(); const label regionid = iter.key();
word name; word name(zoneNames.lookup(regionid, word::null));
Map<word>::const_iterator fnd = zoneNames.find(regionid);
if (fnd != zoneNames.end())
{
name = fnd();
}
if (name.empty()) if (name.empty())
{ {
name = word::printf("patch%d", regionid); name = geometricSurfacePatch::defaultName(regionid);
} }
zoneLst[zoneI] = surfZone zoneLst[zoneI] = surfZone

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -175,7 +175,7 @@ void Foam::MeshedSurface<Face>::addZones
{ {
zones[nZone] = surfZone zones[nZone] = surfZone
( (
word("zone") + ::Foam::name(nZone), surfZone::defaultName(nZone),
sizes[zoneI], sizes[zoneI],
start, start,
nZone nZone

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -368,7 +368,7 @@ void Foam::UnsortedMeshedSurface<Face>::setZones
{ {
zoneToc_[zonei] = surfZoneIdentifier zoneToc_[zonei] = surfZoneIdentifier
( (
"zone" + ::Foam::name(zonei), surfZoneIdentifier::defaultName(zonei),
zonei zonei
); );
@ -496,7 +496,7 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones
zoneNames.lookup zoneNames.lookup
( (
origId, origId,
"zone" + ::Foam::name(zonei) // default name surfZoneIdentifier::defaultName(zonei)
); );
zoneLst[zonei] = surfZone zoneLst[zonei] = surfZone

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -102,7 +102,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
for (label zoneI = 0; zoneI < nZones; ++zoneI) for (label zoneI = 0; zoneI < nZones; ++zoneI)
{ {
names[zoneI] = word("zone") + Foam::name(zoneI); names[zoneI] = surfZone::defaultName(zoneI);
args = cueToOrDie(is, "OBJECT", "while reading " + names[zoneI]); args = cueToOrDie(is, "OBJECT", "while reading " + names[zoneI]);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -228,12 +228,12 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
List<surfZoneIdentifier> newZones(maxZone+1); List<surfZoneIdentifier> newZones(maxZone+1);
forAll(newZones, zoneI) forAll(newZones, zonei)
{ {
newZones[zoneI] = surfZoneIdentifier newZones[zonei] = surfZoneIdentifier
( (
"zone" + ::Foam::name(zoneI), surfZoneIdentifier::defaultName(zonei),
zoneI zonei
); );
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd. Copyright (C) 2017-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -398,7 +398,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
else else
{ {
names[zoneId] = word("zone") + ::Foam::name(zoneId); names[zoneId] = surfZone::defaultName(zoneId);
} }
} }

View File

@ -125,7 +125,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
{ {
if (zoneId != *iterGroup) if (zoneId != *iterGroup)
{ {
sorted = false; // group appeared out of order sorted = false; // Group appeared out of order
} }
zoneId = *iterGroup; zoneId = *iterGroup;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -160,7 +160,7 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
wordList zoneNames(nZones); wordList zoneNames(nZones);
forAll(zoneNames, i) forAll(zoneNames, i)
{ {
zoneNames[i] = "zone" + Foam::name(i); zoneNames[i] = surfZone::defaultName(i);
} }

View File

@ -358,7 +358,7 @@ Foam::triSurface::calcPatches(labelList& faceMap) const
} }
else else
{ {
newPatch.name() = word("patch") + Foam::name(newPatchi); newPatch.name() = surfacePatch::defaultName(newPatchi);
} }
if if