mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 14:35:27 -04:00
Add tests for from_xml methods
This commit is contained in:
parent
f42a75a9e1
commit
c5632794de
4 changed files with 96 additions and 8 deletions
|
|
@ -936,14 +936,6 @@ class Material(IDManagerMixin):
|
|||
elif 'wo' in nuclide.attrib:
|
||||
mat.add_nuclide(name, float(nuclide.attrib['wo']), 'wo')
|
||||
|
||||
# Get each element
|
||||
for element in elem.findall('element'):
|
||||
name = element.attrib['name']
|
||||
if 'ao' in element.attrib:
|
||||
mat.add_element(name, float(element.attrib['ao']))
|
||||
elif 'wo' in element.attrib:
|
||||
mat.add_element(name, float(element.attrib['wo']), 'wo')
|
||||
|
||||
# Get each S(a,b) table
|
||||
for sab in elem.findall('sab'):
|
||||
fraction = float(sab.get('fraction', 1.0))
|
||||
|
|
|
|||
|
|
@ -60,3 +60,54 @@ def cell_with_lattice():
|
|||
return ([inside_cyl, outside_cyl, main_cell],
|
||||
[m_inside[0], m_inside[1], m_inside[3], m_outside],
|
||||
univ, lattice)
|
||||
|
||||
@pytest.fixture
|
||||
def mixed_lattice_model(uo2, water):
|
||||
cyl = openmc.ZCylinder(R=0.4)
|
||||
c1 = openmc.Cell(fill=uo2, region=-cyl)
|
||||
c1.temperature = 600.0
|
||||
c2 = openmc.Cell(fill=water, region=+cyl)
|
||||
pin = openmc.Universe(cells=[c1, c2])
|
||||
|
||||
empty = openmc.Cell()
|
||||
empty_univ = openmc.Universe(cells=[empty])
|
||||
|
||||
hex_lattice = openmc.HexLattice()
|
||||
hex_lattice.center = (0.0, 0.0)
|
||||
hex_lattice.pitch = (1.2, 10.0)
|
||||
outer_ring = [pin]*6
|
||||
inner_ring = [empty_univ]
|
||||
axial_level = [outer_ring, inner_ring]
|
||||
hex_lattice.universes = [axial_level]*3
|
||||
hex_lattice.outer = empty_univ
|
||||
|
||||
cell_hex = openmc.Cell(fill=hex_lattice)
|
||||
u = openmc.Universe(cells=[cell_hex])
|
||||
rotated_cell_hex = openmc.Cell(fill=u)
|
||||
rotated_cell_hex.rotation = (0., 0., 30.)
|
||||
ur = openmc.Universe(cells=[rotated_cell_hex])
|
||||
|
||||
d = 6.0
|
||||
rect_lattice = openmc.RectLattice()
|
||||
rect_lattice.lower_left = (-d, -d)
|
||||
rect_lattice.pitch = (d, d)
|
||||
rect_lattice.outer = empty_univ
|
||||
rect_lattice.universes = [
|
||||
[ur, empty_univ],
|
||||
[empty_univ, u]
|
||||
]
|
||||
|
||||
xmin = openmc.XPlane(x0=-d, boundary_type='periodic')
|
||||
xmax = openmc.XPlane(x0=d, boundary_type='periodic')
|
||||
xmin.periodic_surface = xmax
|
||||
ymin = openmc.YPlane(y0=-d, boundary_type='periodic')
|
||||
ymax = openmc.YPlane(y0=d, boundary_type='periodic')
|
||||
main_cell = openmc.Cell(fill=rect_lattice,
|
||||
region=+xmin & -xmax & +ymin & -ymax)
|
||||
|
||||
# Create geometry and use unique material in each fuel cell
|
||||
geometry = openmc.Geometry([main_cell])
|
||||
geometry.determine_paths()
|
||||
c1.fill = [water.clone() for i in range(c1.num_instances)]
|
||||
|
||||
return openmc.model.Model(geometry)
|
||||
|
|
|
|||
|
|
@ -244,3 +244,14 @@ def test_determine_paths(cell_with_lattice):
|
|||
for i in range(4):
|
||||
assert geom.get_instances(cells[0].paths[i]) == i
|
||||
assert geom.get_instances(mats[-1].paths[i]) == i
|
||||
|
||||
def test_from_xml(run_in_tmpdir, mixed_lattice_model):
|
||||
# Export model
|
||||
mixed_lattice_model.export_to_xml()
|
||||
|
||||
# Import geometry
|
||||
geom = openmc.Geometry.from_xml()
|
||||
assert isinstance(geom, openmc.Geometry)
|
||||
ll, ur = geom.bounding_box
|
||||
assert ll == pytest.approx((-6.0, -6.0, -np.inf))
|
||||
assert ur == pytest.approx((6.0, 6.0, np.inf))
|
||||
|
|
|
|||
|
|
@ -182,3 +182,37 @@ def test_borated_water():
|
|||
# Test the density override
|
||||
m = openmc.model.borated_water(975, 566.5, 15.51, density=0.9)
|
||||
assert m.density == pytest.approx(0.9, 1e-3)
|
||||
|
||||
|
||||
def test_from_xml(run_in_tmpdir):
|
||||
# Create a materials.xml file
|
||||
m1 = openmc.Material(1, 'water')
|
||||
m1.add_nuclide('H1', 1.0)
|
||||
m1.add_nuclide('O16', 2.0)
|
||||
m1.add_s_alpha_beta('c_H_in_H2O')
|
||||
m1.set_density('g/cm3', 0.9)
|
||||
m1.isotropic = ['H1']
|
||||
m2 = openmc.Material(2, 'zirc')
|
||||
m2.add_nuclide('Zr90', 1.0, 'wo')
|
||||
m2.set_density('kg/m3', 10.0)
|
||||
m3 = openmc.Material(3)
|
||||
m3.add_nuclide('N14', 0.02)
|
||||
|
||||
mats = openmc.Materials([m1, m2, m3])
|
||||
mats.cross_sections = 'fake_path.xml'
|
||||
mats.multipole_library = 'fake_multipole/'
|
||||
mats.export_to_xml()
|
||||
|
||||
# Regenerate materials from XML
|
||||
mats = openmc.Materials.from_xml()
|
||||
assert len(mats) == 3
|
||||
m1 = mats[0]
|
||||
assert m1.id == 1
|
||||
assert m1.name == 'water'
|
||||
assert m1.nuclides == [('H1', 1.0, 'ao'), ('O16', 2.0, 'ao')]
|
||||
assert m1.isotropic == ['H1']
|
||||
m2 = mats[1]
|
||||
assert m2.nuclides == [('Zr90', 1.0, 'wo')]
|
||||
assert m2.density == 10.0
|
||||
assert m2.density_units == 'kg/m3'
|
||||
assert mats[2].density_units == 'sum'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue