diff --git a/openmc/capi/cell.py b/openmc/capi/cell.py index ae536e725..959ab08fc 100644 --- a/openmc/capi/cell.py +++ b/openmc/capi/cell.py @@ -143,7 +143,7 @@ class Cell(_FortranObjectWithID): """ if instance is not None: - instance = c_int32(instance) + instance = c_int32(instance) T = c_double() _dll.openmc_cell_get_temperature(self._index, instance, T) @@ -160,7 +160,11 @@ class Cell(_FortranObjectWithID): Which instance of the cell """ - _dll.openmc_cell_set_temperature(self._index, T, c_int32(instance)) + + if instance is not None: + instance = c_int32(instance) + + _dll.openmc_cell_set_temperature(self._index, T, instance) class _CellMapping(Mapping): diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index be88072d9..07fef8516 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -75,6 +75,14 @@ def test_cell(capi_init): assert str(cell) == 'Cell[0]' +def test_cell_temperature(capi_init): + cell = openmc.capi.cells[1] + cell.set_temperature(100.0, 0) + assert cell.get_temperature(0) == 100.0 + cell.set_temperature(200) + assert cell.get_temperature() == 200.0 + + def test_new_cell(capi_init): with pytest.raises(exc.AllocationError): openmc.capi.Cell(1)