Repository: openmc-dev/openmc

Issue:
Materials.from_xml not respecting temperature
Noticed that the newly generated material inputs when running depletion did not have any temperature tags. A simple working example
```
import openmc

mat0 = openmc.Material()
mat0.add_element("H", 2)
mat0.add_element("O", 1)
mat0.temperature = 600

openmc.Materials([mat0]).export_to_xml()

# can check to make sure the temperature tag is present

mat1 = openmc.Materials.from_xml()[0]

assert mat1.temperature is not None
```


Discussion:
Looks like the error is due where `from_xml_element` expects to find temperature
https://github.com/openmc-dev/openmc/blob/448b2ff82c1f64ddcc9e217b2da49b921a108c13/openmc/material.py#L934-L935

and where it is written
https://github.com/openmc-dev/openmc/blob/448b2ff82c1f64ddcc9e217b2da49b921a108c13/openmc/material.py#L842-L845

Resolving patch:
diff --git a/openmc/material.py b/openmc/material.py
--- a/openmc/material.py
+++ b/openmc/material.py
@@ -287,6 +287,8 @@ def from_hdf5(cls, group):
         material.depletable = bool(group.attrs['depletable'])
         if 'volume' in group.attrs:
             material.volume = group.attrs['volume']
+        if "temperature" in group.attrs:
+            material.temperature = group.attrs["temperature"]
 
         # Read the names of the S(a,b) tables for this Material and add them
         if 'sab_names' in group:
@@ -841,8 +843,7 @@ def to_xml_element(self, cross_sections=None):
 
         # Create temperature XML subelement
         if self.temperature is not None:
-            subelement = ET.SubElement(element, "temperature")
-            subelement.text = str(self.temperature)
+            element.set("temperature", str(self.temperature))
 
         # Create density XML subelement
         if self._density is not None or self._density_units == 'sum':
@@ -931,8 +932,10 @@ def from_xml_element(cls, elem):
         mat_id = int(elem.get('id'))
         mat = cls(mat_id)
         mat.name = elem.get('name')
-        if 'temperature' in elem.attrib:
-            mat.temperature = float(elem.get('temperature'))
+
+        if "temperature" in elem.attrib:
+            mat.temperature = float(elem.get("temperature"))
+
         if 'volume' in elem.attrib:
             mat.volume = float(elem.get('volume'))
         mat.depletable = bool(elem.get('depletable'))


Test patch:
diff --git a/tests/regression_tests/source/inputs_true.dat b/tests/regression_tests/source/inputs_true.dat
--- a/tests/regression_tests/source/inputs_true.dat
+++ b/tests/regression_tests/source/inputs_true.dat
@@ -5,8 +5,7 @@
 </geometry>
 <?xml version='1.0' encoding='utf-8'?>
 <materials>
-  <material depletable="true" id="1">
-    <temperature>294</temperature>
+  <material depletable="true" id="1" temperature="294">
     <density units="g/cm3" value="4.5" />
     <nuclide ao="1.0" name="U235" />
   </material>
diff --git a/tests/unit_tests/test_material.py b/tests/unit_tests/test_material.py
--- a/tests/unit_tests/test_material.py
+++ b/tests/unit_tests/test_material.py
@@ -189,6 +189,8 @@ def test_from_xml(run_in_tmpdir):
     m1.add_nuclide('H1', 1.0)
     m1.add_nuclide('O16', 2.0)
     m1.add_s_alpha_beta('c_H_in_H2O')
+    m1.temperature = 300
+    m1.volume = 100
     m1.set_density('g/cm3', 0.9)
     m1.isotropic = ['H1']
     m2 = openmc.Material(2, 'zirc')
@@ -209,6 +211,8 @@ def test_from_xml(run_in_tmpdir):
     assert m1.name == 'water'
     assert m1.nuclides == [('H1', 1.0, 'ao'), ('O16', 2.0, 'ao')]
     assert m1.isotropic == ['H1']
+    assert m1.temperature == 300
+    assert m1.volume == 100
     m2 = mats[1]
     assert m2.nuclides == [('Zr90', 1.0, 'wo')]
     assert m2.density == 10.0