Merge pull request #1414 from gridley/fix_large_hex_lattice_error

use relative distances for coincidence test in hex lattice
This commit is contained in:
Patrick Shriwise 2019-11-21 14:08:36 -06:00 committed by GitHub
commit 8fcd74b14b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -895,8 +895,12 @@ HexLattice::get_indices(Position r, Direction u) const
Position r_t = get_local_position(r, i_xyz);
// calculate distance
double d = r_t.x*r_t.x + r_t.y*r_t.y;
// check for coincidence
bool on_boundary = coincident(d, d_min);
// check for coincidence. Because the numerical error incurred
// in hex geometry is higher than other geometries, the relative
// coincidence is checked here so that coincidence is successfully
// detected on large hex lattice with particles far from the origin
// which have rounding errors larger than the FP_COINCIDENT thresdhold.
bool on_boundary = coincident(1.0, d_min/d);
if (d < d_min || on_boundary) {
// normalize r_t and find dot product
r_t /= std::sqrt(d);