Skip to content

Commit

Permalink
reenable some gmytool regression tests; the cylinder clipping is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
rupertnash committed Jul 7, 2022
1 parent 9184e5e commit 914cdec
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions geometry-tool/tests/Model/test_OutputGeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@

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


def vec2np(v):
ans = np.empty(3, dtype=float)
ans[0] = v.x
ans[1] = v.y
ans[2] = v.z
return ans


class TestPolyDataGenerator:
def test_regression(self, tmpdir):
"""Generate a gmy from a stored profile and check that the output is
Expand Down Expand Up @@ -65,7 +67,9 @@ def test_regression(self, tmpdir):
test_dom = test_ldr.Domain

# Per-block data length must be identical
assert np.all(ref_ldr.BlockUncompressedDataLength == test_ldr.BlockUncompressedDataLength)
assert np.all(
ref_ldr.BlockUncompressedDataLength == test_ldr.BlockUncompressedDataLength
)
# Same for fluid site counts
assert np.all(ref_dom.BlockFluidSiteCounts == test_dom.BlockFluidSiteCounts)
nblocks = len(ref_dom.BlockFluidSiteCounts)
Expand All @@ -90,7 +94,12 @@ def test_regression(self, tmpdir):
if rs.IntersectionDistance is None:
assert ts.IntersectionDistance is None
else:
assert np.allclose(rs.IntersectionDistance, ts.IntersectionDistance, rtol=0, atol=5e-5)
assert np.allclose(
rs.IntersectionDistance,
ts.IntersectionDistance,
rtol=0,
atol=5e-5,
)

assert np.all(rs.IOletIndex == ts.IOletIndex)
assert rs.WallNormalAvailable == ts.WallNormalAvailable
Expand All @@ -104,21 +113,21 @@ def test_regression(self, tmpdir):
def test_cube(self, tmpdir):
"""Generate a gmy from a simple cubic profile and check the output"""
cube = fixtures.cube(tmpdir)
cube.VoxelSize = 0.23
cube.StlFileUnitId = 0
cube.VoxelSize = 0.11
generator = OutputGeneration.GmyPolyDataGenerator(cube)
generator.Execute()
# Load back the resulting geometry file and assert things are as
# expected
checker = CubeTestingGmyParser(cube.OutputXmlFile, cube.VoxelSize)
checker.Load()

fluid_sites = sum(checker.Domain.BlockFluidSiteCounts)
fluid_sites = checker.Domain.BlockFluidSiteCounts.sum()
block_count = len(checker.Domain.Blocks)
block_size = checker.Domain.BlockSize
sites = block_count * block_size**3
# assert(sites==4096)
# assert(fluid_sites==729)
assert sites == 4096
assert fluid_sites == 729
assert sites != fluid_sites
# # Now, turn on the skip-non-intersecting-blocks optimisation, and
# # assert same result
Expand Down Expand Up @@ -168,47 +177,52 @@ def test_cube_normals(self, tmpdir):
checker.Load()

def test_cylinder(self, tmpdir):
"""Generate a gmy from a simple cylinder profile and check the output"""
cylinder = fixtures.cylinder(tmpdir)
cylinder.VoxelSize = 0.23
cylinder.StlFileUnitId = 0
"""Generate a gmy from a cylinder and check the output.
""" The default VTK cylinder is 1 length unit long, aligned with the
The cylinder is 1 length unit long, radius 0.5, aligned with the
y-axis, and centred at the origin of coordinates.
"""
dx = 0.11
cylinder = fixtures.cylinder(tmpdir)
cylinder.VoxelSize = dx
cylinder.StlFileUnitId = 0

inlet = Iolet(
Name="inlet",
Centre=Vector(0.0, -0.5, 0.0),
Centre=Vector(0.0, -0.45, 0.0),
Normal=Vector(0.0, -1.0, 0.0),
Radius=1,
Radius=1.0,
)
outlet = Iolet(
Name="outlet",
Centre=Vector(0.0, 0.5, 0.0),
Centre=Vector(0.0, 0.45, 0.0),
Normal=Vector(0.0, 1.0, 0.0),
Radius=1,
Radius=1.0,
)
cylinder.Iolets = [inlet, outlet]
L = 0.9
R = 0.5

generator = OutputGeneration.GmyPolyDataGenerator(cylinder)

generator.Execute()
# Load back the resulting geometry file and assert things are as
# expected
checker = CylinderTestingGmyParser(
cylinder.OutputXmlFile,
cylinder.VoxelSize,
np.array([0.0, 1.0, 0.0]),
1.0,
0.5,
L,
R,
)
checker.Load()

fluid_sites = sum(checker.Domain.BlockFluidSiteCounts)
fluid_sites = checker.Domain.BlockFluidSiteCounts.sum()
block_count = len(checker.Domain.Blocks)
block_size = checker.Domain.BlockSize
sites = block_count * block_size**3
# assert(sites==4096)
# assert(fluid_sites==621)
assert fluid_sites == 621
assert sites != fluid_sites
# # Now, turn on the skip-non-intersecting-blocks optimisation, and
# # assert same result
Expand Down

0 comments on commit 914cdec

Please sign in to comment.