Various PEP8 fixes. Mostly using 'is not' and 'not in'.

This commit is contained in:
Paul Romano 2015-06-15 10:51:07 +07:00
parent 61db64a1f5
commit 528880cd45
13 changed files with 150 additions and 163 deletions

View file

@ -153,7 +153,7 @@ class CMFDMesh(object):
@width.setter
def width(self, width):
if not width is None:
if width is not None:
if not isinstance(width, (tuple, list, np.ndarray)):
msg = 'Unable to set CMFD Mesh with width {0} which ' \
'is not a Python list, tuple or NumPy array'.format(width)
@ -237,26 +237,26 @@ class CMFDMesh(object):
subelement = ET.SubElement(element, "lower_left")
subelement.text = ' '.join(map(str, self._lower_left))
if not self._upper_right is None:
if self._upper_right is not None:
subelement = ET.SubElement(element, "upper_right")
subelement.text = ' '.join(map(str, self._upper_right))
subelement = ET.SubElement(element, "dimension")
subelement.text = ' '.join(map(str, self._dimension))
if not self._width is None:
if self._width is not None:
subelement = ET.SubElement(element, "width")
subelement.text = ' '.join(map(str, self._width))
if not self._energy is None:
if self._energy is not None:
subelement = ET.SubElement(element, "energy")
subelement.text = ' '.join(map(str, self._energy))
if not self._albedo is None:
if self._albedo is not None:
subelement = ET.SubElement(element, "albedo")
subelement.text = ' '.join(map(str, self._albedo))
if not self._map is None:
if self._map is not None:
subelement = ET.SubElement(element, "map")
subelement.text = ' '.join(map(str, self._map))
@ -578,82 +578,82 @@ class CMFDFile(object):
self._write_matrices = write_matrices
def _create_begin_subelement(self):
if not self._begin is None:
if self._begin is not None:
element = ET.SubElement(self._cmfd_file, "begin")
element.text = str(self._begin)
def _create_dhat_reset_subelement(self):
if not self._dhat_reset is None:
if self._dhat_reset is not None:
element = ET.SubElement(self._cmfd_file, "dhat_reset")
element.text = str(self._dhat_reset).lower()
def _create_display_subelement(self):
if not self._display is None:
if self._display is not None:
element = ET.SubElement(self._cmfd_file, "display")
element.text = str(self._display)
def _create_downscatter_subelement(self):
if not self._downscatter is None:
if self._downscatter is not None:
element = ET.SubElement(self._cmfd_file, "downscatter")
element.text = str(self._downscatter).lower()
def _create_feedback_subelement(self):
if not self._feedback is None:
if self._feedback is not None:
element = ET.SubElement(self._cmfd_file, "feeback")
element.text = str(self._feedback).lower()
def _create_gauss_seidel_tolerance_subelement(self):
if not self._gauss_seidel_tolerance is None:
if self._gauss_seidel_tolerance is not None:
element = ET.SubElement(self._cmfd_file, "gauss_seidel_tolerance")
element.text = ' '.join(map(str, self._gauss_seidel_tolerance))
def _create_ktol_subelement(self):
if not self._ktol is None:
if self._ktol is not None:
element = ET.SubElement(self._ktol, "ktol")
element.text = str(self._ktol)
def _create_mesh_subelement(self):
if not self._mesh is None:
if self._mesh is not None:
xml_element = self._mesh._get_xml_element()
self._cmfd_file.append(xml_element)
def _create_norm_subelement(self):
if not self._norm is None:
if self._norm is not None:
element = ET.SubElement(self._cmfd_file, "norm")
element.text = str(self._norm)
def _create_power_monitor_subelement(self):
if not self._power_monitor is None:
if self._power_monitor is not None:
element = ET.SubElement(self._cmfd_file, "power_monitor")
element.text = str(self._power_monitor).lower()
def _create_run_adjoint_subelement(self):
if not self._run_adjoint is None:
if self._run_adjoint is not None:
element = ET.SubElement(self._cmfd_file, "run_adjoint")
element.text = str(self._run_adjoint).lower()
def _create_shift_subelement(self):
if not self._shift is None:
if self._shift is not None:
element = ET.SubElement(self._shift, "shift")
element.text = str(self._shift)
def _create_spectral_subelement(self):
if not self._spectral is None:
if self._spectral is not None:
element = ET.SubElement(self._spectral, "spectral")
element.text = str(self._spectral)
def _create_stol_subelement(self):
if not self._stol is None:
if self._stol is not None:
element = ET.SubElement(self._stol, "stol")
element.text = str(self._stol)
def _create_tally_reset_subelement(self):
if not self._tally_reset is None:
if self._tally_reset is not None:
element = ET.SubElement(self._tally_reset, "tally_reset")
element.text = ' '.join(map(str, self._tally_reset))
def _create_write_matrices_subelement(self):
if not self._write_matrices is None:
if self._write_matrices is not None:
element = ET.SubElement(self._cmfd_file, "write_matrices")
element.text = str(self._write_matrices).lower()

View file

@ -1,5 +1,6 @@
from openmc.checkvalue import *
class Element(object):
"""A natural element used in a material via <element>. Internally, OpenMC will
expand the natural element into isotopes based on the known natural
@ -29,7 +30,7 @@ class Element(object):
# Set class attributes
self.name = name
if not xs is None:
if xs is not None:
self.xs = xs
def __eq__(self, element2):

View file

@ -53,11 +53,9 @@ class Filter(object):
else:
return True
def __hash__(self):
return hash((self._type, self._bins))
def __deepcopy__(self, memo):
existing = memo.get(id(self))
@ -107,7 +105,7 @@ class Filter(object):
def type(self, type):
if type is None:
self._type = type
elif not type in FILTER_TYPES.values():
elif type not in FILTER_TYPES.values():
msg = 'Unable to set Filter type to "{0}" since it is not one ' \
'of the supported types'.format(type)
raise ValueError(msg)
@ -226,7 +224,6 @@ class Filter(object):
self._stride = stride
def can_merge(self, filter):
"""Determine if filter can be merged with another.

View file

@ -39,14 +39,13 @@ class Geometry(object):
raise ValueError(msg)
elif root_universe._id != 0:
msg = 'Unable to add root Universe {0} to Geometry since ' \
msg = 'Unable to add root Universe {0} to Geometry since ' \
'it has ID={1} instead of ' \
'ID=0'.format(root_universe, root_universe._id)
raise ValueError(msg)
self._root_universe = root_universe
def get_offset(self, path, filter_offset):
"""Returns the corresponding location in the results array for a given
path and filter number.
@ -59,7 +58,6 @@ class Geometry(object):
lattice passed through. For the case of the lattice, a tuple should
be provided to indicate which coordinates in the lattice should be
entered. This should be in the form: (lat_id, i_x, i_y, i_z)
filter_offset : int
An integer that specifies which offset map the filter is using

View file

@ -14,6 +14,7 @@ MATERIAL_IDS = []
# A static variable for auto-generated Material IDs
AUTO_MATERIAL_ID = 10000
def reset_auto_material_id():
global AUTO_MATERIAL_ID, MATERIAL_IDS
AUTO_MATERIAL_ID = 10000
@ -105,7 +106,7 @@ class Material(object):
global AUTO_MATERIAL_ID, MATERIAL_IDS
# If the Material already has an ID, remove it from global list
if hasattr(self, '_id') and not self._id is None:
if hasattr(self, '_id') and self._id is not None:
MATERIAL_IDS.remove(self._id)
if material_id is None:
@ -159,7 +160,7 @@ class Material(object):
'non-floating point value {1}'.format(self._id, density)
raise ValueError(msg)
elif not units in DENSITY_UNITS:
elif units not in DENSITY_UNITS:
msg = 'Unable to set the density for Material ID={0} with ' \
'units {1}'.format(self._id, units)
raise ValueError(msg)
@ -176,10 +177,10 @@ class Material(object):
@distrib_otf_file.setter
def distrib_otf_file(self, filename):
# TODO: remove this when distributed materials are merged
warnings.warn('This feature is not yet implemented in a release ' \
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
if not is_string(filename) and not filename is None:
if not is_string(filename) and filename is not None:
msg = 'Unable to add OTF material file to Material ID={0} with a ' \
'non-string name {1}'.format(self._id, filename)
raise ValueError(msg)
@ -189,12 +190,11 @@ class Material(object):
@convert_to_distrib_comps.setter
def convert_to_distrib_comps(self):
# TODO: remove this when distributed materials are merged
warnings.warn('This feature is not yet implemented in a release ' \
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
self._convert_to_distrib_comps = True
def add_nuclide(self, nuclide, percent, percent_type='ao'):
"""Add a nuclide to the material
@ -219,7 +219,7 @@ class Material(object):
'non-floating point value {1}'.format(self._id, percent)
raise ValueError(msg)
elif not percent_type in ['ao', 'wo', 'at/g-cm']:
elif percent_type not in ['ao', 'wo', 'at/g-cm']:
msg = 'Unable to add a Nuclide to Material ID={0} with a ' \
'percent type {1}'.format(self._id, percent_type)
raise ValueError(msg)
@ -233,7 +233,6 @@ class Material(object):
self._nuclides[nuclide._name] = (nuclide, percent, percent_type)
def remove_nuclide(self, nuclide):
"""Remove a nuclide from the material
@ -277,7 +276,7 @@ class Material(object):
'non-floating point value {1}'.format(self._id, percent)
raise ValueError(msg)
if not percent_type in ['ao', 'wo']:
if percent_type not in ['ao', 'wo']:
msg = 'Unable to add an Element to Material ID={0} with a ' \
'percent type {1}'.format(self._id, percent_type)
raise ValueError(msg)
@ -287,7 +286,6 @@ class Material(object):
self._elements[element._name] = (element, percent, percent_type)
def remove_element(self, element):
"""Remove a natural element from the material
@ -302,7 +300,6 @@ class Material(object):
if element._name in self._elements:
del self._elements[element._name]
def add_s_alpha_beta(self, name, xs):
r"""Add an :math:`S(\alpha,\beta)` table to the material
@ -327,7 +324,6 @@ class Material(object):
self._sab.append((name, xs))
def get_all_nuclides(self):
"""Returns all nuclides in the material
@ -390,7 +386,7 @@ class Material(object):
else:
xml_element.set("wo", str(nuclide[1]))
if not nuclide[0]._xs is None:
if nuclide[0]._xs is not None:
xml_element.set("xs", nuclide[0]._xs)
return xml_element
@ -547,7 +543,6 @@ class MaterialsFile(object):
self._materials.append(material)
def add_materials(self, materials):
"""Add multiple materials to the file.
@ -586,7 +581,7 @@ class MaterialsFile(object):
def _create_material_subelements(self):
subelement = ET.SubElement(self._materials_file, "default_xs")
if not self._default_xs is None:
if self._default_xs is not None:
subelement.text = self._default_xs
for material in self._materials:

View file

@ -164,7 +164,7 @@ class Mesh(object):
msg = 'Unable to set Mesh ID={0} for type {1} which is not ' \
'a string'.format(self._id, type)
raise ValueError(msg)
elif not type in ['rectangular', 'hexagonal']:
elif type not in ['rectangular', 'hexagonal']:
msg = 'Unable to set Mesh ID={0} for type {1} which since ' \
'only rectangular and hexagonal meshes are ' \
'supported '.format(self._id, type)
@ -238,7 +238,7 @@ class Mesh(object):
@width.setter
def width(self, width):
if not width is None:
if width is not None:
if not isinstance(width, (tuple, list, np.ndarray)):
msg = 'Unable to set Mesh ID={0} with width {1} which ' \
'is not a Python list, tuple or NumPy ' \
@ -290,11 +290,11 @@ class Mesh(object):
subelement = ET.SubElement(element, "lower_left")
subelement.text = ' '.join(map(str, self._lower_left))
if not self._upper_right is None:
if self._upper_right is not None:
subelement = ET.SubElement(element, "upper_right")
subelement.text = ' '.join(map(str, self._upper_right))
if not self._width is None:
if self._width is not None:
subelement = ET.SubElement(element, "width")
subelement.text = ' '.join(map(str, self._width))

View file

@ -32,7 +32,7 @@ class Nuclide(object):
# Set the Material class attributes
self.name = name
if not xs is None:
if xs is not None:
self.xs = xs
def __eq__(self, nuclide2):
@ -97,5 +97,5 @@ class Nuclide(object):
string = 'Nuclide - {0}\n'.format(self._name)
string += '{0: <16}{1}{2}\n'.format('\tXS', '=\t', self._xs)
if self._zaid is not None:
string += '{0: <16}{1}{2}\n'.format('\tZAID', '=\t', self._zaid)
string += '{0: <16}{1}{2}\n'.format('\tZAID', '=\t', self._zaid)
return string

View file

@ -333,7 +333,6 @@ def get_openmc_surface(opencg_surface):
'Surface type in OpenMC'.format(opencg_surface._type)
raise ValueError(msg)
# Add the OpenMC Surface to the global collection of all OpenMC Surfaces
OPENMC_SURFACES[surface_id] = openmc_surface
@ -520,7 +519,7 @@ def get_compatible_opencg_cells(opencg_cell, opencg_surface, halfspace):
'not an OpenCG Surface'.format(opencg_surface)
raise ValueError(msg)
elif not halfspace in [-1, +1]:
elif halfspace not in [-1, +1]:
msg = 'Unable to create compatible Cell since {0}' \
'is not a +/-1 halfspace'.format(halfspace)
raise ValueError(msg)
@ -868,7 +867,7 @@ def get_opencg_lattice(openmc_lattice):
lower_left = new_lower_left
# Initialize an empty array for the OpenCG nested Universes in this Lattice
universe_array = np.ndarray(tuple(np.array(dimension)[::-1]), \
universe_array = np.ndarray(tuple(np.array(dimension)[::-1]),
dtype=opencg.Universe)
# Create OpenCG Universes for each unique nested Universe in this Lattice
@ -890,8 +889,8 @@ def get_opencg_lattice(openmc_lattice):
opencg_lattice.setUniverses(universe_array)
offset = np.array(lower_left, dtype=np.float64) - \
((np.array(pitch, dtype=np.float64) * \
np.array(dimension, dtype=np.float64))) / -2.0
((np.array(pitch, dtype=np.float64) *
np.array(dimension, dtype=np.float64))) / -2.0
opencg_lattice.setOffset(offset)
# Add the OpenMC Lattice to the global collection of all OpenMC Lattices
@ -936,7 +935,7 @@ def get_openmc_lattice(opencg_lattice):
universes = opencg_lattice._universes
# Initialize an empty array for the OpenMC nested Universes in this Lattice
universe_array = np.ndarray(tuple(np.array(dimension)), \
universe_array = np.ndarray(tuple(np.array(dimension)),
dtype=openmc.Universe)
# Create OpenMC Universes for each unique nested Universe in this Lattice
@ -953,11 +952,11 @@ def get_openmc_lattice(opencg_lattice):
universe_array[x][y][z] = unique_universes[universe_id]
# Reverse y-dimension in array to match ordering in OpenCG
universe_array = universe_array[:,::-1,:]
universe_array = universe_array[:, ::-1, :]
lower_left = np.array(offset, dtype=np.float64) + \
((np.array(width, dtype=np.float64) * \
np.array(dimension, dtype=np.float64))) / -2.0
((np.array(width, dtype=np.float64) *
np.array(dimension, dtype=np.float64))) / -2.0
openmc_lattice = openmc.RectLattice(lattice_id=lattice_id)
openmc_lattice.dimension = dimension
@ -1055,8 +1054,8 @@ def get_openmc_geometry(opencg_geometry):
# Make the entire geometry "compatible" before assigning auto IDs
universes = opencg_geometry.getAllUniverses()
for universe_id, universe in universes.items():
if not isinstance(universe, opencg.Lattice):
make_opencg_cells_compatible(universe)
if not isinstance(universe, opencg.Lattice):
make_opencg_cells_compatible(universe)
opencg_geometry.assignAutoIds()

View file

@ -9,6 +9,7 @@ from openmc.clean_xml import *
# A static variable for auto-generated Plot IDs
AUTO_PLOT_ID = 10000
def reset_auto_plot_id():
global AUTO_PLOT_ID
AUTO_PLOT_ID = 10000
@ -243,7 +244,7 @@ class Plot(object):
'a string'.format(self._id, color)
raise ValueError(msg)
elif not color in ['cell', 'mat']:
elif color not in ['cell', 'mat']:
msg = 'Unable to create Plot ID={0} with color {1} which is not ' \
'a cell or mat'.format(self._id, color)
raise ValueError(msg)
@ -257,7 +258,7 @@ class Plot(object):
'a string'.format(self._id, type)
raise ValueError(msg)
elif not type in ['slice', 'voxel']:
elif type not in ['slice', 'voxel']:
msg = 'Unable to create Plot ID={0} with type {1} which is not ' \
'slice or voxel'.format(self._id, type)
raise ValueError(msg)
@ -271,7 +272,7 @@ class Plot(object):
'a string'.format(self._id, basis)
raise ValueError(msg)
elif not basis in ['xy', 'xz', 'yz']:
elif basis not in ['xy', 'xz', 'yz']:
msg = 'Unable to create Plot ID={0} with basis {1} which is not ' \
'xy, xz, or yz'.format(self._id, basis)
raise ValueError(msg)
@ -308,9 +309,9 @@ class Plot(object):
@col_spec.setter
def col_spec(self, col_spec):
if not isinstance(col_spec, dict):
msg= 'Unable to create Plot ID={0} with col_spec parameter {1} ' \
'which is not a Python dictionary of IDs to ' \
'pixels'.format(self._id, col_spec)
msg = 'Unable to create Plot ID={0} with col_spec parameter {1} ' \
'which is not a Python dictionary of IDs to ' \
'pixels'.format(self._id, col_spec)
raise ValueError(msg)
for key in col_spec:
@ -434,18 +435,18 @@ class Plot(object):
subelement = ET.SubElement(element, "pixels")
subelement.text = ' '.join(map(str, self._pixels))
if not self._mask_background is None:
if self._mask_background is not None:
subelement = ET.SubElement(element, "background")
subelement.text = ' '.join(map(str, self._background))
if not self._col_spec is None:
if self._col_spec is not None:
for key in self._col_spec:
subelement = ET.SubElement(element, "col_spec")
subelement.set("id", str(key))
subelement.set("rgb", ' '.join(map(
str, self._col_spec[key])))
if not self._mask_components is None:
if self._mask_components is not None:
subelement = ET.SubElement(element, "mask")
subelement.set("components", ' '.join(map(
str, self._mask_components)))

View file

@ -456,17 +456,17 @@ class SettingsFile(object):
'is not a Python dictionary'.format(keff_trigger)
raise ValueError(msg)
elif not 'type' in keff_trigger:
elif 'type' not in keff_trigger:
msg = 'Unable to set a trigger on keff from {0} which ' \
'does not have a "type" key'.format(keff_trigger)
raise ValueError(msg)
elif not keff_trigger['type'] in ['variance', 'std_dev', 'rel_err']:
elif keff_trigger['type'] not in ['variance', 'std_dev', 'rel_err']:
msg = 'Unable to set a trigger on keff with ' \
'type {0}'.format(keff_trigger['type'])
raise ValueError(msg)
elif not 'threshold' in keff_trigger:
elif 'threshold' not in keff_trigger:
msg = 'Unable to set a trigger on keff from {0} which ' \
'does not have a "threshold" key'.format(keff_trigger)
raise ValueError(msg)
@ -522,7 +522,7 @@ class SettingsFile(object):
'value {0}'.format(stype)
raise ValueError(msg)
elif not stype in ['box', 'point']:
elif stype not in ['box', 'point']:
msg = 'Unable to set source space type to {0} since it is not ' \
'box or point'.format(stype)
raise ValueError(msg)
@ -577,7 +577,7 @@ class SettingsFile(object):
'value {0}'.format(stype)
raise ValueError(msg)
elif not stype in ['isotropic', 'monodirectional']:
elif stype not in ['isotropic', 'monodirectional']:
msg = 'Unable to set source angle type to {0} since it is not ' \
'isotropic or monodirectional'.format(stype)
raise ValueError(msg)
@ -587,7 +587,7 @@ class SettingsFile(object):
'not a Python list/tuple or NumPy array'.format(params)
raise ValueError(msg)
elif stype == 'isotropic' and not params is None:
elif stype == 'isotropic' and params is not None:
msg = 'Unable to set source angle parameters since they are not ' \
'it is not supported for isotropic type sources'
raise ValueError(msg)
@ -638,7 +638,7 @@ class SettingsFile(object):
'value {0}'.format(stype)
raise ValueError(msg)
elif not stype in ['monoenergetic', 'watt', 'maxwell']:
elif stype not in ['monoenergetic', 'watt', 'maxwell']:
msg = 'Unable to set source energy type to {0} since it is not ' \
'monoenergetic, watt or maxwell'.format(stype)
raise ValueError(msg)
@ -684,7 +684,7 @@ class SettingsFile(object):
for element in output:
keys = ['summary', 'cross_sections', 'tallies', 'distribmats']
if not element in keys:
if element not in keys:
msg = 'Unable to set output to {0} which is unsupported by ' \
'OpenMC'.format(element)
raise ValueError(msg)
@ -824,7 +824,7 @@ class SettingsFile(object):
@energy_grid.setter
def energy_grid(self, energy_grid):
if not energy_grid in ['nuclide', 'logarithm', 'material-union']:
if energy_grid not in ['nuclide', 'logarithm', 'material-union']:
msg = 'Unable to set energy grid to {0} which is neither ' \
'nuclide, logarithm, nor material-union'.format(energy_grid)
raise ValueError(msg)
@ -1010,7 +1010,7 @@ class SettingsFile(object):
'value {0}'.format(threads)
raise ValueError(msg)
elif threads <=0:
elif threads <= 0:
msg = 'Unable to set the threads to a negative ' \
'value {0}'.format(threads)
raise ValueError(msg)
@ -1130,7 +1130,7 @@ class SettingsFile(object):
@dd_mesh_dimension.setter
def dd_mesh_dimension(self, dimension):
# TODO: remove this when domain decomposition is merged
warnings.warn('This feature is not yet implemented in a release ' \
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
if not isinstance(dimension, (tuple, list)):
@ -1148,7 +1148,7 @@ class SettingsFile(object):
@dd_mesh_lower_left.setter
def dd_mesh_lower_left(self, lower_left):
# TODO: remove this when domain decomposition is merged
warnings.warn('This feature is not yet implemented in a release ' \
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
if not isinstance(lower_left, (tuple, list, np.ndarray)):
@ -1166,7 +1166,7 @@ class SettingsFile(object):
@dd_mesh_upper_right.setter
def dd_mesh_upper_right(self, upper_right):
# TODO: remove this when domain decomposition is merged
warnings.warn('This feature is not yet implemented in a release ' \
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
if not isinstance(upper_right, tuple) and \
@ -1185,11 +1185,10 @@ class SettingsFile(object):
@dd_nodemap.setter
def dd_nodemap(self, nodemap):
# TODO: remove this when domain decomposition is merged
warnings.warn('This feature is not yet implemented in a release ' \
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
if not isinstance(nodemap, tuple) and \
not isinstance(nodemap, list):
if not isinstance(nodemap, (tuple, list)):
msg = 'Unable to set DD nodemap {0} which is ' \
'not a Python tuple or list'.format(nodemap)
raise ValueError(msg)
@ -1214,7 +1213,7 @@ class SettingsFile(object):
def dd_allow_leakage(self, allow):
# TODO: remove this when domain decomposition is merged
warnings.warn('This feature is not yet implemented in a release ' \
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
if not isinstance(allow, bool):
@ -1228,7 +1227,7 @@ class SettingsFile(object):
def dd_count_interactions(self, interactions):
# TODO: remove this when domain decomposition is merged
warnings.warn('This feature is not yet implemented in a release ' \
warnings.warn('This feature is not yet implemented in a release '
'version of openmc')
if not isinstance(interactions, bool):
@ -1246,7 +1245,7 @@ class SettingsFile(object):
self._create_keff_trigger_subelement()
def _create_batches_subelement(self):
if not self._batches is None:
if self._batches is not None:
if self._eigenvalue_subelement is None:
self._eigenvalue_subelement = ET.SubElement(self._settings_file,
"eigenvalue")
@ -1255,7 +1254,7 @@ class SettingsFile(object):
element.text = str(self._batches)
def _create_generations_per_batch_subelement(self):
if not self._generations_per_batch is None:
if self._generations_per_batch is not None:
if self._eigenvalue_subelement is None:
self._eigenvalue_subelement = ET.SubElement(self._settings_file,
"eigenvalue")
@ -1265,7 +1264,7 @@ class SettingsFile(object):
element.text = str(self._generations_per_batch)
def _create_inactive_subelement(self):
if not self._inactive is None:
if self._inactive is not None:
if self._eigenvalue_subelement is None:
self._eigenvalue_subelement = ET.SubElement(self._settings_file,
"eigenvalue")
@ -1274,7 +1273,7 @@ class SettingsFile(object):
element.text = str(self._inactive)
def _create_particles_subelement(self):
if not self._particles is None:
if self._particles is not None:
if self._eigenvalue_subelement is None:
self._eigenvalue_subelement = ET.SubElement(self._settings_file,
"eigenvalue")
@ -1283,7 +1282,7 @@ class SettingsFile(object):
element.text = str(self._particles)
def _create_keff_trigger_subelement(self):
if not self._keff_trigger is None:
if self._keff_trigger is not None:
if self._eigenvalue_subelement is None:
self._eigenvalue_subelement = ET.SubElement(self._settings_file,
"eigenvalue")
@ -1300,7 +1299,7 @@ class SettingsFile(object):
self._create_source_angle_subelement()
def _create_source_space_subelement(self):
if not self._source_space_params is None:
if self._source_space_params is not None:
if self._source_subelement is None:
self._source_subelement = ET.SubElement(self._settings_file,
"source")
@ -1312,7 +1311,7 @@ class SettingsFile(object):
subelement.text = ' '.join(map(str, self._source_space_params))
def _create_source_angle_subelement(self):
if not self._source_angle_params is None:
if self._source_angle_params is not None:
if self._source_subelement is None:
self._source_subelement = ET.SubElement(self._settings_file,
"source")
@ -1324,7 +1323,7 @@ class SettingsFile(object):
subelement.text = ' '.join(map(str, self._source_angle_params))
def _create_source_energy_subelement(self):
if not self._source_energy_params is None:
if self._source_energy_params is not None:
if self._source_subelement is None:
self._source_subelement = ET.SubElement(self._settings_file,
"source")
@ -1336,7 +1335,7 @@ class SettingsFile(object):
subelement.text = ' '.join(map(str, self._source_energy_params))
def _create_output_subelement(self):
if not self._output is None:
if self._output is not None:
element = ET.SubElement(self._settings_file, "output")
for key in self._output:
@ -1346,93 +1345,93 @@ class SettingsFile(object):
self._create_output_path_subelement()
def _create_output_path_subelement(self):
if not self._output_path is None:
if self._output_path is not None:
element = ET.SubElement(self._settings_file, "output_path")
element.text = self._output_path
def _create_verbosity_subelement(self):
if not self._verbosity is None:
if self._verbosity is not None:
element = ET.SubElement(self._settings_file, "verbosity")
element.text = str(self._verbosity)
def _create_statepoint_subelement(self):
# Batches subelement
if not self._statepoint_batches is None:
if self._statepoint_batches is not None:
element = ET.SubElement(self._settings_file, "state_point")
subelement = ET.SubElement(element, "batches")
subelement.text = ' '.join(map(str, self._statepoint_batches))
# Interval subelement
elif not self._statepoint_interval is None:
elif self._statepoint_interval is not None:
element = ET.SubElement(self._settings_file, "state_point")
subelement = ET.SubElement(element, "interval")
subelement.text = str(self._statepoint_interval)
def _create_sourcepoint_subelement(self):
# Batches subelement
if not self._sourcepoint_batches is None:
if self._sourcepoint_batches is not None:
element = ET.SubElement(self._settings_file, "source_point")
subelement = ET.SubElement(element, "batches")
subelement.text = ' '.join(map(str, self._sourcepoint_batches))
# Interval subelement
elif not self._sourcepoint_interval is None:
elif self._sourcepoint_interval is not None:
element = ET.SubElement(self._settings_file, "source_point")
subelement = ET.SubElement(element, "interval")
subelement.text = str(self._sourcepoint_interval)
# Separate subelement
if not self._sourcepoint_separate is None:
if self._sourcepoint_separate is not None:
subelement = ET.SubElement(element, "separate")
subelement.text = str(self._sourcepoint_separate).lower()
# Write subelement
if not self._sourcepoint_write is None:
if self._sourcepoint_write is not None:
subelement = ET.SubElement(element, "write")
subelement.text = str(self._sourcepoint_write).lower()
# Overwrite latest subelement
if not self._sourcepoint_overwrite is None:
if self._sourcepoint_overwrite is not None:
subelement = ET.SubElement(element, "overwrite_latest")
subelement.text = str(self._sourcepoint_overwrite).lower()
def _create_confidence_intervals(self):
if not self._confidence_intervals is None:
if self._confidence_intervals is not None:
element = ET.SubElement(self._settings_file, "confidence_intervals")
element.text = str(self._confidence_intervals).lower()
def _create_cross_sections_subelement(self):
if not self._cross_sections is None:
if self._cross_sections is not None:
element = ET.SubElement(self._settings_file, "cross_sections")
element.text = str(self._cross_sections)
def _create_energy_grid_subelement(self):
if not self._energy_grid is None:
if self._energy_grid is not None:
element = ET.SubElement(self._settings_file, "energy_grid")
element.text = str(self._energy_grid)
def _create_ptables_subelement(self):
if not self._ptables is None:
if self._ptables is not None:
element = ET.SubElement(self._settings_file, "ptables")
element.text = str(self._ptables).lower()
def _create_run_cmfd_subelement(self):
if not self._run_cmfd is None:
if self._run_cmfd is not None:
element = ET.SubElement(self._settings_file, "run_cmfd")
element.text = str(self._run_cmfd).lower()
def _create_seed_subelement(self):
if not self._seed is None:
if self._seed is not None:
element = ET.SubElement(self._settings_file, "seed")
element.text = str(self._seed)
def _create_survival_biasing_subelement(self):
if not self._survival_biasing is None:
if self._survival_biasing is not None:
element = ET.SubElement(self._settings_file, "survival_biasing")
element.text = str(self._survival_biasing).lower()
def _create_cutoff_subelement(self):
if not self._weight is None:
if self._weight is not None:
element = ET.SubElement(self._settings_file, "cutoff")
subelement = ET.SubElement(element, "weight")
@ -1442,8 +1441,8 @@ class SettingsFile(object):
subelement.text = str(self._weight_avg)
def _create_entropy_subelement(self):
if not self._entropy_lower_left is None and \
not self._entropy_upper_right is None:
if self._entropy_lower_left is not None and \
self._entropy_upper_right is not None:
element = ET.SubElement(self._settings_file, "entropy")
@ -1462,7 +1461,7 @@ class SettingsFile(object):
self._create_trigger_batch_interval_subelement()
def _create_trigger_active_subelement(self):
if not self._trigger_active is None:
if self._trigger_active is not None:
if self._trigger_subelement is None:
self._trigger_subelement = ET.SubElement(self._settings_file,
"trigger")
@ -1471,7 +1470,7 @@ class SettingsFile(object):
element.text = str(self._trigger_active).lower()
def _create_trigger_max_batches_subelement(self):
if not self._trigger_max_batches is None:
if self._trigger_max_batches is not None:
if self._trigger_subelement is None:
self._trigger_subelement = ET.SubElement(self._settings_file,
"trigger")
@ -1480,7 +1479,7 @@ class SettingsFile(object):
element.text = str(self._trigger_max_batches)
def _create_trigger_batch_interval_subelement(self):
if not self._trigger_batch_interval is None:
if self._trigger_batch_interval is not None:
if self._trigger_subelement is None:
self._trigger_subelement = ET.SubElement(self._settings_file,
"trigger")
@ -1489,28 +1488,28 @@ class SettingsFile(object):
element.text = str(self._trigger_batch_interval)
def _create_no_reduce_subelement(self):
if not self._no_reduce is None:
if self._no_reduce is not None:
element = ET.SubElement(self._settings_file, "no_reduce")
element.text = str(self._no_reduce).lower()
def _create_threads_subelement(self):
if not self._threads is None:
if self._threads is not None:
element = ET.SubElement(self._settings_file, "threads")
element.text = str(self._threads)
def _create_trace_subelement(self):
if not self._trace is None:
if self._trace is not None:
element = ET.SubElement(self._settings_file, "trace")
element.text = ' '.join(map(str, self._trace))
def _create_track_subelement(self):
if not self._track is None:
if self._track is not None:
element = ET.SubElement(self._settings_file, "track")
element.text = ' '.join(map(str, self._track))
def _create_ufs_subelement(self):
if not self._ufs_lower_left is None and \
not self._ufs_upper_right is None:
if self._ufs_lower_left is not None and \
self._ufs_upper_right is not None:
element = ET.SubElement(self._settings_file, "uniform_fs")
@ -1524,9 +1523,9 @@ class SettingsFile(object):
subelement.text = ' '.join(map(str, self._ufs_upper_right))
def _create_dd_subelement(self):
if not self._dd_mesh_lower_left is None and \
not self._dd_mesh_upper_right is None and \
not self._dd_mesh_dimension is None:
if self._dd_mesh_lower_left is not None and \
self._dd_mesh_upper_right is not None and \
self._dd_mesh_dimension is not None:
element = ET.SubElement(self._settings_file, "domain_decomposition")
@ -1540,7 +1539,7 @@ class SettingsFile(object):
subsubelement = ET.SubElement(subelement, "upper_right")
subsubelement.text = ' '.join(map(str, self._dd_mesh_upper_right))
if not self._dd_nodemap is None:
if self._dd_nodemap is not None:
subelement = ET.SubElement(element, "nodemap")
subelement.text = ' '.join(map(str, self._dd_nodemap))

View file

@ -309,7 +309,6 @@ class StatePoint(object):
# Add mesh to the global dictionary of all Meshes
self._meshes[mesh_id] = mesh
def _read_tallies(self):
# Initialize dictionaries for the Tallies
# Keys - Tally IDs
@ -468,7 +467,7 @@ class StatePoint(object):
"""
# Number of realizations for global Tallies
# Number of realizations for global Tallies
self._n_realizations = self._get_int(path='n_realizations')[0]
# Read global Tallies
@ -511,7 +510,8 @@ class StatePoint(object):
sum_sq = results[1::2]
# Define a routine to convert 0 to 1
nonzero = lambda val: 1 if not val else val
def nonzero(val):
return 1 if not val else val
# Reshape the results arrays
new_shape = (nonzero(tally.num_filter_bins),
@ -678,7 +678,7 @@ class StatePoint(object):
# Iterate over the scores requested by the user
for score in scores:
if not score in test_tally.scores:
if score not in test_tally.scores:
contains_scores = False
break
@ -691,7 +691,7 @@ class StatePoint(object):
# Iterate over the Filters requested by the user
for filter in filters:
if not filter in test_tally.filters:
if filter not in test_tally.filters:
contains_filters = False
break
@ -704,7 +704,7 @@ class StatePoint(object):
# Iterate over the Nuclides requested by the user
for nuclide in nuclides:
if not nuclide in test_tally.nuclides:
if nuclide not in test_tally.nuclides:
contains_nuclides = False
break
@ -789,7 +789,7 @@ class StatePoint(object):
self._with_summary = True
def _get_data(self, n, typeCode, size):
return list(struct.unpack('={0}{1}'.format(n,typeCode),
return list(struct.unpack('={0}{1}'.format(n, typeCode),
self._f.read(n*size)))
def _get_int(self, n=1, path=None):

View file

@ -362,7 +362,6 @@ class Summary(object):
lattice.lower_left = lower_left
lattice.pitch = pitch
# If the Universe specified outer the Lattice is not void (-22)
if outer != -22:
lattice.outer = self.universes[outer]
@ -374,14 +373,14 @@ class Summary(object):
for x in range(universe_ids.shape[0]):
for y in range(universe_ids.shape[1]):
for z in range(universe_ids.shape[2]):
universes[x,y,z] = \
self.get_universe_by_id(universe_ids[x,y,z])
universes[x, y, z] = \
self.get_universe_by_id(universe_ids[x, y, z])
# Transpose, reverse y-dimension for appropriate ordering
shape = universes.shape
universes = np.transpose(universes, (1,0,2))
universes = np.transpose(universes, (1, 0, 2))
universes.shape = shape
universes = universes[:,::-1,:]
universes = universes[:, ::-1, :]
lattice.universes = universes
if offset_size > 0:
@ -399,8 +398,8 @@ class Summary(object):
pitch = self._f['geometry/lattices'][key]['pitch'][...]
outer = self._f['geometry/lattices'][key]['outer'][0]
universe_ids = \
self._f['geometry/lattices'][key]['universes'][...]
universe_ids = self._f[
'geometry/lattices'][key]['universes'][...]
# Create the Lattice
lattice = openmc.HexLattice(lattice_id=lattice_id, name=name)
@ -420,9 +419,9 @@ class Summary(object):
for i in range(universe_ids.shape[0]):
for j in range(universe_ids.shape[1]):
for k in range(universe_ids.shape[2]):
if universe_ids[i,j,k] != -1:
universes[i,j,k] = \
self.get_universe_by_id(universe_ids[i,j,k])
if universe_ids[i, j, k] != -1:
universes[i, j, k] = self.get_universe_by_id(
universe_ids[i, j, k])
if offset_size > 0:
lattice.offsets = offsets
@ -465,7 +464,7 @@ class Summary(object):
self.tallies = {}
# Read the number of tallies
if not 'tallies' in self._f.keys():
if 'tallies' not in self._f:
self.n_tallies = 0
return
@ -560,7 +559,6 @@ class Summary(object):
"""
for index, nuclide in self.nuclides.items():
if nuclide._zaid == zaid:
return nuclide

View file

@ -138,7 +138,7 @@ class Tally(object):
return False
for filter in self.filters:
if not filter in tally2.filters:
if filter not in tally2.filters:
return False
# Check all nuclides
@ -146,7 +146,7 @@ class Tally(object):
return False
for nuclide in self.nuclides:
if not nuclide in tally2.nuclides:
if nuclide not in tally2.nuclides:
return False
# Check all scores
@ -154,7 +154,7 @@ class Tally(object):
return False
for score in self.scores:
if not score in tally2.scores:
if score not in tally2.scores:
return False
if self.estimator != tally2.estimator:
@ -269,7 +269,7 @@ class Tally(object):
@estimator.setter
def estimator(self, estimator):
if not estimator in ['analog', 'tracklength']:
if estimator not in ['analog', 'tracklength']:
msg = 'Unable to set the estimator for Tally ID={0} to {1} since ' \
'it is not a valid estimator type'.format(self.id, estimator)
raise ValueError(msg)
@ -486,7 +486,7 @@ class Tally(object):
# Calculate sample mean and standard deviation
self._mean = self.sum / self.num_realizations
self._std_dev = np.sqrt((self.sum_sq / self.num_realizations - \
self._std_dev = np.sqrt((self.sum_sq / self.num_realizations -
self.mean**2) / (self.num_realizations - 1))
self._std_dev *= t_value
@ -538,7 +538,7 @@ class Tally(object):
return False
for nuclide in self.nuclides:
if not nuclide in tally.nuclides:
if nuclide not in tally.nuclides:
return False
# Must have same or mergeable filters
@ -628,7 +628,7 @@ class Tally(object):
subelement = ET.SubElement(element, "filter")
subelement.set("type", str(filter.type))
if not filter.bins is None:
if filter.bins is not None:
bins = ''
for bin in filter.bins:
bins += '{0} '.format(bin)
@ -662,7 +662,7 @@ class Tally(object):
subelement.text = scores.rstrip(' ')
# Tally estimator type
if not self.estimator is None:
if self.estimator is not None:
subelement = ET.SubElement(element, "estimator")
subelement.text = self.estimator
@ -868,7 +868,6 @@ class Tally(object):
'Tally.get_values(...)'.format(self.id)
raise ValueError(msg)
# Compute batch statistics if not yet computed
self.compute_std_dev()
@ -897,7 +896,7 @@ class Tally(object):
# Create list of 2- or 3-tuples tuples for mesh cell bins
if filter.type == 'mesh':
dimension = filter.mesh.dimension
xyz = map(lambda x: np.arange(1,x+1), dimension)
xyz = map(lambda x: np.arange(1, x+1), dimension)
bins = list(itertools.product(*xyz))
# Create list of 2-tuples for energy boundary bins
@ -1176,7 +1175,7 @@ class Tally(object):
# If entire LocalCoords has been unraveled into
# Multi-index columns already, continue
if coords == None:
if coords is None:
continue
# Assign entry to Universe Multi-index column
@ -1198,7 +1197,7 @@ class Tally(object):
level_dict[lat_z_key][offset] = lat_z
# Move to next node in LocalCoords linked list
if coords._next == None:
if coords._next is None:
offsets_to_coords[offset] = None
else:
offsets_to_coords[offset] = coords._next
@ -1324,7 +1323,7 @@ class Tally(object):
'string'.format(self.id, directory)
raise ValueError(msg)
elif not format in ['hdf5', 'pkl', 'csv']:
elif format not in ['hdf5', 'pkl', 'csv']:
msg = 'Unable to export the results for Tally ID={0} to format ' \
'"{1}" since it is not supported'.format(self.id, format)
raise ValueError(msg)
@ -1407,7 +1406,7 @@ class Tally(object):
for nuclide in self.nuclides:
nuclides.append(nuclide.name)
tally_group['nuclides']= np.array(nuclides)
tally_group['nuclides'] = np.array(nuclides)
# Create a nested dictionary for the Filters
tally_group['filters'] = {}