Skip to content

Commit

Permalink
Ruff comments on code (#2696)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
shimwell and paulromano authored Sep 26, 2023
1 parent d765bd0 commit 9b7b33c
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 50 deletions.
9 changes: 0 additions & 9 deletions openmc/cmfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,6 @@ def _cmfd_solver_execute(self, adjoint=False):
Whether or not to run an adjoint calculation
"""
# Check for physical adjoint
physical_adjoint = adjoint and self._adjoint_type == 'physical'

# Start timer for build
time_start_buildcmfd = time.time()

Expand Down Expand Up @@ -1432,9 +1429,6 @@ def _calc_fission_source(self):
# indices of the actual problem so that cmfd_flux can be multiplied by
# nfissxs

# Calculate volume
vol = np.prod(self._hxyz, axis=3)

# Reshape phi by number of groups
phi = self._phi.reshape((n, ng))

Expand Down Expand Up @@ -2148,7 +2142,6 @@ def _precompute_array_indices(self):
is_accel = self._coremap != _CMFD_NOACCEL
# Logical for determining whether a zero flux "albedo" b.c. should be
# applied
is_zero_flux_alb = abs(self._albedo - _ZERO_FLUX) < _TINY_BIT
x_inds, y_inds, z_inds = np.indices((nx, ny, nz))

# Define slice equivalent to is_accel[0,:,:]
Expand Down Expand Up @@ -2725,8 +2718,6 @@ def _compute_dhat(self):

# Define flux in each cell
cell_flux = self._flux / dxdydz
# Extract indices of coremap that are accelerated
is_accel = self._coremap != _CMFD_NOACCEL

# Define dhat at left surface for all mesh cells on left boundary
boundary = self._first_x_accel
Expand Down
5 changes: 0 additions & 5 deletions openmc/data/angle_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def from_endf(cls, ev, mt):
items = get_cont_record(file_obj)
li = items[2]
nk = items[4]
center_of_mass = (items[3] == 2)

# Check for obsolete energy transformation matrix. If present, just skip
# it and keep reading
Expand All @@ -259,7 +258,6 @@ def from_endf(cls, ev, mt):
mu = []
for i in range(n_energy):
items, al = get_list_record(file_obj)
temperature = items[0]
energy[i] = items[1]
coefficients = np.asarray([1.0] + al)
mu.append(Legendre(coefficients))
Expand All @@ -273,7 +271,6 @@ def from_endf(cls, ev, mt):
mu = []
for i in range(n_energy):
params, f = get_tab1_record(file_obj)
temperature = params[0]
energy[i] = params[1]
if f.n_regions > 1:
raise NotImplementedError('Angular distribution with multiple '
Expand All @@ -289,7 +286,6 @@ def from_endf(cls, ev, mt):
mu = []
for i in range(n_energy_legendre):
items, al = get_list_record(file_obj)
temperature = items[0]
energy_legendre[i] = items[1]
coefficients = np.asarray([1.0] + al)
mu.append(Legendre(coefficients))
Expand All @@ -300,7 +296,6 @@ def from_endf(cls, ev, mt):
energy_tabulated = np.zeros(n_energy_tabulated)
for i in range(n_energy_tabulated):
params, f = get_tab1_record(file_obj)
temperature = params[0]
energy_tabulated[i] = params[1]
if f.n_regions > 1:
raise NotImplementedError('Angular distribution with multiple '
Expand Down
1 change: 0 additions & 1 deletion openmc/data/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def _get_products(ev, mt):

za = int(params[0])
awr = params[1]
lip = params[2]
law = params[3]

if za == 0:
Expand Down
6 changes: 1 addition & 5 deletions openmc/data/resonance.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ def from_endf(cls, ev):
n_isotope = items[4] # Number of isotopes

ranges = []
for iso in range(n_isotope):
for _ in range(n_isotope):
items = get_cont_record(file_obj)
abundance = items[1]
fission_widths = (items[3] == 1) # fission widths are given?
n_ranges = items[4] # number of resonance energy ranges

Expand Down Expand Up @@ -424,14 +423,12 @@ def _prepare_resonances(self):
# Determine penetration and shift corresponding to resonance energy
k = wave_number(A, E)
rho = k*self.channel_radius[l](E)
rhohat = k*self.scattering_radius[l](E)
p[i], s[i] = penetration_shift(l, rho)

# Determine penetration at modified energy for competitive reaction
if gx > 0:
Ex = E + self.q_value[l]*(A + 1)/A
rho = k*self.channel_radius[l](Ex)
rhohat = k*self.scattering_radius[l](Ex)
px[i], sx[i] = penetration_shift(l, rho)
else:
px[i] = sx[i] = 0.0
Expand Down Expand Up @@ -680,7 +677,6 @@ def _prepare_resonances(self):
# Determine penetration and shift corresponding to resonance energy
k = wave_number(A, E)
rho = k*self.channel_radius[l](E)
rhohat = k*self.scattering_radius[l](E)
p[i], s[i] = penetration_shift(l, rho)

df['p'] = p
Expand Down
14 changes: 1 addition & 13 deletions openmc/data/resonance_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ def from_endf(cls, ev, resonances):
n_isotope = items[4] # Number of isotopes

ranges = []
for iso in range(n_isotope):
for _ in range(n_isotope):
items = endf.get_cont_record(file_obj)
abundance = items[1]
fission_widths = (items[3] == 1) # Flag for fission widths
n_ranges = items[4] # Number of resonance energy ranges

for j in range(n_ranges):
Expand Down Expand Up @@ -378,7 +376,6 @@ def from_endf(cls, ev, file_obj, items, resonance):

# Other scatter radius parameters
items = endf.get_cont_record(file_obj)
target_spin = items[0]
lcomp = items[3] # Flag for compatibility 0, 1, 2 - 2 is compact form
nls = items[4] # number of l-values

Expand All @@ -387,8 +384,6 @@ def from_endf(cls, ev, file_obj, items, resonance):
items = endf.get_cont_record(file_obj)
# Number of short range type resonance covariances
num_short_range = items[4]
# Number of long range type resonance covariances
num_long_range = items[5]

# Read resonance widths, J values, etc
records = []
Expand Down Expand Up @@ -421,7 +416,6 @@ def from_endf(cls, ev, file_obj, items, resonance):
# compact correlations
elif lcomp == 2:
items, values = endf.get_list_record(file_obj)
mean = items
num_res = items[5]
energy = values[0::12]
spin = values[1::12]
Expand Down Expand Up @@ -613,20 +607,14 @@ def from_endf(cls, ev, file_obj, items, resonance):

# Other scatter radius parameters
items = endf.get_cont_record(file_obj)
target_spin = items[0]
lcomp = items[3] # Flag for compatibility 0, 1, 2 - 2 is compact form
nls = items[4] # Number of l-values

# Build covariance matrix for General Resolved Resonance Formats
if lcomp == 1:
items = endf.get_cont_record(file_obj)
# Number of short range type resonance covariances
num_short_range = items[4]
# Number of long range type resonance covariances
num_long_range = items[5]
# Read resonance widths, J values, etc
channel_radius = {}
scattering_radius = {}
records = []
for i in range(num_short_range):
items, values = endf.get_list_record(file_obj)
Expand Down
1 change: 0 additions & 1 deletion openmc/deplete/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ def __init__(self, chain_nuclides, energy=0.0253):
self._constant_yields[name] = yield_data
continue
# Specific energy not found, use closest energy
distances = [abs(energy - ene) for ene in nuc.yield_energies]
min_E = min(nuc.yield_energies, key=lambda e: abs(e - energy))
self._constant_yields[name] = nuc.yield_data[min_E]

Expand Down
4 changes: 2 additions & 2 deletions openmc/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,8 @@ def is_subset(self, other):
def get_bin_index(self, filter_bin):
i = np.where(self.bins[:, 1] == filter_bin[1])[0]
if len(i) == 0:
msg = (f'Unable to get the bin index for Filter since '
'"{filter_bin}" is not one of the bins')
msg = ('Unable to get the bin index for Filter since '
f'"{filter_bin}" is not one of the bins')
raise ValueError(msg)
else:
return i[0]
Expand Down
5 changes: 1 addition & 4 deletions openmc/mgxs/mdgxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def filters(self):
group_edges = self.energy_groups.group_edges
energy_filter = openmc.EnergyFilter(group_edges)

if self.delayed_groups != None:
if self.delayed_groups is not None:
delayed_filter = openmc.DelayedGroupFilter(self.delayed_groups)
filters = [[energy_filter], [delayed_filter, energy_filter]]
else:
Expand Down Expand Up @@ -1884,9 +1884,6 @@ def tally_keys(self):
@property
def filters(self):

# Create the non-domain specific Filters for the Tallies
group_edges = self.energy_groups.group_edges

if self.delayed_groups is not None:
delayed_filter = openmc.DelayedGroupFilter(self.delayed_groups)
filters = [[delayed_filter], [delayed_filter]]
Expand Down
2 changes: 0 additions & 2 deletions openmc/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,6 @@ def export_to_model_xml(self, path='model.xml', remove_surfs=False):
warnings.warn("remove_surfs kwarg will be deprecated soon, please "
"set the Geometry.merge_surfaces attribute instead.")
self.geometry.merge_surfaces = True
# Can be used to modify tallies in case any surfaces are redundant
redundant_surfaces = self.geometry.remove_redundant_surfaces()

# provide a memo to track which meshes have been written
mesh_memo = set()
Expand Down
10 changes: 5 additions & 5 deletions openmc/model/surface_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ def __init__(self,
**kwargs):

if r2 <= r1:
raise ValueError(f'r2 must be greater than r1.')
raise ValueError('r2 must be greater than r1.')

if theta2 <= theta1:
raise ValueError(f'theta2 must be greater than theta1.')
raise ValueError('theta2 must be greater than theta1.')

phi1 = pi / 180 * theta1
phi2 = pi / 180 * theta2
Expand Down Expand Up @@ -204,7 +204,7 @@ def from_theta_alpha(cls,
offset.
"""
if theta >= 360. or theta <= 0:
raise ValueError(f'theta must be less than 360 and greater than 0.')
raise ValueError('theta must be less than 360 and greater than 0.')

theta1 = alpha
theta2 = alpha + theta
Expand Down Expand Up @@ -288,10 +288,10 @@ def __init__(self, center, r1, r2, axis='z', **kwargs):

# Side lengths
if r2 > r1 * sqrt(2):
raise ValueError(f'r2 is greater than sqrt(2) * r1. Octagon' +
raise ValueError('r2 is greater than sqrt(2) * r1. Octagon' +
' may be erroneous.')
if r1 > r2 * sqrt(2):
raise ValueError(f'r1 is greater than sqrt(2) * r2. Octagon' +
raise ValueError('r1 is greater than sqrt(2) * r2. Octagon' +
' may be erroneous.')

L_basis_ax = (r2 * sqrt(2) - r1)
Expand Down
1 change: 0 additions & 1 deletion openmc/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import typing # imported separately as py3.8 requires typing.Iterable
from collections.abc import Iterable, Mapping, MutableSequence
from enum import Enum
import itertools
Expand Down
2 changes: 0 additions & 2 deletions openmc/weight_windows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import annotations
from collections.abc import Iterable
from numbers import Real, Integral
from typing import Iterable, List, Optional, Dict, Sequence
import warnings
Expand Down Expand Up @@ -481,7 +480,6 @@ def wwinp_to_wws(path: PathLike) -> List[WeightWindows]:
# read file type, time-dependence, number of
# particles, mesh type and problem identifier
_if, iv, ni, nr = [int(x) for x in header[:4]]
probid = header[4] if len(header) > 4 else ""

# header value checks
if _if != 1:
Expand Down

0 comments on commit 9b7b33c

Please sign in to comment.