diff --git a/openmc/dagmc.py b/openmc/dagmc.py index 8ab0aaf69e7..3249fd8945f 100644 --- a/openmc/dagmc.py +++ b/openmc/dagmc.py @@ -557,14 +557,25 @@ def sync_dagmc_cells(self, mats: Iterable[openmc.Material]): f"the number of cells in the Python universe." ) - mats_per_id = {mat.id: mat for mat in mats} - for dag_cell_id in dagmc_cell_ids: - dag_cell = openmc.lib.cells[dag_cell_id] - if isinstance(dag_cell.fill, Iterable): - fill = [mats_per_id[mat.id] for mat in dag_cell.fill if mat] - else: - fill = mats_per_id[dag_cell.fill.id] if dag_cell.fill else None - self.add_cell(openmc.DAGMCCell(cell_id=dag_cell_id, fill=fill)) + with warnings.catch_warnings(): + warnings.filterwarnings('ignore', category=UserWarning) + + mats_per_id = {mat.id: mat for mat in mats} + for dag_cell_id in dagmc_cell_ids: + dag_cell = openmc.lib.cells[dag_cell_id] + if isinstance(dag_cell.fill, Iterable): + fill = [mats_per_id[mat.id] for mat in dag_cell.fill if mat] + else: + fill = mats_per_id[dag_cell.fill.id] if dag_cell.fill else None + cell = openmc.DAGMCCell(cell_id=int(dag_cell_id), fill=fill) + + n_instances = dag_cell.num_instances + if n_instances > 1: + cell.temperature = [dag_cell.get_temperature(i) for i in range(n_instances)] + else: + cell.temperature = dag_cell.get_temperature() + + self.add_cell(cell) class DAGMCCell(openmc.Cell): @@ -601,9 +612,15 @@ def DAG_parent_universe(self, universe): """Set the parent universe of the cell.""" self._parent_universe = universe.id + @property def bounding_box(self): return BoundingBox.infinite() + @openmc.Cell.temperature.setter + def temperature(self, val): + warnings.warn('Changes to temperatures on DAGMCCell\'s will not be reflected in transport') + openmc.Cell.temperature.fset(self, val) + def get_all_cells(self, memo=None): return {} diff --git a/tests/unit_tests/dagmc/test_model.py b/tests/unit_tests/dagmc/test_model.py index 9fdfbcebc68..1c9afaba06e 100644 --- a/tests/unit_tests/dagmc/test_model.py +++ b/tests/unit_tests/dagmc/test_model.py @@ -4,6 +4,7 @@ import numpy as np import pytest import openmc +import openmc.lib from openmc.utility_funcs import change_directory pytestmark = pytest.mark.skipif( @@ -13,6 +14,7 @@ @pytest.fixture() def model(request): + openmc.reset_auto_ids() pitch = 1.26 mats = {} @@ -69,6 +71,24 @@ def model(request): openmc.reset_auto_ids() +def test_temperature_read(model): + # because the DAGMC unvierse is repeated, all cells will have more than one + # instance and in turn more than one temperature + for cell in model.geometry.get_all_material_cells().values(): + cell_temps = cell.temperature + for t in cell_temps: + if cell.id == 3: + assert t == 300.0 + else: + assert t == pytest.approx(293.6) + + +def test_cell_temperature_warning(model): + c = list(model.geometry.get_all_material_cells().values())[0] + with pytest.warns(UserWarning): + c.temperature = 800 + + def test_dagmc_replace_material_assignment(model): mats = {}