diff --git a/pygeo/parameterization/DVGeoMulti.py b/pygeo/parameterization/DVGeoMulti.py index d2c9cec0..eeec1d16 100644 --- a/pygeo/parameterization/DVGeoMulti.py +++ b/pygeo/parameterization/DVGeoMulti.py @@ -979,6 +979,9 @@ def __init__( # same communicator with DVGeo self.comm = DVGeo.comm + # define epsilon as a small value to prevent division by zero in the inverse distance computation + self.eps = 1e-20 + # counter for outputting curves etc at each update self.counter = 0 @@ -1451,9 +1454,6 @@ def update(self, ptSetName, delta): print("The intersection topology has changed. The intersection will not be updated.") return delta - # Define an epsilon to avoid dividing by zero later on - eps = 1e-50 - # Get the two end points for the line elements r0 = coor[conn[:, 0]] r1 = coor[conn[:, 1]] @@ -1506,10 +1506,11 @@ def update(self, ptSetName, delta): sc = np.sqrt(c) # Compute denominators for the integral evaluations - # Add an epsilon so that these terms never become zero - # disc <= 0, sabc and sc >= 0, therefore the den1 and den2 should be <=0 - den1 = disc * sabc - eps - den2 = disc * sc - eps + # We clip these values so that they are at max -eps to prevent them from getting a value of zero. + # disc <= 0, sabc and sc >= 0, therefore the den1 and den2 should be <=0. + # The clipping forces these terms to be <= -eps + den1 = np.minimum(disc * sabc, -self.eps) + den2 = np.minimum(disc * sc, -self.eps) # integral evaluations eval1 = (-2 * (2 * a + b) / den1 + 2 * b / den2) * length @@ -1549,9 +1550,6 @@ def sens(self, dIdPt, ptSetName, comm): # bar connectivity for the remeshed elements conn = self.seamConn - # Define an epsilon to avoid dividing by zero later on - eps = 1e-50 - # Get the two end points for the line elements r0 = coor[conn[:, 0]] r1 = coor[conn[:, 1]] @@ -1598,8 +1596,8 @@ def sens(self, dIdPt, ptSetName, comm): sc = np.sqrt(c) # Compute denominators for the integral evaluations - den1 = disc * sabc - eps - den2 = disc * sc - eps + den1 = np.minimum(disc * sabc, -self.eps) + den2 = np.minimum(disc * sc, -self.eps) # integral evaluations eval1 = (-2 * (2 * a + b) / den1 + 2 * b / den2) * length diff --git a/tests/reg_tests/ref/test_DVGeometryMulti.ref b/tests/reg_tests/ref/test_DVGeometryMulti.ref index 57901797..d97797b7 100644 --- a/tests/reg_tests/ref/test_DVGeometryMulti.ref +++ b/tests/reg_tests/ref/test_DVGeometryMulti.ref @@ -33,14 +33,14 @@ 0.5000000000000001 ], [ - 0.7558449428676686, - -0.24394738447815498, - 0.5999996601638932 + 0.7558449426479021, + -0.2439473847057298, + 0.5999997165630315 ], [ - 0.256052615521845, - -0.2558449428676688, - 0.5999996601638931 + 0.2560526152942702, + -0.2558449426479023, + 0.5999997165630314 ], [ 0.244155058456546, @@ -58,9 +58,9 @@ 0.49999999999999994 ], [ - 0.24708302434712967, - 0.11366224292977958, - 0.5099995525452042 + 0.24708313975314067, + 0.1136576670970726, + 0.5099996220283098 ], [ 0.4991275125824375, @@ -83,14 +83,14 @@ 0.5 ], [ - 0.5033972433771731, - 0.2501558793802895, - 0.39999967796693864 + 0.5034043514208585, + 0.2501560711472582, + 0.399999734349053 ], [ - 0.7439510846445981, - 0.2556895615629042, - 0.599999995198642 + 0.7439510052288243, + 0.25569291087605306, + 0.6000000785150911 ], [ 0.4940512221529827, @@ -103,9 +103,9 @@ 0.6 ], [ - 0.5058601713172411, - -0.2498982730316979, - 0.5999996580987095 + 0.5058672786729258, + -0.24989810383051725, + 0.5999997144892112 ], [ 0.24999999999999997, diff --git a/tests/reg_tests/test_DVGeometryMulti.py b/tests/reg_tests/test_DVGeometryMulti.py index 7b6a9120..4ff0b851 100644 --- a/tests/reg_tests/test_DVGeometryMulti.py +++ b/tests/reg_tests/test_DVGeometryMulti.py @@ -31,6 +31,9 @@ class TestDVGeoMulti(unittest.TestCase): N_PROCS = 1 + def train_boxes(self, train=True): + self.test_boxes(train=train) + def test_boxes(self, train=False): # box1 and box2 intersect # box3 does not intersect anything