From 5635549cac8a9cf423336356145245db8db48d95 Mon Sep 17 00:00:00 2001 From: Florian Hindenlang Date: Fri, 21 Jun 2024 09:34:01 +0200 Subject: [PATCH] The method `_test_inside_point` of the global smooth boundary (GSB) is unreliable, it fails for many points inside the boundary. * A test is written in an ipython notebook that can demonstrate this, see `tests/test_global_smooth_boundary.ipynb`. * The updated `_test_inside_point` method is now using the same algorithm as in `find_inside_points`, via`contains_points` method in the path object of matplotlib. Therefore, the boundary curve in GSB is also saved as a path (`self.poly`) during the initialization. --- .../global_smooth_boundary.py | 48 +++++++- tests/test_global_smooth_boundary.ipynb | 105 ++++++++++++++++++ 2 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 tests/test_global_smooth_boundary.ipynb diff --git a/pybie2d/boundaries/global_smooth_boundary/global_smooth_boundary.py b/pybie2d/boundaries/global_smooth_boundary/global_smooth_boundary.py index b2e594e..3eefc1d 100644 --- a/pybie2d/boundaries/global_smooth_boundary/global_smooth_boundary.py +++ b/pybie2d/boundaries/global_smooth_boundary/global_smooth_boundary.py @@ -1,5 +1,6 @@ import numpy as np import scipy as sp +import matplotlib as mpl import scipy.signal import warnings import os @@ -74,6 +75,7 @@ def __init__(self, x=None, y=None, c=None): self.max_h = np.max(self.weights) self.area = self.dt*np.sum(self.x*self.cp.imag) self.perimeter = self.dt*np.sum(self.speed) + self.poly= mpl.path.Path(np.column_stack([self.x, self.y])) self.defined_modules = [ 'Laplace_SLP_Self_Kress', 'Stokes_SLP_Self_Kress', @@ -193,15 +195,49 @@ def Get_Close_Corrector(self, kernel, *args, **kwargs): ######################### #### Private Methods #### ######################### - - def _test_inside_point(self, candidate, eps=1e-10): + + # THIS ROUTINE IS NOT RELIABLE + #def _test_inside_point(self, candidate, eps=1e-10): + # """ + # Test whether the provided or generated inside point is acceptable + # returns True if the point is okay, False if its not + # """ + # test_value = np.sum(self.complex_weights/(self.c-candidate)) + # return np.abs(test_value - 2.0j*np.pi) < eps + ## end _test_inside_point function + + # THIS ROUTINE IS RELIABLE AND INDEPENDENT OF MATPLOTLIB + #def _test_inside_point(self, candidate, eps=1e-12): + # """ + # Test whether the provided or generated inside point is acceptable + # returns True if the point is okay, False if its not + # Algorithm: point in polygon (the points in self.c are interpreted as closed polygon), + # the sum of angles between the vectors from the point (candidate) to two consecutive points on the boundary # + # polygon. the sum is equal 2pi only if the point lies inside. Safe way to compute the angle is using arctan2 of #(a x b)/(a.b). + # """ + # a=self.c-candidate + # if (np.any(np.abs(a)