From 0fcc44bedb7975beda0444153964457e87f45079 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 13 Sep 2016 23:16:10 +0200 Subject: [PATCH] Fix specification of material temperature. Allow XML files to be exported to non-default paths. --- openmc/geometry.py | 5 ++--- openmc/material.py | 31 ++++++++++++------------------- openmc/plots.py | 5 ++--- openmc/settings.py | 5 ++--- tests/test_source/test_source.py | 2 +- 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/openmc/geometry.py b/openmc/geometry.py index b2a9b5e4aa..6d9330dc6e 100644 --- a/openmc/geometry.py +++ b/openmc/geometry.py @@ -64,7 +64,7 @@ class Geometry(object): if cell.id in volume_calc.results: cell.add_volume_information(volume_calc) - def export_to_xml(self): + def export_to_xml(self, path='geometry.xml'): """Create a geometry.xml file that can be used for a simulation. """ @@ -82,8 +82,7 @@ class Geometry(object): # Write the XML Tree to the geometry.xml file tree = ET.ElementTree(geometry_file) - tree.write("geometry.xml", xml_declaration=True, encoding='utf-8', - method="xml") + tree.write(path, xml_declaration=True, encoding='utf-8', method="xml") def find(self, point): """Find cells/universes/lattices which contain a given point diff --git a/openmc/material.py b/openmc/material.py index f56af485a4..2861d5be6b 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -41,19 +41,16 @@ class Material(object): name : str, optional Name of the material. If not specified, the name will be the empty string. - temperature : str, optional - The temperature identifier applied to this material. The units are - in Kelvin and the temperature rounded to the nearest integer. - For example, a tempreature of 293.6K would be provided as '294K' + temperature : float, optional + Temperature of the material in Kelvin. If not specified, the material + inherits the default temperature applied to the model. Attributes ---------- id : int Unique identifier for the material - temperature : str - The temperature identifier applied to this material. The units are - in Kelvin and the temperature rounded to the nearest integer. - For example, a tempreature of 293.6K would be provided as '294K' + temperature : float + Temperature of the material in Kelvin. density : float Density of the material (units defined separately) density_units : str @@ -217,12 +214,9 @@ class Material(object): @temperature.setter def temperature(self, temperature): - if temperature is not None: - cv.check_type('Temperature for Material ID="{0}"'.format(self._id), - temperature, basestring) - self._temperature = temperature - else: - self._temperature = '' + cv.check_type('Temperature for Material ID="{0}"'.format(self._id), + temperature, (Real, type(None))) + self._temperature = temperature def set_density(self, units, density=None): """Set the density of the material @@ -631,9 +625,9 @@ class Material(object): element.set("name", str(self._name)) # Create temperature XML subelement - if len(self.temperature) > 0: + if self.temperature is not None: subelement = ET.SubElement(element, "temperature") - subelement.text = self.temperature + subelement.text = str(self.temperature) # Create density XML subelement subelement = ET.SubElement(element, "density") @@ -817,7 +811,7 @@ class Materials(cv.CheckedList): xml_element = material.get_material_xml() self._materials_file.append(xml_element) - def export_to_xml(self): + def export_to_xml(self, path='materials.xml'): """Create a materials.xml file that can be used for a simulation. """ @@ -833,5 +827,4 @@ class Materials(cv.CheckedList): # Write the XML Tree to the materials.xml file tree = ET.ElementTree(self._materials_file) - tree.write("materials.xml", xml_declaration=True, - encoding='utf-8', method="xml") + tree.write(path, xml_declaration=True, encoding='utf-8', method="xml") diff --git a/openmc/plots.py b/openmc/plots.py index cc5c0d44b3..f5c1f2b2ab 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -616,7 +616,7 @@ class Plots(cv.CheckedList): self._plots_file.append(xml_element) - def export_to_xml(self): + def export_to_xml(self, path='plots.xml'): """Create a plots.xml file that can be used by OpenMC. """ @@ -631,5 +631,4 @@ class Plots(cv.CheckedList): # Write the XML Tree to the plots.xml file tree = ET.ElementTree(self._plots_file) - tree.write("plots.xml", xml_declaration=True, - encoding='utf-8', method="xml") + tree.write(path, xml_declaration=True, encoding='utf-8', method="xml") diff --git a/openmc/settings.py b/openmc/settings.py index c7d6debb9e..15898a2b8c 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -1118,7 +1118,7 @@ class Settings(object): for r in self.resonance_scattering: elem.append(r.to_xml_element()) - def export_to_xml(self): + def export_to_xml(self, path='settings.xml'): """Create a settings.xml file that can be used for a simulation. """ @@ -1162,8 +1162,7 @@ class Settings(object): # Write the XML Tree to the settings.xml file tree = ET.ElementTree(self._settings_file) - tree.write("settings.xml", xml_declaration=True, - encoding='utf-8', method="xml") + tree.write(path, xml_declaration=True, encoding='utf-8', method="xml") class ResonanceScattering(object): diff --git a/tests/test_source/test_source.py b/tests/test_source/test_source.py index ce9012bc26..26844ea4e6 100644 --- a/tests/test_source/test_source.py +++ b/tests/test_source/test_source.py @@ -13,7 +13,7 @@ import openmc class SourceTestHarness(PyAPITestHarness): def _build_inputs(self): - mat1 = openmc.Material(material_id=1, temperature='294') + mat1 = openmc.Material(material_id=1, temperature=294) mat1.set_density('g/cm3', 4.5) mat1.add_nuclide(openmc.Nuclide('U235'), 1.0) materials = openmc.Materials([mat1])