Read in material temperatures from xml subelement

Closes #1280 by reading the temperature from an xml
subelement as it is written, not an attribute.

Added loading of temperature and volume material attributes
from xml in unit test
This commit is contained in:
Andrew Johnson 2019-07-05 14:44:21 -05:00
parent 448b2ff82c
commit ff13e98a09
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB
2 changed files with 9 additions and 2 deletions

View file

@ -931,8 +931,11 @@ class Material(IDManagerMixin):
mat_id = int(elem.get('id')) mat_id = int(elem.get('id'))
mat = cls(mat_id) mat = cls(mat_id)
mat.name = elem.get('name') mat.name = elem.get('name')
if 'temperature' in elem.attrib:
mat.temperature = float(elem.get('temperature')) temp_node = elem.find("temperature")
if temp_node is not None:
mat.temperature = float(temp_node.text)
if 'volume' in elem.attrib: if 'volume' in elem.attrib:
mat.volume = float(elem.get('volume')) mat.volume = float(elem.get('volume'))
mat.depletable = bool(elem.get('depletable')) mat.depletable = bool(elem.get('depletable'))

View file

@ -189,6 +189,8 @@ def test_from_xml(run_in_tmpdir):
m1.add_nuclide('H1', 1.0) m1.add_nuclide('H1', 1.0)
m1.add_nuclide('O16', 2.0) m1.add_nuclide('O16', 2.0)
m1.add_s_alpha_beta('c_H_in_H2O') m1.add_s_alpha_beta('c_H_in_H2O')
m1.temperature = 300
m1.volume = 100
m1.set_density('g/cm3', 0.9) m1.set_density('g/cm3', 0.9)
m1.isotropic = ['H1'] m1.isotropic = ['H1']
m2 = openmc.Material(2, 'zirc') m2 = openmc.Material(2, 'zirc')
@ -209,6 +211,8 @@ def test_from_xml(run_in_tmpdir):
assert m1.name == 'water' assert m1.name == 'water'
assert m1.nuclides == [('H1', 1.0, 'ao'), ('O16', 2.0, 'ao')] assert m1.nuclides == [('H1', 1.0, 'ao'), ('O16', 2.0, 'ao')]
assert m1.isotropic == ['H1'] assert m1.isotropic == ['H1']
assert m1.temperature == 300
assert m1.volume == 100
m2 = mats[1] m2 = mats[1]
assert m2.nuclides == [('Zr90', 1.0, 'wo')] assert m2.nuclides == [('Zr90', 1.0, 'wo')]
assert m2.density == 10.0 assert m2.density == 10.0