Simplify usage of DataLibrary.register_file()

This commit is contained in:
Paul Romano 2016-09-23 06:26:33 -05:00
parent 2f639aa258
commit fbcb15f8c5
9 changed files with 60 additions and 12 deletions

View file

@ -81,7 +81,7 @@ if os.path.exists(endf70sab):
data.export_to_hdf5(h5_file, 'w')
# Register with library
library.register_file(h5_file, 'thermal')
library.register_file(h5_file)
# Write cross_sections.xml
libpath = os.path.join(args.destination, 'cross_sections.xml')

View file

@ -219,7 +219,7 @@ for name, filenames in sorted(tables.items()):
data.export_to_hdf5(h5_file, 'w')
# Register with library
library.register_file(h5_file, 'thermal')
library.register_file(h5_file)
# Write cross_sections.xml
libpath = os.path.join(args.destination, 'cross_sections.xml')

View file

@ -366,6 +366,7 @@ Core Classes
openmc.data.ThermalScattering
openmc.data.CoherentElastic
openmc.data.FissionEnergyRelease
openmc.data.DataLibrary
Angle-Energy Distributions
--------------------------

View file

@ -8,20 +8,50 @@ from openmc.clean_xml import clean_xml_indentation
class DataLibrary(EqualityMixin):
"""Collection of cross section data libraries.
Attributes
----------
libraries : list of dict
List in which each item is a dictionary summarizing cross section data
from a single file. The dictionary has keys 'path', 'type', and
'materials'.
"""
def __init__(self):
self.libraries = []
def register_file(self, filename, filetype='neutron'):
def register_file(self, filename):
"""Register a file with the data library.
Parameters
----------
filename : str
Path to the file to be registered.
"""
h5file = h5py.File(filename, 'r')
materials = []
filetype = 'neutron'
for name in h5file:
if name.startswith('c_'):
filetype = 'thermal'
materials.append(name)
library = {'path': filename, 'type': filetype, 'materials': materials}
self.libraries.append(library)
def export_to_xml(self, path='cross_sections.xml'):
"""Export cross section data library to an XML file.
Parameters
----------
path : str
Path to file to write. Defaults to 'cross_sections.xml'.
"""
root = ET.Element('cross_sections')
# Determine common directory for library paths

View file

@ -65,10 +65,14 @@ class Geometry(object):
cell.add_volume_information(volume_calc)
def export_to_xml(self, path='geometry.xml'):
"""Create a geometry.xml file that can be used for a simulation.
"""Export geometry to an XML file.
Parameters
----------
path : str
Path to file to write. Defaults to 'geometry.xml'.
"""
# Clear OpenMC written IDs used to optimize XML generation
openmc.universe.WRITTEN_IDS = {}

View file

@ -812,7 +812,12 @@ class Materials(cv.CheckedList):
self._materials_file.append(xml_element)
def export_to_xml(self, path='materials.xml'):
"""Create a materials.xml file that can be used for a simulation.
"""Export material collection to an XML file.
Parameters
----------
path : str
Path to file to write. Defaults to 'materials.xml'.
"""

View file

@ -617,10 +617,14 @@ class Plots(cv.CheckedList):
self._plots_file.append(xml_element)
def export_to_xml(self, path='plots.xml'):
"""Create a plots.xml file that can be used by OpenMC.
"""Export plot specifications to an XML file.
Parameters
----------
path : str
Path to file to write. Defaults to 'plots.xml'.
"""
# Reset xml element tree
self._plots_file.clear()

View file

@ -15,8 +15,7 @@ if sys.version_info[0] >= 3:
class Settings(object):
"""Settings file used for an OpenMC simulation. Corresponds directly to the
settings.xml input file.
"""Settings used for an OpenMC simulation.
Attributes
----------
@ -1119,7 +1118,12 @@ class Settings(object):
elem.append(r.to_xml_element())
def export_to_xml(self, path='settings.xml'):
"""Create a settings.xml file that can be used for a simulation.
"""Export simulation settings to an XML file.
Parameters
----------
path : str
Path to file to write. Defaults to 'settings.xml'.
"""

View file

@ -190,7 +190,7 @@ for filename in ace_libraries:
thermal.export_to_hdf5(outfile, 'w')
# Register with library
library.register_file(outfile, 'thermal')
library.register_file(outfile)
# Add data to list
nuclides[name] = outfile