Performance update in immersed boundary search

This commit is contained in:
Hrvoje Jasak 2016-08-01 14:37:19 +01:00
parent ac941215d5
commit a214f5e6fe
2 changed files with 68 additions and 12 deletions

View file

@ -30,6 +30,8 @@ License
#include "SortableList.H" #include "SortableList.H"
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "treeBoundBox.H"
#include "treeDataCell.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -1127,7 +1129,7 @@ void Foam::immersedBoundaryFvPatch::makeIbCellCells() const
// Note: the algorithm is originally written with inward-facing normals // Note: the algorithm is originally written with inward-facing normals
// and subsequently changed: IB surface normals point outwards // and subsequently changed: IB surface normals point outwards
// HJ, 21/May/2012 // HJ, 21/May/2012
// const vectorField& ibn = ibNormals(); const vectorField& ibn = ibNormals();
forAll (cellCells, cellI) forAll (cellCells, cellI)
{ {
@ -1152,14 +1154,14 @@ void Foam::immersedBoundaryFvPatch::makeIbCellCells() const
// Collect the cells within rM of the fitting cell // Collect the cells within rM of the fitting cell
if (r <= rM[cellI]) if (r <= rM[cellI])
{ {
// scalar angleLimit = scalar angleLimit =
// -Foam::cos(angleFactor_()*mathematicalConstant::pi/180); -Foam::cos(angleFactor_()*mathematicalConstant::pi/180);
vector dir = (C[curCell] - ibp[cellI]); vector dir = (C[curCell] - ibp[cellI]);
dir /= mag(dir) + SMALL; dir /= mag(dir) + SMALL;
// Change of sign of normal. HJ, 21/May/2012 // Change of sign of normal. HJ, 21/May/2012
// if ((-ibn[cellI] & dir) >= angleLimit) if ((-ibn[cellI] & dir) >= angleLimit)
{ {
cellCells[cellI][cI++] = curCell; cellCells[cellI][cI++] = curCell;
} }
@ -2583,6 +2585,24 @@ Foam::immersedBoundaryFvPatch::triFacesInMesh() const
triFacesInMesh_.clear(); triFacesInMesh_.clear();
triFacesInMesh_.setCapacity(triCf.size()/2); triFacesInMesh_.setCapacity(triCf.size()/2);
// Use octree search to find the cell
treeBoundBox overallBb(mesh_.points());
Random rndGen(123456);
overallBb = overallBb.extend(rndGen, 1E-4);
overallBb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
overallBb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
// Search
indexedOctree<treeDataCell> cellSearch
(
treeDataCell(false, mesh_),
overallBb, // overall search domain
8, // maxLevel
10, // leafsize
3.0 // duplicity
);
scalar span = cellSearch.bb().mag();
// Find tri faces with centre inside the processor mesh // Find tri faces with centre inside the processor mesh
forAll (triCf, fI) forAll (triCf, fI)
{ {
@ -2595,10 +2615,34 @@ Foam::immersedBoundaryFvPatch::triFacesInMesh() const
} }
else else
{ {
#if 0
// Slow mesh cell search
if (mesh_.findCell(curTriCf) != -1) if (mesh_.findCell(curTriCf) != -1)
{ {
triFacesInMesh_.append(fI); triFacesInMesh_.append(fI);
} }
#else
// Octree mesh search
pointIndexHit pih = cellSearch.findNearest(curTriCf, span);
if (pih.hit())
{
// Found a hit. Additional check for point in cell
const label hitCell = pih.index();
if
(
mesh_.pointInCellBB
(
curTriCf,
hitCell
)
)
{
triFacesInMesh_.append(fI);
}
}
#endif
} }
} }

View file

@ -114,11 +114,15 @@ void Foam::immersedBoundaryFvPatch::makeTriAddressing() const
do do
{ {
const label curTri = nextToVisit.removeHead(); const label curTri = nextToVisit.removeHead();
// Discard tri if already visited // Discard tri if already visited
if (visited[curTri]) continue; if (visited[curTri])
{
continue;
}
else
{
visited.insert(curTri); visited.insert(curTri);
}
const triFace& curTriPoints = triPatch[curTri]; const triFace& curTriPoints = triPatch[curTri];
@ -144,6 +148,14 @@ void Foam::immersedBoundaryFvPatch::makeTriAddressing() const
} }
} }
} }
// If the search has gone wrong, escape with
// poorer interpolation.
if (nextToVisit.size() > 200 && !ibPointsToUse.empty())
{
Info<< "ESCAPE " << ibPointsToUse.size() << endl;
break;
}
} while } while
( (
ibPointsToUse.size() < 3 ibPointsToUse.size() < 3