Revised Python API to used underscore separated instance method names to comply with PEP8

This commit is contained in:
Will Boyd 2014-11-03 19:38:02 -05:00
parent 0b5a33b2bd
commit 2767d3f53f
13 changed files with 506 additions and 413 deletions

View file

@ -4,7 +4,6 @@ from openmc.element import *
from openmc.geometry import *
from openmc.nuclide import *
from openmc.material import *
from openmc.opencsg_compatible import *
from openmc.plots import *
from openmc.settings import *
from openmc.surface import *
@ -12,3 +11,8 @@ from openmc.universe import *
from openmc.tallies import *
from openmc.executor import *
#from statepoint import *
try:
from openmc.opencsg_compatible import *
except ImportError:
pass

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python
"""Dictionaries of integer-to-string mapppings from openmc/src/constants.F90"""
"""Dictionaries of integer-to-string mappings from openmc/src/constants.F90"""
SURFACE_TYPES = {1: 'x-plane',
2: 'y-plane',
@ -122,4 +122,4 @@ SCORE_TYPES.update({MT: '(n,p' + str(MT-600) + ')' for MT in range(600,649)})
SCORE_TYPES.update({MT: '(n,d' + str(MT-650) + ')' for MT in range(650,699)})
SCORE_TYPES.update({MT: '(n,t' + str(MT-700) + ')' for MT in range(700,749)})
SCORE_TYPES.update({MT: '(n,3He' + str(MT-750) + ')' for MT in range(750,649)})
SCORE_TYPES.update({MT: '(n,a' + str(MT-800) + ')' for MT in range(800,849)})
SCORE_TYPES.update({MT: '(n,a' + str(MT-800) + ')' for MT in range(800,849)})

View file

@ -11,15 +11,15 @@ class Element(object):
self._xs = None
# Set the Material class attributes
self.setName(name)
self.set_name(name)
if not xs is None:
self.setXS(xs)
self.set_xs(xs)
def __eq__(self, element2):
# check type
# Check type
if not isinstance(element2, Element):
return False
@ -42,7 +42,7 @@ class Element(object):
return hash(tuple(hashable))
def setName(self, name):
def set_name(self, name):
if not is_string(name):
msg = 'Unable to set name for Element with a non-string ' \
@ -52,7 +52,7 @@ class Element(object):
self._name = name
def setXS(self, xs):
def set_xs(self, xs):
if not is_string(xs):
msg = 'Unable to set cross-section identifier xs for Element ' \

View file

@ -15,7 +15,7 @@ class Executor(object):
self._working_directory = '.'
def setWorkingDirectory(self, working_directory):
def set_working_directory(self, working_directory):
if not is_string(working_directory):
msg = 'Unable to set Executor\'s working directory to {0} ' \
@ -30,7 +30,7 @@ class Executor(object):
self._working_directory = working_directory
def plotGeometry(self, output=True):
def plot_geometry(self, output=True):
if output:
subprocess.check_call('openmc -p', shell=True,
@ -40,8 +40,9 @@ class Executor(object):
cwd=self._working_directory)
def runSimulation(self, particles=None, threads=None, geometry_debug=False,
restart_file=None, tracks=False, mpi_procs=1, output=True):
def run_simulation(self, particles=None, threads=None,
geometry_debug=False, restart_file=None,
tracks=False, mpi_procs=1, output=True):
post_args = ' '
pre_args = ''

View file

@ -20,7 +20,7 @@ class Geometry(object):
self._offsets = dict()
def getOffset(self, path, filter_offset):
def get_offset(self, path, filter_offset):
"""
Returns the corresponding location in the results array for a given
path and filter number.
@ -46,35 +46,35 @@ class Geometry(object):
# Begin recursive call to compute offset starting with the base Universe
else:
offset = self._root_universe.getOffset(path, filter_offset)
offset = self._root_universe.get_offset(path, filter_offset)
self._offsets[(path, filter_offset)] = offset
# Return the final offset
return offset
def getAllCells(self):
return self._root_universe.getAllCells()
def get_all_cells(self):
return self._root_universe.get_all_cells()
def getAllUniverses(self):
return self._root_universe.getAllUniverses()
def get_all_universes(self):
return self._root_universe.get_all_universes()
def getAllNuclides(self):
def get_all_nuclides(self):
nuclides = dict()
materials = self.getAllMaterials()
materials = self.get_all_materials()
for material in materials:
nuclides.update(material.getAllNuclides())
nuclides.update(material.get_all_nuclides())
return nuclides
def getAllMaterials(self):
def get_all_materials(self):
material_cells = self.getAllMaterialCells()
material_cells = self.get_all_material_cells()
materials = set()
for cell in material_cells:
@ -83,9 +83,9 @@ class Geometry(object):
return list(materials)
def getAllMaterialCells(self):
def get_all_material_cells(self):
all_cells = self.getAllCells()
all_cells = self.get_all_cells()
material_cells = set()
for cell_id, cell in all_cells.items():
@ -95,9 +95,9 @@ class Geometry(object):
return list(material_cells)
def getAllMaterialUniverses(self):
def get_all_material_universes(self):
all_universes = self.getAllUniverses()
all_universes = self.get_all_universes()
material_universes = set()
for universe_id, universe in all_universes.items():
@ -111,7 +111,7 @@ class Geometry(object):
return list(material_universes)
def setRootUniverse(self, root_universe):
def set_root_universe(self, root_universe):
if not isinstance(root_universe, openmc.Universe):
msg = 'Unable to add root Universe {0} to Geometry since ' \
@ -137,7 +137,7 @@ class GeometryFile(object):
self._geometry_file = ET.Element("geometry")
def setGeometry(self, geometry):
def set_geometry(self, geometry):
if not isinstance(geometry, Geometry):
msg = 'Unable to set the Geometry to {0} for the GeometryFile ' \
@ -147,10 +147,10 @@ class GeometryFile(object):
self._geometry = geometry
def exportToXML(self):
def export_to_xml(self):
root_universe = self._geometry._root_universe
root_universe.createXMLSubElement(self._geometry_file)
root_universe.create_xml_subelement(self._geometry_file)
# Clean the indentation in the file to be user-readable
sort_xml_elements(self._geometry_file)
@ -159,4 +159,4 @@ class GeometryFile(object):
# Write the XML Tree to the materials.xml file
tree = ET.ElementTree(self._geometry_file)
tree.write("geometry.xml", xml_declaration=True,
encoding='utf-8', method="xml")
encoding='utf-8', method="xml")

View file

@ -58,11 +58,11 @@ class Material(object):
self._sab = list()
# Set the Material class attributes
self.setId(material_id)
self.setName(name)
self.set_id(material_id)
self.set_name(name)
def setId(self, material_id=None):
def set_id(self, material_id=None):
global MATERIAL_IDS
@ -97,7 +97,7 @@ class Material(object):
MATERIAL_IDS.append(material_id)
def setName(self, name):
def set_name(self, name):
if not is_string(name):
msg = 'Unable to set name for Material ID={0} with a non-string ' \
@ -108,7 +108,7 @@ class Material(object):
self._name = name
def setDensity(self, units, density=NO_DENSITY):
def set_density(self, units, density=NO_DENSITY):
if not is_float(density):
msg = 'Unable to set the density for Material ID={0} to a ' \
@ -130,7 +130,7 @@ class Material(object):
self._density_units = units
def addNuclide(self, nuclide, percent, percent_type='ao'):
def add_nuclide(self, nuclide, percent, percent_type='ao'):
if not isinstance(nuclide, openmc.Nuclide):
msg = 'Unable to add an Nuclide to Material ID={0} with a ' \
@ -153,7 +153,7 @@ class Material(object):
self._nuclides[nuclide._name] = (nuclide, percent, percent_type)
def removeNuclide(self, nuclide):
def remove_nuclide(self, nuclide):
if not isinstance(nuclide, openmc.Nuclide):
msg = 'Unable to remove a Nuclide {0} in Material ID={1} ' \
@ -165,7 +165,7 @@ class Material(object):
del self._nuclides[nuclide._name]
def addElement(self, element, percent, percent_type='ao'):
def add_element(self, element, percent, percent_type='ao'):
if not isinstance(element, openmc.Element):
msg = 'Unable to add an Element to Material ID={0} with a ' \
@ -188,14 +188,14 @@ class Material(object):
self._elements[element._name] = (element, percent, percent_type)
def removeElement(self, element):
def remove_element(self, element):
# If the Material contains the Element, delete it
if element._name in self._elements:
del self._elements[element._name]
def addSAlphaBeta(self, name, xs):
def add_s_alpha_beta(self, name, xs):
if not is_string(name):
msg = 'Unable to add an S(a,b) table to Material ID={0} with a ' \
@ -210,7 +210,7 @@ class Material(object):
self._sab.append((name, xs))
def getAllNuclides(self):
def get_all_nuclides(self):
nuclides = dict()
@ -256,7 +256,7 @@ class Material(object):
return string
def getNuclideXML(self, nuclide):
def get_nuclide_xml(self, nuclide):
xml_element = ET.Element("nuclide")
xml_element.set("name", nuclide[0]._name)
@ -272,7 +272,7 @@ class Material(object):
return xml_element
def getElementXML(self, element):
def get_element_xml(self, element):
xml_element = ET.Element("element")
xml_element.set("name", str(element[0]._name))
@ -285,27 +285,27 @@ class Material(object):
return xml_element
def getNuclidesXML(self, nuclides):
def get_nuclides_xml(self, nuclides):
xml_elements = list()
for nuclide in nuclides.values():
xml_elements.append(self.getNuclideXML(nuclide))
xml_elements.append(self.get_nuclide_xml(nuclide))
return xml_elements
def getElementsXML(self, elements):
def get_elements_xml(self, elements):
xml_elements = list()
for element in elements.values():
xml_elements.append(self.getElementXML(element))
xml_elements.append(self.get_element_xml(element))
return xml_elements
def getMaterialXML(self):
def get_material_xml(self):
# Create Material XML element
element = ET.Element("material")
@ -318,12 +318,12 @@ class Material(object):
subelement.set("units", self._density_units)
# Create nuclide XML subelements
subelements = self.getNuclidesXML(self._nuclides)
subelements = self.get_nuclides_xml(self._nuclides)
for subelement in subelements:
element.append(subelement)
# Create element XML subelements
subelements = self.getElementsXML(self._elements)
subelements = self.get_elements_xml(self._elements)
for subelement in subelements:
element.append(subelement)
@ -346,7 +346,7 @@ class MaterialsFile(object):
self._materials_file = ET.Element("materials")
def addMaterial(self, material):
def add_material(self, material):
if not isinstance(material, Material):
msg = 'Unable to add a non-Material {0} to the ' \
@ -356,7 +356,7 @@ class MaterialsFile(object):
self._materials.append(material)
def addMaterials(self, materials):
def add_materials(self, materials):
if not isinstance(materials, (tuple, list, MappingView)):
msg = 'Unable to create OpenMC materials.xml file from {0} which ' \
@ -364,10 +364,10 @@ class MaterialsFile(object):
raise ValueError(msg)
for material in materials:
self.addMaterial(material)
self.add_material(material)
def removeMaterial(self, material):
def remove_materials(self, material):
if not isinstance(material, Material):
msg = 'Unable to remove a non-Material {0} from the ' \
@ -377,7 +377,7 @@ class MaterialsFile(object):
self._materials.remove(material)
def setDefaultXS(self, xs):
def set_default_xs(self, xs):
if not is_string(xs):
msg = 'Unable to set default xs to a non-string value'.format(xs)
@ -386,7 +386,7 @@ class MaterialsFile(object):
self._default_xs = xs
def createMaterialSubelements(self):
def create_material_subelements(self):
subelement = ET.SubElement(self._materials_file, "default_xs")
@ -394,7 +394,7 @@ class MaterialsFile(object):
subelement.text = self._default_xs
for material in self._materials:
xml_element = material.getMaterialXML()
xml_element = material.get_material_xml()
if len(material._name) > 0:
self._materials_file.append(ET.Comment(material._name))
@ -402,9 +402,9 @@ class MaterialsFile(object):
self._materials_file.append(xml_element)
def exportToXML(self):
def export_to_xml(self):
self.createMaterialSubelements()
self.create_material_subelements()
# Clean the indentation in the file to be user-readable
sort_xml_elements(self._materials_file)

View file

@ -12,10 +12,10 @@ class Nuclide(object):
self._xs = None
# Set the Material class attributes
self.setName(name)
self.set_name(name)
if not xs is None:
self.setXS(xs)
self.set_xs(xs)
def __eq__(self, nuclide2):
@ -43,7 +43,7 @@ class Nuclide(object):
return hash(tuple(hashable))
def setName(self, name):
def set_name(self, name):
if not is_string(name):
msg = 'Unable to set name for Nuclide with a non-string ' \
@ -53,7 +53,7 @@ class Nuclide(object):
self._name = name
def setXS(self, xs):
def set_xs(self, xs):
if not is_string(xs):
msg = 'Unable to set cross-section identifier xs for Nuclide ' \

View file

@ -438,47 +438,47 @@ def get_compatible_opencsg_cells(opencsg_cell, opencsg_surface, halfspace):
# Top left subcell - add left XPlane, top YPlane
if clone_id == 0:
clone.addSurface(compatible_surfaces[0], -1)
clone.addSurface(compatible_surfaces[3], +1)
clone.add_surface(compatible_surfaces[0], -1)
clone.add_surface(compatible_surfaces[3], +1)
# Top center subcell - add top YPlane, left/right XPlanes
elif clone_id == 1:
clone.addSurface(compatible_surfaces[0], +1)
clone.addSurface(compatible_surfaces[1], -1)
clone.addSurface(compatible_surfaces[3], +1)
clone.add_surface(compatible_surfaces[0], +1)
clone.add_surface(compatible_surfaces[1], -1)
clone.add_surface(compatible_surfaces[3], +1)
# Top right subcell - add top YPlane, right XPlane
elif clone_id == 2:
clone.addSurface(compatible_surfaces[1], +1)
clone.addSurface(compatible_surfaces[3], +1)
clone.add_surface(compatible_surfaces[1], +1)
clone.add_surface(compatible_surfaces[3], +1)
# Right center subcell - add right XPlane, top/bottom YPlanes
elif clone_id == 3:
clone.addSurface(compatible_surfaces[1], +1)
clone.addSurface(compatible_surfaces[3], -1)
clone.addSurface(compatible_surfaces[2], +1)
clone.add_surface(compatible_surfaces[1], +1)
clone.add_surface(compatible_surfaces[3], -1)
clone.add_surface(compatible_surfaces[2], +1)
# Bottom right subcell - add right XPlane, bottom YPlane
elif clone_id == 4:
clone.addSurface(compatible_surfaces[1], +1)
clone.addSurface(compatible_surfaces[2], -1)
clone.add_surface(compatible_surfaces[1], +1)
clone.add_surface(compatible_surfaces[2], -1)
# Bottom center subcell - add bottom YPlane, left/right XPlanes
elif clone_id == 5:
clone.addSurface(compatible_surfaces[0], +1)
clone.addSurface(compatible_surfaces[1], -1)
clone.addSurface(compatible_surfaces[2], -1)
clone.add_surface(compatible_surfaces[0], +1)
clone.add_surface(compatible_surfaces[1], -1)
clone.add_surface(compatible_surfaces[2], -1)
# Bottom left subcell - add bottom YPlane, left XPlane
elif clone_id == 6:
clone.addSurface(compatible_surfaces[0], -1)
clone.addSurface(compatible_surfaces[2], -1)
clone.add_surface(compatible_surfaces[0], -1)
clone.add_surface(compatible_surfaces[2], -1)
# Left center subcell - add left XPlane, top/bottom YPlanes
elif clone_id == 7:
clone.addSurface(compatible_surfaces[0], -1)
clone.addSurface(compatible_surfaces[3], -1)
clone.addSurface(compatible_surfaces[2], +1)
clone.add_surface(compatible_surfaces[0], -1)
clone.add_surface(compatible_surfaces[3], -1)
clone.add_surface(compatible_surfaces[2], +1)
# Remove redundant Surfaces from the Cells
for cell in compatible_cells:
@ -557,21 +557,21 @@ def get_openmc_cell(opencsg_cell):
rot = opencsg_cell._rotation
if (opencsg_cell._type == 'universe'):
openmc_cell.setFill(get_openmc_universe(fill))
openmc_cell.set_fill(get_openmc_universe(fill))
elif (opencsg_cell._type == 'lattice'):
openmc_cell.setFill(get_openmc_lattice(fill))
openmc_cell.set_fill(get_openmc_lattice(fill))
else:
openmc_cell.setFill(get_openmc_material(fill))
openmc_cell.set_fill(get_openmc_material(fill))
if rot:
openmc_cell.setRotation(rot)
openmc_cell.set_rotation(rot)
surfaces = opencsg_cell._surfaces
for surface_id in surfaces:
surface = surfaces[surface_id][0]
halfspace = surfaces[surface_id][1]
openmc_cell.addSurface(get_openmc_surface(surface), halfspace)
openmc_cell.add_surface(get_openmc_surface(surface), halfspace)
# Add the OpenMC Cell to the global collection of all OpenMC Cells
OPENMC_CELLS[cell_id] = openmc_cell
@ -643,7 +643,7 @@ def get_openmc_universe(opencsg_universe):
for cell_id, opencsg_cell in opencsg_cells.items():
openmc_cell = get_openmc_cell(opencsg_cell)
openmc_universe.addCell(openmc_cell)
openmc_universe.add_cell(openmc_cell)
# Add the OpenMC Universe to the global collection of all OpenMC Universes
OPENMC_UNIVERSES[universe_id] = openmc_universe
@ -680,7 +680,7 @@ def get_opencsg_lattice(openmc_lattice):
dtype=opencsg.Universe)
# Create OpenCSG Universes for each unique nested Universe in this Lattice
unique_universes = openmc_lattice.getUniqueUniverses()
unique_universes = openmc_lattice.get_unique_universes()
for universe_id, universe in unique_universes.items():
unique_universes[universe_id] = get_opencsg_universe(universe)
@ -758,10 +758,10 @@ def get_openmc_lattice(opencsg_lattice):
universe_array = np.squeeze(universe_array)
openmc_lattice = openmc.Lattice(lattice_id=lattice_id)
openmc_lattice.setDimension(dimension)
openmc_lattice.setWidth(width)
openmc_lattice.setUniverses(universe_array)
openmc_lattice.setLowerLeft(lower_left)
openmc_lattice.set_dimension(dimension)
openmc_lattice.set_width(width)
openmc_lattice.set_universes(universe_array)
openmc_lattice.set_lower_left(lower_left)
# Add the OpenMC Lattice to the global collection of all OpenMC Lattices
OPENMC_LATTICES[lattice_id] = openmc_lattice
@ -831,6 +831,6 @@ def get_openmc_geometry(opencsg_geometry):
openmc_root_universe = get_openmc_universe(opencsg_root_universe)
openmc_geometry = openmc.Geometry()
openmc_geometry.setRootUniverse(openmc_root_universe)
openmc_geometry.set_root_universe(openmc_root_universe)
return openmc_geometry

View file

@ -36,11 +36,11 @@ class Plot(object):
self._mask_background = None
self._col_spec = None
self.setId(plot_id)
self.setName(name)
self.set_id(plot_id)
self.set_name(name)
def setId(self, plot_id=None):
def set_id(self, plot_id=None):
if plot_id is None:
global AUTO_PLOT_ID
@ -61,7 +61,7 @@ class Plot(object):
self._id = plot_id
def setName(self, name):
def set_name(self, name):
if not is_string(name):
msg = 'Unable to set name for Plot ID={0} with a non-string ' \
@ -72,7 +72,7 @@ class Plot(object):
self._name = name
def setWidth(self, width):
def set_width(self, width):
if not isinstance(width, (tuple, list, np.ndarray)):
msg = 'Unable to create Plot ID={0} with width {1} which is not ' \
@ -94,7 +94,7 @@ class Plot(object):
self._width = width
def setOrigin(self, origin):
def set_origin(self, origin):
if not isinstance(origin, (tuple, list, np.ndarray)):
msg = 'Unable to create Plot ID={0} with origin {1} which is not ' \
@ -117,7 +117,7 @@ class Plot(object):
self._origin = origin
def setPixels(self, pixels):
def set_pixels(self, pixels):
if not isinstance(pixels, (tuple, list, np.ndarray)):
msg = 'Unable to create Plot ID={0} with pixels {1} which is not ' \
@ -144,7 +144,7 @@ class Plot(object):
self._pixels = pixels
def setFilename(self, filename):
def set_filename(self, filename):
if not is_string(filename):
msg = 'Unable to create Plot ID={0} with filename {1} which is ' \
@ -154,7 +154,7 @@ class Plot(object):
self._filename = filename
def setColor(self, color):
def set_color(self, color):
if not is_string(color):
msg = 'Unable to create Plot ID={0} with color {1} which is not ' \
@ -169,7 +169,7 @@ class Plot(object):
self._color = color
def setType(self, type):
def set_type(self, type):
if not is_string(type):
msg = 'Unable to create Plot ID={0} with type {1} which is not ' \
@ -184,7 +184,7 @@ class Plot(object):
self._type = type
def setBasis(self, basis):
def set_basis(self, basis):
if not is_string(basis):
msg = 'Unable to create Plot ID={0} with basis {1} which is not ' \
@ -199,7 +199,7 @@ class Plot(object):
self._basis = basis
def setBackground(self, background):
def set_background(self, background):
if not isinstance(background, (tuple, list, np.ndarray)):
msg = 'Unable to create Plot ID={0} with background {1} ' \
@ -228,7 +228,7 @@ class Plot(object):
self._background = background
def setColSpec(self, col_spec):
def set_col_spec(self, col_spec):
if not isinstance(col_spec, dict):
msg= 'Unable to create Plot ID={0} with col_spec parameter {1} ' \
@ -263,7 +263,7 @@ class Plot(object):
self._col_spec = col_spec
def setMaskComponents(self, mask_components):
def set_mask_components(self, mask_components):
if not isinstance(mask_components, (list, tuple, np.ndarray)):
msg = 'Unable to create Plot ID={0} with mask components {1} ' \
@ -285,7 +285,7 @@ class Plot(object):
self._mask_components = mask_components
def setMaskBackground(self, mask_background):
def set_mask_background(self, mask_background):
if not isinstance(mask_background, (list, tuple, np.ndarray)):
msg = 'Unable to create Plot ID={0} with mask background {1} ' \
@ -335,7 +335,7 @@ class Plot(object):
return string
def getPlotXML(self):
def get_plot_xml(self):
element = ET.Element("plot")
element.set("id", str(self._id))
@ -404,7 +404,7 @@ class PlotsFile(object):
self._plots_file = ET.Element("plots")
def addPlot(self, plot):
def add_plot(self, plot):
if not isinstance(plot, Plot):
msg = 'Unable to add a non-Plot {0} to the PlotsFile'.format(plot)
@ -413,15 +413,15 @@ class PlotsFile(object):
self._plots.append(plot)
def removePlot(self, plot):
def remove_plot(self, plot):
self._plots.remove(plot)
def createPlotSubelements(self):
def create_plot_subelements(self):
for plot in self._plots:
xml_element = plot.getPlotXML()
xml_element = plot.get_plot_xml()
if len(plot._name) > 0:
self._plots_file.append(ET.Comment(plot._name))
@ -429,9 +429,9 @@ class PlotsFile(object):
self._plots_file.append(xml_element)
def exportToXML(self):
def export_to_xml(self):
self.createPlotSubelements()
self.create_plot_subelements()
# Clean the indentation in the file to be user-readable
clean_xml_indentation(self._plots_file)

View file

@ -74,7 +74,7 @@ class SettingsFile(object):
self._source_element = None
def setBatches(self, batches):
def set_batches(self, batches):
if not is_integer(batches):
msg = 'Unable to set batches to a non-integer ' \
@ -89,7 +89,7 @@ class SettingsFile(object):
self._batches = batches
def setGenerationsPerBatch(self, generations_per_batch):
def set_generations_per_batch(self, generations_per_batch):
if not is_integer(generations_per_batch):
msg = 'Unable to set generations per batch to a non-integer ' \
@ -104,7 +104,7 @@ class SettingsFile(object):
self._generations_per_batch = generations_per_batch
def setInactive(self, inactive):
def set_inactive(self, inactive):
if not is_integer(inactive):
msg = 'Unable to set inactive batches to a non-integer ' \
@ -119,7 +119,7 @@ class SettingsFile(object):
self._inactive = inactive
def setParticles(self, particles):
def set_particles(self, particles):
if not is_integer(particles):
msg = 'Unable to set particles to a non-integer ' \
@ -134,7 +134,7 @@ class SettingsFile(object):
self._particles = particles
def setSourceFile(self, source_file):
def set_source_file(self, source_file):
if not is_string(source_file):
msg = 'Unable to set source file to a non-string ' \
@ -144,7 +144,7 @@ class SettingsFile(object):
self._source_file = source_file
def setSourceSpace(self, type, params):
def set_source_space(self, type, params):
if not is_string(type):
msg = 'Unable to set source space type to a non-string ' \
@ -177,7 +177,7 @@ class SettingsFile(object):
self._source_space_params = params
def setSourceAngle(self, type, params=[]):
def set_source_angle(self, type, params=[]):
if not is_string(type):
msg = 'Unable to set source angle type to a non-string ' \
@ -216,7 +216,7 @@ class SettingsFile(object):
self._source_angle_params = params
def setSourceEnergy(self, type, params=[]):
def set_source_energy(self, type, params=[]):
if not is_string(type):
msg = 'Unable to set source energy type to a non-string ' \
@ -262,7 +262,7 @@ class SettingsFile(object):
self._source_energy_params = params
def setOutput(self, output):
def set_output(self, output):
if not isinstance(output, dict):
msg = 'Unable to set output to {0} which is not a Python ' \
@ -285,7 +285,7 @@ class SettingsFile(object):
self._output = output
def setOutputPath(self, output_path):
def set_output_path(self, output_path):
if not is_string(output_path):
msg = 'Unable to set output path to non-string ' \
@ -295,7 +295,7 @@ class SettingsFile(object):
self._output_path = output_path
def setVerbosity(self, verbosity):
def set_verbosity(self, verbosity):
if not is_integer(verbosity):
msg = 'Unable to set verbosity to non-integer ' \
@ -310,7 +310,7 @@ class SettingsFile(object):
self._verbosity = verbosity
def setStatepointBatches(self, batches):
def set_statepoint_batches(self, batches):
if not isinstance(batches, (tuple, list, np.ndarray)):
msg = 'Unable to set statepoint batches to {0} which is not a ' \
@ -332,7 +332,7 @@ class SettingsFile(object):
self._statepoint_batches = batches
def setStatepointInterval(self, interval):
def set_statepoint_interval(self, interval):
if not is_integer(interval):
msg = 'Unable to set statepoint interval to non-integer ' \
@ -342,7 +342,7 @@ class SettingsFile(object):
self._statepoint_interval = interval
def setSourcepointBatches(self, batches):
def set_sourcepoint_batches(self, batches):
if not isinstance(batches, (tuple, list, np.ndarray)):
msg = 'Unable to set sourcepoint batches to {0} which is ' \
@ -364,7 +364,7 @@ class SettingsFile(object):
self._sourcepoint_batches = batches
def setSourcepointInterval(self, interval):
def set_sourcepoint_interval(self, interval):
if not is_integer(interval):
msg = 'Unable to set sourcepoint interval to non-integer ' \
@ -374,7 +374,7 @@ class SettingsFile(object):
self._sourcepoint_interval = interval
def setSourcepointSeparate(self, source_separate):
def set_sourcepoint_separate(self, source_separate):
if not isinstance(source_separate, (bool, np.bool)):
msg = 'Unable to set sourcepoint separate to non-boolean ' \
@ -384,7 +384,7 @@ class SettingsFile(object):
self._sourcepoint_separate = source_separate
def setSourcepointWrite(self, source_write):
def set_sourcepoint_write(self, source_write):
if not isinstance(source_write, (bool, np.bool)):
msg = 'Unable to set sourcepoint write to non-boolean ' \
@ -394,7 +394,7 @@ class SettingsFile(object):
self._sourcepoint_write = source_write
def setSourcepointOverwrite(self, source_overwrite):
def set_sourcepoint_overwrite(self, source_overwrite):
if not isinstance(source_overwrite, (bool, np.bool)):
msg = 'Unable to set sourcepoint overwrite to non-boolean ' \
@ -404,7 +404,7 @@ class SettingsFile(object):
self._sourcepoint_overwrite = source_overwrite
def setConfidenceIntervals(self, confidence_intervals):
def set_confidence_intervals(self, confidence_intervals):
if not isinstance(confidence_intervals, (bool, np.bool)):
msg = 'Unable to set confidence interval to non-boolean ' \
@ -414,7 +414,7 @@ class SettingsFile(object):
self._confidence_intervals = confidence_intervals
def setCrossSections(self, cross_sections):
def set_cross_sections(self, cross_sections):
if not is_string(cross_sections):
msg = 'Unable to set cross sections to non-string ' \
@ -424,7 +424,7 @@ class SettingsFile(object):
self._cross_sections = cross_sections
def setEnergyGrid(self, energy_grid):
def set_energy_grid(self, energy_grid):
if not energy_grid in ['union', 'nuclide']:
msg = 'Unable to set energy grid to {0} which is neither ' \
@ -434,7 +434,7 @@ class SettingsFile(object):
self._energy_grid = energy_grid
def setPTables(self, ptables):
def set_ptables(self, ptables):
if not isinstance(ptables, (bool, np.bool)):
msg = 'Unable to set ptables to non-boolean ' \
@ -444,7 +444,7 @@ class SettingsFile(object):
self._ptables = ptables
def setRunCMFD(self, run_cmfd):
def set_run_cmfd(self, run_cmfd):
if not isinstance(run_cmfd, (bool, np.bool)):
msg = 'Unable to set run_cmfd to non-boolean ' \
@ -454,7 +454,7 @@ class SettingsFile(object):
self._run_cmfd = run_cmfd
def setSeed(self, seed):
def set_seed(self, seed):
if not is_integer(seed):
msg = 'Unable to set seed to non-integer value {0}'.format(seed)
@ -467,7 +467,7 @@ class SettingsFile(object):
self._seed = seed
def setSurvivalBiasing(self, survival_biasing):
def set_survival_biasing(self, survival_biasing):
if not isinstance(survival_biasing, (bool, np.bool)):
msg = 'Unable to set survival biasing to non-boolean ' \
@ -477,7 +477,7 @@ class SettingsFile(object):
self._survival_biasing = survival_biasing
def setWeight(self, weight, weight_avg):
def set_weight(self, weight, weight_avg):
if not is_float(weight):
msg = 'Unable to set weight cutoff to non-floating point ' \
@ -503,7 +503,7 @@ class SettingsFile(object):
self._weight_avg = weight_avg
def setEntropyDimension(self, dimension):
def set_entropy_dimension(self, dimension):
if not isinstance(dimension, (tuple, list)):
msg = 'Unable to set entropy mesh dimension to {0} which is ' \
@ -525,7 +525,7 @@ class SettingsFile(object):
self._entropy_dimension = dimension
def setEntropyLowerLeft(self, lower_left):
def set_entropy_lower_left(self, lower_left):
if not isinstance(lower_left, (tuple, list)):
msg = 'Unable to set entropy mesh lower left corner to {0} which ' \
@ -548,7 +548,7 @@ class SettingsFile(object):
self._entropy_lower_left = lower_left
def setEntropyUpperRight(self, upper_right):
def set_entropy_upper_right(self, upper_right):
if not isinstance(upper_right, (tuple, list)):
msg = 'Unable to set entropy mesh upper right corner to {0} ' \
@ -571,7 +571,7 @@ class SettingsFile(object):
self._entropy_upper_right = upper_right
def setNoReduce(self, no_reduce):
def set_no_reduce(self, no_reduce):
if not isinstance(no_reduce, (bool, np.bool)):
msg = 'Unable to set the no_reduce to a non-boolean ' \
@ -581,7 +581,7 @@ class SettingsFile(object):
self._no_reduce = no_reduce
def setThreads(self, threads):
def set_threads(self, threads):
if not is_integer(threads):
msg = 'Unable to set the threads to a non-integer ' \
@ -596,7 +596,7 @@ class SettingsFile(object):
self._threads = threads
def setTrace(self, trace):
def set_trace(self, trace):
if not isinstance(trace, (list, tuple)):
msg = 'Unable to set the trace to {0} which is not a Python ' \
@ -626,7 +626,7 @@ class SettingsFile(object):
self._trace = trace
def setTrack(self, track):
def set_track(self, track):
if not isinstance(track, (list, tuple)):
msg = 'Unable to set the track to {0} which is not a Python ' \
@ -657,7 +657,7 @@ class SettingsFile(object):
self._track = track
def setUFSDimension(self, dimension):
def set_ufs_dimension(self, dimension):
if not is_integer(dimension) and not is_float(dimension):
msg = 'Unable to set UFS dimension to non-integer or ' \
@ -672,7 +672,7 @@ class SettingsFile(object):
self._ufs_dimension = dimension
def setUFSLowerLeft(self, lower_left):
def set_ufs_lower_left(self, lower_left):
if not isinstance(lower_left, (tuple, list, np.ndarray)):
msg = 'Unable to set UFS mesh lower left corner to {0} which is ' \
@ -687,7 +687,7 @@ class SettingsFile(object):
self._ufs_lower_left = lower_left
def setUFSUpperRight(self, upper_right):
def set_ufs_upper_right(self, upper_right):
if not isinstance(upper_right, tuple) and \
not isinstance(upper_right, list):
@ -703,15 +703,15 @@ class SettingsFile(object):
self._ufs_upper_right = upper_right
def createEigenvalueSubelement(self):
def create_eigenvalue_subelement(self):
self.createParticlesSubelement()
self.createBatchesSubelement()
self.createInactiveSubelement()
self.createGenerationsPerBatchSubelement()
self.create_particles_subelement()
self.create_batches_subelement()
self.create_inactive_subelement()
self.create_generations_per_batch_subelement()
def createBatchesSubelement(self):
def create_batches_subelement(self):
if not self._batches is None:
@ -723,7 +723,7 @@ class SettingsFile(object):
element.text = '{0}'.format(self._batches)
def createGenerationsPerBatchSubelement(self):
def create_generations_per_batch_subelement(self):
if not self._generations_per_batch is None:
@ -736,7 +736,7 @@ class SettingsFile(object):
element.text = '{0}'.format(self._generations_per_batch)
def createInactiveSubelement(self):
def create_inactive_subelement(self):
if not self._inactive is None:
@ -748,7 +748,7 @@ class SettingsFile(object):
element.text = '{0}'.format(self._inactive)
def createParticlesSubelement(self):
def create_particles_subelement(self):
if not self._particles is None:
@ -760,14 +760,14 @@ class SettingsFile(object):
element.text = '{0}'.format(self._particles)
def createSourceSubelement(self):
def create_source_subelement(self):
self.createSourceSpaceSubelement()
self.createSourceEnergySubelement()
self.createSourceAngleSubelement()
self.create_source_space_subelement()
self.create_source_energy_subelement()
self.create_source_angle_subelement()
def createSourceSpaceSubelement(self):
def create_source_space_subelement(self):
if not self._source_space_params is None:
@ -787,7 +787,7 @@ class SettingsFile(object):
subelement.text = text.rstrip(' ')
def createSourceAngleSubelement(self):
def create_source_angle_subelement(self):
if not self._source_angle_params is None:
@ -806,7 +806,7 @@ class SettingsFile(object):
subelement.text = text.rstrip(' ')
def createSourceEnergySubelement(self):
def create_source_energy_subelement(self):
if not self._source_energy_params is None:
@ -825,7 +825,7 @@ class SettingsFile(object):
subelement.text = text.rstrip(' ')
def createOutputSubelement(self):
def create_output_subelement(self):
if not self._output is None:
element = ET.SubElement(self._settings_file, "output")
@ -834,24 +834,24 @@ class SettingsFile(object):
subelement = ET.SubElement(element, key)
subelement.text = str(self._output[key]).lower()
self.createOuputPathSubelement()
self.create_output_path_subelement()
def createOuputPathSubelement(self):
def create_output_path_subelement(self):
if not self._output_path is None:
element = ET.SubElement(self._settings_file, "output_path")
element.text = self._output_path
def createVerbositySubelement(self):
def create_verbosity_subelement(self):
if not self._verbosity is None:
element = ET.SubElement(self._settings_file, "verbosity")
element.text = '{0}'.format(self._verbosity)
def createStatepointSubelement(self):
def create_statepoint_subelement(self):
# Batches subelement
if not self._statepoint_batches is None:
@ -869,7 +869,7 @@ class SettingsFile(object):
subelement.text = '{0}'.format(self._statepoint_interval)
def createSourcepointSubelement(self):
def create_sourcepoint_subelement(self):
# Batches subelement
if not self._sourcepoint_batches is None:
@ -902,56 +902,56 @@ class SettingsFile(object):
subelement.text = '{0}'.format(str(self._sourcepoint_overwrite).lower())
def createConfidenceIntervalsSubelement(self):
def create_confidence_intervals(self):
if not self._confidence_intervals is None:
element = ET.SubElement(self._settings_file, "confidence_intervals")
element.text = '{0}'.format(str(self._confidence_intervals).lower())
def createCrossSectionsSubelement(self):
def create_cross_sections_subelement(self):
if not self._cross_sections is None:
element = ET.SubElement(self._settings_file, "cross_sections")
element.text = '{0}'.format(self._cross_sections)
def createEnergyGridSubelement(self):
def create_energy_grid_subelement(self):
if not self._energy_grid is None:
element = ET.SubElement(self._settings_file, "energy_grid")
element.text = '{0}'.format(self._energy_grid)
def createPTablesSubelement(self):
def create_ptables_subelement(self):
if not self._ptables is None:
element = ET.SubElement(self._settings_file, "ptables")
element.text = '{0}'.format(str(self._ptables).lower())
def createRunCMFDSubelement(self):
def create_run_cmfd_subelement(self):
if not self._run_cmfd is None:
element = ET.SubElement(self._settings_file, "run_cmfd")
element.text = '{0}'.format(str(self._run_cmfd).lower())
def createSeedSubelement(self):
def create_seed_subelement(self):
if not self._seed is None:
element = ET.SubElement(self._settings_file, "seed")
element.text = '{0}'.format(self._seed)
def createSurvivalBiasingSubelement(self):
def create_survival_biasing_subelement(self):
if not self._survival_biasing is None:
element = ET.SubElement(self._settings_file, "survival_biasing")
element.text = '{0}'.format(str(self._survival_biasing).lower())
def createCutoffSubelement(self):
def create_cutoff_subelement(self):
if not self._weight is None:
element = ET.SubElement(self._settings_file, "cutoff")
@ -963,7 +963,7 @@ class SettingsFile(object):
subelement.text = '{0}'.format(self._weight_avg)
def createEntropySubelement(self):
def create_entropy_subelement(self):
if not self._entropy_lower_left is None and \
not self._entropy_upper_right is None:
@ -986,21 +986,21 @@ class SettingsFile(object):
self._entropy_upper_right[2])
def createNoReduceSubelement(self):
def create_no_reduce_subelement(self):
if not self._no_reduce is None:
element = ET.SubElement(self._settings_file, "no_reduce")
element.text = '{0}'.format(str(self._no_reduce).lower())
def createThreadsSubelement(self):
def create_threads_subelement(self):
if not self._threads is None:
element = ET.SubElement(self._settings_file, "threads")
element.text = '{0}'.format(self._threads)
def createTraceSubelement(self):
def create_trace_subelement(self):
if not self._trace is None:
element = ET.SubElement(self._settings_file, "trace")
@ -1011,7 +1011,7 @@ class SettingsFile(object):
element.text = text.rstrip(' ')
def createTrackSubelement(self):
def create_track_subelement(self):
if not self._track is None:
element = ET.SubElement(self._settings_file, "track")
@ -1022,7 +1022,7 @@ class SettingsFile(object):
element.text = text.rstrip(' ')
def createUFSSubelement(self):
def create_ufs_subelement(self):
if not self._ufs_lower_left is None and \
not self._ufs_upper_right is None:
@ -1043,28 +1043,28 @@ class SettingsFile(object):
self._ufs_upper_right[2])
def exportToXML(self):
def export_to_xml(self):
self.createEigenvalueSubelement()
self.createSourceSubelement()
self.createOutputSubelement()
self.createStatepointSubelement()
self.createSourcepointSubelement()
self.createConfidenceIntervalsSubelement()
self.createCrossSectionsSubelement()
self.createEnergyGridSubelement()
self.createPTablesSubelement()
self.createRunCMFDSubelement()
self.createSeedSubelement()
self.createSurvivalBiasingSubelement()
self.createCutoffSubelement()
self.createEntropySubelement()
self.createNoReduceSubelement()
self.createThreadsSubelement()
self.createVerbositySubelement()
self.createTraceSubelement()
self.createTrackSubelement()
self.createUFSSubelement()
self.create_eigenvalue_subelement()
self.create_source_subelement()
self.create_output_subelement()
self.create_statepoint_subelement()
self.create_sourcepoint_subelement()
self.create_confidence_intervals()
self.create_cross_sections_subelement()
self.create_energy_grid_subelement()
self.create_ptables_subelement()
self.create_run_cmfd_subelement()
self.create_seed_subelement()
self.create_survival_biasing_subelement()
self.create_cutoff_subelement()
self.create_entropy_subelement()
self.create_no_reduce_subelement()
self.create_threads_subelement()
self.create_verbosity_subelement()
self.create_trace_subelement()
self.create_track_subelement()
self.create_ufs_subelement()
# Clean the indentation in the file to be user-readable
clean_xml_indentation(self._settings_file)

View file

@ -33,12 +33,12 @@ class Surface(object):
# proper order
self._coeff_keys = list()
self.setId(surface_id)
self.setBoundaryType(bc_type)
self.setName(name)
self.set_id(surface_id)
self.set_boundary_type(bc_type)
self.set_name(name)
def setId(self, surface_id=None):
def set_id(self, surface_id=None):
if surface_id is None:
global AUTO_SURFACE_ID
@ -60,7 +60,7 @@ class Surface(object):
self._id = surface_id
def setName(self, name):
def set_name(self, name):
if not is_string(name):
msg = 'Unable to set name for Surface ID={0} with a non-string ' \
@ -71,7 +71,7 @@ class Surface(object):
self._name = name
def setBoundaryType(self, bc_type):
def set_boundary_type(self, bc_type):
if not is_string(bc_type):
msg = 'Unable to set boundary type for Surface ID={0} with a ' \
@ -106,7 +106,7 @@ class Surface(object):
return string
def createXMLSubElement(self):
def create_xml_subelement(self):
element = ET.Element("surface")
element.set("id", str(self._id))
@ -140,19 +140,19 @@ class Plane(Surface):
self._coeff_keys = ['A', 'B', 'C', 'D']
if not A is None:
self.setA(A)
self.set_A(A)
if not B is None:
self.setB(B)
self.set_B(B)
if not C is None:
self.setC(C)
self.set_C(C)
if not D is None:
self.setD(D)
self.set_D(D)
def setA(self, A):
def set_A(self, A):
if not is_integer(A) and not is_float(A):
msg = 'Unable to set A coefficient for Plane ID={0} to a ' \
@ -162,7 +162,7 @@ class Plane(Surface):
self._coeffs['A'] = A
def setB(self, B):
def set_B(self, B):
if not is_integer(B) and not is_float(B):
msg = 'Unable to set B coefficient for Plane ID={0} to a ' \
@ -172,7 +172,7 @@ class Plane(Surface):
self._coeffs['B'] = B
def setC(self, C):
def set_C(self, C):
if not is_integer(C) and not is_float(C):
msg = 'Unable to set C coefficient for Plane ID={0} to a ' \
@ -182,7 +182,7 @@ class Plane(Surface):
self._coeffs['C'] = C
def setD(self, D):
def set_D(self, D):
if not is_integer(D) and not is_float(D):
msg = 'Unable to set D coefficient for Plane ID={0} to a ' \
@ -206,10 +206,10 @@ class XPlane(Plane):
self._coeff_keys = ['x0']
if not x0 is None:
self.setX0(x0)
self.set_X0(x0)
def setX0(self, x0):
def set_X0(self, x0):
if not is_integer(x0) and not is_float(x0):
msg = 'Unable to set x0 coefficient for XPlane ID={0} to a ' \
@ -233,10 +233,10 @@ class YPlane(Plane):
self._coeff_keys = ['y0']
if not y0 is None:
self.setY0(y0)
self.set_Y0(y0)
def setY0(self, y0):
def set_Y0(self, y0):
if not is_integer(y0) and not is_float(y0):
msg = 'Unable to set y0 coefficient for XPlane ID={0} to a ' \
@ -260,10 +260,10 @@ class ZPlane(Plane):
self._coeff_keys = ['z0']
if not z0 is None:
self.setZ0(z0)
self.set_Z0(z0)
def setZ0(self, z0):
def set_Z0(self, z0):
if not is_integer(z0) and not is_float(z0):
msg = 'Unable to set z0 coefficient for ZPlane ID={0} to a ' \
@ -286,10 +286,10 @@ class Cylinder(Surface):
self._coeff_keys = ['R']
if not R is None:
self.setR(R)
self.set_R(R)
def setR(self, R):
def set_R(self, R):
if not is_integer(R) and not is_float(R):
msg = 'Unable to set R coefficient for Cylinder ID={0} to a ' \
@ -314,13 +314,13 @@ class XCylinder(Cylinder):
self._coeff_keys = ['y0', 'z0', 'R']
if not y0 is None:
self.setY0(y0)
self.set_Y0(y0)
if not z0 is None:
self.setZ0(z0)
self.set_Z0(z0)
def setY0(self, y0):
def set_Y0(self, y0):
if not is_integer(y0) and not is_float(y0):
msg = 'Unable to set y0 coefficient for XCylinder ID={0} to a ' \
@ -330,7 +330,7 @@ class XCylinder(Cylinder):
self._coeffs['y0'] = y0
def setZ0(self, z0):
def set_Z0(self, z0):
if not is_integer(z0) and not is_float(z0):
msg = 'Unable to set z0 coefficient for XCylinder ID={0} to a ' \
@ -355,13 +355,13 @@ class YCylinder(Cylinder):
self._coeff_keys = ['x0', 'z0', 'R']
if not x0 is None:
self.setX0(x0)
self.set_X0(x0)
if not z0 is None:
self.setZ0(z0)
self.set_Z0(z0)
def setX0(self, x0):
def set_X0(self, x0):
if not is_integer(x0) and not is_float(x0):
msg = 'Unable to set x0 coefficient for YCylinder ID={0} to a ' \
@ -371,7 +371,7 @@ class YCylinder(Cylinder):
self._coeffs['x0'] = x0
def setZ0(self, z0):
def set_Z0(self, z0):
if not is_integer(z0) and not is_float(z0):
msg = 'Unable to set z0 coefficient for YCylinder ID={0} to a ' \
@ -396,13 +396,13 @@ class ZCylinder(Cylinder):
self._coeff_keys = ['x0', 'y0', 'R']
if not x0 is None:
self.setX0(x0)
self.set_X0(x0)
if not y0 is None:
self.setY0(y0)
self.set_Y0(y0)
def setX0(self, x0):
def set_X0(self, x0):
if not is_integer(x0) and not is_float(x0):
msg = 'Unable to set x0 coefficient for ZCylinder ID={0} to a ' \
@ -412,7 +412,7 @@ class ZCylinder(Cylinder):
self._coeffs['x0'] = x0
def setY0(self, y0):
def set_Y0(self, y0):
if not is_integer(y0) and not is_float(y0):
msg = 'Unable to set y0 coefficient for ZCylinder ID={0} to a ' \
@ -439,19 +439,19 @@ class Sphere(Surface):
self._coeff_keys = ['x0', 'y0', 'z0', 'R']
if not x0 is None:
self.setX0(x0)
self.set_X0(x0)
if not y0 is None:
self.setY0(y0)
self.set_Y0(y0)
if not z0 is None:
self.setZ0(z0)
self.set_Z0(z0)
if not R is None:
self.setZ0(R)
self.set_Z0(R)
def setX0(self, x0):
def set_X0(self, x0):
if not is_integer(x0) and not is_float(x0):
msg = 'Unable to set x0 coefficient for Sphere ID={0} to a ' \
@ -461,7 +461,7 @@ class Sphere(Surface):
self._coeffs['x0'] = x0
def setY0(self, y0):
def set_Y0(self, y0):
if not is_integer(y0) and not is_float(y0):
msg = 'Unable to set y0 coefficient for Sphere ID={0} to a ' \
@ -471,7 +471,7 @@ class Sphere(Surface):
self._coeffs['y0'] = y0
def setZ0(self, z0):
def set_Z0(self, z0):
if not is_integer(z0) and not is_float(z0):
msg = 'Unable to set z0 coefficient for Sphere ID={0} to a ' \
@ -481,7 +481,7 @@ class Sphere(Surface):
self._coeffs['z0'] = z0
def setR(self, R):
def set_R(self, R):
if not is_integer(R) and not is_float(R):
msg = 'Unable to set R coefficient for Sphere ID={0} to a ' \
@ -507,19 +507,19 @@ class Cone(Surface):
self._coeff_keys = ['x0', 'y0', 'z0', 'R2']
if not x0 is None:
self.setX0(x0)
self.set_X0(x0)
if not y0 is None:
self.setY0(y0)
self.set_Y0(y0)
if not z0 is None:
self.setZ0(z0)
self.set_Z0(z0)
if not R2 is None:
self.setZ0(R2)
self.set_Z0(R2)
def setX0(self, x0):
def set_X0(self, x0):
if not is_integer(x0) and not is_float(x0):
msg = 'Unable to set x0 coefficient for Cone ID={0} to a ' \
@ -529,7 +529,7 @@ class Cone(Surface):
self._coeffs['x0'] = x0
def setY0(self, y0):
def set_Y0(self, y0):
if not is_integer(y0) and not is_float(y0):
msg = 'Unable to set y0 coefficient for Cone ID={0} to a ' \
@ -539,7 +539,7 @@ class Cone(Surface):
self._coeffs['y0'] = y0
def setZ0(self, z0):
def set_Z0(self, z0):
if not is_integer(z0) and not is_float(z0):
msg = 'Unable to set z0 coefficient for Cone ID={0} to a ' \
@ -549,7 +549,7 @@ class Cone(Surface):
self._coeffs['z0'] = z0
def setR2(self, R2):
def set_R2(self, R2):
if not is_integer(R2) and not is_float(R2):
msg = 'Unable to set R^2 coefficient for Cone ID={0} to a ' \

View file

@ -6,7 +6,7 @@ from openmc.checkvalue import *
from openmc.constants import *
from xml.etree import ElementTree as ET
import numpy as np
import os
import os, copy
# "Static" variables for auto-generated Tally and Mesh IDs
@ -39,10 +39,10 @@ class Filter(object):
self._num_bins = None
if not type is None:
self.setType(type)
self.set_type(type)
if not bins is None:
self.setBinEdges(bins)
self.set_bin_edges(bins)
def __eq__(self, filter2):
@ -66,7 +66,31 @@ class Filter(object):
return hash(tuple(hashable))
def setType(self, type):
def __deepcopy__(self, memo):
existing = memo.get(id(self))
# If this is the first time we have tried to copy this object, create a copy
if existing is None:
clone = type(self).__new__(type(self))
clone._type = self._type
clone._bins = copy.deepcopy(self._bins, memo)
clone._num_bins = self._num_bins
clone._mesh = copy.deepcopy(self._mesh, memo)
clone._offset = self._offset
clone._stride = self._stride
memo[id(self)] = clone
return clone
# If this object has been copied before, return the first copy made
else:
return existing
def set_type(self, type):
if not type in FILTER_TYPES.values():
msg = 'Unable to set Filter type to {0} since it is not one ' \
@ -76,7 +100,7 @@ class Filter(object):
self._type = type
def setBinEdges(self, bins):
def set_bin_edges(self, bins):
if self._type is None:
msg = 'Unable to set bin edges for Filter to {0} since ' \
@ -155,7 +179,7 @@ class Filter(object):
# FIXME
def setNumBins(self, num_bins):
def set_num_bins(self, num_bins):
if not is_integer(num_bins) or num_bins < 0:
msg = 'Unable to set the number of bins {0} for a {1} Filter ' \
@ -166,7 +190,7 @@ class Filter(object):
self._num_bins = num_bins
def setMesh(self, mesh):
def set_mesh(self, mesh):
if not isinstance(mesh, Mesh):
msg = 'Unable to set Mesh to {0} for Filter since it is not a ' \
@ -174,11 +198,11 @@ class Filter(object):
raise ValueError(msg)
self._mesh = mesh
self.setType('mesh')
self.setBinEdges(self._mesh._id)
self.set_type('mesh')
self.set_bin_edges(self._mesh._id)
def setOffset(self, offset):
def set_offset(self, offset):
if not is_integer(offset):
msg = 'Unable to set offset {0} for a {1} Filter since it is a ' \
@ -188,7 +212,7 @@ class Filter(object):
self._offset = offset
def setStride(self, stride):
def set_stride(self, stride):
if not is_integer(stride):
msg = 'Unable to set stride {0} for a {1} Filter since it is a ' \
@ -203,7 +227,7 @@ class Filter(object):
self._stride = stride
def getNumBins(self):
def get_num_bins(self):
# FIXME
#if self._type == 'mesh':
@ -218,7 +242,7 @@ class Filter(object):
return self._num_bins
def getBinIndex(self, bin):
def get_bin_index(self, bin):
try:
index = self._bins.index(bin)
@ -254,11 +278,36 @@ class Mesh(object):
self._upper_right = None
self._width = None
self.setId(mesh_id)
self.setName(name)
self.set_id(mesh_id)
self.set_name(name)
def setId(self, mesh_id=None):
def __deepcopy__(self, memo):
existing = memo.get(id(self))
# If this is the first time we have tried to copy this object, create a copy
if existing is None:
clone = type(self).__new__(type(self))
clone._id = self._id
clone._name = self._name
clone._type = self._type
clone._dimension = copy.deepcopy(self._dimension, memo)
clone._lower_left = copy.deepcopy(self._lower_left, memo)
clone._upper_right = copy.deepcopy(self._upper_right, memo)
clone._width = copy.deepcopy(self._width, memo)
memo[id(self)] = clone
return clone
# If this object has been copied before, return the first copy made
else:
return existing
def set_id(self, mesh_id=None):
if mesh_id is None:
global AUTO_MESH_ID
@ -279,7 +328,7 @@ class Mesh(object):
self._id = mesh_id
def setName(self, name):
def set_name(self, name):
if not is_string(name):
msg = 'Unable to set name for Mesh ID={0} with a non-string ' \
@ -290,7 +339,7 @@ class Mesh(object):
self._name = name
def setType(self, type):
def set_type(self, type):
if not is_string(type):
msg = 'Unable to set Mesh ID={0} for type {1} which is not ' \
@ -306,7 +355,7 @@ class Mesh(object):
self._type = type
def setDimension(self, dimension):
def set_dimension(self, dimension):
if not isinstance(dimension, (tuple, list, np.ndarray)):
msg = 'Unable to set Mesh ID={0} with dimension {1} which is ' \
@ -329,7 +378,7 @@ class Mesh(object):
self._dimension = dimension
def setLowerLeft(self, lower_left):
def set_lower_left(self, lower_left):
if not isinstance(lower_left, (tuple, list, np.ndarray)):
msg = 'Unable to set Mesh ID={0} with lower_left {1} which is ' \
@ -353,7 +402,7 @@ class Mesh(object):
self._lower_left = lower_left
def setUpperRight(self, upper_right):
def set_upper_right(self, upper_right):
if not isinstance(upper_right, (tuple, list, np.ndarray)):
msg = 'Unable to set Mesh ID={0} with upper_right {1} which ' \
@ -377,7 +426,7 @@ class Mesh(object):
self._upper_right = upper_right
def setWidth(self, width):
def set_width(self, width):
if not width is None:
@ -416,11 +465,11 @@ class Mesh(object):
return string
def getNumMeshCells(self):
def get_num_mesh_cells(self):
return np.prod(self._dimension)
def getMeshXML(self):
def get_mesh_xml(self):
element = ET.Element("mesh")
element.set("id", str(self._id))
@ -492,8 +541,47 @@ class Tally(object):
self._mean = None
self._std_dev = None
self.setId(tally_id)
self.setLabel(label)
self.set_id(tally_id)
self.set_label(label)
def __deepcopy__(self, memo):
existing = memo.get(id(self))
# If this is the first time we have tried to copy this object, create a copy
if existing is None:
clone = type(self).__new__(type(self))
clone._id = self._id
clone._label = self._label
clone._estimator = self._estimator
clone._num_score_bins = self._num_score_bins
clone._num_realizations = self._num_realizations
clone._sum = copy.deepcopy(self._sum, memo)
clone._sum_sq = copy.deepcopy(self._sum_sq, memo)
clone._mean = copy.deepcopy(self._mean, memo)
clone._std_dev = copy.deepcopy(self._std_dev, memo)
clone._filters = list()
for filter in self._filters:
clone.add_filter(copy.deepcopy(filter, memo))
clone._nuclides = list()
for nuclide in self._nuclides:
clone.add_nuclide(copy.deepcopy(nuclide, memo))
clone._scores = list()
for score in self._scores:
clone.add_score(score)
memo[id(self)] = clone
return clone
# If this object has been copied before, return the first copy made
else:
return existing
def __eq__(self, tally2):
@ -537,15 +625,6 @@ class Tally(object):
return hash(tuple(hashable))
def setEstimator(self, estimator):
if not estimator 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)
self._estimator = estimator
def __add__(self, other):
# FIXME: Error checking: must check that results has been
@ -556,7 +635,16 @@ class Tally(object):
new_tally._std_dev = np.sqrt(self._std_dev**2 + other._std_dev**2)
def setId(self, tally_id=None):
def set_estimator(self, estimator):
if not estimator 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)
self._estimator = estimator
def set_id(self, tally_id=None):
if tally_id is None:
global AUTO_TALLY_ID
@ -577,7 +665,7 @@ class Tally(object):
self._id = tally_id
def setLabel(self, label=None):
def set_label(self, label=None):
if not is_string(label):
msg = 'Unable to set name for Tally ID={0} with a non-string ' \
@ -588,7 +676,7 @@ class Tally(object):
self._label = label
def addFilter(self, filter):
def add_filter(self, filter):
global filters
@ -600,11 +688,11 @@ class Tally(object):
self._filters.append(filter)
def addNuclide(self, nuclide):
def add_nuclide(self, nuclide):
self._nuclides.append(nuclide)
def addScore(self, score):
def add_score(self, score):
if not is_string(score):
msg = 'Unable to add score {0} to Tally ID={1} since it is not a ' \
@ -636,11 +724,11 @@ class Tally(object):
self._scores.append(score)
def setNumScoreBins(self, num_score_bins):
def set_num_score_bins(self, num_score_bins):
self._num_score_bins = num_score_bins
def setNumRealizations(self, num_realizations):
def set_num_realizations(self, num_realizations):
if not is_integer(num_realizations):
msg = 'Unable to set the number of realizations to {0} for ' \
@ -657,7 +745,7 @@ class Tally(object):
self._num_realizations = num_realizations
def setResults(self, sum, sum_sq):
def set_results(self, sum, sum_sq):
if not isinstance(sum, (tuple, list, np.ndarray)):
msg = 'Unable to set the sum to {0}for Tally ID={1} since ' \
@ -675,7 +763,7 @@ class Tally(object):
self._sum_sq = sum_sq
def removeScore(self, score):
def remove_score(self, score):
if not score in self._scores:
msg = 'Unable to remove score {0} from Tally ID={1} since the ' \
@ -685,7 +773,7 @@ class Tally(object):
self._scores.remove(score)
def removeFilter(self, filter):
def remove_filter(self, filter):
if not filter in self._filters:
msg = 'Unable to remove filter {0} from Tally ID={1} since the ' \
@ -695,7 +783,7 @@ class Tally(object):
self._filters.remove(filter)
def removeNuclide(self, nuclide):
def remove_nuclide(self, nuclide):
if not nuclide in self._nuclides:
msg = 'Unable to remove nuclide {0} from Tally ID={1} since the ' \
@ -705,7 +793,7 @@ class Tally(object):
self._nuclides.remove(nuclide)
def computeStdDev(self, t_value=1.0):
def compute_std_dev(self, t_value=1.0):
# Calculate sample mean and standard deviation
self._mean = self._sum / self._num_realizations
@ -739,40 +827,40 @@ class Tally(object):
return string
def getNumFilters(self):
def get_num_filters(self):
return len(self._filters)
def getNumFilterBins(self):
def get_num_filter_bins(self):
num_bins = 1
for filter in self._filters:
num_bins *= filter.getNumBins()
num_bins *= filter.get_num_bins()
return num_bins
def getNumNuclides(self):
def get_num_nuclides(self):
return len(self._nuclides)
def getNumScores(self):
def get_num_scores(self):
return len(self._scores)
def getNumScoreBins(self):
def get_num_score_bins(self):
return self._num_score_bins
def getNumBins(self):
num_bins = self.getNumFilterBins()
num_bins *= self.getNumNuclides()
num_bins *= self.getNumScoreBins()
def get_num_bins(self):
num_bins = self.get_num_filter_bins()
num_bins *= self.get_num_nuclides()
num_bins *= self.get_num_score_bins()
return num_bins
def getTallyXML(self):
def get_tally_xml(self):
element = ET.Element("tally")
@ -830,7 +918,7 @@ class Tally(object):
return element
def findFilter(self, filter_type, bins):
def find_filter(self, filter_type, bins):
filter = None
@ -859,7 +947,7 @@ class Tally(object):
raise ValueError(msg)
def getScoreIndex(self, score):
def get_score_index(self, score):
try:
index = self._scores.index(score)
@ -872,7 +960,7 @@ class Tally(object):
return index
def getValue(self, score, filters, filter_bins, nuclide=None, value='mean'):
def get_value(self, score, filters, filter_bins, nuclide=None, value='mean'):
"""Returns a tally score value given a list of filters to satisfy.
Parameters
@ -914,7 +1002,7 @@ class Tally(object):
for i, filter in enumerate(filters):
# Find the equivalent Filter in this Tally's list of Filters
test_filter = self.findFilter(filter._type, filter._bins)
test_filter = self.find_filter(filter._type, filter._bins)
# Filter bins for a mesh are an (x,y,z) tuple
if filter._type == 'mesh':
@ -937,7 +1025,7 @@ class Tally(object):
else:
bin = filter_bins[i]
bin_index = test_filter.getBinIndex(bin)
bin_index = test_filter.get_bin_index(bin)
filter_index += bin_index * test_filter._stride
# Return the desired result from Tally
@ -956,7 +1044,7 @@ class Tally(object):
raise LookupError(msg)
def exportResults(self, filename='tally-results', directory='.',
def export_results(self, filename='tally-results', directory='.',
format='hdf5', append=True):
"""Returns a tally score value given a list of filters to satisfy.
@ -1107,7 +1195,7 @@ class TalliesFile(object):
self._tallies_file = ET.Element("tallies")
def addTally(self, tally):
def add_tally(self, tally):
if not isinstance(tally, Tally):
msg = 'Unable to add a non-Tally {0} to the TalliesFile'.format(tally)
@ -1116,11 +1204,11 @@ class TalliesFile(object):
self._tallies.append(tally)
def removeTally(self, tally):
def remove_tally(self, tally):
self._tallies.remove(tally)
def addMesh(self, mesh):
def add_mesh(self, mesh):
if not isinstance(mesh, Mesh):
msg = 'Unable to add a non-Mesh {0} to the TalliesFile'.format(mesh)
@ -1129,32 +1217,32 @@ class TalliesFile(object):
self._meshes.append(mesh)
def removeMesh(self, mesh):
def remove_mesh(self, mesh):
self._meshes.remove(mesh)
def createTallySubelements(self):
def create_tally_subelements(self):
for tally in self._tallies:
xml_element = tally.getTallyXML()
xml_element = tally.get_tally_xml()
self._tallies_file.append(xml_element)
def createMeshSubelements(self):
def create_mesh_subelements(self):
for mesh in self._meshes:
if len(mesh._name) > 0:
self._tallies_file.append(ET.Comment(mesh._name))
xml_element = mesh.getMeshXML()
xml_element = mesh.get_mesh_xml()
self._tallies_file.append(xml_element)
def exportToXML(self):
def export_to_xml(self):
self.createMeshSubelements()
self.createTallySubelements()
self.create_mesh_subelements()
self.create_tally_subelements()
# Clean the indentation in the file to be user-readable
clean_xml_indentation(self._tallies_file)

View file

@ -33,11 +33,11 @@ class Cell(object):
self._translation = None
self._offset = None
self.setId(cell_id)
self.setName(name)
self.set_id(cell_id)
self.set_name(name)
def getOffset(self, path, filter_offset):
def get_offset(self, path, filter_offset):
# Get the current element and remove it from the list
cell_id = path[0]
@ -50,22 +50,22 @@ class Cell(object):
# If the Cell is filled by a Universe
elif self._type == 'fill':
offset = self._offset[filter_offset-1]
offset += self._fill.getOffset(path, filter_offset)
offset += self._fill.get_offset(path, filter_offset)
# If the Cell is filled by a Lattice
else:
offset = self._fill.getOffset(path, filter_offset)
offset = self._fill.get_offset(path, filter_offset)
return offset
# Make a recursive call to the Universe filling this Cell
offset = self._cells[cell_id].getOffset(path, filter_offset)
offset = self._cells[cell_id].get_offset(path, filter_offset)
# Return the offset computed at all nested Universe levels
return offset
def setId(self, cell_id=None):
def set_id(self, cell_id=None):
if cell_id is None:
global AUTO_CELL_ID
@ -86,7 +86,7 @@ class Cell(object):
self._id = cell_id
def setName(self, name):
def set_name(self, name):
if not isinstance(name, str):
msg = 'Unable to set name for Cell ID={0} with a non-string ' \
@ -97,7 +97,7 @@ class Cell(object):
self._name = name
def setFill(self, fill):
def set_fill(self, fill):
if not isinstance(fill, (openmc.Material, Universe, Lattice)) \
and fill != 'void':
@ -117,7 +117,7 @@ class Cell(object):
self._type = 'normal'
def addSurface(self, surface, halfspace):
def add_surface(self, surface, halfspace):
if not isinstance(surface, openmc.Surface):
msg = 'Unable to add Surface {0} to Cell ID={1} since it is ' \
@ -134,7 +134,7 @@ class Cell(object):
self._surfaces[surface._id] = (surface, halfspace)
def removeSurface(self, surface):
def remove_surface(self, surface):
if not isinstance(surface, openmc.Surface):
msg = 'Unable to remove Surface {0} from Cell ID={1} since it is ' \
@ -146,7 +146,7 @@ class Cell(object):
del self._surfaces[surface._id]
def setSurfaces(self, surfaces, halfspaces):
def set_surfaces(self, surfaces, halfspaces):
if not isinstance(surfaces, (tuple, list, np.ndarray)):
msg = 'Unable to set Cell ID={0} with Surfaces {1} since ' \
@ -161,10 +161,10 @@ class Cell(object):
raise ValueError(msg)
for surface in surfaces:
self.addSurface(surface)
self.add_surface(surface)
def setRotation(self, rotation):
def set_rotation(self, rotation):
if not isinstance(rotation, (tuple, list, np.ndarray)):
msg = 'Unable to add rotation {0} to Cell ID={1} since ' \
@ -188,7 +188,7 @@ class Cell(object):
self._rotation = rotation
def setTranslation(self, translation):
def set_translation(self, translation):
if not isinstance(translation, (tuple, list, np.ndarray)):
msg = 'Unable to add translation {0} to Cell ID={1} since ' \
@ -210,7 +210,7 @@ class Cell(object):
self._translation = translation
def setOffset(self, offset):
def set_offset(self, offset):
if not isinstance(offset, (tuple, list, np.ndarray)):
msg = 'Unable to set offset {0} to Cell ID={1} since ' \
@ -221,35 +221,35 @@ class Cell(object):
self._offset = offset
def getAllNuclides(self):
def get_all_nuclides(self):
nuclides = dict()
if self._type != 'void':
nuclides.update(self._fill.getAllNuclides())
nuclides.update(self._fill.get_all_nuclides())
return nuclides
def getAllCells(self):
def get_all_cells(self):
cells = dict()
if self._type == 'fill' or self._type == 'lattice':
cells.update(self._fill.getAllCells())
cells.update(self._fill.get_all_cells())
return cells
def getAllUniverses(self):
def get_all_universes(self):
universes = dict()
if self._type == 'fill':
universes[self._fill._id] = self._fill
universes.update(self._fill.getAllUniverses())
universes.update(self._fill.get_all_universes())
elif self._type == 'lattice':
universes.update(self._fill.getAllUniverses())
universes.update(self._fill.get_all_universes())
return universes
@ -286,7 +286,7 @@ class Cell(object):
return string
def createXMLSubElement(self, xml_element):
def create_xml_subelement(self, xml_element):
element = ET.Element("cell")
element.set("id", str(self._id))
@ -296,11 +296,11 @@ class Cell(object):
elif isinstance(self._fill, (Universe, Lattice)):
element.set("fill", str(self._fill._id))
self._fill.createXMLSubElement(xml_element)
self._fill.create_xml_subelement(xml_element)
else:
element.set("fill", str(self._fill))
self._fill.createXMLSubElement(xml_element)
self._fill.create_xml_subelement(xml_element)
if not self._surfaces is None:
@ -318,7 +318,7 @@ class Cell(object):
# Create the XML subelement for this Surface
surface = self._surfaces[surface_id][0]
surface_subelement = surface.createXMLSubElement()
surface_subelement = surface.create_xml_subelement()
if len(surface._name) > 0:
xml_element.append(ET.Comment(surface._name))
@ -384,11 +384,11 @@ class Universe(object):
self._cell_offsets = OrderedDict()
self._num_regions = 0
self.setId(universe_id)
self.setName(name)
self.set_id(universe_id)
self.set_name(name)
def setId(self, universe_id=None):
def set_id(self, universe_id=None):
if universe_id is None:
global AUTO_UNIVERSE_ID
@ -410,7 +410,7 @@ class Universe(object):
self._id = universe_id
def setName(self, name):
def set_name(self, name):
if not is_string(name):
msg = 'Unable to set name for Universe ID={0} with a non-string ' \
@ -421,7 +421,7 @@ class Universe(object):
self._name = name
def addCell(self, cell):
def add_cell(self, cell):
if not isinstance(cell, Cell):
msg = 'Unable to add a Cell to Universe ID={0} since {1} is not ' \
@ -434,7 +434,7 @@ class Universe(object):
self._cells[cell_id] = cell
def addCells(self, cells):
def add_cells(self, cells):
if not isinstance(cells, (list, tuple, np.ndarray)):
msg = 'Unable to add Cells to Universe ID={0} since {1} is not a ' \
@ -442,10 +442,10 @@ class Universe(object):
raise ValueError(msg)
for i in range(len(cells)):
self.addCell(cells[i])
self.add_cell(cells[i])
def removeCell(self, cell):
def remove_cell(self, cell):
if not isinstance(cell, Cell):
msg = 'Unable to remove a Cell from Universe ID={0} since {1} is ' \
@ -459,11 +459,11 @@ class Universe(object):
del self._cells[cell_id]
def clearCells(self):
def clear_cells(self):
self._cells.clear()
def getOffset(self, path, filter_offset):
def get_offset(self, path, filter_offset):
# Get the current element and remove it from the list
path = path[1:]
@ -472,24 +472,24 @@ class Universe(object):
cell_id = path[0]
# Make a recursive call to the Cell within this Universe
offset = self._cells[cell_id].getOffset(path, filter_offset)
offset = self._cells[cell_id].get_offset(path, filter_offset)
# Return the offset computed at all nested Universe levels
return offset
def getAllNuclides(self):
def get_all_nuclides(self):
nuclides = dict()
# Append all Nuclides in each Cell in the Universe to the dictionary
for cell_id, cell in self._cells.items():
nuclides.update(cell.getAllNuclides())
nuclides.update(cell.get_all_nuclides())
return nuclides
def getAllCells(self):
def get_all_cells(self):
cells = dict()
@ -498,21 +498,21 @@ class Universe(object):
# Append all Cells in each Cell in the Universe to the dictionary
for cell_id, cell in self._cells.items():
cells.update(cell.getAllCells())
cells.update(cell.get_all_cells())
return cells
def getAllUniverses(self):
def get_all_universes(self):
# Get all Cells in this Universe
cells = self.getAllCells()
cells = self.get_all_cells()
universes = dict()
# Append all Universes containing each Cell to the dictionary
for cell_id, cell in cells.items():
universes.update(cell.getAllUniverses())
universes.update(cell.get_all_universes())
return universes
@ -529,7 +529,7 @@ class Universe(object):
return string
def createXMLSubElement(self, xml_element):
def create_xml_subelement(self, xml_element):
# Iterate over all Cells
for cell_id, cell in self._cells.items():
@ -542,7 +542,7 @@ class Universe(object):
if test is None:
# Create XML subelement for this Cell
cell_subelement = cell.createXMLSubElement(xml_element)
cell_subelement = cell.create_xml_subelement(xml_element)
# Append the Universe ID to the subelement and add to Element
cell_subelement.set("universe", str(self._id))
@ -575,12 +575,12 @@ class Lattice(object):
self._offsets = None
self.setId(lattice_id)
self.setName(name)
self.setType(type)
self.set_id(lattice_id)
self.set_name(name)
self.set_type(type)
def setId(self, lattice_id=None):
def set_id(self, lattice_id=None):
if lattice_id is None:
global AUTO_UNIVERSE_ID
@ -601,7 +601,7 @@ class Lattice(object):
self._id = lattice_id
def setName(self, name):
def set_name(self, name):
if not is_string(name):
msg = 'Unable to set name for Lattice ID={0} with a non-string ' \
@ -612,7 +612,7 @@ class Lattice(object):
self._name = name
def setType(self, type):
def set_type(self, type):
if not is_string(type):
msg = 'Unable to set type for Lattice ID={0} with a non-string ' \
@ -627,7 +627,7 @@ class Lattice(object):
self._type = type
def setDimension(self, dimension):
def set_dimension(self, dimension):
if not isinstance(dimension, (tuple, list, np.ndarray)):
msg = 'Unable to set Lattice ID={0} dimension to {1} since ' \
@ -658,7 +658,7 @@ class Lattice(object):
self._dimension = dimension
def setLowerLeft(self, lower_left):
def set_lower_left(self, lower_left):
if not isinstance(lower_left, (tuple, list, np.ndarray)):
msg = 'Unable to set Lattice ID={0} lower_left to {1} since ' \
@ -684,7 +684,7 @@ class Lattice(object):
self._lower_left = lower_left
def setWidth(self, width):
def set_width(self, width):
if not isinstance(width, (tuple, list, np.ndarray)):
msg = 'Unable to set Lattice ID={0} width to {1} since ' \
@ -714,7 +714,7 @@ class Lattice(object):
self._width = width
def setOutside(self, outside):
def set_outside(self, outside):
if not isinstance(outside, Universe):
msg = 'Unable to set Lattice ID={0} outside universe to {1} ' \
@ -724,7 +724,7 @@ class Lattice(object):
self._outside = outside
def setUniverses(self, universes):
def set_universes(self, universes):
if not isinstance(universes, (tuple, list, np.ndarray)):
msg = 'Unable to set Lattice ID={0} universes to {1} since ' \
@ -735,7 +735,7 @@ class Lattice(object):
self._universes = np.asarray(universes, dtype=Universe)
def setOffsets(self, offsets):
def set_offsets(self, offsets):
if not isinstance(offsets, (tuple, list, np.ndarray)):
msg = 'Unable to set Lattice ID={0} offsets to {1} since ' \
@ -746,7 +746,7 @@ class Lattice(object):
self._offsets = offsets
def getOffset(self, path, filter_offset):
def get_offset(self, path, filter_offset):
# Get the current element and remove it from the list
i = path[0]
@ -755,18 +755,18 @@ class Lattice(object):
# For 2D Lattices
if len(self._dimension) == 2:
offset = self._offsets[i[1]-1, i[2]-1, 0, filter_offset-1]
offset += self._universes[i[1]][i[2]].getOffset(path, filter_offset)
offset += self._universes[i[1]][i[2]].get_offset(path, filter_offset)
# For 3D Lattices
else:
offset = self._offsets[i[1]-1, i[2]-1, i[3]-1, filter_offset-1]
offset += self._universes[i[1]-1][i[2]-1][i[3]-1].getOffset(path,
offset += self._universes[i[1]-1][i[2]-1][i[3]-1].get_offset(path,
filter_offset)
return offset
def getUniqueUniverses(self):
def get_unique_universes(self):
unique_universes = np.unique(self._universes.ravel())
universes = dict()
@ -777,46 +777,46 @@ class Lattice(object):
return universes
def getAllNuclides(self):
def get_all_nuclides(self):
nuclides = dict()
# Get all unique Universes contained in each of the lattice cells
unique_universes = self.getUniqueUniverses()
unique_universes = self.get_unique_universes()
# Append all Universes containing each cell to the dictionary
for universe_id, universe in unique_universes.items():
nuclides.update(universe.getAllNuclides())
nuclides.update(universe.get_all_nuclides())
return nuclides
def getAllCells(self):
def get_all_cells(self):
cells = dict()
unique_universes = self.getUniqueUniverses()
unique_universes = self.get_unique_universes()
for universe_id, universe in unique_universes.items():
cells.update(universe.getAllCells())
cells.update(universe.get_all_cells())
return cells
def getAllUniverses(self):
def get_all_universes(self):
# Initialize a dictionary of all Universes contained by the Lattice
# in each nested Universe level
all_universes = dict()
# Get all unique Universes contained in each of the lattice cells
unique_universes = self.getUniqueUniverses()
unique_universes = self.get_unique_universes()
# Add the unique Universes filling each Lattice cell
all_universes.update(unique_universes)
# Append all Universes containing each cell to the dictionary
for universe_id, universe in unique_universes.items():
all_universes.update(universe.getAllUniverses())
all_universes.update(universe.get_all_universes())
return all_universes
@ -869,7 +869,7 @@ class Lattice(object):
return string
def createXMLSubElement(self, xml_element):
def create_xml_subelement(self, xml_element):
# Determine if XML element already contains subelement for this Lattice
path = './lattice[@id=\'{0}\']'.format(self._id)
@ -936,7 +936,7 @@ class Lattice(object):
universe_ids += '{0} '.format(universe._id)
# Create XML subelement for this Universe
universe.createXMLSubElement(xml_element)
universe.create_xml_subelement(xml_element)
# Add newline character when we reach end of row of cells
universe_ids += '\n'
@ -955,7 +955,7 @@ class Lattice(object):
universe_ids += '{0} '.format(universe._id)
# Create XML subelement for this Universe
universe.createXMLSubElement(xml_element)
universe.create_xml_subelement(xml_element)
# Add newline character when we reach end of row of cells
universe_ids += '\n'