mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
particle: Improved robustness of locate method
This commit is contained in:
@ -409,20 +409,55 @@ void Foam::particle::locate
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put the particle at the cell centre and in a random tet
|
// Track from the centre of the cell to the desired position
|
||||||
|
const vector displacement = position - mesh_.cellCentres()[celli_];
|
||||||
|
|
||||||
|
// Loop all cell tets to find the one containing the position. Track
|
||||||
|
// through each tet from the cell centre. If a tet contains the position
|
||||||
|
// then the track will end with a single trackToTri.
|
||||||
|
const class cell& c = mesh_.cells()[celli_];
|
||||||
|
label minF = 1, minTetFacei = -1, minTetPti = -1;
|
||||||
|
forAll(c, cellTetFacei)
|
||||||
|
{
|
||||||
|
const class face& f = mesh_.faces()[c[cellTetFacei]];
|
||||||
|
for (label tetPti = 1; tetPti < f.size() - 1; ++ tetPti)
|
||||||
|
{
|
||||||
coordinates_ = barycentric(1, 0, 0, 0);
|
coordinates_ = barycentric(1, 0, 0, 0);
|
||||||
tetFacei_ = mesh_.cells()[celli_][0];
|
tetFacei_ = c[cellTetFacei];
|
||||||
tetPti_ = 1;
|
tetPti_ = tetPti;
|
||||||
facei_ = -1;
|
facei_ = -1;
|
||||||
|
|
||||||
// Track to the injection point
|
label tetTriI = -1;
|
||||||
track(position - mesh_.cellCentres()[celli_], 0);
|
const scalar f = trackToTri(displacement, 0, tetTriI);
|
||||||
|
|
||||||
|
if (tetTriI == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f < minF)
|
||||||
|
{
|
||||||
|
minF = f;
|
||||||
|
minTetFacei = tetFacei_;
|
||||||
|
minTetPti = tetPti_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The particle must be (hopefully only slightly) outside the cell. Track
|
||||||
|
// into the tet which got the furthest.
|
||||||
|
coordinates_ = barycentric(1, 0, 0, 0);
|
||||||
|
tetFacei_ = minTetFacei;
|
||||||
|
tetPti_ = minTetPti;
|
||||||
|
facei_ = -1;
|
||||||
|
|
||||||
|
track(displacement, 0);
|
||||||
if (!onFace())
|
if (!onFace())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We hit a boundary ...
|
// If we are here then we hit a boundary
|
||||||
if (boundaryFail)
|
if (boundaryFail)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction << boundaryMsg << exit(FatalError);
|
FatalErrorInFunction << boundaryMsg << exit(FatalError);
|
||||||
@ -440,13 +475,12 @@ void Foam::particle::locate
|
|||||||
}
|
}
|
||||||
|
|
||||||
const vector n = *direction/mag(*direction);
|
const vector n = *direction/mag(*direction);
|
||||||
const vector s = position - mesh_.cellCentres()[celli_];
|
const vector sN = (displacement & n)*n;
|
||||||
const vector sN = (s & n)*n;
|
const vector sT = displacement - sN;
|
||||||
const vector sT = s - sN;
|
|
||||||
|
|
||||||
coordinates_ = barycentric(1, 0, 0, 0);
|
coordinates_ = barycentric(1, 0, 0, 0);
|
||||||
tetFacei_ = mesh_.cells()[celli_][0];
|
tetFacei_ = minTetFacei;
|
||||||
tetPti_ = 1;
|
tetPti_ = minTetPti;
|
||||||
facei_ = -1;
|
facei_ = -1;
|
||||||
|
|
||||||
track(sT, 0);
|
track(sT, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user