Skip to content

Commit 34066e2

Browse files
committed
Adding checks that resulting vtkhdf file is able to be read and contains the intended data
1 parent 5e76e96 commit 34066e2

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

tests/unit_tests/test_mesh.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def test_umesh(run_in_tmpdir, simple_umesh, export_type):
489489

490490

491491
@pytest.mark.skipif(not openmc.lib._dagmc_enabled(), reason="DAGMC not enabled.")
492-
def test_write_vtkhdf(request, run_in_tmpdir):
492+
def test_write_vtkhdf(request):
493493
"""Performs a minimal UnstructuredMesh simulation, reads in the resulting
494494
statepoint file and writes the mesh data to vtk and vtkhdf files. It is
495495
necessary to read in the unstructured mesh from a statepoint file to ensure
@@ -554,6 +554,25 @@ def test_write_vtkhdf(request, run_in_tmpdir):
554554
with h5py.File("test_mesh.vtkhdf", "r"):
555555
...
556556

557+
import vtk
558+
reader = vtk.vtkHDFReader()
559+
reader.SetFileName("test_mesh.vtkhdf")
560+
reader.Update()
561+
562+
# Get mean from file and make sure it matches original data
563+
num_elements = reader.GetOutput().GetNumberOfCells()
564+
assert num_elements == umesh_from_sp.n_elements
565+
566+
num_vertices = reader.GetOutput().GetNumberOfPoints()
567+
assert num_vertices == umesh_from_sp.n_vertices
568+
569+
arr = reader.GetOutput().GetCellData().GetArray("mean")
570+
mean = np.array([arr.GetTuple1(i) for i in range(my_tally.mean.size)])
571+
np.testing.assert_almost_equal(mean, my_tally.mean.flatten()/umesh_from_sp.volumes)
572+
573+
std_dev = np.array([arr.GetTuple1(i) for i in range(my_tally.std_dev.size)])
574+
np.testing.assert_almost_equal(std_dev, my_tally.std_dev.flatten()/umesh_from_sp.volumes)
575+
557576

558577
def test_mesh_get_homogenized_materials():
559578
"""Test the get_homogenized_materials method"""

0 commit comments

Comments
 (0)