Skip to content

Commit 4500f07

Browse files
authored
Remove reorder_attributes from openmc._xml (#3519)
1 parent 4fabed5 commit 4500f07

180 files changed

Lines changed: 5006 additions & 5035 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openmc/_xml.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ def get_text(elem, name, default=None):
6363
return child.text if child is not None else default
6464

6565

66-
def reorder_attributes(root):
67-
"""Sort attributes in XML to preserve pre-Python 3.8 behavior
68-
69-
Parameters
70-
----------
71-
root : lxml.etree._Element
72-
Root element
73-
74-
"""
75-
for el in root.iter():
76-
attrib = el.attrib
77-
if len(attrib) > 1:
78-
# adjust attribute order, e.g. by sorting
79-
attribs = sorted(attrib.items())
80-
attrib.clear()
81-
attrib.update(attribs)
82-
8366

8467
def get_elem_tuple(elem, name, dtype=int):
8568
"""Helper function to get a tuple of values from an elem

openmc/data/library.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lxml.etree as ET
66

77
import openmc
8-
from openmc._xml import clean_indentation, reorder_attributes
8+
from openmc._xml import clean_indentation
99

1010

1111
class DataLibrary(list):
@@ -132,7 +132,6 @@ def export_to_xml(self, path='cross_sections.xml'):
132132
clean_indentation(root)
133133

134134
# Write XML file
135-
reorder_attributes(root) # TODO: Remove when support is Python 3.8+
136135
tree = ET.ElementTree(root)
137136
tree.write(str(path), xml_declaration=True, encoding='utf-8',
138137
method='xml')

openmc/geometry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def to_xml_element(self, remove_surfs=False) -> ET.Element:
140140

141141
# Clean the indentation in the file to be user-readable
142142
xml.clean_indentation(element)
143-
xml.reorder_attributes(element) # TODO: Remove when support is Python 3.8+
144143

145144
return element
146145

openmc/material.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import openmc
1818
import openmc.data
1919
import openmc.checkvalue as cv
20-
from ._xml import clean_indentation, reorder_attributes
20+
from ._xml import clean_indentation
2121
from .mixin import IDManagerMixin
2222
from .utility_funcs import input_path
2323
from . import waste
@@ -1919,7 +1919,6 @@ def _write_xml(self, file, header=True, level=0, spaces_per_level=2,
19191919
clean_indentation(element, level=level+1)
19201920
element.tail = element.tail.strip(' ')
19211921
file.write((level+1)*spaces_per_level*' ')
1922-
reorder_attributes(element) # TODO: Remove when support is Python 3.8+
19231922
file.write(ET.tostring(element, encoding="unicode"))
19241923

19251924
# Write the <material> elements.
@@ -1928,7 +1927,6 @@ def _write_xml(self, file, header=True, level=0, spaces_per_level=2,
19281927
clean_indentation(element, level=level+1)
19291928
element.tail = element.tail.strip(' ')
19301929
file.write((level+1)*spaces_per_level*' ')
1931-
reorder_attributes(element) # TODO: Remove when support is Python 3.8+
19321930
file.write(ET.tostring(element, encoding="unicode"))
19331931

19341932
# Write the closing tag for the root element.

openmc/plots.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import openmc.checkvalue as cv
1111
from openmc.checkvalue import PathLike
1212

13-
from ._xml import clean_indentation, get_elem_tuple, reorder_attributes, get_text
13+
from ._xml import clean_indentation, get_elem_tuple, get_text
1414
from .mixin import IDManagerMixin
1515

1616
_BASES = {'xy', 'xz', 'yz'}
@@ -1857,8 +1857,6 @@ def to_xml_element(self):
18571857

18581858
# Clean the indentation in the file to be user-readable
18591859
clean_indentation(self._plots_file)
1860-
# TODO: Remove when support is Python 3.8+
1861-
reorder_attributes(self._plots_file)
18621860

18631861
return self._plots_file
18641862

openmc/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import openmc.checkvalue as cv
1212
from openmc.checkvalue import PathLike
1313
from openmc.stats.multivariate import MeshSpatial
14-
from ._xml import clean_indentation, get_text, reorder_attributes
14+
from ._xml import clean_indentation, get_text
1515
from .mesh import _read_meshes, RegularMesh, MeshBase
1616
from .source import SourceBase, MeshSource, IndependentSource
1717
from .utility_funcs import input_path
@@ -2201,7 +2201,6 @@ def to_xml_element(self, mesh_memo=None):
22012201

22022202
# Clean the indentation in the file to be user-readable
22032203
clean_indentation(element)
2204-
reorder_attributes(element) # TODO: Remove when support is Python 3.8+
22052204

22062205
return element
22072206

openmc/tallies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import openmc
1717
import openmc.checkvalue as cv
18-
from ._xml import clean_indentation, reorder_attributes, get_text
18+
from ._xml import clean_indentation, get_text
1919
from .mixin import IDManagerMixin
2020
from .mesh import MeshBase
2121

@@ -3329,7 +3329,6 @@ def to_xml_element(self, memo=None):
33293329

33303330
# Clean the indentation in the file to be user-readable
33313331
clean_indentation(element)
3332-
reorder_attributes(element) # TODO: Remove when support is Python 3.8+
33333332

33343333
return element
33353334

tests/regression_tests/adj_cell_rotation/inputs_true.dat

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
<?xml version='1.0' encoding='utf-8'?>
22
<model>
33
<materials>
4-
<material depletable="true" id="1">
5-
<density units="g/cc" value="10.0"/>
6-
<nuclide ao="1.0" name="U235"/>
4+
<material id="1" depletable="true">
5+
<density value="10.0" units="g/cc"/>
6+
<nuclide name="U235" ao="1.0"/>
77
</material>
88
<material id="2">
9-
<density units="g/cc" value="0.1"/>
10-
<nuclide ao="0.1" name="H1"/>
9+
<density value="0.1" units="g/cc"/>
10+
<nuclide name="H1" ao="0.1"/>
1111
</material>
1212
</materials>
1313
<geometry>
1414
<cell id="1" material="1" region="-1" universe="1"/>
1515
<cell id="2" material="2" region="1" universe="1"/>
16-
<cell fill="1" id="3" region="2 -3 4 -5 6 -8" rotation="10 20 30" universe="2"/>
17-
<cell fill="1" id="4" region="2 -3 4 -5 8 -7" translation="0 0 15" universe="2"/>
18-
<surface coeffs="1.0 0.0 0.0 5.0" id="1" type="sphere"/>
19-
<surface boundary="vacuum" coeffs="-7.5" id="2" name="minimum x" type="x-plane"/>
20-
<surface boundary="vacuum" coeffs="7.5" id="3" name="maximum x" type="x-plane"/>
21-
<surface boundary="vacuum" coeffs="-7.5" id="4" name="minimum y" type="y-plane"/>
22-
<surface boundary="vacuum" coeffs="7.5" id="5" name="maximum y" type="y-plane"/>
23-
<surface boundary="vacuum" coeffs="-7.5" id="6" type="z-plane"/>
24-
<surface boundary="vacuum" coeffs="22.5" id="7" type="z-plane"/>
25-
<surface coeffs="7.5" id="8" type="z-plane"/>
16+
<cell id="3" fill="1" region="2 -3 4 -5 6 -8" rotation="10 20 30" universe="2"/>
17+
<cell id="4" fill="1" region="2 -3 4 -5 8 -7" translation="0 0 15" universe="2"/>
18+
<surface id="1" type="sphere" coeffs="1.0 0.0 0.0 5.0"/>
19+
<surface id="2" name="minimum x" type="x-plane" boundary="vacuum" coeffs="-7.5"/>
20+
<surface id="3" name="maximum x" type="x-plane" boundary="vacuum" coeffs="7.5"/>
21+
<surface id="4" name="minimum y" type="y-plane" boundary="vacuum" coeffs="-7.5"/>
22+
<surface id="5" name="maximum y" type="y-plane" boundary="vacuum" coeffs="7.5"/>
23+
<surface id="6" type="z-plane" boundary="vacuum" coeffs="-7.5"/>
24+
<surface id="7" type="z-plane" boundary="vacuum" coeffs="22.5"/>
25+
<surface id="8" type="z-plane" coeffs="7.5"/>
2626
</geometry>
2727
<settings>
2828
<run_mode>eigenvalue</run_mode>
2929
<particles>10000</particles>
3030
<batches>10</batches>
3131
<inactive>5</inactive>
32-
<source particle="neutron" strength="1.0" type="independent">
32+
<source type="independent" strength="1.0" particle="neutron">
3333
<space type="box">
3434
<parameters>-4.0 -4.0 -4.0 4.0 4.0 4.0</parameters>
3535
</space>

tests/regression_tests/asymmetric_lattice/inputs_true.dat

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
<?xml version='1.0' encoding='utf-8'?>
22
<model>
33
<materials>
4-
<material depletable="true" id="1" name="UOX fuel">
5-
<density units="g/cm3" value="10.062"/>
6-
<nuclide ao="4.9476e-06" name="U234"/>
7-
<nuclide ao="0.00048218" name="U235"/>
8-
<nuclide ao="0.021504" name="U238"/>
9-
<nuclide ao="1.0801e-08" name="Xe135"/>
10-
<nuclide ao="0.045737" name="O16"/>
4+
<material id="1" name="UOX fuel" depletable="true">
5+
<density value="10.062" units="g/cm3"/>
6+
<nuclide name="U234" ao="4.9476e-06"/>
7+
<nuclide name="U235" ao="0.00048218"/>
8+
<nuclide name="U238" ao="0.021504"/>
9+
<nuclide name="Xe135" ao="1.0801e-08"/>
10+
<nuclide name="O16" ao="0.045737"/>
1111
</material>
1212
<material id="2" name="Zircaloy">
13-
<density units="g/cm3" value="5.77"/>
14-
<nuclide ao="0.5145" name="Zr90"/>
15-
<nuclide ao="0.1122" name="Zr91"/>
16-
<nuclide ao="0.1715" name="Zr92"/>
17-
<nuclide ao="0.1738" name="Zr94"/>
18-
<nuclide ao="0.028" name="Zr96"/>
13+
<density value="5.77" units="g/cm3"/>
14+
<nuclide name="Zr90" ao="0.5145"/>
15+
<nuclide name="Zr91" ao="0.1122"/>
16+
<nuclide name="Zr92" ao="0.1715"/>
17+
<nuclide name="Zr94" ao="0.1738"/>
18+
<nuclide name="Zr96" ao="0.028"/>
1919
</material>
2020
<material id="3" name="Cold borated water">
21-
<density units="atom/b-cm" value="0.07416"/>
22-
<nuclide ao="2.0" name="H1"/>
23-
<nuclide ao="1.0" name="O16"/>
24-
<nuclide ao="0.000649" name="B10"/>
25-
<nuclide ao="0.002689" name="B11"/>
21+
<density value="0.07416" units="atom/b-cm"/>
22+
<nuclide name="H1" ao="2.0"/>
23+
<nuclide name="O16" ao="1.0"/>
24+
<nuclide name="B10" ao="0.000649"/>
25+
<nuclide name="B11" ao="0.002689"/>
2626
<sab name="c_H_in_H2O"/>
2727
</material>
2828
<material id="4" name="Hot borated water">
29-
<density units="atom/b-cm" value="0.06614"/>
30-
<nuclide ao="2.0" name="H1"/>
31-
<nuclide ao="1.0" name="O16"/>
32-
<nuclide ao="0.000649" name="B10"/>
33-
<nuclide ao="0.002689" name="B11"/>
29+
<density value="0.06614" units="atom/b-cm"/>
30+
<nuclide name="H1" ao="2.0"/>
31+
<nuclide name="O16" ao="1.0"/>
32+
<nuclide name="B10" ao="0.000649"/>
33+
<nuclide name="B11" ao="0.002689"/>
3434
<sab name="c_H_in_H2O"/>
3535
</material>
3636
<material id="5" name="Reactor pressure vessel steel">
37-
<density units="g/cm3" value="7.9"/>
37+
<density value="7.9" units="g/cm3"/>
3838
<nuclide name="Fe54" wo="0.05437098"/>
3939
<nuclide name="Fe56" wo="0.88500663"/>
4040
<nuclide name="Fe57" wo="0.0208008"/>
@@ -47,7 +47,7 @@
4747
<nuclide name="Cu63" wo="0.0013696"/>
4848
</material>
4949
<material id="6" name="Lower radial reflector">
50-
<density units="g/cm3" value="4.32"/>
50+
<density value="4.32" units="g/cm3"/>
5151
<nuclide name="H1" wo="0.0095661"/>
5252
<nuclide name="O16" wo="0.0759107"/>
5353
<nuclide name="B10" wo="3.08409e-05"/>
@@ -62,7 +62,7 @@
6262
<sab name="c_H_in_H2O"/>
6363
</material>
6464
<material id="7" name="Upper radial reflector / Top plate region">
65-
<density units="g/cm3" value="4.28"/>
65+
<density value="4.28" units="g/cm3"/>
6666
<nuclide name="H1" wo="0.0086117"/>
6767
<nuclide name="O16" wo="0.0683369"/>
6868
<nuclide name="B10" wo="2.77638e-05"/>
@@ -77,7 +77,7 @@
7777
<sab name="c_H_in_H2O"/>
7878
</material>
7979
<material id="8" name="Bottom plate region">
80-
<density units="g/cm3" value="7.184"/>
80+
<density value="7.184" units="g/cm3"/>
8181
<nuclide name="H1" wo="0.0011505"/>
8282
<nuclide name="O16" wo="0.0091296"/>
8383
<nuclide name="B10" wo="3.70915e-06"/>
@@ -92,7 +92,7 @@
9292
<sab name="c_H_in_H2O"/>
9393
</material>
9494
<material id="9" name="Bottom nozzle region">
95-
<density units="g/cm3" value="2.53"/>
95+
<density value="2.53" units="g/cm3"/>
9696
<nuclide name="H1" wo="0.0245014"/>
9797
<nuclide name="O16" wo="0.1944274"/>
9898
<nuclide name="B10" wo="7.89917e-05"/>
@@ -107,7 +107,7 @@
107107
<sab name="c_H_in_H2O"/>
108108
</material>
109109
<material id="10" name="Top nozzle region">
110-
<density units="g/cm3" value="1.746"/>
110+
<density value="1.746" units="g/cm3"/>
111111
<nuclide name="H1" wo="0.035887"/>
112112
<nuclide name="O16" wo="0.2847761"/>
113113
<nuclide name="B10" wo="0.000115699"/>
@@ -122,7 +122,7 @@
122122
<sab name="c_H_in_H2O"/>
123123
</material>
124124
<material id="11" name="Top of fuel assemblies">
125-
<density units="g/cm3" value="3.044"/>
125+
<density value="3.044" units="g/cm3"/>
126126
<nuclide name="H1" wo="0.0162913"/>
127127
<nuclide name="O16" wo="0.1292776"/>
128128
<nuclide name="B10" wo="5.25228e-05"/>
@@ -135,7 +135,7 @@
135135
<sab name="c_H_in_H2O"/>
136136
</material>
137137
<material id="12" name="Bottom of fuel assemblies">
138-
<density units="g/cm3" value="1.762"/>
138+
<density value="1.762" units="g/cm3"/>
139139
<nuclide name="H1" wo="0.0292856"/>
140140
<nuclide name="O16" wo="0.2323919"/>
141141
<nuclide name="B10" wo="9.44159e-05"/>
@@ -149,15 +149,15 @@
149149
</material>
150150
</materials>
151151
<geometry>
152-
<cell fill="202" id="1" region="9 -10 11 -12 13 -14" universe="0"/>
152+
<cell id="1" fill="202" region="9 -10 11 -12 13 -14" universe="0"/>
153153
<cell id="27" material="1" region="-1" universe="3"/>
154154
<cell id="28" material="2" region="1 -2" universe="3"/>
155155
<cell id="29" material="4" region="2" universe="3"/>
156156
<cell id="30" material="4" region="-3" universe="4"/>
157157
<cell id="31" material="2" region="3 -4" universe="4"/>
158158
<cell id="32" material="4" region="4" universe="4"/>
159159
<cell id="70" material="4" region="35 -36" universe="7"/>
160-
<cell fill="101" id="80" region="35 -36" universe="8"/>
160+
<cell id="80" fill="101" region="35 -36" universe="8"/>
161161
<lattice id="101" name="Fuel assembly (upper half)">
162162
<pitch>1.26 1.26</pitch>
163163
<dimension>17 17</dimension>
@@ -190,25 +190,25 @@
190190
8 8 8
191191
7 7 7 </universes>
192192
</lattice>
193-
<surface coeffs="0.0 0.0 0.41" id="1" type="z-cylinder"/>
194-
<surface coeffs="0.0 0.0 0.475" id="2" type="z-cylinder"/>
195-
<surface coeffs="0.0 0.0 0.56" id="3" type="z-cylinder"/>
196-
<surface coeffs="0.0 0.0 0.62" id="4" type="z-cylinder"/>
197-
<surface boundary="reflective" coeffs="-32.13" id="9" type="x-plane"/>
198-
<surface boundary="reflective" coeffs="32.13" id="10" type="x-plane"/>
199-
<surface boundary="reflective" coeffs="-32.13" id="11" type="y-plane"/>
200-
<surface boundary="reflective" coeffs="32.13" id="12" type="y-plane"/>
201-
<surface boundary="reflective" coeffs="0" id="13" type="z-plane"/>
202-
<surface boundary="reflective" coeffs="32.13" id="14" type="z-plane"/>
203-
<surface coeffs="0.0" id="35" type="z-plane"/>
204-
<surface coeffs="183.0" id="36" type="z-plane"/>
193+
<surface id="1" type="z-cylinder" coeffs="0.0 0.0 0.41"/>
194+
<surface id="2" type="z-cylinder" coeffs="0.0 0.0 0.475"/>
195+
<surface id="3" type="z-cylinder" coeffs="0.0 0.0 0.56"/>
196+
<surface id="4" type="z-cylinder" coeffs="0.0 0.0 0.62"/>
197+
<surface id="9" type="x-plane" boundary="reflective" coeffs="-32.13"/>
198+
<surface id="10" type="x-plane" boundary="reflective" coeffs="32.13"/>
199+
<surface id="11" type="y-plane" boundary="reflective" coeffs="-32.13"/>
200+
<surface id="12" type="y-plane" boundary="reflective" coeffs="32.13"/>
201+
<surface id="13" type="z-plane" boundary="reflective" coeffs="0"/>
202+
<surface id="14" type="z-plane" boundary="reflective" coeffs="32.13"/>
203+
<surface id="35" type="z-plane" coeffs="0.0"/>
204+
<surface id="36" type="z-plane" coeffs="183.0"/>
205205
</geometry>
206206
<settings>
207207
<run_mode>eigenvalue</run_mode>
208208
<particles>100</particles>
209209
<batches>10</batches>
210210
<inactive>5</inactive>
211-
<source particle="neutron" strength="1.0" type="independent">
211+
<source type="independent" strength="1.0" particle="neutron">
212212
<space type="box">
213213
<parameters>-32 -32 0 32 32 32</parameters>
214214
</space>

0 commit comments

Comments
 (0)