Fix specification of material temperature. Allow XML files to be exported to

non-default paths.
This commit is contained in:
Paul Romano 2016-09-13 23:16:10 +02:00
parent 9de22b96b3
commit 0fcc44bedb
5 changed files with 19 additions and 29 deletions

View file

@ -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

View file

@ -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")

View file

@ -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")

View file

@ -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):

View file

@ -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])