|
1 | 1 | import h5py |
| 2 | +import numpy as np |
| 3 | +import pytest |
2 | 4 | import openmc |
3 | 5 |
|
4 | 6 |
|
@@ -44,3 +46,26 @@ def test_export_hdf5_format(request, run_in_tmpdir): |
44 | 46 | for name in m_grp: |
45 | 47 | assert 'id' in m_grp[name].attrs |
46 | 48 | assert 'type' in m_grp[name] |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.parametrize('library', ('libmesh', 'moab')) |
| 52 | +def test_export_hdf5_unstructured_mesh(request, run_in_tmpdir, library): |
| 53 | + # UnstructuredMesh can't be serialized from pure Python; export_to_hdf5 |
| 54 | + # routes it through openmc.lib.export_weight_windows (a live session). |
| 55 | + if library == 'libmesh' and not openmc.lib._libmesh_enabled(): |
| 56 | + pytest.skip('LibMesh not enabled in this build.') |
| 57 | + if library == 'moab' and not openmc.lib._dagmc_enabled(): |
| 58 | + pytest.skip('DAGMC (and MOAB) not enabled in this build.') |
| 59 | + |
| 60 | + mesh = openmc.UnstructuredMesh( |
| 61 | + str(request.path.with_name('test_mesh_tets.exo')), library) |
| 62 | + ww = openmc.WeightWindows(mesh, np.ones((12_000,)), upper_bound_ratio=5.0) |
| 63 | + openmc.WeightWindowsList([ww]).export_to_hdf5('ww.h5') |
| 64 | + |
| 65 | + with h5py.File('ww.h5') as f: |
| 66 | + assert f.attrs['filetype'] == b'weight_windows' |
| 67 | + assert list(f.attrs['version']) == [1, 0] |
| 68 | + assert int(f['weight_windows'].attrs['n_weight_windows']) == 1 |
| 69 | + m_grp = f['meshes'][f'mesh {mesh.id}'] |
| 70 | + assert m_grp['type'][()] == b'unstructured' |
| 71 | + assert 'filename' in m_grp |
0 commit comments