Skip to content

Commit f5eb8ef

Browse files
committed
add checks for volume consistency
1 parent d9d981e commit f5eb8ef

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

adaptive/learner/triangulation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ def bowyer_watson(self, pt_index, containing_simplex=None, transform=None):
520520
deleted_simplices = bad_triangles - new_triangles
521521
new_simplices = new_triangles - bad_triangles
522522

523+
old_vol = sum([self.volume(simplex) for simplex in deleted_simplices])
524+
new_vol = sum([self.volume(simplex) for simplex in new_simplices])
525+
assert np.isclose(old_vol, new_vol), f"{old_vol} !== {new_vol}"
526+
523527
return deleted_simplices, new_simplices
524528

525529
def add_point(self, point, simplex=None, transform=None):

adaptive/tests/test_learnernd.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# -*- coding: utf-8 -*-
22

33
from ..learner import LearnerND
4-
from ..runner import replay_log
4+
from ..runner import replay_log, BlockingRunner
5+
import numpy as np
56

67

7-
def test_faiure_case_LearnerND():
8+
def sphere(xyz):
9+
x, y, z = xyz
10+
a = 0.4
11+
return x + z**2 + np.exp(-(x**2 + y**2 + z**2 - 0.75**2)**2/a**4)
12+
13+
14+
def test_failure_case_LearnerND():
815
log = [
916
('ask', 4),
1017
('tell', (-1, -1, -1), 1.607873907219222e-101),
@@ -21,3 +28,18 @@ def test_faiure_case_LearnerND():
2128
]
2229
learner = LearnerND(lambda *x: x, bounds=[(-1, 1), (-1, 1), (-1, 1)])
2330
replay_log(learner, log)
31+
32+
33+
def test_anisotropic_3d():
34+
# there was this bug that the total volume would exceed the bounding box
35+
# volume for the anisotropic 3d learnerND
36+
# learner = adaptive.LearnerND(ring, bounds=[(-1, 1), (-1, 1)], anisotropic=True)
37+
learner = LearnerND(sphere, bounds=[(-1, 1), (-1, 1), (-1, 1)], anisotropic=True)
38+
def goal(l):
39+
if l.tri:
40+
sum_of_simplex_volumes = np.sum(l.tri.volumes())
41+
assert sum_of_simplex_volumes < 8.00000000001
42+
return l.npoints >= 1000
43+
BlockingRunner(learner, goal, ntasks=1)
44+
45+
assert learner.npoints >= 1000

0 commit comments

Comments
 (0)