Commit 72f7d46f authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add operator[](const word&) as "find-by-name" to some classes

- affected: polyBoundary, fvBoundaryMesh, ZoneMesh, searchableSurfaces

  before:
      const label zoneI = mesh.cellZones().findZoneID(zoneName);
      const cellZone& cz = mesh.cellZones()[zoneI];
  after:
      const cellZone& cz = mesh.cellZones()[zoneName];
parent 845314b2
......@@ -63,8 +63,7 @@
<< exit(FatalIOError);
}
const labelList& faces =
mesh.faceZones()[magnetZonei];
const labelList& faces = mesh.faceZones()[magnetZonei];
const scalar muri = magnets[i].mur();
const scalar Mri = magnets[i].Mr().value();
......
Info << "Reading field p\n" << endl;
Info<< "Reading field p\n" << endl;
volScalarField p
(
IOobject
......@@ -12,7 +12,7 @@
mesh
);
Info << "Reading field U\n" << endl;
Info<< "Reading field U\n" << endl;
volVectorField U
(
IOobject
......@@ -34,7 +34,7 @@
setRefCell(p, mesh.solutionDict().subDict("SIMPLE"), pRefCell, pRefValue);
Info << "Reading field pa\n" << endl;
Info<< "Reading field pa\n" << endl;
volScalarField pa
(
IOobject
......@@ -48,7 +48,7 @@
mesh
);
Info << "Reading field Ua\n" << endl;
Info<< "Reading field Ua\n" << endl;
volVectorField Ua
(
IOobject
......@@ -84,10 +84,8 @@
dimensionedScalar lambda(laminarTransport.lookup("lambda"));
dimensionedScalar alphaMax(laminarTransport.lookup("alphaMax"));
const labelList& inletCells =
mesh.boundary()[mesh.boundaryMesh().findPatchID("inlet")].faceCells();
//const labelList& outletCells =
// mesh.boundary()[mesh.boundaryMesh().findPatchID("outlet")].faceCells();
const labelList& inletCells = mesh.boundary()["inlet"].faceCells();
//const labelList& outletCells = mesh.boundary()["outlet"].faceCells();
volScalarField alpha
(
......
......@@ -220,10 +220,7 @@ int main(int argc, char *argv[])
# include "createPolyMesh.H"
const word patchName = args[1];
label patchI = mesh.boundaryMesh().findPatchID(patchName);
const polyPatch& patch = mesh.boundaryMesh()[patchI];
const polyPatch& patch = mesh.boundaryMesh()[patchName];
Info<< "Patch:" << patch.name() << endl;
......
......@@ -20,8 +20,7 @@ Notes for fluentMeshToFoam with zone preservation
with the cellZones(), faceZones() and pointZones() member functions
- Example (Members from polyMesh.H and ZoneMesh.H):
label thisCellZoneID = mesh.cellZones().findZoneID("thisZoneName");
const labelList& thisCellZone = mesh.cellZones()[thisCellZoneID];
const labelList& thisCellZone = mesh.cellZones()["thisZoneName"];
- Zone integrity is preserved during mesh modification and decompomposition.
......
......@@ -27,10 +27,7 @@
// Master patch
const word masterPatchName(mergePatchPairs[pairI].first());
const polyPatch& masterPatch =
mesh.boundaryMesh()
[
mesh.boundaryMesh().findPatchID(masterPatchName)
];
mesh.boundaryMesh()[masterPatchName];
labelList isf(masterPatch.size());
......@@ -51,10 +48,7 @@
// Slave patch
const word slavePatchName(mergePatchPairs[pairI].second());
const polyPatch& slavePatch =
mesh.boundaryMesh()
[
mesh.boundaryMesh().findPatchID(slavePatchName)
];
mesh.boundaryMesh()[slavePatchName];
labelList osf(slavePatch.size());
......
......@@ -123,7 +123,7 @@ void createDummyFvMeshFiles(const polyMesh& mesh, const word& regionName)
label findPatchID(const polyBoundaryMesh& patches, const word& name)
{
label patchID = patches.findPatchID(name);
const label patchID = patches.findPatchID(name);
if (patchID == -1)
{
......
......@@ -849,8 +849,7 @@ int main(int argc, char *argv[])
nExtrudeFaces = 0;
forAll(zoneNames, i)
{
label zoneI = faceZones.findZoneID(zoneNames[i]);
const faceZone& fz = faceZones[zoneI];
const faceZone& fz = faceZones[zoneNames[i]];
forAll(fz, j)
{
extrudeTopPatchID[nExtrudeFaces] = interRegionTopPatch[i];
......
......@@ -107,7 +107,7 @@ void modifyOrAddFace
label findPatchID(const polyMesh& mesh, const word& name)
{
label patchI = mesh.boundaryMesh().findPatchID(name);
const label patchI = mesh.boundaryMesh().findPatchID(name);
if (patchI == -1)
{
......
......@@ -678,17 +678,17 @@ int main(int argc, char *argv[])
{
const dictionary& dict = patchSources[addedI];
word patchName(dict.lookup("name"));
const word patchName(dict.lookup("name"));
label destPatchI = patches.findPatchID(patchName);
if (destPatchI == -1)
{
FatalErrorIn(args.executable()) << "patch " << patchName
<< " not added. Problem." << abort(FatalError);
FatalErrorIn(args.executable())
<< "patch " << patchName << " not added. Problem."
<< abort(FatalError);
}
word sourceType(dict.lookup("constructFrom"));
const word sourceType(dict.lookup("constructFrom"));
if (sourceType == "patches")
{
......@@ -716,7 +716,7 @@ int main(int argc, char *argv[])
}
else if (sourceType == "set")
{
word setName(dict.lookup("set"));
const word setName(dict.lookup("set"));
faceSet faces(mesh, setName);
......
......@@ -85,12 +85,12 @@ label findEdge(const primitiveMesh& mesh, const label v0, const label v1)
// Checks whether patch present
void checkPatch(const polyBoundaryMesh& bMesh, const word& name)
{
label patchI = bMesh.findPatchID(name);
const label patchI = bMesh.findPatchID(name);
if (patchI == -1)
{
FatalErrorIn("checkPatch(const polyBoundaryMesh&, const word&)")
<< "Cannot find patch " << name << endl
<< "Cannot find patch " << name << nl
<< "It should be present but of zero size" << endl
<< "Valid patches are " << bMesh.names()
<< exit(FatalError);
......
......@@ -170,7 +170,7 @@ label addCellZone(const polyMesh& mesh, const word& name)
// Checks whether patch present
void checkPatch(const polyBoundaryMesh& bMesh, const word& name)
{
label patchI = bMesh.findPatchID(name);
const label patchI = bMesh.findPatchID(name);
if (patchI == -1)
{
......@@ -312,11 +312,7 @@ int main(int argc, char *argv[])
// Create and add face zones and mesh modifiers
// Master patch
const polyPatch& masterPatch =
mesh.boundaryMesh()
[
mesh.boundaryMesh().findPatchID(masterPatchName)
];
const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchName];
// Make list of masterPatch faces
labelList isf(masterPatch.size());
......@@ -373,11 +369,7 @@ int main(int argc, char *argv[])
);
// Slave patch
const polyPatch& slavePatch =
mesh.boundaryMesh()
[
mesh.boundaryMesh().findPatchID(slavePatchName)
];
const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchName];
labelList osf(slavePatch.size());
......
......@@ -55,7 +55,7 @@ void Foam::domainDecomposition::distributeCells()
forAll(pNames, i)
{
label patchI = patches.findPatchID(pNames[i]);
const label patchI = patches.findPatchID(pNames[i]);
if (patchI == -1)
{
......
......@@ -328,7 +328,7 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
VTK_POLYHEDRON,
nodeCount,
uniqueNodeIds.data(),
faceCount,
nFaces,
faceLabels.data()
);
#else
......
......@@ -236,7 +236,7 @@ Foam::channelIndex::channelIndex
forAll(patchNames, i)
{
label patchI = patches.findPatchID(patchNames[i]);
const label patchI = patches.findPatchID(patchNames[i]);
if (patchI == -1)
{
......@@ -254,7 +254,7 @@ Foam::channelIndex::channelIndex
forAll(patchNames, i)
{
const polyPatch& pp = patches[patches.findPatchID(patchNames[i])];
const polyPatch& pp = patches[patchNames[i]];
forAll(pp, j)
{
......
......@@ -65,8 +65,8 @@ int main(int argc, char *argv[])
{
mesh.readUpdate();
label patchi = mesh.boundaryMesh().findPatchID(patchName);
if (patchi < 0)
const label patchI = mesh.boundaryMesh().findPatchID(patchName);
if (patchI < 0)
{
FatalError
<< "Unable to find patch " << patchName << nl
......@@ -78,20 +78,20 @@ int main(int argc, char *argv[])
Info<< " Reading volScalarField " << fieldName << endl;
volScalarField field(fieldHeader, mesh);
scalar area = gSum(mesh.magSf().boundaryField()[patchi]);
scalar area = gSum(mesh.magSf().boundaryField()[patchI]);
scalar sumField = 0;
if (area > 0)
{
sumField = gSum
(
mesh.magSf().boundaryField()[patchi]
* field.boundaryField()[patchi]
mesh.magSf().boundaryField()[patchI]
* field.boundaryField()[patchI]
) / area;
}
Info<< " Average of " << fieldName << " over patch "
<< patchName << '[' << patchi << ']' << " = "
<< patchName << '[' << patchI << ']' << " = "
<< sumField << endl;
}
else
......
......@@ -67,8 +67,8 @@ int main(int argc, char *argv[])
{
mesh.readUpdate();
label patchi = mesh.boundaryMesh().findPatchID(patchName);
if (patchi < 0)
const label patchI = mesh.boundaryMesh().findPatchID(patchName);
if (patchI < 0)
{
FatalError
<< "Unable to find patch " << patchName << nl
......@@ -76,16 +76,16 @@ int main(int argc, char *argv[])
}
// Give patch area
if (isA<cyclicPolyPatch>(mesh.boundaryMesh()[patchi]))
if (isA<cyclicPolyPatch>(mesh.boundaryMesh()[patchI]))
{
Info<< " Cyclic patch vector area: " << nl;
label nFaces = mesh.boundaryMesh()[patchi].size();
label nFaces = mesh.boundaryMesh()[patchI].size();
vector sum1 = vector::zero;
vector sum2 = vector::zero;
for (label i=0; i<nFaces/2; i++)
{
sum1 += mesh.Sf().boundaryField()[patchi][i];
sum2 += mesh.Sf().boundaryField()[patchi][i+nFaces/2];
sum1 += mesh.Sf().boundaryField()[patchI][i];
sum2 += mesh.Sf().boundaryField()[patchI][i+nFaces/2];
}
reduce(sum1, sumOp<vector>());
reduce(sum2, sumOp<vector>());
......@@ -94,16 +94,16 @@ int main(int argc, char *argv[])
<< " - total = " << (sum1 + sum2) << ", "
<< mag(sum1 + sum2) << endl;
Info<< " Cyclic patch area magnitude = "
<< gSum(mesh.magSf().boundaryField()[patchi])/2.0 << endl;
<< gSum(mesh.magSf().boundaryField()[patchI])/2.0 << endl;
}
else
{
Info<< " Area vector of patch "
<< patchName << '[' << patchi << ']' << " = "
<< gSum(mesh.Sf().boundaryField()[patchi]) << endl;
<< patchName << '[' << patchI << ']' << " = "
<< gSum(mesh.Sf().boundaryField()[patchI]) << endl;
Info<< " Area magnitude of patch "
<< patchName << '[' << patchi << ']' << " = "
<< gSum(mesh.magSf().boundaryField()[patchi]) << endl;
<< patchName << '[' << patchI << ']' << " = "
<< gSum(mesh.magSf().boundaryField()[patchI]) << endl;
}
// Read field and calc integral
......@@ -116,21 +116,21 @@ int main(int argc, char *argv[])
Info<< " Integral of " << fieldName
<< " over vector area of patch "
<< patchName << '[' << patchi << ']' << " = "
<< patchName << '[' << patchI << ']' << " = "
<< gSum
(
mesh.Sf().boundaryField()[patchi]
*field.boundaryField()[patchi]
mesh.Sf().boundaryField()[patchI]
*field.boundaryField()[patchI]
)
<< nl;
Info<< " Integral of " << fieldName
<< " over area magnitude of patch "
<< patchName << '[' << patchi << ']' << " = "
<< patchName << '[' << patchI << ']' << " = "
<< gSum
(
mesh.magSf().boundaryField()[patchi]
*field.boundaryField()[patchi]
mesh.magSf().boundaryField()[patchI]
*field.boundaryField()[patchI]
)
<< nl;
}
......@@ -143,10 +143,10 @@ int main(int argc, char *argv[])
<< fieldName << endl;
surfaceScalarField field(fieldHeader, mesh);
scalar sumField = gSum(field.boundaryField()[patchi]);
scalar sumField = gSum(field.boundaryField()[patchI]);
Info<< " Integral of " << fieldName << " over patch "
<< patchName << '[' << patchi << ']' << " = "
<< patchName << '[' << patchI << ']' << " = "
<< sumField << nl;
}
else
......
......@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
forAll(patchNames, patchNameI)
{
const word& patchName = patchNames[patchNameI];
label patchI = bMesh.findPatchID(patchName);
const label patchI = bMesh.findPatchID(patchName);
if (patchI == -1)
{
......
......@@ -120,9 +120,9 @@ Foam::polyBoundaryMesh::~polyBoundaryMesh()
void Foam::polyBoundaryMesh::clearGeom()
{
forAll(*this, patchi)
forAll(*this, patchI)
{
operator[](patchi).clearGeom();
operator[](patchI).clearGeom();
}
}
......@@ -132,9 +132,9 @@ void Foam::polyBoundaryMesh::clearAddressing()
neighbourEdgesPtr_.clear();
patchIDPtr_.clear();
forAll(*this, patchi)
forAll(*this, patchI)
{
operator[](patchi).clearAddressing();
operator[](patchI).clearAddressing();
}
}
......@@ -151,16 +151,16 @@ void Foam::polyBoundaryMesh::calcGeometry()
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
forAll(*this, patchi)
forAll(*this, patchI)
{
operator[](patchi).initGeometry(pBufs);
operator[](patchI).initGeometry(pBufs);
}
pBufs.finishedSends();
forAll(*this, patchi)
forAll(*this, patchI)
{
operator[](patchi).calcGeometry(pBufs);
operator[](patchI).calcGeometry(pBufs);
}
}
else if (Pstream::defaultCommsType == Pstream::scheduled)
......@@ -172,15 +172,15 @@ void Foam::polyBoundaryMesh::calcGeometry()
forAll(patchSchedule, patchEvali)
{
label patchi = patchSchedule[patchEvali].patch;
const label patchI = patchSchedule[patchEvali].patch;
if (patchSchedule[patchEvali].init)
{
operator[](patchi).initGeometry(pBufs);
operator[](patchI).initGeometry(pBufs);
}
else
{
operator[](patchi).calcGeometry(pBufs);
operator[](patchI).calcGeometry(pBufs);
}
}
}
......@@ -204,15 +204,15 @@ Foam::polyBoundaryMesh::neighbourEdges() const
// Initialize.
label nEdgePairs = 0;
forAll(*this, patchi)
forAll(*this, patchI)
{
const polyPatch& pp = operator[](patchi);
const polyPatch& pp = operator[](patchI);
neighbourEdges[patchi].setSize(pp.nEdges() - pp.nInternalEdges());
neighbourEdges[patchI].setSize(pp.nEdges() - pp.nInternalEdges());
forAll(neighbourEdges[patchi], i)
forAll(neighbourEdges[patchI], i)
{
labelPair& edgeInfo = neighbourEdges[patchi][i];
labelPair& edgeInfo = neighbourEdges[patchI][i];
edgeInfo[0] = -1;
edgeInfo[1] = -1;
......@@ -225,9 +225,9 @@ Foam::polyBoundaryMesh::neighbourEdges() const
// point addressing) to patch + relative edge index.
HashTable<labelPair, edge, Hash<edge> > pointsToEdge(nEdgePairs);
forAll(*this, patchi)
forAll(*this, patchI)
{
const polyPatch& pp = operator[](patchi);
const polyPatch& pp = operator[](patchI);
const edgeList& edges = pp.edges();
......@@ -256,7 +256,7 @@ Foam::polyBoundaryMesh::neighbourEdges() const
meshEdge,
labelPair
(
patchi,
patchI,
edgei - pp.nInternalEdges()
)
);
......@@ -266,11 +266,11 @@ Foam::polyBoundaryMesh::neighbourEdges() const
// Second occurrence. Store.
const labelPair& edgeInfo = fnd();
neighbourEdges[patchi][edgei - pp.nInternalEdges()] =
neighbourEdges[patchI][edgei - pp.nInternalEdges()] =
edgeInfo;
neighbourEdges[edgeInfo[0]][edgeInfo[1]]
= labelPair(patchi, edgei - pp.nInternalEdges());
= labelPair(patchI, edgei - pp.nInternalEdges());
// Found all two occurrences of this edge so remove from
// hash to save space. Note that this will give lots of
......@@ -288,11 +288,11 @@ Foam::polyBoundaryMesh::neighbourEdges() const
<< abort(FatalError);
}
forAll(*this, patchi)
forAll(*this, patchI)
{
const polyPatch& pp = operator[](patchi);
const polyPatch& pp = operator[](patchI);
const labelPairList& nbrEdges = neighbourEdges[patchi];
const labelPairList& nbrEdges = neighbourEdges[patchI];
forAll(nbrEdges, i)
{
......@@ -409,8 +409,7 @@ Foam::label Foam::polyBoundaryMesh::findPatchID(const word& patchName) const
// Patch not found
if (debug)
{
Pout<< "label polyBoundaryMesh::findPatchID(const word& "
<< "patchName) const"
Pout<< "label polyBoundaryMesh::findPatchID(const word&) const"
<< "Patch named " << patchName << " not found. "
<< "List of available patch names: " << names() << endl;
}
......@@ -641,16 +640,16 @@ void Foam::polyBoundaryMesh::movePoints(const pointField& p)
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
forAll(*this, patchi)
forAll(*this, patchI)
{
operator[](patchi).initMovePoints(pBufs, p);
operator[](patchI).initMovePoints(pBufs, p);
}
pBufs.finishedSends();
forAll(*this, patchi)
forAll(*this, patchI)
{
operator[](patchi).movePoints(pBufs, p);
operator[](patchI).movePoints(pBufs, p);
}
}
else if (Pstream::defaultCommsType == Pstream::scheduled)
......@@ -662,15 +661,15 @@ void Foam::polyBoundaryMesh::movePoints(const pointField& p)
forAll(patchSchedule, patchEvali)
{
label patchi = patchSchedule[patchEvali].patch;
const label patchI = patchSchedule[patchEvali].patch;
if (patchSchedule[patchEvali].init)
{
operator[](patchi).initMovePoints(pBufs, p);
operator[](patchI).initMovePoints(pBufs, p);
}
else
{
operator[](patchi).movePoints(pBufs, p);
operator[](patchI).movePoints(pBufs, p);
}
}
}
......@@ -690,16 +689,16 @@ void Foam::polyBoundaryMesh::updateMesh()
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
forAll(*this, patchi)
forAll(*this, patchI)
{
operator[](patchi).initUpdateMesh(pBufs);