Skip to content

Commit 923130f

Browse files
committed
Remove default dimension on from_domain. Add a test
1 parent 90d1b8d commit 923130f

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

openmc/mesh.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,15 +937,29 @@ def _check_vtk_dataset(self, label: str, dataset: np.ndarray):
937937
)
938938

939939
@classmethod
940-
def from_domain(cls, domain, dimension=1000, mesh_id=None, name='', **kwargs):
940+
def from_domain(
941+
cls,
942+
domain: HasBoundingBox | BoundingBox,
943+
dimension: Sequence[int] | int | None = None,
944+
mesh_id: int | None = None,
945+
name: str = '',
946+
**kwargs
947+
):
948+
"""Create a structured mesh from a domain using its bounding box."""
941949
if isinstance(domain, BoundingBox):
942950
bbox = domain
943951
elif hasattr(domain, 'bounding_box'):
944952
bbox = domain.bounding_box
945953
else:
946954
raise TypeError("Domain must be a BoundingBox or have a "
947955
"bounding_box property")
948-
return cls.from_bounding_box(bbox, dimension=dimension, mesh_id=mesh_id, name=name, **kwargs)
956+
957+
if dimension is None:
958+
return cls.from_bounding_box(
959+
bbox, mesh_id=mesh_id, name=name, **kwargs)
960+
961+
return cls.from_bounding_box(
962+
bbox, dimension=dimension, mesh_id=mesh_id, name=name, **kwargs)
949963

950964
@classmethod
951965
@abstractmethod

tests/unit_tests/test_mesh_from_domain.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ def test_reg_mesh_from_bounding_box():
2727
assert np.array_equal(mesh.upper_right, bb[1])
2828

2929

30+
def test_rectilinear_mesh_from_bounding_box():
31+
"""Tests a RectilinearMesh can be made from a BoundingBox directly."""
32+
bb = openmc.BoundingBox([-8, -7, -5], [12, 13, 15])
33+
34+
mesh = openmc.RectilinearMesh.from_bounding_box(bb, dimension=[2, 4, 5])
35+
assert isinstance(mesh, openmc.RectilinearMesh)
36+
assert np.array_equal(mesh.dimension, (2, 4, 5))
37+
assert np.array_equal(mesh.lower_left, bb[0])
38+
assert np.array_equal(mesh.upper_right, bb[1])
39+
assert np.array_equal(mesh.x_grid, [-8., 2., 12.])
40+
assert np.array_equal(mesh.y_grid, [-7., -2., 3., 8., 13.])
41+
assert np.array_equal(mesh.z_grid, [-5., -1., 3., 7., 11., 15.])
42+
43+
3044
def test_cylindrical_mesh_from_cell():
3145
"""Tests a CylindricalMesh can be made from a Cell and the specified
3246
dimensions are propagated through."""

0 commit comments

Comments
 (0)