patvarilly / periodic_kdtree

SciPy-based kd-tree with periodic boundary conditions
36 stars 13 forks source link

_gen_relevant_images misses some images #7

Open jmborr opened 7 years ago

jmborr commented 7 years ago

I think there are scenarios when _gen_relevant_images misses generation of some needed image. See picture below for a scenario with 2D periodic boundary conditions. The query particle is located at the center of the red circle on the left. The query search radius is r.

screenshot

According to periodic_kdtree.py L90-91:

        self.max_distance_upper_bound = np.min(
            np.where(self.bounds > 0, 0.5 * self.bounds, np.inf))

from the picture, self.max_distance_upper_bound == d.

Now if we set distance_upper_bound == r with r that of the picture, then the capping of this quantity at periodic_kdtree.py L105-106

        distance_upper_bound = np.min([distance_upper_bound,
                                      self.max_distance_upper_bound])

will result in distance_upper_bound == d

In the picture, the query particle is located at the center of the red circle on the left. The shaded red area indicates that we will need to add an image, the red-dashed circle. If we go to _gen_relevant_images() and start checking along the X-axis (i=0) we have that abs(real_x[i]) > d so condition at line 35 is not met. We also have abs(bounds[i] - real_x[i]) > d so condition at line 39 is not met either. We end up adding no image.

jmborr commented 7 years ago

@patvarilly Can you please verify the analysis of the scenario I showed is correct?