Skip to content

Commit 4fc003a

Browse files
committed
Finish openmc.lib implementation and add tests for density multipliers.
1 parent 15bbd9b commit 4fc003a

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

openmc/lib/cell.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,43 @@ def set_temperature(self, T, instance=None, set_contained=False):
244244

245245
_dll.openmc_cell_set_temperature(self._index, T, instance, set_contained)
246246

247+
def get_density_mult(self, instance=None):
248+
"""Get the density multiplier of a cell
249+
250+
Parameters
251+
----------
252+
instance: int or None
253+
Which instance of the cell
254+
255+
"""
256+
257+
if instance is not None:
258+
instance = c_int32(instance)
259+
260+
rho = c_double()
261+
_dll.openmc_cell_get_density_mult(self._index, instance, rho)
262+
return rho.value
263+
264+
def set_density_mult(self, rho, instance=None, set_contained=False):
265+
"""Set the density multiplier of a cell
266+
267+
Parameters
268+
----------
269+
rho : float
270+
Unitless density multiplier
271+
instance : int or None
272+
Which instance of the cell
273+
set_contained: bool
274+
If cell is not filled by a material, whether to set the density
275+
multiplier of all filled cells
276+
277+
"""
278+
279+
if instance is not None:
280+
instance = c_int32(instance)
281+
282+
_dll.openmc_cell_set_density_mult(self._index, rho, instance, set_contained)
283+
247284
@property
248285
def translation(self):
249286
translation = np.zeros(3)

tests/unit_tests/test_lib.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,29 @@ def test_properties_temperature(lib_init):
159159
assert cell.get_temperature() == pytest.approx(200.0)
160160

161161

162+
def test_cell_density_mult(lib_init):
163+
cell = openmc.lib.cells[1]
164+
cell.set_density_mult(1.5, 0)
165+
assert cell.get_density_mult(0) == pytest.approx(1.5)
166+
cell.set_density_mult(2.0)
167+
assert cell.get_density_mult() == pytest.approx(2.0)
168+
169+
170+
def test_properties_density_mult(lib_init):
171+
# Cell density multiplier should be 2.0 from above test
172+
cell = openmc.lib.cells[1]
173+
assert cell.get_density_mult() == pytest.approx(2.0)
174+
175+
# Export properties and change density multiplier
176+
openmc.lib.export_properties('properties.h5')
177+
cell.set_density_mult(3.0)
178+
assert cell.get_density_mult() == pytest.approx(3.0)
179+
180+
# Import properties and check that density multiplier is restored
181+
openmc.lib.import_properties('properties.h5')
182+
assert cell.get_density_mult() == pytest.approx(2.0)
183+
184+
162185
def test_new_cell(lib_init):
163186
with pytest.raises(exc.AllocationError):
164187
openmc.lib.Cell(1)

0 commit comments

Comments
 (0)