ENH: added polyBoundaryMesh patchID(meshFacei) method

- this complements the whichPatch(meshFacei) method [binary search]
  and the list of patchID() by adding internal range checks.

  eg,
     Before
     ~~~~~~
     if (facei >= mesh.nInternalFaces() && facei < mesh.nFaces())
     {
         patchi = pbm.patchID()[facei - mesh.nInternalFaces()];
         ...
     }

     After
     ~~~~~
     patchi = pbm.patchID(facei);

     if (patchi >= 0)
     {
         ...
     }
This commit is contained in:
Mark Olesen
2023-05-09 10:22:29 +02:00
parent dfa5c05a16
commit f462a850ce
17 changed files with 123 additions and 109 deletions

View File

@ -39,7 +39,8 @@ void Foam::pressurePIDControlInletVelocityFvPatchVectorField::faceZoneAverage
Type& average
) const
{
const fvMesh& mesh(patch().boundaryMesh().mesh());
const fvMesh& mesh = patch().boundaryMesh().mesh();
const auto& pbm = mesh.boundaryMesh();
bitSet isMasterFace(syncTools::getInternalOrMasterFaces(mesh));
@ -48,33 +49,30 @@ void Foam::pressurePIDControlInletVelocityFvPatchVectorField::faceZoneAverage
area = 0;
average = Type(Zero);
forAll(zone, faceI)
for (const label meshFacei : zone)
{
const label f(zone[faceI]);
if (mesh.isInternalFace(f))
if (mesh.isInternalFace(meshFacei))
{
const scalar da(mesh.magSf()[f]);
const scalar da = mesh.magSf()[meshFacei];
area += da;
average += da*field[f];
average += da*field[meshFacei];
}
else if (isMasterFace[f])
else if (isMasterFace[meshFacei])
{
const label bf(f-mesh.nInternalFaces());
const label patchID = mesh.boundaryMesh().patchID()[bf];
const label lf(mesh.boundaryMesh()[patchID].whichFace(f));
const scalar da(mesh.magSf().boundaryField()[patchID][lf]);
const label patchi = pbm.patchID(meshFacei);
const label patchFacei = pbm[patchi].whichFace(meshFacei);
const scalar da = mesh.magSf().boundaryField()[patchi][patchFacei];
area += da;
average += da*field.boundaryField()[patchID][lf];
average += da*field.boundaryField()[patchi][patchFacei];
}
}
reduce(area, sumOp<scalar>());
reduce(average, sumOp<Type>());
average /= area;
average /= (area + VSMALL);
}

View File

@ -50,13 +50,13 @@ Type Foam::interpolationCellPatchConstrained<Type>::interpolate
const label facei
) const
{
if (facei >= 0 && facei >= this->psi_.mesh().nInternalFaces())
{
// Use boundary value
const polyBoundaryMesh& pbm = this->psi_.mesh().boundaryMesh();
label patchi = pbm.patchID()[facei-this->psi_.mesh().nInternalFaces()];
label patchFacei = pbm[patchi].whichFace(facei);
const auto& pbm = this->psi_.mesh().boundaryMesh();
const label patchi = pbm.patchID(facei);
if (patchi >= 0)
{
// Boundary value
const label patchFacei = pbm[patchi].whichFace(facei);
return this->psi_.boundaryField()[patchi][patchFacei];
}
else