From ab403b2fc8cf0aed15065c7caeafdfa79f4c07af Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 27 Mar 2023 16:15:38 -0500 Subject: [PATCH] Improvements to tests --- tests/unit_tests/test_cylindrical_mesh.py | 22 ++++++++++++-------- tests/unit_tests/test_spherical_mesh.py | 25 ++++++++++++----------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/tests/unit_tests/test_cylindrical_mesh.py b/tests/unit_tests/test_cylindrical_mesh.py index c8346bb4a..27c4d5a1f 100644 --- a/tests/unit_tests/test_cylindrical_mesh.py +++ b/tests/unit_tests/test_cylindrical_mesh.py @@ -149,12 +149,12 @@ def _check_void_cylindrical_tally(statepoint_filename): with openmc.StatePoint(statepoint_filename) as sp: flux_tally = sp.tallies[1] mesh = flux_tally.find_filter(openmc.MeshFilter).mesh - neutron_flux = flux_tally.get_reshaped_data().squeeze() / mesh.volumes.flatten() - flux_diff = np.diff(neutron_flux) - # ensure flux values are monotonically decreasing due to - # geometric attenuation - assert (flux_diff < 0.0).all() - + neutron_flux = flux_tally.get_reshaped_data().squeeze() + # we expect the tally results to be the same as the mesh grid width + # for these cases + print(neutron_flux) + d_r = mesh.r_grid[1] - mesh.r_grid[0] + assert neutron_flux == pytest.approx(d_r) def test_void_geom_pnt_src(run_in_tmpdir, void_coincident_geom_model): src = openmc.Source() @@ -168,11 +168,15 @@ def test_void_geom_pnt_src(run_in_tmpdir, void_coincident_geom_model): def test_void_geom_boundary_src(run_in_tmpdir, void_coincident_geom_model): + # update source to a number of points on the outside of the cylinder + # with directions pointing toward the origin bbox = void_coincident_geom_model.geometry.bounding_box - outer_r = bbox[1][0] - 0.0001 + # can't source particle directly on the geometry boundary + outer_r = bbox[1][0] - 1e-08 - radial_vals = np.linspace(0.0, 2.0*np.pi, 100) + n_sources = 100 + radial_vals = np.linspace(0.0, 2.0*np.pi, n_sources) sources = [] @@ -185,7 +189,7 @@ def test_void_geom_boundary_src(run_in_tmpdir, void_coincident_geom_model): u = -pnt src.space = openmc.stats.Point(outer_r*pnt) src.angle = openmc.stats.Monodirectional(u) - + src.strength = 0.5/n_sources sources.append(src) void_coincident_geom_model.settings.source = sources diff --git a/tests/unit_tests/test_spherical_mesh.py b/tests/unit_tests/test_spherical_mesh.py index 860156671..0f02e9699 100644 --- a/tests/unit_tests/test_spherical_mesh.py +++ b/tests/unit_tests/test_spherical_mesh.py @@ -155,11 +155,11 @@ def _check_void_spherical_tally(statepoint_filename): with openmc.StatePoint(statepoint_filename) as sp: flux_tally = sp.tallies[1] mesh = flux_tally.find_filter(openmc.MeshFilter).mesh - neutron_flux = flux_tally.get_reshaped_data().squeeze() / mesh.volumes.flatten() - flux_diff = np.diff(neutron_flux) - # ensure flux values are monotonically decreasing due to - # geometric attenuation - assert (flux_diff < 0.0).all() + neutron_flux = flux_tally.get_reshaped_data().squeeze() + # the flux values for each bin should equal the width + # width of the mesh bins + d_r = mesh.r_grid[1] - mesh.r_grid[0] + assert neutron_flux == pytest.approx(d_r) def test_void_geom_pnt_src(run_in_tmpdir, void_coincident_geom_model): @@ -169,22 +169,21 @@ def test_void_geom_pnt_src(run_in_tmpdir, void_coincident_geom_model): src.energy = openmc.stats.Discrete([14.06e6], [1]) void_coincident_geom_model.settings.source = src + # run model and check tally results sp_filename = void_coincident_geom_model.run() - _check_void_spherical_tally(sp_filename) def test_void_geom_boundary_src(run_in_tmpdir, void_coincident_geom_model): # update source to a number of points on the outside of the sphere # with directions pointing toward the origin - - # sources - phi_vals = np.linspace(0, np.pi, 20) - theta_vals = np.linspace(0, 2.0*np.pi, 20) + n_sources = 20 + phi_vals = np.linspace(0, np.pi, n_sources) + theta_vals = np.linspace(0, 2.0*np.pi, n_sources) bbox = void_coincident_geom_model.geometry.bounding_box # can't source particles directly on the geometry boundary - outer_r = bbox[1][0] - 0.00001 + outer_r = bbox[1][0] - 1e-08 sources = [] @@ -199,11 +198,13 @@ def test_void_geom_boundary_src(run_in_tmpdir, void_coincident_geom_model): u = -pnt src.space = openmc.stats.Point(outer_r*pnt) src.angle = openmc.stats.Monodirectional(u) + # set source strengths so that we can still expect + # a tally value of 0.5 + src.strength = 0.5/n_sources sources.append(src) void_coincident_geom_model.settings.source = sources sp_filename = void_coincident_geom_model.run() - _check_void_spherical_tally(sp_filename)