From 9b7b33c7fab86170d7f55cc048b67ab1337a59c7 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 26 Sep 2023 04:37:19 +0100 Subject: [PATCH] Ruff comments on code (#2696) Co-authored-by: Paul Romano --- openmc/cmfd.py | 9 --------- openmc/data/angle_distribution.py | 5 ----- openmc/data/reaction.py | 1 - openmc/data/resonance.py | 6 +----- openmc/data/resonance_covariance.py | 14 +------------- openmc/deplete/helpers.py | 1 - openmc/filter.py | 4 ++-- openmc/mgxs/mdgxs.py | 5 +---- openmc/model/model.py | 2 -- openmc/model/surface_composite.py | 10 +++++----- openmc/settings.py | 1 - openmc/weight_windows.py | 2 -- 12 files changed, 10 insertions(+), 50 deletions(-) diff --git a/openmc/cmfd.py b/openmc/cmfd.py index d45396f141..1b4bfa5e27 100644 --- a/openmc/cmfd.py +++ b/openmc/cmfd.py @@ -1308,9 +1308,6 @@ class CMFDRun: 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() @@ -1432,9 +1429,6 @@ class CMFDRun: # 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)) @@ -2148,7 +2142,6 @@ class CMFDRun: 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,:,:] @@ -2725,8 +2718,6 @@ class CMFDRun: # 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 diff --git a/openmc/data/angle_distribution.py b/openmc/data/angle_distribution.py index bb0eafe5a0..e59ffa0c73 100644 --- a/openmc/data/angle_distribution.py +++ b/openmc/data/angle_distribution.py @@ -235,7 +235,6 @@ class AngleDistribution(EqualityMixin): 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 @@ -259,7 +258,6 @@ class AngleDistribution(EqualityMixin): 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)) @@ -273,7 +271,6 @@ class AngleDistribution(EqualityMixin): 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 ' @@ -289,7 +286,6 @@ class AngleDistribution(EqualityMixin): 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)) @@ -300,7 +296,6 @@ class AngleDistribution(EqualityMixin): 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 ' diff --git a/openmc/data/reaction.py b/openmc/data/reaction.py index 650e8663ef..04a68d7399 100644 --- a/openmc/data/reaction.py +++ b/openmc/data/reaction.py @@ -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: diff --git a/openmc/data/resonance.py b/openmc/data/resonance.py index 7b9cd268f5..340d73a186 100644 --- a/openmc/data/resonance.py +++ b/openmc/data/resonance.py @@ -93,9 +93,8 @@ class Resonances: 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 @@ -424,14 +423,12 @@ class MultiLevelBreitWigner(ResonanceRange): # 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 @@ -680,7 +677,6 @@ class ReichMoore(ResonanceRange): # 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 diff --git a/openmc/data/resonance_covariance.py b/openmc/data/resonance_covariance.py index 9e80e52f2c..9ba429cb48 100644 --- a/openmc/data/resonance_covariance.py +++ b/openmc/data/resonance_covariance.py @@ -93,10 +93,8 @@ class ResonanceCovariances(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): @@ -378,7 +376,6 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange): # 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 @@ -387,8 +384,6 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange): 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 = [] @@ -421,7 +416,6 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange): # 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] @@ -613,20 +607,14 @@ class ReichMooreCovariance(ResonanceCovarianceRange): # 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) diff --git a/openmc/deplete/helpers.py b/openmc/deplete/helpers.py index 3da8c5c9e7..f24b89868b 100644 --- a/openmc/deplete/helpers.py +++ b/openmc/deplete/helpers.py @@ -594,7 +594,6 @@ class ConstantFissionYieldHelper(FissionYieldHelper): 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] diff --git a/openmc/filter.py b/openmc/filter.py index d8cf59c007..311db94d19 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -1222,8 +1222,8 @@ class RealFilter(Filter): 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] diff --git a/openmc/mgxs/mdgxs.py b/openmc/mgxs/mdgxs.py index 3a6732748b..c9d76bc108 100644 --- a/openmc/mgxs/mdgxs.py +++ b/openmc/mgxs/mdgxs.py @@ -216,7 +216,7 @@ class MDGXS(MGXS): 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: @@ -1884,9 +1884,6 @@ class DecayRate(MDGXS): @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]] diff --git a/openmc/model/model.py b/openmc/model/model.py index 2b5681d811..7f9cbdfbeb 100644 --- a/openmc/model/model.py +++ b/openmc/model/model.py @@ -499,8 +499,6 @@ class Model: 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() diff --git a/openmc/model/surface_composite.py b/openmc/model/surface_composite.py index c52ce44e12..279f3ed06a 100644 --- a/openmc/model/surface_composite.py +++ b/openmc/model/surface_composite.py @@ -120,10 +120,10 @@ class CylinderSector(CompositeSurface): **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 @@ -204,7 +204,7 @@ class CylinderSector(CompositeSurface): 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 @@ -288,10 +288,10 @@ class IsogonalOctagon(CompositeSurface): # 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) diff --git a/openmc/settings.py b/openmc/settings.py index bf24dcc040..13024c47f2 100644 --- a/openmc/settings.py +++ b/openmc/settings.py @@ -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 diff --git a/openmc/weight_windows.py b/openmc/weight_windows.py index 9f0f2e1235..a8e41a3c87 100644 --- a/openmc/weight_windows.py +++ b/openmc/weight_windows.py @@ -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 @@ -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: