Skip to content

Commit 914cdec

Browse files
committed
reenable some gmytool regression tests; the cylinder clipping is wrong
1 parent 9184e5e commit 914cdec

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

geometry-tool/tests/Model/test_OutputGeneration.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727

2828
dataDir = os.path.join(os.path.split(__file__)[0], "data")
2929

30+
3031
def vec2np(v):
3132
ans = np.empty(3, dtype=float)
3233
ans[0] = v.x
3334
ans[1] = v.y
3435
ans[2] = v.z
3536
return ans
3637

38+
3739
class TestPolyDataGenerator:
3840
def test_regression(self, tmpdir):
3941
"""Generate a gmy from a stored profile and check that the output is
@@ -65,7 +67,9 @@ def test_regression(self, tmpdir):
6567
test_dom = test_ldr.Domain
6668

6769
# Per-block data length must be identical
68-
assert np.all(ref_ldr.BlockUncompressedDataLength == test_ldr.BlockUncompressedDataLength)
70+
assert np.all(
71+
ref_ldr.BlockUncompressedDataLength == test_ldr.BlockUncompressedDataLength
72+
)
6973
# Same for fluid site counts
7074
assert np.all(ref_dom.BlockFluidSiteCounts == test_dom.BlockFluidSiteCounts)
7175
nblocks = len(ref_dom.BlockFluidSiteCounts)
@@ -90,7 +94,12 @@ def test_regression(self, tmpdir):
9094
if rs.IntersectionDistance is None:
9195
assert ts.IntersectionDistance is None
9296
else:
93-
assert np.allclose(rs.IntersectionDistance, ts.IntersectionDistance, rtol=0, atol=5e-5)
97+
assert np.allclose(
98+
rs.IntersectionDistance,
99+
ts.IntersectionDistance,
100+
rtol=0,
101+
atol=5e-5,
102+
)
94103

95104
assert np.all(rs.IOletIndex == ts.IOletIndex)
96105
assert rs.WallNormalAvailable == ts.WallNormalAvailable
@@ -104,21 +113,21 @@ def test_regression(self, tmpdir):
104113
def test_cube(self, tmpdir):
105114
"""Generate a gmy from a simple cubic profile and check the output"""
106115
cube = fixtures.cube(tmpdir)
107-
cube.VoxelSize = 0.23
108116
cube.StlFileUnitId = 0
117+
cube.VoxelSize = 0.11
109118
generator = OutputGeneration.GmyPolyDataGenerator(cube)
110119
generator.Execute()
111120
# Load back the resulting geometry file and assert things are as
112121
# expected
113122
checker = CubeTestingGmyParser(cube.OutputXmlFile, cube.VoxelSize)
114123
checker.Load()
115124

116-
fluid_sites = sum(checker.Domain.BlockFluidSiteCounts)
125+
fluid_sites = checker.Domain.BlockFluidSiteCounts.sum()
117126
block_count = len(checker.Domain.Blocks)
118127
block_size = checker.Domain.BlockSize
119128
sites = block_count * block_size**3
120-
# assert(sites==4096)
121-
# assert(fluid_sites==729)
129+
assert sites == 4096
130+
assert fluid_sites == 729
122131
assert sites != fluid_sites
123132
# # Now, turn on the skip-non-intersecting-blocks optimisation, and
124133
# # assert same result
@@ -168,47 +177,52 @@ def test_cube_normals(self, tmpdir):
168177
checker.Load()
169178

170179
def test_cylinder(self, tmpdir):
171-
"""Generate a gmy from a simple cylinder profile and check the output"""
172-
cylinder = fixtures.cylinder(tmpdir)
173-
cylinder.VoxelSize = 0.23
174-
cylinder.StlFileUnitId = 0
180+
"""Generate a gmy from a cylinder and check the output.
175181
176-
""" The default VTK cylinder is 1 length unit long, aligned with the
182+
The cylinder is 1 length unit long, radius 0.5, aligned with the
177183
y-axis, and centred at the origin of coordinates.
178184
"""
185+
dx = 0.11
186+
cylinder = fixtures.cylinder(tmpdir)
187+
cylinder.VoxelSize = dx
188+
cylinder.StlFileUnitId = 0
189+
179190
inlet = Iolet(
180191
Name="inlet",
181-
Centre=Vector(0.0, -0.5, 0.0),
192+
Centre=Vector(0.0, -0.45, 0.0),
182193
Normal=Vector(0.0, -1.0, 0.0),
183-
Radius=1,
194+
Radius=1.0,
184195
)
185196
outlet = Iolet(
186197
Name="outlet",
187-
Centre=Vector(0.0, 0.5, 0.0),
198+
Centre=Vector(0.0, 0.45, 0.0),
188199
Normal=Vector(0.0, 1.0, 0.0),
189-
Radius=1,
200+
Radius=1.0,
190201
)
191202
cylinder.Iolets = [inlet, outlet]
203+
L = 0.9
204+
R = 0.5
192205

193206
generator = OutputGeneration.GmyPolyDataGenerator(cylinder)
207+
194208
generator.Execute()
195209
# Load back the resulting geometry file and assert things are as
196210
# expected
197211
checker = CylinderTestingGmyParser(
198212
cylinder.OutputXmlFile,
199213
cylinder.VoxelSize,
200214
np.array([0.0, 1.0, 0.0]),
201-
1.0,
202-
0.5,
215+
L,
216+
R,
203217
)
204218
checker.Load()
205219

206-
fluid_sites = sum(checker.Domain.BlockFluidSiteCounts)
220+
fluid_sites = checker.Domain.BlockFluidSiteCounts.sum()
207221
block_count = len(checker.Domain.Blocks)
208222
block_size = checker.Domain.BlockSize
209223
sites = block_count * block_size**3
210224
# assert(sites==4096)
211-
# assert(fluid_sites==621)
225+
assert fluid_sites == 621
212226
assert sites != fluid_sites
213227
# # Now, turn on the skip-non-intersecting-blocks optimisation, and
214228
# # assert same result

0 commit comments

Comments
 (0)