Skip to content

Commit 409847a

Browse files
committed
autopep8
1 parent f22753a commit 409847a

File tree

5 files changed

+137
-100
lines changed

5 files changed

+137
-100
lines changed

openmc/examples.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
C5G7_N_DG = 8
88
PINCELL_PITCH = 1.26
99

10+
1011
def pwr_pin_cell() -> openmc.Model:
1112
"""Create a PWR pin-cell model.
1213
@@ -656,6 +657,7 @@ def slab_mg(num_regions=1, mat_names=None, mgxslib_name='2g.h5') -> openmc.Model
656657

657658
return model
658659

660+
659661
def _generate_c5g7_materials(kinetic) -> openmc.Materials:
660662
"""Generate materials utilizing multi-group cross sections based on the
661663
the C5G7 Benchmark.
@@ -836,6 +838,7 @@ def _generate_c5g7_materials(kinetic) -> openmc.Materials:
836838
materials.cross_sections = "mgxs.h5"
837839
return materials
838840

841+
839842
def _generate_random_ray_pin_cell(uo2, water) -> openmc.Universe:
840843
"""Create a random ray pin cell universe. Helper function for
841844
random_ray_pin_cell() and random_ray_lattice()
@@ -905,6 +908,7 @@ def _generate_random_ray_pin_cell(uo2, water) -> openmc.Universe:
905908

906909
return pincell
907910

911+
908912
def random_ray_pin_cell(kinetic=False) -> openmc.Model:
909913
"""Create a PWR pin cell example using C5G7 cross section data.
910914
cross section data.
@@ -998,6 +1002,7 @@ def random_ray_pin_cell(kinetic=False) -> openmc.Model:
9981002
model.tallies = tallies
9991003
return model
10001004

1005+
10011006
def random_ray_lattice(kinetic=False) -> openmc.Model:
10021007
"""Create a 2x2 PWR pin cell asymmetrical lattice example.
10031008
@@ -1034,7 +1039,7 @@ def random_ray_lattice(kinetic=False) -> openmc.Model:
10341039
moderator_infinite = openmc.Cell(name='moderator infinite')
10351040
if kinetic:
10361041
water_reflector = water.clone()
1037-
water_reflector.name='Water Reflector'
1042+
water_reflector.name = 'Water Reflector'
10381043
water_reflector.set_density('macro', 1.0)
10391044
materials.append(water_reflector)
10401045
moderator_infinite.fill = water_reflector
@@ -1146,6 +1151,7 @@ def random_ray_lattice(kinetic=False) -> openmc.Model:
11461151
model.tallies = tallies
11471152
return model
11481153

1154+
11491155
def random_ray_three_region_cube() -> openmc.Model:
11501156
"""Create a three region cube model.
11511157

openmc/material.py

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ def __init__(
183183
if components is not None:
184184
self.add_components(components, percent_type=percent_type)
185185

186-
187186
def __repr__(self) -> str:
188187
string = 'Material\n'
189188
string += '{: <16}=\t{}\n'.format('\tID', self._id)
@@ -204,7 +203,8 @@ def __repr__(self) -> str:
204203
string += '{: <16}\n'.format('\tS(a,b) Tables')
205204

206205
if self._ncrystal_cfg:
207-
string += '{: <16}=\t{}\n'.format('\tNCrystal conf', self._ncrystal_cfg)
206+
string += '{: <16}=\t{}\n'.format('\tNCrystal conf',
207+
self._ncrystal_cfg)
208208

209209
for sab in self._sab:
210210
string += '{: <16}=\t{}\n'.format('\tS(a,b)', sab)
@@ -335,7 +335,7 @@ def fissionable_mass(self) -> float:
335335
Z = openmc.data.zam(nuc)[0]
336336
if Z >= 90:
337337
density += 1e24 * atoms_per_bcm * openmc.data.atomic_mass(nuc) \
338-
/ openmc.data.AVOGADRO
338+
/ openmc.data.AVOGADRO
339339
return density*self.volume
340340

341341
@property
@@ -384,7 +384,8 @@ def get_decay_photon_energy(
384384
cv.check_value('units', units, {'Bq', 'Bq/g', 'Bq/kg', 'Bq/cm3'})
385385

386386
if exclude_nuclides is not None and include_nuclides is not None:
387-
raise ValueError("Cannot specify both exclude_nuclides and include_nuclides")
387+
raise ValueError(
388+
"Cannot specify both exclude_nuclides and include_nuclides")
388389

389390
if units == 'Bq':
390391
multiplier = volume if volume is not None else self.volume
@@ -515,12 +516,12 @@ def from_ncrystal(cls, cfg, **kwargs) -> Material:
515516
nc_mat = NCrystal.createInfo(cfg)
516517

517518
def openmc_natabund(Z):
518-
#nc_mat.getFlattenedComposition might need natural abundancies.
519-
#This call-back function is used so NCrystal can flatten composition
520-
#using OpenMC's natural abundancies. In practice this function will
521-
#only get invoked in the unlikely case where a material is specified
522-
#by referring both to natural elements and specific isotopes of the
523-
#same element.
519+
# nc_mat.getFlattenedComposition might need natural abundancies.
520+
# This call-back function is used so NCrystal can flatten composition
521+
# using OpenMC's natural abundancies. In practice this function will
522+
# only get invoked in the unlikely case where a material is specified
523+
# by referring both to natural elements and specific isotopes of the
524+
# same element.
524525
elem_name = openmc.data.ATOMIC_SYMBOL[Z]
525526
return [
526527
(int(iso_name[len(elem_name):]), abund)
@@ -564,7 +565,8 @@ def add_volume_information(self, volume_calc):
564565
raise ValueError('No volume information found for material ID={}.'
565566
.format(self.id))
566567
else:
567-
raise ValueError(f'No volume information found for material ID={self.id}.')
568+
raise ValueError(
569+
f'No volume information found for material ID={self.id}.')
568570

569571
def set_density(self, units: str, density: float | None = None,
570572
density_timeseries: list[float] | None = None):
@@ -608,9 +610,9 @@ def set_density(self, units: str, density: float | None = None,
608610
self._density = density
609611
if density_timeseries is not None:
610612
cv.check_type(f'the density timeseries for Material ID="{self.id}"',
611-
density_timeseries, Iterable, Real)
613+
density_timeseries, Iterable, Real)
612614
[cv.check_greater_than(f'an element in density timeseries for Material ID="{self.id}"',
613-
x, 0.0) for x in density_timeseries]
615+
x, 0.0) for x in density_timeseries]
614616
self._density_timeseries = density_timeseries
615617
else:
616618
self._density_timeseries = None
@@ -635,7 +637,8 @@ def add_nuclide(self, nuclide: str, percent: float, percent_type: str = 'ao'):
635637

636638
if self._macroscopic is not None:
637639
msg = 'Unable to add a Nuclide to Material ID="{}" as a ' \
638-
'macroscopic data-set has already been added'.format(self._id)
640+
'macroscopic data-set has already been added'.format(
641+
self._id)
639642
raise ValueError(msg)
640643

641644
if self._ncrystal_cfg is not None:
@@ -872,7 +875,8 @@ def add_element(self, element: str, percent: float, percent_type: str = 'ao',
872875

873876
if self._macroscopic is not None:
874877
msg = 'Unable to add an Element to Material ID="{}" as a ' \
875-
'macroscopic data-set has already been added'.format(self._id)
878+
'macroscopic data-set has already been added'.format(
879+
self._id)
876880
raise ValueError(msg)
877881

878882
if enrichment is not None and enrichment_target is None:
@@ -961,10 +965,10 @@ def add_elements_from_formula(self, formula: str, percent_type: str = 'ao',
961965
msg = f'Formula entry {token} not an element symbol.'
962966
raise ValueError(msg)
963967
elif token not in ['(', ')', ''] and not token.isdigit():
964-
msg = 'Formula must be made from a sequence of ' \
965-
'element symbols, integers, and brackets. ' \
966-
'{} is not an allowable entry.'.format(token)
967-
raise ValueError(msg)
968+
msg = 'Formula must be made from a sequence of ' \
969+
'element symbols, integers, and brackets. ' \
970+
'{} is not an allowable entry.'.format(token)
971+
raise ValueError(msg)
968972

969973
# Checks that the number of opening and closing brackets are equal
970974
if formula.count('(') != formula.count(')'):
@@ -1026,12 +1030,13 @@ def add_s_alpha_beta(self, name: str, fraction: float = 1.0):
10261030

10271031
if self._macroscopic is not None:
10281032
msg = 'Unable to add an S(a,b) table to Material ID="{}" as a ' \
1029-
'macroscopic data-set has already been added'.format(self._id)
1033+
'macroscopic data-set has already been added'.format(
1034+
self._id)
10301035
raise ValueError(msg)
10311036

10321037
if not isinstance(name, str):
10331038
msg = 'Unable to add an S(a,b) table to Material ID="{}" with a ' \
1034-
'non-string table name "{}"'.format(self._id, name)
1039+
'non-string table name "{}"'.format(self._id, name)
10351040
raise ValueError(msg)
10361041

10371042
cv.check_type('S(a,b) fraction', fraction, Real)
@@ -1168,7 +1173,7 @@ def get_nuclide_atom_densities(self, nuclide: str | None = None) -> dict[str, fl
11681173
if not percent_in_atom:
11691174
for n, nuc in enumerate(nucs):
11701175
nuc_densities[n] *= self.average_molar_mass / \
1171-
openmc.data.atomic_mass(nuc)
1176+
openmc.data.atomic_mass(nuc)
11721177

11731178
# Now that we have the atomic amounts, lets finish calculating densities
11741179
sum_percent = np.sum(nuc_densities)
@@ -1177,7 +1182,7 @@ def get_nuclide_atom_densities(self, nuclide: str | None = None) -> dict[str, fl
11771182
# Convert the mass density to an atom density
11781183
if not density_in_atom:
11791184
density = -density / self.average_molar_mass * 1.e-24 \
1180-
* openmc.data.AVOGADRO
1185+
* openmc.data.AVOGADRO
11811186

11821187
nuc_densities = density * nuc_densities
11831188

@@ -1217,19 +1222,19 @@ def get_element_atom_densities(self, element: str | None = None) -> dict[str, fl
12171222

12181223
# Accumulate densities for each nuclide
12191224
for nuclide, density in nuc_densities.items():
1220-
nuc_element = openmc.data.ATOMIC_SYMBOL[openmc.data.zam(nuclide)[0]]
1225+
nuc_element = openmc.data.ATOMIC_SYMBOL[openmc.data.zam(nuclide)[
1226+
0]]
12211227
if element is None or element == nuc_element:
12221228
if nuc_element not in densities:
12231229
densities[nuc_element] = 0.0
12241230
densities[nuc_element] += float(density)
12251231

12261232
# If specific element was requested, make sure it is present
12271233
if element is not None and element not in densities:
1228-
raise ValueError(f'Element {element} not found in material.')
1234+
raise ValueError(f'Element {element} not found in material.')
12291235

12301236
return densities
12311237

1232-
12331238
def get_activity(self, units: str = 'Bq/cm3', by_nuclide: bool = False,
12341239
volume: float | None = None) -> dict[str, float] | float:
12351240
"""Returns the activity of the material or of each nuclide within.
@@ -1259,7 +1264,8 @@ def get_activity(self, units: str = 'Bq/cm3', by_nuclide: bool = False,
12591264
of the material is returned as a float.
12601265
"""
12611266

1262-
cv.check_value('units', units, {'Bq', 'Bq/g', 'Bq/kg', 'Bq/cm3', 'Ci', 'Ci/m3'})
1267+
cv.check_value('units', units, {
1268+
'Bq', 'Bq/g', 'Bq/kg', 'Bq/cm3', 'Ci', 'Ci/m3'})
12631269
cv.check_type('by_nuclide', by_nuclide, bool)
12641270

12651271
if volume is None:
@@ -1332,7 +1338,8 @@ def get_decay_heat(self, units: str = 'W', by_nuclide: bool = False,
13321338
decay_erg = openmc.data.decay_energy(nuclide)
13331339
inv_seconds = openmc.data.decay_constant(nuclide)
13341340
decay_erg *= openmc.data.JOULE_PER_EV
1335-
decayheat[nuclide] = inv_seconds * decay_erg * 1e24 * atoms_per_bcm * multiplier
1341+
decayheat[nuclide] = inv_seconds * decay_erg * \
1342+
1e24 * atoms_per_bcm * multiplier
13361343

13371344
return decayheat if by_nuclide else sum(decayheat.values())
13381345

@@ -1383,7 +1390,7 @@ def get_mass_density(self, nuclide: str | None = None) -> float:
13831390
mass_density = 0.0
13841391
for nuc, atoms_per_bcm in self.get_nuclide_atom_densities(nuclide=nuclide).items():
13851392
density_i = 1e24 * atoms_per_bcm * openmc.data.atomic_mass(nuc) \
1386-
/ openmc.data.AVOGADRO
1393+
/ openmc.data.AVOGADRO
13871394
mass_density += density_i
13881395
return mass_density
13891396

@@ -1566,12 +1573,13 @@ def _get_macroscopic_xml(self, macroscopic: str) -> ET.Element:
15661573

15671574
def _get_nuclides_xml(
15681575
self, nuclides: Iterable[NuclideTuple],
1569-
nuclides_to_ignore: Iterable[str] | None = None)-> list[ET.Element]:
1576+
nuclides_to_ignore: Iterable[str] | None = None) -> list[ET.Element]:
15701577
xml_elements = []
15711578

15721579
# Remove any nuclides to ignore from the XML export
15731580
if nuclides_to_ignore:
1574-
nuclides = [nuclide for nuclide in nuclides if nuclide.name not in nuclides_to_ignore]
1581+
nuclides = [
1582+
nuclide for nuclide in nuclides if nuclide.name not in nuclides_to_ignore]
15751583

15761584
xml_elements = [self._get_nuclide_xml(nuclide) for nuclide in nuclides]
15771585

@@ -1608,9 +1616,11 @@ def to_xml_element(
16081616

16091617
if self._ncrystal_cfg:
16101618
if self._sab:
1611-
raise ValueError("NCrystal materials are not compatible with S(a,b).")
1619+
raise ValueError(
1620+
"NCrystal materials are not compatible with S(a,b).")
16121621
if self._macroscopic is not None:
1613-
raise ValueError("NCrystal materials are not compatible with macroscopic cross sections.")
1622+
raise ValueError(
1623+
"NCrystal materials are not compatible with macroscopic cross sections.")
16141624

16151625
element.set("cfg", str(self._ncrystal_cfg))
16161626

@@ -1625,11 +1635,13 @@ def to_xml_element(
16251635
subelement.set("value", str(self._density))
16261636
subelement.set("units", self._density_units)
16271637
if self._density_timeseries is not None:
1628-
timeseries_text = " ".join(str(x) for x in self._density_timeseries)
1638+
timeseries_text = " ".join(str(x)
1639+
for x in self._density_timeseries)
16291640
subelement.set("value_timeseries", timeseries_text)
16301641

16311642
else:
1632-
raise ValueError(f'Density has not been set for material {self.id}!')
1643+
raise ValueError(
1644+
f'Density has not been set for material {self.id}!')
16331645

16341646
if self._macroscopic is None:
16351647
# Create nuclide XML subelements
@@ -1730,17 +1742,18 @@ def mix_materials(cls, materials, fracs: Iterable[float],
17301742
nuc_per_cc = wgt*1.e24*atoms_per_bcm
17311743
nuclides_per_cc[nuc] += nuc_per_cc
17321744
mass_per_cc[nuc] += nuc_per_cc*openmc.data.atomic_mass(nuc) / \
1733-
openmc.data.AVOGADRO
1745+
openmc.data.AVOGADRO
17341746

17351747
# Create the new material with the desired name
17361748
if "name" not in kwargs:
17371749
kwargs["name"] = '-'.join([f'{m.name}({f})' for m, f in
1738-
zip(materials, fracs)])
1750+
zip(materials, fracs)])
17391751

17401752
new_mat = cls(**kwargs)
17411753

17421754
# Compute atom fractions of nuclides and add them to the new material
1743-
tot_nuclides_per_cc = np.sum([dens for dens in nuclides_per_cc.values()])
1755+
tot_nuclides_per_cc = np.sum(
1756+
[dens for dens in nuclides_per_cc.values()])
17441757
for nuc, atom_dens in nuclides_per_cc.items():
17451758
new_mat.add_nuclide(nuc, atom_dens/tot_nuclides_per_cc, 'ao')
17461759

@@ -1887,7 +1900,6 @@ def deplete(
18871900

18881901
return depleted_materials_dict[self.id]
18891902

1890-
18911903
def mean_free_path(self, energy: float) -> float:
18921904
"""Calculate the mean free path of neutrons in the material at a given
18931905
energy.
@@ -2030,7 +2042,8 @@ def _write_xml(self, file, header=True, level=0, spaces_per_level=2,
20302042

20312043
# Write the <material> elements.
20322044
for material in sorted(set(self), key=lambda x: x.id):
2033-
element = material.to_xml_element(nuclides_to_ignore=nuclides_to_ignore)
2045+
element = material.to_xml_element(
2046+
nuclides_to_ignore=nuclides_to_ignore)
20342047
clean_indentation(element, level=level+1)
20352048
element.tail = element.tail.strip(' ')
20362049
file.write((level+1)*spaces_per_level*' ')
@@ -2116,7 +2129,6 @@ def from_xml(cls, path: PathLike = 'materials.xml') -> Materials:
21162129

21172130
return cls.from_xml_element(root)
21182131

2119-
21202132
def deplete(
21212133
self,
21222134
multigroup_fluxes: Sequence[Sequence[float]],

0 commit comments

Comments
 (0)