Skip to content

Commit

Permalink
DVGeoMulti test fix (#199)
Browse files Browse the repository at this point in the history
* bugfix to the clipping and retrained the test

* changed eps and reran test

* moved the eps definition to class init and updated comment
  • Loading branch information
anilyil authored May 11, 2023
1 parent ba53e25 commit b7138ab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
22 changes: 10 additions & 12 deletions pygeo/parameterization/DVGeoMulti.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions tests/reg_tests/ref/test_DVGeometryMulti.ref
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -58,9 +58,9 @@
0.49999999999999994
],
[
0.24708302434712967,
0.11366224292977958,
0.5099995525452042
0.24708313975314067,
0.1136576670970726,
0.5099996220283098
],
[
0.4991275125824375,
Expand All @@ -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,
Expand All @@ -103,9 +103,9 @@
0.6
],
[
0.5058601713172411,
-0.2498982730316979,
0.5999996580987095
0.5058672786729258,
-0.24989810383051725,
0.5999997144892112
],
[
0.24999999999999997,
Expand Down
3 changes: 3 additions & 0 deletions tests/reg_tests/test_DVGeometryMulti.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b7138ab

Please sign in to comment.