Skip to content

Commit

Permalink
cy mesh origin from start of z_grid and _r_grid (#2680)
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell authored Sep 4, 2023
1 parent 2de2023 commit a42b9ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions openmc/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ def from_domain(
(openmc.Cell, openmc.Region, openmc.Universe, openmc.Geometry),
)

# loaded once to avoid reading h5m file repeatedly
# loaded once to avoid recalculating bounding box
cached_bb = domain.bounding_box
max_bounding_box_radius = max(
[
Expand All @@ -1438,7 +1438,7 @@ def from_domain(
cached_bb[1][2],
num=dimension[2]+1
)
origin = cached_bb.center
origin = (cached_bb.center[0], cached_bb.center[1], z_grid[0])
mesh = cls(
r_grid=r_grid,
z_grid=z_grid,
Expand Down
30 changes: 25 additions & 5 deletions tests/unit_tests/test_mesh_from_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,39 @@ def test_reg_mesh_from_cell():

def test_cylindrical_mesh_from_cell():
"""Tests a CylindricalMesh can be made from a Cell and the specified
dimensions are propagated through. Cell is not centralized"""
dimensions are propagated through."""
# Cell is not centralized on Z axis
cy_surface = openmc.ZCylinder(r=50)
z_surface_1 = openmc.ZPlane(z0=30)
z_surface_2 = openmc.ZPlane(z0=0)
z_surface_1 = openmc.ZPlane(z0=40)
z_surface_2 = openmc.ZPlane(z0=10)
cell = openmc.Cell(region=-cy_surface & -z_surface_1 & +z_surface_2)
mesh = openmc.CylindricalMesh.from_domain(domain=cell, dimension=[2, 4, 3])

assert isinstance(mesh, openmc.CylindricalMesh)
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, [0., 10., 20., 30.])
assert np.array_equal(mesh.origin, [0., 0., 15.])
assert np.array_equal(mesh.z_grid, [10., 20., 30., 40.])
assert np.array_equal(mesh.origin, [0., 0., 10.])

# Cell is not centralized on Z or X axis
cy_surface = openmc.ZCylinder(r=50, x0=100)
cell = openmc.Cell(region=-cy_surface & -z_surface_1 & +z_surface_2)
mesh = openmc.CylindricalMesh.from_domain(domain=cell, dimension=[1, 1, 1])

assert isinstance(mesh, openmc.CylindricalMesh)
assert np.array_equal(mesh.dimension, (1, 1, 1))
assert np.array_equal(mesh.r_grid, [0., 150.])
assert np.array_equal(mesh.origin, [100., 0., 10.])

# Cell is not centralized on Z, X or Y axis
cy_surface = openmc.ZCylinder(r=50, x0=100, y0=170)
cell = openmc.Cell(region=-cy_surface & -z_surface_1 & +z_surface_2)
mesh = openmc.CylindricalMesh.from_domain(domain=cell, dimension=[1, 1, 1])

assert isinstance(mesh, openmc.CylindricalMesh)
assert np.array_equal(mesh.r_grid, [0., 220.])
assert np.array_equal(mesh.origin, [100., 170., 10.])


def test_reg_mesh_from_region():
Expand Down

0 comments on commit a42b9ba

Please sign in to comment.