Commit f0be8679 authored by Mark Olesen's avatar Mark Olesen
Browse files

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

- consistent way of writing "patch" + Foam::name(id) etc.
parent 2a98c4e6
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -521,7 +521,7 @@ int main(int argc, char *argv[])
}
boundary[patchi] = patchFaces;
patchNames[patchi] = "patch" + Foam::name(patchi + 1);
patchNames[patchi] = polyPatch::defaultName(patchi + 1);
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -1465,7 +1466,7 @@ int main(int argc, char *argv[])
physicalNames.lookup
(
patchToPhys[patchi],
"patch" + Foam::name(patchi) // default name
polyPatch::defaultName(patchi)
);
Info<< "Patch " << patchi << " gets name "
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -263,7 +264,7 @@ int main(int argc, char *argv[])
forAll(patchNames, patchi)
{
patchNames[patchi] = word("patch") + name(patchi);
patchNames[patchi] = polyPatch::defaultName(patchi);
}
wordList patchTypes(nPatches, polyPatch::typeName);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -483,8 +483,8 @@ int main(int argc, char *argv[])
forAllConstIters(regionToPatch, iter)
{
Info<< " region:" << iter.key() << '\t' << "patch:"
<< iter() << endl;
Info<< " region:" << iter.key()
<< '\t' << "patch:" << iter.val() << nl;
}
Info<< endl;
......@@ -495,7 +495,7 @@ int main(int argc, char *argv[])
forAll(patchNames, patchi)
{
patchNames[patchi] = "patch" + Foam::name(patchi);
patchNames[patchi] = polyPatch::defaultName(patchi);
}
wordList patchTypes(nPatches, polyPatch::typeName);
......
......@@ -58,7 +58,7 @@ Info<< "Creating patch dictionaries" << endl;
wordList patchNames(boundary.size());
forAll(patchNames, patchi)
{
patchNames[patchi] = "patch" + Foam::name(patchi);
patchNames[patchi] = polyPatch::defaultName(patchi);
}
PtrList<dictionary> boundaryDicts(boundary.size());
......@@ -69,11 +69,11 @@ forAll(boundaryDicts, patchi)
word nbrPatchName;
if (patchi % 2 == 0)
{
nbrPatchName = "patch" + Foam::name(patchi + 1);
nbrPatchName = polyPatch::defaultName(patchi + 1);
}
else
{
nbrPatchName = "patch" + Foam::name(patchi - 1);
nbrPatchName = polyPatch::defaultName(patchi - 1);
}
patchDict.add("type", cyclicPolyPatch::typeName);
......
......@@ -78,7 +78,7 @@ void Foam::searchableSurfaceModifiers::cut::triangulate
{
patches[patchi] = geometricSurfacePatch
(
"patch" + Foam::name(patchi),
geometricSurfacePatch::defaultName(patchi),
patchi
);
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -72,11 +73,11 @@ int main(int argc, char *argv[])
{
const geometricSurfacePatch& pp = patches[patchi];
word patchName = pp.name();
word patchName(pp.name());
if (patchName.empty())
{
patchName = "patch" + Foam::name(patchi);
patchName = geometricSurfacePatch::defaultName(patchi);
}
fileName outFile(surfBase + '_' + patchName + '.' + extension);
......
......@@ -70,6 +70,20 @@ class patchIdentifier
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
//- Copy construct
......
......@@ -71,6 +71,20 @@ public:
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
//- Helper to convert identifier types as an operation
......
......@@ -78,6 +78,20 @@ public:
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
//- Copy construct
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -2419,7 +2419,7 @@ void Foam::ccm::reader::addPatches
// provide some fallback values
forAll(newPatches, patchI)
{
const word fallbackName("patch" + Foam::name(patchI));
const word fallbackName(polyPatch::defaultName(patchI));
word patchName;
word patchType;
......
......@@ -680,11 +680,11 @@ void Foam::boundaryMesh::readTriSurface(const fileName& fName)
patchi,
new boundaryPatch
(
"patch" + name(patchi),
geometricSurfacePatch::defaultName(patchi),
patchi,
0,
0,
"empty"
geometricSurfacePatch::emptyType
)
);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -128,15 +128,14 @@ bool Foam::fileFormats::STLReader::readBINARY
// interpret STL attribute as a zone
const label origId = stlTri.attrib();
Map<label>::const_iterator fnd = lookup.find(origId);
if (fnd != lookup.end())
auto fnd = lookup.cfind(origId);
if (fnd.found())
{
if (zoneI != fnd())
if (zoneI != *fnd)
{
// group appeared out of order
sorted_ = false;
sorted_ = false; // Group appeared out of order
}
zoneI = fnd();
zoneI = *fnd;
}
else
{
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -542,7 +542,7 @@ Foam::autoPtr<Foam::fvMesh> Foam::voxelMeshSearch::makeMesh
wordList patchNames(boundary.size());
forAll(patchNames, patchi)
{
patchNames[patchi] = "patch" + Foam::name(patchi);
patchNames[patchi] = polyPatch::defaultName(patchi);
}
PtrList<dictionary> boundaryDicts(boundary.size());
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -313,7 +313,7 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher)
patchi,
(
patches[patchi].name().empty()
? word::printf("patch%d", patchi)
? geometricSurfacePatch::defaultName(patchi)
: patches[patchi].name()
)
);
......@@ -343,7 +343,11 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher)
{
// This shouldn't happen
zoneSizes.insert(regionid, 1);
zoneNames.set(regionid, word::printf("patch%d", regionid));
zoneNames.set
(
regionid,
geometricSurfacePatch::defaultName(regionid)
);
}
// Store new faces compact
......@@ -388,7 +392,7 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher)
}
if (name.empty())
{
name = word::printf("patch%d", regionid);
name = geometricSurfacePatch::defaultName(regionid);
}
zoneLst[zoneI] = surfZone
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -307,7 +307,7 @@ bool Foam::discreteSurface::update(const meshSearch& meshSearcher)
patchi,
(
patches[patchi].name().empty()
? word::printf("patch%d", patchi)
? geometricSurfacePatch::defaultName(patchi)
: patches[patchi].name()
)
);
......@@ -328,10 +328,10 @@ bool Foam::discreteSurface::update(const meshSearch& meshSearcher)
const triSurface::FaceType& f = s[facei];
const label regionid = f.region();
Map<label>::iterator fnd = zoneSizes.find(regionid);
if (fnd != zoneSizes.end())
auto fnd = zoneSizes.find(regionid);
if (fnd.found())
{
fnd()++;
++(*fnd);
}
else
{
......@@ -340,7 +340,7 @@ bool Foam::discreteSurface::update(const meshSearch& meshSearcher)
zoneNames.set
(
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
const label regionid = iter.key();
word name;
Map<word>::const_iterator fnd = zoneNames.find(regionid);
if (fnd != zoneNames.end())
{
name = fnd();
}
word name(zoneNames.lookup(regionid, word::null));
if (name.empty())
{
name = word::printf("patch%d", regionid);
name = geometricSurfacePatch::defaultName(regionid);
}
zoneLst[zoneI] = surfZone
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -175,7 +175,7 @@ void Foam::MeshedSurface<Face>::addZones
{
zones[nZone] = surfZone
(
word("zone") + ::Foam::name(nZone),
surfZone::defaultName(nZone),
sizes[zoneI],
start,
nZone
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -368,7 +368,7 @@ void Foam::UnsortedMeshedSurface<Face>::setZones
{
zoneToc_[zonei] = surfZoneIdentifier
(
"zone" + ::Foam::name(zonei),
surfZoneIdentifier::defaultName(zonei),
zonei
);
......@@ -496,7 +496,7 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones
zoneNames.lookup
(
origId,
"zone" + ::Foam::name(zonei) // default name
surfZoneIdentifier::defaultName(zonei)
);
zoneLst[zonei] = surfZone
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -102,7 +102,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
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]);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2017 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -228,12 +228,12 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
List<surfZoneIdentifier> newZones(maxZone+1);
forAll(newZones, zoneI)
forAll(newZones, zonei)
{
newZones[zoneI] = surfZoneIdentifier
newZones[zonei] = surfZoneIdentifier
(
"zone" + ::Foam::name(zoneI),
zoneI
surfZoneIdentifier::defaultName(zonei),
zonei
);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment