Skip to content

Commit b86a84d

Browse files
committed
Updating Delaunay tests
1 parent 21fd75b commit b86a84d

File tree

4 files changed

+72
-32
lines changed

4 files changed

+72
-32
lines changed

example.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import matplotlib.pyplot as plt
55
op.visualization.set_mpl_style()
66
ws = op.Workspace()
7+
ws.settings['default_solver'] = 'ScipySpsolve'
78
ws.clear()
89

10+
911
pn = op.network.Cubic(shape=[25, 25, 1], spacing=1e-4)
1012

1113
# Create domain

openpnm/_skgraph/generators/tools/_funcs.py

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def parse_points(shape, points, reflect=False):
3434
if points.shape[1] == 2:
3535
zeros = np.atleast_2d(np.zeros_like(points[:, 0])).T
3636
points = np.hstack((points, zeros))
37+
# Ensure z-axis is all 0's if shape ends in 0 (ie. square or disk)
38+
if shape[-1] == 0:
39+
points[:, -1] = 0.0
3740
return points
3841

3942

tests/unit/network/DelaunayGabrielTest.py

-32
This file was deleted.

tests/unit/network/DelaunayTest.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import numpy as np
2+
import openpnm as op
3+
4+
5+
class DelaunayGabrielTest:
6+
def setup_class(self):
7+
pass
8+
9+
def teardown_class(self):
10+
pass
11+
12+
def test_delaunay_square_with_2D_points(self):
13+
np.random.seed(0)
14+
pts = np.random.rand(50, 2)
15+
tri = op.network.Delaunay(points=pts, shape=[1, 1, 0])
16+
assert tri.coords.shape == (50, 3)
17+
assert np.all(tri.coords[:, :2] == pts)
18+
19+
def test_delaunay_square_with_3D_points(self):
20+
np.random.seed(0)
21+
pts = np.random.rand(50, 3)
22+
tri = op.network.Delaunay(points=pts, shape=[1, 1, 0])
23+
assert tri.coords.shape == (50, 3)
24+
assert np.all(tri.coords[:, :2] == pts[:, :2])
25+
assert np.all(tri.coords[:, -1] != pts[:, -1])
26+
assert np.all(tri.coords[:, -1] == 0.0)
27+
28+
def test_delaunay_cube_with_points(self):
29+
np.random.seed(0)
30+
pts = np.random.rand(50, 3)
31+
tri = op.network.Delaunay(points=pts, shape=[1, 1, 1])
32+
assert tri.coords.shape == (50, 3)
33+
assert np.all(tri.coords == pts)
34+
35+
def test_delaunay_disk_with_2D_points(self):
36+
np.random.seed(0)
37+
pts = np.random.rand(50, 2)
38+
tri = op.network.Delaunay(points=pts, shape=[1, 0])
39+
assert tri.coords.shape == (50, 3)
40+
assert np.all(tri.coords[:, :2] == pts[:, :2])
41+
assert np.all(tri.coords[:, -1] != pts[:, -1])
42+
assert np.all(tri.coords[:, -1] == 0.0)
43+
44+
def test_delaunay_disk_with_3D_points(self):
45+
np.random.seed(0)
46+
pts = np.random.rand(50, 3)
47+
tri = op.network.Delaunay(points=pts, shape=[1, 1])
48+
assert tri.coords.shape == (50, 3)
49+
assert np.all(tri.coords == pts)
50+
51+
def test_delaunay_cylinder_with_points(self):
52+
np.random.seed(0)
53+
pts = np.random.rand(50, 3)
54+
tri = op.network.Delaunay(points=pts, shape=[1, 1])
55+
assert tri.coords.shape == (50, 3)
56+
assert np.all(tri.coords == pts)
57+
58+
59+
if __name__ == '__main__':
60+
61+
t = DelaunayGabrielTest()
62+
t.setup_class()
63+
self = t
64+
for item in t.__dir__():
65+
if item.startswith('test'):
66+
print('running test: '+item)
67+
t.__getattribute__(item)()

0 commit comments

Comments
 (0)