Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1893,18 +1893,19 @@ double CylindricalMesh::find_r_crossing(
const double inv_denominator = 1.0 / denominator;

const double p = (u.x * r.x + u.y * r.y) * inv_denominator;
double c = r.x * r.x + r.y * r.y - r0 * r0;
double D = p * p - c * inv_denominator;
double R = std::sqrt(r.x * r.x + r.y * r.y);
double D = p * p - (R - r0) * (R + r0) * inv_denominator;

if (D < 0.0)
return INFTY;

D = std::sqrt(D);

// the solution -p - D is always smaller as -p + D : Check this one first
if (std::abs(c) <= RADIAL_MESH_TOL)
// Particle is already on the shell surface; avoid spurious crossing
if (std::abs(R - r0) <= RADIAL_MESH_TOL * (1.0 + std::abs(r0)))
return INFTY;

// Check -p - D first because it is always smaller as -p + D
if (-p - D > l)
return -p - D;
if (-p + D > l)
Expand Down Expand Up @@ -2178,15 +2179,16 @@ double SphericalMesh::find_r_crossing(
if (r0 == 0.0)
return INFTY;
const double p = r.dot(u);
double c = r.dot(r) - r0 * r0;
double D = p * p - c;
double R = r.norm();
double D = p * p - (R - r0) * (R + r0);

if (std::abs(c) <= RADIAL_MESH_TOL)
// Particle is already on the shell surface; avoid spurious crossing
if (std::abs(R - r0) <= RADIAL_MESH_TOL * (1.0 + std::abs(r0)))
return INFTY;

if (D >= 0.0) {
D = std::sqrt(D);
// the solution -p - D is always smaller as -p + D : Check this one first
// Check -p - D first because it is always smaller as -p + D
if (-p - D > l)
return -p - D;
if (-p + D > l)
Expand Down
Loading