Merge branch 'develop' into moving_voxel_plot_code

This commit is contained in:
Jonathan Shimwell 2023-04-20 18:19:28 +01:00 committed by GitHub
commit 63603dbabd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 452 additions and 199 deletions

Binary file not shown.

View file

@ -0,0 +1,81 @@
import numpy as np
from pathlib import Path
import openmc
import openmc.lib
import pytest
pytestmark = pytest.mark.skipif(
not openmc.lib._dagmc_enabled(),
reason="DAGMC CAD geometry is not enabled.")
@pytest.fixture
def broken_dagmc_model(request):
openmc.reset_auto_ids()
model = openmc.Model()
### MATERIALS ###
fuel = openmc.Material(name='no-void fuel')
fuel.set_density('g/cc', 10.29769)
fuel.add_nuclide('U233', 1.0)
cladding = openmc.Material(name='clad')
cladding.set_density('g/cc', 6.55)
cladding.add_nuclide('Zr90', 1.0)
h1 = openmc.Material(name='water')
h1.set_density('g/cc', 0.75)
h1.add_nuclide('H1', 1.0)
model.materials = openmc.Materials([fuel, cladding, h1])
### GEOMETRY ###
# create the DAGMC universe using a model that has many triangles
# removed
dagmc_file = Path(request.fspath).parent / "broken_model.h5m"
pincell_univ = openmc.DAGMCUniverse(filename=dagmc_file, auto_geom_ids=True)
# create a 2 x 2 lattice using the DAGMC pincell
pitch = np.asarray((24.0, 24.0))
lattice = openmc.RectLattice()
lattice.pitch = pitch
lattice.universes = [[pincell_univ] * 2] * 2
lattice.lower_left = -pitch
# clip the DAGMC geometry at +/- 10 cm w/ CSG planes
rpp = openmc.model.RectangularParallelepiped(
-pitch[0], pitch[0], -pitch[1], pitch[1], -10.0, 10.0, boundary_type='reflective')
bounding_cell = openmc.Cell(fill=lattice, region=-rpp)
model.geometry = openmc.Geometry(root=[bounding_cell])
# settings
model.settings.particles = 100
model.settings.batches = 10
model.settings.inactive = 2
model.settings.output = {'summary': False}
model.export_to_xml()
return model
def test_lost_particles(run_in_tmpdir, broken_dagmc_model):
broken_dagmc_model.export_to_xml()
# ensure that particles will be lost when cell intersections can't be found
# due to the removed triangles in this model
with pytest.raises(RuntimeError, match='Maximum number of lost particles has been reached.'):
openmc.run()
# run this again, but with the dagmc universe as the root unvierse
for univ in broken_dagmc_model.geometry.get_all_universes().values():
if isinstance(univ, openmc.DAGMCUniverse):
broken_dagmc_model.geometry.root_unvierse = univ
break
broken_dagmc_model.export_to_xml()
with pytest.raises(RuntimeError, match='Maximum number of lost particles has been reached.'):
openmc.run()

View file

@ -187,9 +187,9 @@ def test_plots(run_in_tmpdir):
plots.export_to_xml()
# from_xml
openmc.Plots.from_xml()
assert len(plots)
assert plots[0].origin == p1.origin
assert plots[0].colors == p1.colors
assert plots[0].mask_components == p1.mask_components
assert plots[1].origin == p2.origin
new_plots = openmc.Plots.from_xml()
assert len(new_plots)
assert new_plots[0].origin == p1.origin
assert new_plots[0].colors == p1.colors
assert new_plots[0].mask_components == p1.mask_components
assert new_plots[1].origin == p2.origin

View file

@ -59,6 +59,7 @@ def test_plot(run_in_tmpdir, sphere_model):
pixels=(10, 10),
color_by='material',
colors=colors,
outline=True,
)