Change xml_write -> export_to_xml, xml_read -> from_xml for consistency

This commit is contained in:
Paul Romano 2018-02-14 10:17:30 -06:00
parent 26852f79f4
commit 43147b70eb
6 changed files with 20 additions and 19 deletions

View file

@ -317,7 +317,7 @@ class DepletionChain(object):
return depl_chain
@classmethod
def xml_read(cls, filename):
def from_xml(cls, filename):
"""Reads a depletion chain XML file.
Parameters
@ -343,7 +343,7 @@ class DepletionChain(object):
reaction_index = 0
for i, nuclide_elem in enumerate(root.findall('nuclide_table')):
nuc = Nuclide.xml_read(nuclide_elem)
nuc = Nuclide.from_xml(nuclide_elem)
depl_chain.nuclide_dict[nuc.name] = i
# Check for reaction paths
@ -356,7 +356,7 @@ class DepletionChain(object):
return depl_chain
def xml_write(self, filename):
def export_to_xml(self, filename):
"""Writes a depletion chain XML file.
Parameters
@ -368,7 +368,7 @@ class DepletionChain(object):
root_elem = ET.Element('depletion')
for nuclide in self.nuclides:
root_elem.append(nuclide.xml_write())
root_elem.append(nuclide.to_xml_element())
tree = ET.ElementTree(root_elem)
if _have_lxml:

View file

@ -71,7 +71,7 @@ class Nuclide(object):
return len(self.reactions)
@classmethod
def xml_read(cls, element):
def from_xml(cls, element):
"""Read nuclide from an XML element.
Parameters
@ -129,7 +129,7 @@ class Nuclide(object):
return nuc
def xml_write(self):
def to_xml_element(self):
"""Write nuclide to XML element.
Returns

View file

@ -186,7 +186,7 @@ class OpenMCOperator(Operator):
self.burn_nuc_to_ind = None
# Read depletion chain
self.chain = DepletionChain.xml_read(settings.chain_file)
self.chain = DepletionChain.from_xml(settings.chain_file)
# Clear out OpenMC, create task lists, distribute
if comm.rank == 0:

View file

@ -53,7 +53,7 @@ def main():
neutron_files = glob.glob(os.path.join('neutrons', '*.endf'))
chain = openmc.deplete.DepletionChain.from_endf(decay_files, nfy_files, neutron_files)
chain.xml_write('chain_endfb71.xml')
chain.export_to_xml('chain_endfb71.xml')
if __name__ == '__main__':

View file

@ -35,7 +35,7 @@ class TestNuclide(unittest.TestCase):
self.assertEqual(nuc.n_reaction_paths, 3)
def test_xml_read(self):
def test_from_xml(self):
"""Test reading nuclide data from an XML element."""
data = """
@ -58,7 +58,7 @@ class TestNuclide(unittest.TestCase):
"""
element = ET.fromstring(data)
u235 = nuclide.Nuclide.xml_read(element)
u235 = nuclide.Nuclide.from_xml(element)
self.assertEqual(u235.decay_modes, [
nuclide.DecayTuple('sf', 'U235', 7.2e-11),
@ -77,7 +77,7 @@ class TestNuclide(unittest.TestCase):
('Xe138', 0.0481413)]
})
def test_xml_write(self):
def test_to_xml_element(self):
"""Test writing nuclide data to an XML element."""
C = nuclide.Nuclide()
@ -93,7 +93,7 @@ class TestNuclide(unittest.TestCase):
]
C.yield_energies = [0.0253]
C.yield_data = {0.0253: [("A", 0.0292737), ("B", 0.002566345)]}
element = C.xml_write()
element = C.to_xml_element()
self.assertEqual(element.get("half_life"), "0.123")

View file

@ -36,13 +36,13 @@ class TestDepletionChain(unittest.TestCase):
out a good way to unit-test this."""
pass
def test_xml_read(self):
def test_from_xml(self):
""" Read chain_test.xml and ensure all values are correct. """
# Unfortunately, this routine touches a lot of the code, but most of
# the components external to depletion_chain.py are simple storage
# types.
dep = depletion_chain.DepletionChain.xml_read(_test_filename)
dep = depletion_chain.DepletionChain.from_xml(_test_filename)
# Basic checks
self.assertEqual(dep.n_nuclides, 3)
@ -93,11 +93,11 @@ class TestDepletionChain(unittest.TestCase):
self.assertEqual(nuc.yield_data[0.0253],
[("A", 0.0292737), ("B", 0.002566345)])
def test_xml_write(self):
def test_export_to_xml(self):
"""Test writing a depletion chain to XML."""
# Prevent different MPI ranks from conflicting
filename = 'test%u.xml' % comm.rank
filename = 'test{}.xml'.format(comm.rank)
A = nuclide.Nuclide()
A.name = "A"
@ -126,7 +126,7 @@ class TestDepletionChain(unittest.TestCase):
chain = depletion_chain.DepletionChain()
chain.nuclides = [A, B, C]
chain.xml_write(filename)
chain.export_to_xml(filename)
original = open(_test_filename, 'r').read()
chain_xml = open(filename, 'r').read()
@ -136,9 +136,9 @@ class TestDepletionChain(unittest.TestCase):
def test_form_matrix(self):
""" Using chain_test, and a dummy reaction rate, compute the matrix. """
# Relies on test_xml_read passing.
# Relies on test_from_xml passing.
dep = depletion_chain.DepletionChain.xml_read(_test_filename)
dep = depletion_chain.DepletionChain.from_xml(_test_filename)
cell_ind = {"10000": 0, "10001": 1}
nuc_ind = {"A": 0, "B": 1, "C": 2}
@ -196,5 +196,6 @@ class TestDepletionChain(unittest.TestCase):
self.assertEqual("NucB", dep.nuc_by_ind("NucB"))
self.assertEqual("NucC", dep.nuc_by_ind("NucC"))
if __name__ == '__main__':
unittest.main()