Skip to content

Read additional information for DAGMC cells from openmc.lib #3401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions openmc/dagmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 {}

Expand Down
20 changes: 20 additions & 0 deletions tests/unit_tests/dagmc/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -13,6 +14,7 @@

@pytest.fixture()
def model(request):
openmc.reset_auto_ids()
pitch = 1.26

mats = {}
Expand Down Expand Up @@ -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 = {}

Expand Down