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];
This commit is contained in:
Mark Olesen
2010-04-29 10:12:35 +02:00
parent 845314b280
commit 72f7d46f23
46 changed files with 438 additions and 258 deletions

View File

@ -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();

View File

@ -1,4 +1,4 @@
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
(

View File

@ -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;

View File

@ -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.

View File

@ -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());

View File

@ -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)
{

View File

@ -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];

View File

@ -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)
{

View File

@ -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);

View File

@ -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);

View File

@ -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());

View File

@ -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)
{

View File

@ -328,7 +328,7 @@ vtkUnstructuredGrid* Foam::vtkPV3Foam::volumeVTKMesh
VTK_POLYHEDRON,
nodeCount,
uniqueNodeIds.data(),
faceCount,
nFaces,
faceLabels.data()
);
#else

View File

@ -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)
{

View File

@ -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

View File

@ -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

View File

@ -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)
{