BUGFIX: next wall distance may cause seg fault
This commit is contained in:
parent
08a7e2e03b
commit
7fe57ece38
2 changed files with 92 additions and 65 deletions
|
@ -33,31 +33,16 @@ License
|
||||||
|
|
||||||
void Foam::nearWallDist::doAll()
|
void Foam::nearWallDist::doAll()
|
||||||
{
|
{
|
||||||
cellDistFuncs wallUtils(mesh_);
|
|
||||||
|
|
||||||
// AJ: make sure to pick up all patches that are specified as a wall
|
|
||||||
const polyBoundaryMesh& bMesh = wallUtils.mesh().boundaryMesh();
|
|
||||||
labelHashSet wallPatchIDs(bMesh.size());
|
|
||||||
forAll(bMesh, patchI)
|
|
||||||
{
|
|
||||||
if (bMesh[patchI].isWall())
|
|
||||||
{
|
|
||||||
wallPatchIDs.insert(patchI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get patch ids of walls
|
|
||||||
// labelHashSet wallPatchIDs(wallUtils.getPatchIDs<wallPolyPatch>());
|
|
||||||
|
|
||||||
// Size neighbours array for maximum possible
|
|
||||||
|
|
||||||
labelList neighbours(wallUtils.maxPatchSize(wallPatchIDs));
|
|
||||||
|
|
||||||
|
|
||||||
// Correct all cells with face on wall
|
// Correct all cells with face on wall
|
||||||
|
|
||||||
const volVectorField& cellCentres = mesh_.C();
|
const volVectorField& cellCentres = mesh_.C();
|
||||||
|
|
||||||
|
// HR 12.02.18: Use hashSet to determine nbs
|
||||||
|
// This should removes a possible error due to wrong sizing since
|
||||||
|
// getPointNeighbours may still run over AND should be faster
|
||||||
|
// since the linear search (again getPointNeighbours) is removed.
|
||||||
|
labelHashSet nbs(20);
|
||||||
|
|
||||||
|
// Correct all cells with face on wall
|
||||||
forAll(mesh_.boundary(), patchI)
|
forAll(mesh_.boundary(), patchI)
|
||||||
{
|
{
|
||||||
fvPatchScalarField& ypatch = operator[](patchI);
|
fvPatchScalarField& ypatch = operator[](patchI);
|
||||||
|
@ -67,29 +52,45 @@ void Foam::nearWallDist::doAll()
|
||||||
if (patch.isWall())
|
if (patch.isWall())
|
||||||
{
|
{
|
||||||
const polyPatch& pPatch = patch.patch();
|
const polyPatch& pPatch = patch.patch();
|
||||||
|
const pointField& points = pPatch.points();
|
||||||
const unallocLabelList& faceCells = patch.faceCells();
|
const unallocLabelList& faceCells = pPatch.faceCells();
|
||||||
|
|
||||||
// Check cells with face on wall
|
// Check cells with face on wall
|
||||||
forAll(patch, patchFaceI)
|
forAll(patch, patchFaceI)
|
||||||
{
|
{
|
||||||
label nNeighbours = wallUtils.getPointNeighbours
|
const face& f = pPatch.localFaces()[patchFaceI];
|
||||||
|
|
||||||
|
scalar minDist = GREAT;
|
||||||
|
|
||||||
|
// Loop over points
|
||||||
|
forAll(f, fI)
|
||||||
|
{
|
||||||
|
const labelList& pointNbs = pPatch.pointFaces()[f[fI]];
|
||||||
|
|
||||||
|
// Loop over faces sharing current point
|
||||||
|
// This will include the face itself
|
||||||
|
forAll(pointNbs, pointNbsI)
|
||||||
|
{
|
||||||
|
const label nbr = pointNbs[pointNbsI];
|
||||||
|
if (nbs.insert(nbr))
|
||||||
|
{
|
||||||
|
const pointHit curHit = pPatch[nbr].nearestPoint
|
||||||
(
|
(
|
||||||
pPatch,
|
cellCentres[faceCells[nbr]],
|
||||||
patchFaceI,
|
points
|
||||||
neighbours
|
|
||||||
);
|
);
|
||||||
|
|
||||||
label minFaceI = -1;
|
if (curHit.distance() < minDist)
|
||||||
|
{
|
||||||
|
minDist = curHit.distance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ypatch[patchFaceI] = wallUtils.smallestDist
|
ypatch[patchFaceI] = minDist;
|
||||||
(
|
|
||||||
cellCentres[faceCells[patchFaceI]],
|
nbs.clear();
|
||||||
pPatch,
|
|
||||||
nNeighbours,
|
|
||||||
neighbours,
|
|
||||||
minFaceI
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -181,6 +181,12 @@ Foam::label Foam::cellDistFuncs::getPointNeighbours
|
||||||
label faceI = pointNbs[nbI];
|
label faceI = pointNbs[nbI];
|
||||||
|
|
||||||
// Check for faceI in edge-neighbours part of neighbours
|
// Check for faceI in edge-neighbours part of neighbours
|
||||||
|
|
||||||
|
// HR 12.02.18: Should start the search from the begining
|
||||||
|
// of the list. Otherwise we may append a face that is
|
||||||
|
// also an edge neighbour -> Inefficient + sizing may not
|
||||||
|
// be adequate on processors with very small wall patches.
|
||||||
|
// Therefore replaced and not used anymore!
|
||||||
if (findIndex(nEdgeNbs, neighbours, faceI) == -1)
|
if (findIndex(nEdgeNbs, neighbours, faceI) == -1)
|
||||||
{
|
{
|
||||||
neighbours[nNeighbours++] = faceI;
|
neighbours[nNeighbours++] = faceI;
|
||||||
|
@ -297,11 +303,11 @@ void Foam::cellDistFuncs::correctBoundaryFaceCells
|
||||||
Map<label>& nearestFace
|
Map<label>& nearestFace
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// Size neighbours array for maximum possible (= size of largest patch)
|
// HR 12.02.18: Use hashSet to determine nbs
|
||||||
label maxPointNeighbours = maxPatchSize(patchIDs);
|
// This should removes a possible error due to wrong sizing since
|
||||||
|
// getPointNeighbours may still run over AND should be faster
|
||||||
labelList neighbours(maxPointNeighbours);
|
// since the linear search (again getPointNeighbours) is removed.
|
||||||
|
labelHashSet nbs(20);
|
||||||
|
|
||||||
// Correct all cells with face on wall
|
// Correct all cells with face on wall
|
||||||
const vectorField& cellCentres = mesh().cellCentres();
|
const vectorField& cellCentres = mesh().cellCentres();
|
||||||
|
@ -311,37 +317,57 @@ void Foam::cellDistFuncs::correctBoundaryFaceCells
|
||||||
{
|
{
|
||||||
if (patchIDs.found(patchI))
|
if (patchIDs.found(patchI))
|
||||||
{
|
{
|
||||||
const polyPatch& patch = mesh().boundaryMesh()[patchI];
|
const polyPatch& pPatch = mesh().boundaryMesh()[patchI];
|
||||||
|
const pointField& points = pPatch.points();
|
||||||
|
const unallocLabelList& faceCells = pPatch.faceCells();
|
||||||
|
|
||||||
// Check cells with face on wall
|
forAll(pPatch, patchFaceI)
|
||||||
forAll(patch, patchFaceI)
|
|
||||||
{
|
{
|
||||||
label nNeighbours = getPointNeighbours
|
const face& f = pPatch.localFaces()[patchFaceI];
|
||||||
(
|
|
||||||
patch,
|
|
||||||
patchFaceI,
|
|
||||||
neighbours
|
|
||||||
);
|
|
||||||
|
|
||||||
label cellI = faceOwner[patch.start() + patchFaceI];
|
|
||||||
|
|
||||||
|
scalar minDist = GREAT;
|
||||||
label minFaceI = -1;
|
label minFaceI = -1;
|
||||||
|
|
||||||
wallDistCorrected[cellI] = smallestDist
|
// Loop over points
|
||||||
|
forAll(f, fI)
|
||||||
|
{
|
||||||
|
const labelList& pointNbs = pPatch.pointFaces()[f[fI]];
|
||||||
|
|
||||||
|
// Loop over faces sharing current point
|
||||||
|
// This will include the face itself
|
||||||
|
forAll(pointNbs, pointNbsI)
|
||||||
|
{
|
||||||
|
const label nbr = pointNbs[pointNbsI];
|
||||||
|
if (nbs.insert(nbr))
|
||||||
|
{
|
||||||
|
const pointHit curHit = pPatch[nbr].nearestPoint
|
||||||
(
|
(
|
||||||
cellCentres[cellI],
|
cellCentres[faceCells[nbr]],
|
||||||
patch,
|
points
|
||||||
nNeighbours,
|
|
||||||
neighbours,
|
|
||||||
minFaceI
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Store wallCell and its nearest neighbour
|
if (curHit.distance() < minDist)
|
||||||
nearestFace.insert(cellI, minFaceI);
|
{
|
||||||
|
minDist = curHit.distance();
|
||||||
|
minFaceI = nbr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wallDistCorrected[patchFaceI] = minDist;
|
||||||
|
|
||||||
|
// Store wallCell and its nearest neighbour
|
||||||
|
nearestFace.insert
|
||||||
|
(
|
||||||
|
faceOwner[pPatch.start() + patchFaceI],
|
||||||
|
pPatch.start() + minFaceI
|
||||||
|
);
|
||||||
|
|
||||||
|
nbs.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue