mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Adding a check to ensure we dont translate a cell not filled with a universe and then incorporating this in the unit test.
This commit is contained in:
parent
1d8f4c922e
commit
7bcf2ca9e8
2 changed files with 40 additions and 6 deletions
|
|
@ -1318,6 +1318,12 @@ extern "C" int openmc_cell_get_translation(int32_t index, double xyz[])
|
|||
extern "C" int openmc_cell_set_translation(int32_t index, const double xyz[])
|
||||
{
|
||||
if (index >= 0 && index < model::cells.size()) {
|
||||
if (model::cells[index]->fill_ == C_NONE) {
|
||||
set_errmsg(fmt::format("Cannot apply a translation to cell {}"
|
||||
" because it is not filled with another universe",
|
||||
index));
|
||||
return OPENMC_E_GEOMETRY;
|
||||
}
|
||||
model::cells[index]->translation_ = Position(xyz);
|
||||
return 0;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -99,6 +99,21 @@ def lib_run(lib_simulation_init):
|
|||
openmc.lib.run()
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def pincell_model_w_univ():
|
||||
"""Set up a model to test with and delete files when done"""
|
||||
openmc.reset_auto_ids()
|
||||
pincell = openmc.examples.pwr_pin_cell()
|
||||
clad_univ = openmc.Universe(cells=[openmc.Cell(fill=pincell.materials[1])])
|
||||
pincell.geometry.root_universe.cells[2].fill = clad_univ
|
||||
pincell.settings.verbosity = 1
|
||||
|
||||
# Write XML files in tmpdir
|
||||
with cdtemp():
|
||||
pincell.export_to_xml()
|
||||
yield
|
||||
|
||||
|
||||
def test_cell_mapping(lib_init):
|
||||
cells = openmc.lib.cells
|
||||
assert isinstance(cells, Mapping)
|
||||
|
|
@ -141,12 +156,6 @@ def test_properties_temperature(lib_init):
|
|||
openmc.lib.import_properties('properties.h5')
|
||||
assert cell.get_temperature() == pytest.approx(200.0)
|
||||
|
||||
def test_cell_translation(lib_init):
|
||||
cell = openmc.lib.cells[1]
|
||||
assert cell.get_translation() == pytest.approx([0., 0., 0.])
|
||||
cell.set_translation(np.array([1., 0., -1.]))
|
||||
assert cell.get_translation() == pytest.approx([1., 0., -1.])
|
||||
|
||||
|
||||
def test_new_cell(lib_init):
|
||||
with pytest.raises(exc.AllocationError):
|
||||
|
|
@ -699,3 +708,22 @@ def test_trigger_set_n_batches(uo2_trigger_model, mpi_intracomm):
|
|||
# Ensure statepoint was created only at batch 20 when calling set_batches
|
||||
assert not os.path.exists('statepoint.12.h5')
|
||||
assert os.path.exists('statepoint.20.h5')
|
||||
|
||||
|
||||
def test_cell_translation(pincell_model_w_univ, mpi_intracomm):
|
||||
openmc.lib.finalize()
|
||||
openmc.lib.init(intracomm=mpi_intracomm)
|
||||
openmc.lib.simulation_init()
|
||||
# Cell 1 is filled with a material so it has a translation, but we can't
|
||||
# set it.
|
||||
cell = openmc.lib.cells[1]
|
||||
assert cell.get_translation() == pytest.approx([0., 0., 0.])
|
||||
with pytest.raises(exc.GeometryError, match='not filled with'):
|
||||
cell.set_translation(np.array([1., 0., -1.]))
|
||||
|
||||
# Cell 2 was given a universe, so we can assign it a translation vector
|
||||
cell = openmc.lib.cells[2]
|
||||
assert cell.get_translation() == pytest.approx([0., 0., 0.])
|
||||
# This time we *can* set it
|
||||
cell.set_translation(np.array([1., 0., -1.]))
|
||||
assert cell.get_translation() == pytest.approx([1., 0., -1.])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue