From f7bb27e0d924d9a6bffdf02cfa2eecc0d8ef194d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 27 Sep 2023 13:46:53 -0500 Subject: [PATCH] Making z-grid relative to the mesh origin in from_domain. (#2710) --- openmc/mesh.py | 4 ++++ tests/unit_tests/test_mesh_from_domain.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index d683c880869..a655e7a89ec 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -1439,6 +1439,10 @@ def from_domain( num=dimension[2]+1 ) origin = (cached_bb.center[0], cached_bb.center[1], z_grid[0]) + + # make z-grid relative to the origin + z_grid -= origin[2] + mesh = cls( r_grid=r_grid, z_grid=z_grid, diff --git a/tests/unit_tests/test_mesh_from_domain.py b/tests/unit_tests/test_mesh_from_domain.py index c75e8fd078c..0cbe413e86a 100644 --- a/tests/unit_tests/test_mesh_from_domain.py +++ b/tests/unit_tests/test_mesh_from_domain.py @@ -30,7 +30,7 @@ def test_cylindrical_mesh_from_cell(): assert np.array_equal(mesh.dimension, (2, 4, 3)) assert np.array_equal(mesh.r_grid, [0., 25., 50.]) assert np.array_equal(mesh.phi_grid, [0., 0.5*np.pi, np.pi, 1.5*np.pi, 2.*np.pi]) - assert np.array_equal(mesh.z_grid, [10., 20., 30., 40.]) + assert np.array_equal(mesh.z_grid, [0., 10., 20., 30.]) assert np.array_equal(mesh.origin, [0., 0., 10.]) # Cell is not centralized on Z or X axis @@ -83,7 +83,8 @@ def test_cylindrical_mesh_from_region(): assert np.array_equal(mesh.dimension, (6, 2, 3)) assert np.array_equal(mesh.r_grid, [0., 1., 2., 3., 4., 5., 6.]) assert np.array_equal(mesh.phi_grid, [0., 0.5*np.pi, np.pi]) - assert np.array_equal(mesh.z_grid, [-30., -10., 10., 30.]) + assert np.array_equal(mesh.z_grid, [0.0, 20., 40., 60]) + assert np.array_equal(mesh.origin, (0.0, 0.0, -30.)) def test_reg_mesh_from_universe():