mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Merge pull request #2333 from openmc-dev/optional_materials_when_loading_geometry_2
allowing xml file for materials
This commit is contained in:
commit
02abb63bcf
2 changed files with 36 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import xml.etree.ElementTree as ET
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import openmc
|
||||
|
|
@ -274,7 +275,22 @@ def test_from_xml(run_in_tmpdir, mixed_lattice_model):
|
|||
# Export model
|
||||
mixed_lattice_model.export_to_xml()
|
||||
|
||||
# Import geometry
|
||||
mats_from_xml = openmc.Materials.from_xml('materials.xml')
|
||||
# checking string a Path are both acceptable
|
||||
for path in ['geometry.xml', Path('geometry.xml')]:
|
||||
for materials in [mats_from_xml, 'materials.xml']:
|
||||
# Import geometry from file
|
||||
geom = openmc.Geometry.from_xml(path=path, materials=materials)
|
||||
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))
|
||||
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
geom = openmc.Geometry.from_xml(path='geometry.xml', materials=None)
|
||||
assert 'Unable to set "materials" to "None"' in str(excinfo.value)
|
||||
|
||||
# checking that the default args also work
|
||||
geom = openmc.Geometry.from_xml()
|
||||
assert isinstance(geom, openmc.Geometry)
|
||||
ll, ur = geom.bounding_box
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue