mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Made all 2 space tabs in Python API 4 spaces to meet PEP8 standards
This commit is contained in:
parent
2081e29771
commit
40ad679644
14 changed files with 3950 additions and 3854 deletions
|
|
@ -11,4 +11,4 @@ from openmc.surface import *
|
|||
from openmc.universe import *
|
||||
from openmc.tallies import *
|
||||
from openmc.executor import *
|
||||
from statepoint import *
|
||||
#from statepoint import *
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import numpy as np
|
|||
|
||||
|
||||
def is_integer(val):
|
||||
return isinstance(val, (int, np.int32, np.int64))
|
||||
return isinstance(val, (int, np.int32, np.int64))
|
||||
|
||||
|
||||
def is_float(val):
|
||||
return isinstance(val, (float, np.float32, np.float64))
|
||||
return isinstance(val, (float, np.float32, np.float64))
|
||||
|
||||
|
||||
def is_string(val):
|
||||
return isinstance(val, (str, np.str))
|
||||
return isinstance(val, (str, np.str))
|
||||
|
||||
|
|
|
|||
|
|
@ -2,94 +2,94 @@
|
|||
|
||||
def sort_xml_elements(tree):
|
||||
|
||||
# Retrieve all children of the root XML node in the tree
|
||||
elements = tree.getchildren()
|
||||
# Retrieve all children of the root XML node in the tree
|
||||
elements = tree.getchildren()
|
||||
|
||||
# Initialize empty lists for the sorted and comment elements
|
||||
sorted_elements = list()
|
||||
# Initialize empty lists for the sorted and comment elements
|
||||
sorted_elements = list()
|
||||
|
||||
# Initialize an empty set of tags (e.g., Surface, Cell, and Lattice)
|
||||
tags = set()
|
||||
# Initialize an empty set of tags (e.g., Surface, Cell, and Lattice)
|
||||
tags = set()
|
||||
|
||||
# Find the unique tags in the tree
|
||||
for element in elements:
|
||||
tags.add(element.tag)
|
||||
# Find the unique tags in the tree
|
||||
for element in elements:
|
||||
tags.add(element.tag)
|
||||
|
||||
# Initialize an empty list for the comment elements
|
||||
comment_elements = list()
|
||||
# Initialize an empty list for the comment elements
|
||||
comment_elements = list()
|
||||
|
||||
# Find the comment elements and record their ordering within the
|
||||
# tree using a precedence with respect to the subsequent nodes
|
||||
for index, element in enumerate(elements):
|
||||
next_element = None
|
||||
# Find the comment elements and record their ordering within the
|
||||
# tree using a precedence with respect to the subsequent nodes
|
||||
for index, element in enumerate(elements):
|
||||
next_element = None
|
||||
|
||||
if 'Comment' in str(element.tag):
|
||||
if 'Comment' in str(element.tag):
|
||||
|
||||
if index < len(elements)-1:
|
||||
next_element = elements[index+1]
|
||||
if index < len(elements)-1:
|
||||
next_element = elements[index+1]
|
||||
|
||||
comment_elements.append((element, next_element))
|
||||
comment_elements.append((element, next_element))
|
||||
|
||||
# Now iterate over all tags and order the elements within each tag
|
||||
for tag in tags:
|
||||
# Now iterate over all tags and order the elements within each tag
|
||||
for tag in tags:
|
||||
|
||||
# Retrieve all of the elements for this tag
|
||||
try:
|
||||
tagged_elements = tree.findall(tag)
|
||||
except:
|
||||
continue
|
||||
# Retrieve all of the elements for this tag
|
||||
try:
|
||||
tagged_elements = tree.findall(tag)
|
||||
except:
|
||||
continue
|
||||
|
||||
# Initialize an empty list of tuples to sort (id, element)
|
||||
tagged_data = list()
|
||||
# Initialize an empty list of tuples to sort (id, element)
|
||||
tagged_data = list()
|
||||
|
||||
# Retrieve the IDs for each of the elements
|
||||
for element in tagged_elements:
|
||||
key = element.get('id')
|
||||
# Retrieve the IDs for each of the elements
|
||||
for element in tagged_elements:
|
||||
key = element.get('id')
|
||||
|
||||
# If this element has an "ID" tag, append it to the list to sort
|
||||
if not key is None:
|
||||
tagged_data.append((key, element))
|
||||
# If this element has an "ID" tag, append it to the list to sort
|
||||
if not key is None:
|
||||
tagged_data.append((key, element))
|
||||
|
||||
# Sort the elements according to the IDs for this tag
|
||||
tagged_data.sort()
|
||||
sorted_elements.extend(list(item[-1] for item in tagged_data))
|
||||
# Sort the elements according to the IDs for this tag
|
||||
tagged_data.sort()
|
||||
sorted_elements.extend(list(item[-1] for item in tagged_data))
|
||||
|
||||
# Add the comment elements while preserving the original precedence
|
||||
for element, next_element in comment_elements:
|
||||
index = sorted_elements.index(next_element)
|
||||
sorted_elements.insert(index, element)
|
||||
# Add the comment elements while preserving the original precedence
|
||||
for element, next_element in comment_elements:
|
||||
index = sorted_elements.index(next_element)
|
||||
sorted_elements.insert(index, element)
|
||||
|
||||
# Remove all of the sorted elements from the tree
|
||||
for element in sorted_elements:
|
||||
tree.remove(element)
|
||||
# Remove all of the sorted elements from the tree
|
||||
for element in sorted_elements:
|
||||
tree.remove(element)
|
||||
|
||||
# Add the sorted elements back to the tree in the proper order
|
||||
tree.extend(sorted_elements)
|
||||
# Add the sorted elements back to the tree in the proper order
|
||||
tree.extend(sorted_elements)
|
||||
|
||||
|
||||
def clean_xml_indentation(element, level=0):
|
||||
'''
|
||||
copy and paste from http://effbot.org/zone/elementent-lib.htm#prettyprint
|
||||
it basically walks your tree and adds spaces and newlines so the tree is
|
||||
printed in a nice way
|
||||
'''
|
||||
'''
|
||||
copy and paste from http://effbot.org/zone/elementent-lib.htm#prettyprint
|
||||
it basically walks your tree and adds spaces and newlines so the tree is
|
||||
printed in a nice way
|
||||
'''
|
||||
|
||||
i = "\n" + level*" "
|
||||
i = "\n" + level*" "
|
||||
|
||||
if len(element):
|
||||
if len(element):
|
||||
|
||||
if not element.text or not element.text.strip():
|
||||
element.text = i + " "
|
||||
if not element.text or not element.text.strip():
|
||||
element.text = i + " "
|
||||
|
||||
if not element.tail or not element.tail.strip():
|
||||
element.tail = i
|
||||
if not element.tail or not element.tail.strip():
|
||||
element.tail = i
|
||||
|
||||
for element in element:
|
||||
clean_xml_indentation(element, level+1)
|
||||
for element in element:
|
||||
clean_xml_indentation(element, level+1)
|
||||
|
||||
if not element.tail or not element.tail.strip():
|
||||
element.tail = i
|
||||
if not element.tail or not element.tail.strip():
|
||||
element.tail = i
|
||||
|
||||
else:
|
||||
if level and (not element.tail or not element.tail.strip()):
|
||||
element.tail = i
|
||||
else:
|
||||
if level and (not element.tail or not element.tail.strip()):
|
||||
element.tail = i
|
||||
|
|
@ -4,66 +4,66 @@ from openmc.checkvalue import *
|
|||
|
||||
class Element(object):
|
||||
|
||||
def __init__(self, name='', xs=None):
|
||||
def __init__(self, name='', xs=None):
|
||||
|
||||
# Initialize class attributes
|
||||
self._name = ''
|
||||
self._xs = None
|
||||
# Initialize class attributes
|
||||
self._name = ''
|
||||
self._xs = None
|
||||
|
||||
# Set the Material class attributes
|
||||
self.setName(name)
|
||||
# Set the Material class attributes
|
||||
self.setName(name)
|
||||
|
||||
if not xs is None:
|
||||
self.setXS(xs)
|
||||
if not xs is None:
|
||||
self.setXS(xs)
|
||||
|
||||
|
||||
def __eq__(self, element2):
|
||||
def __eq__(self, element2):
|
||||
|
||||
# check type
|
||||
if not isinstance(element2, Element):
|
||||
return False
|
||||
# check type
|
||||
if not isinstance(element2, Element):
|
||||
return False
|
||||
|
||||
# Check name
|
||||
if self._name != element2._name:
|
||||
return False
|
||||
# Check name
|
||||
if self._name != element2._name:
|
||||
return False
|
||||
|
||||
# Check xs
|
||||
elif self._xs != element2._xs:
|
||||
return False
|
||||
# Check xs
|
||||
elif self._xs != element2._xs:
|
||||
return False
|
||||
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def __hash__(self):
|
||||
hashable = list()
|
||||
hashable.append(self._name)
|
||||
hashable.append(self._xs)
|
||||
return hash(tuple(hashable))
|
||||
def __hash__(self):
|
||||
hashable = list()
|
||||
hashable.append(self._name)
|
||||
hashable.append(self._xs)
|
||||
return hash(tuple(hashable))
|
||||
|
||||
|
||||
def setName(self, name):
|
||||
def setName(self, name):
|
||||
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Element with a non-string ' \
|
||||
'value {0}'.format(name)
|
||||
raise ValueError(msg)
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Element with a non-string ' \
|
||||
'value {0}'.format(name)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._name = name
|
||||
self._name = name
|
||||
|
||||
|
||||
def setXS(self, xs):
|
||||
def setXS(self, xs):
|
||||
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set cross-section identifier xs for Element with ' \
|
||||
'a non-string value {0}'.format(xs)
|
||||
raise ValueError(msg)
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set cross-section identifier xs for Element ' \
|
||||
'with a non-string value {0}'.format(xs)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._xs = xs
|
||||
self._xs = xs
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self):
|
||||
|
||||
string = 'Element - {0}\n'.format(self._name)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tXS', '=\t', self._xs)
|
||||
return string
|
||||
string = 'Element - {0}\n'.format(self._name)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tXS', '=\t', self._xs)
|
||||
return string
|
||||
|
|
|
|||
|
|
@ -11,64 +11,64 @@ FNULL = open(os.devnull, 'w')
|
|||
class Executor(object):
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self._working_directory = '.'
|
||||
def __init__(self):
|
||||
self._working_directory = '.'
|
||||
|
||||
|
||||
def setWorkingDirectory(self, working_directory):
|
||||
def setWorkingDirectory(self, working_directory):
|
||||
|
||||
if not is_string(working_directory):
|
||||
msg = 'Unable to set Executor\'s working directory to {0} ' \
|
||||
'since it is not a string'.format(working_directory)
|
||||
raise ValueError(msg)
|
||||
if not is_string(working_directory):
|
||||
msg = 'Unable to set Executor\'s working directory to {0} ' \
|
||||
'since it is not a string'.format(working_directory)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not os.path.isdir(working_directory):
|
||||
msg = 'Unable to set Executor\'s working directory to {0} ' \
|
||||
'which does not exist'.format(working_directory)
|
||||
raise ValueError(msg)
|
||||
elif not os.path.isdir(working_directory):
|
||||
msg = 'Unable to set Executor\'s working directory to {0} ' \
|
||||
'which does not exist'.format(working_directory)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._working_directory = working_directory
|
||||
self._working_directory = working_directory
|
||||
|
||||
|
||||
def plotGeometry(self, output=True):
|
||||
def plotGeometry(self, output=True):
|
||||
|
||||
if output:
|
||||
subprocess.check_call('openmc -p', shell=True,
|
||||
cwd=self._working_directory)
|
||||
else:
|
||||
subprocess.check_call('openmc -p', shell=True, stdout=FNULL,
|
||||
cwd=self._working_directory)
|
||||
if output:
|
||||
subprocess.check_call('openmc -p', shell=True,
|
||||
cwd=self._working_directory)
|
||||
else:
|
||||
subprocess.check_call('openmc -p', shell=True, stdout=FNULL,
|
||||
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 runSimulation(self, particles=None, threads=None, geometry_debug=False,
|
||||
restart_file=None, tracks=False, mpi_procs=1, output=True):
|
||||
|
||||
post_args = ' '
|
||||
pre_args = ''
|
||||
post_args = ' '
|
||||
pre_args = ''
|
||||
|
||||
if is_integer(particles) and particles > 0:
|
||||
post_args += '-n {0} '.format(particles)
|
||||
if is_integer(particles) and particles > 0:
|
||||
post_args += '-n {0} '.format(particles)
|
||||
|
||||
if is_integer(threads) and threads > 0:
|
||||
post_args += '-s {0} '.format(threads)
|
||||
if is_integer(threads) and threads > 0:
|
||||
post_args += '-s {0} '.format(threads)
|
||||
|
||||
if geometry_debug:
|
||||
post_args += '-g '
|
||||
if geometry_debug:
|
||||
post_args += '-g '
|
||||
|
||||
if is_string(restart_file):
|
||||
post_args += '-r {0} '.format(restart_file)
|
||||
if is_string(restart_file):
|
||||
post_args += '-r {0} '.format(restart_file)
|
||||
|
||||
if tracks:
|
||||
post_args += '-t'
|
||||
if tracks:
|
||||
post_args += '-t'
|
||||
|
||||
if is_integer(mpi_procs) and mpi_procs > 1:
|
||||
pre_args += 'mpirun -n {0} '.format(mpi_procs)
|
||||
if is_integer(mpi_procs) and mpi_procs > 1:
|
||||
pre_args += 'mpirun -n {0} '.format(mpi_procs)
|
||||
|
||||
command = pre_args + 'openmc ' + post_args
|
||||
command = pre_args + 'openmc ' + post_args
|
||||
|
||||
if output:
|
||||
subprocess.check_call(command, shell=True,
|
||||
cwd=self._working_directory)
|
||||
else:
|
||||
subprocess.check_call(command, shell=True, stdout=FNULL,
|
||||
cwd=self._working_directory)
|
||||
if output:
|
||||
subprocess.check_call(command, shell=True,
|
||||
cwd=self._working_directory)
|
||||
else:
|
||||
subprocess.check_call(command, shell=True, stdout=FNULL,
|
||||
cwd=self._working_directory)
|
||||
|
|
@ -5,156 +5,158 @@ from openmc.clean_xml import *
|
|||
from xml.etree import ElementTree as ET
|
||||
|
||||
def reset_auto_ids():
|
||||
openmc.reset_auto_material_id()
|
||||
openmc.reset_auto_surface_id()
|
||||
openmc.reset_auto_cell_id()
|
||||
openmc.reset_auto_universe_id()
|
||||
openmc.reset_auto_material_id()
|
||||
openmc.reset_auto_surface_id()
|
||||
openmc.reset_auto_cell_id()
|
||||
openmc.reset_auto_universe_id()
|
||||
|
||||
|
||||
class Geometry(object):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self):
|
||||
|
||||
# Initialize Geometry class attributes
|
||||
self._root_universe = None
|
||||
self._offsets = dict()
|
||||
# Initialize Geometry class attributes
|
||||
self._root_universe = None
|
||||
self._offsets = dict()
|
||||
|
||||
|
||||
def getOffset(self, path, filter_offset):
|
||||
"""
|
||||
Returns the corresponding location in the results array for a given
|
||||
path and filter number.
|
||||
def getOffset(self, path, filter_offset):
|
||||
"""
|
||||
Returns the corresponding location in the results array for a given
|
||||
path and filter number.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
path : list
|
||||
A list of IDs that form the path to the target. It should begin with 0
|
||||
for the base universe, and should cover every universe, cell, and
|
||||
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)
|
||||
Parameters
|
||||
----------
|
||||
path : list
|
||||
A list of IDs that form the path to the target. It should begin
|
||||
with 0 for the base universe, and should cover every universe,
|
||||
cell, and 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
|
||||
filter_offset : int
|
||||
An integer that specifies which offset map the filter is using
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
# Return memoize'd offset if possible
|
||||
if (path, filter_offset) in self._offsets:
|
||||
offset = self._offsets[(path, filter_offset)]
|
||||
# Return memoize'd offset if possible
|
||||
if (path, filter_offset) in self._offsets:
|
||||
offset = self._offsets[(path, filter_offset)]
|
||||
|
||||
# Begin recursive call to compute the offset starting with the base Universe
|
||||
else:
|
||||
offset = self._root_universe.getOffset(path, filter_offset)
|
||||
self._offsets[(path, filter_offset)] = offset
|
||||
# Begin recursive call to compute offset starting with the base Universe
|
||||
else:
|
||||
offset = self._root_universe.getOffset(path, filter_offset)
|
||||
self._offsets[(path, filter_offset)] = offset
|
||||
|
||||
# Return the final offset
|
||||
return offset
|
||||
# Return the final offset
|
||||
return offset
|
||||
|
||||
|
||||
def getAllCells(self):
|
||||
return self._root_universe.getAllCells()
|
||||
def getAllCells(self):
|
||||
return self._root_universe.getAllCells()
|
||||
|
||||
|
||||
def getAllUniverses(self):
|
||||
return self._root_universe.getAllUniverses()
|
||||
def getAllUniverses(self):
|
||||
return self._root_universe.getAllUniverses()
|
||||
|
||||
|
||||
def getAllNuclides(self):
|
||||
def getAllNuclides(self):
|
||||
|
||||
nuclides = dict()
|
||||
materials = self.getAllMaterials()
|
||||
nuclides = dict()
|
||||
materials = self.getAllMaterials()
|
||||
|
||||
for material in materials:
|
||||
nuclides.update(material.getAllNuclides())
|
||||
for material in materials:
|
||||
nuclides.update(material.getAllNuclides())
|
||||
|
||||
return nuclides
|
||||
return nuclides
|
||||
|
||||
|
||||
def getAllMaterials(self):
|
||||
def getAllMaterials(self):
|
||||
|
||||
material_cells = self.getAllMaterialCells()
|
||||
materials = set()
|
||||
material_cells = self.getAllMaterialCells()
|
||||
materials = set()
|
||||
|
||||
for cell in material_cells:
|
||||
materials.add(cell._fill)
|
||||
for cell in material_cells:
|
||||
materials.add(cell._fill)
|
||||
|
||||
return list(materials)
|
||||
return list(materials)
|
||||
|
||||
|
||||
def getAllMaterialCells(self):
|
||||
def getAllMaterialCells(self):
|
||||
|
||||
all_cells = self.getAllCells()
|
||||
material_cells = set()
|
||||
all_cells = self.getAllCells()
|
||||
material_cells = set()
|
||||
|
||||
for cell_id, cell in all_cells.items():
|
||||
if cell._type == 'normal':
|
||||
material_cells.add(cell)
|
||||
for cell_id, cell in all_cells.items():
|
||||
if cell._type == 'normal':
|
||||
material_cells.add(cell)
|
||||
|
||||
return list(material_cells)
|
||||
return list(material_cells)
|
||||
|
||||
|
||||
def getAllMaterialUniverses(self):
|
||||
def getAllMaterialUniverses(self):
|
||||
|
||||
all_universes = self.getAllUniverses()
|
||||
material_universes = set()
|
||||
all_universes = self.getAllUniverses()
|
||||
material_universes = set()
|
||||
|
||||
for universe_id, universe in all_universes.items():
|
||||
for universe_id, universe in all_universes.items():
|
||||
|
||||
cells = universe._cells
|
||||
cells = universe._cells
|
||||
|
||||
for cell_id, cell in cells.items():
|
||||
if cell._type == 'normal':
|
||||
material_universes.add(universe)
|
||||
for cell_id, cell in cells.items():
|
||||
if cell._type == 'normal':
|
||||
material_universes.add(universe)
|
||||
|
||||
return list(material_universes)
|
||||
return list(material_universes)
|
||||
|
||||
|
||||
def setRootUniverse(self, root_universe):
|
||||
def setRootUniverse(self, root_universe):
|
||||
|
||||
if not isinstance(root_universe, openmc.Universe):
|
||||
msg = 'Unable to add root Universe {0} to Geometry since ' \
|
||||
'it is not a Universe'.format(root_universe)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(root_universe, openmc.Universe):
|
||||
msg = 'Unable to add root Universe {0} to Geometry since ' \
|
||||
'it is not a Universe'.format(root_universe)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif root_universe._id != 0:
|
||||
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)
|
||||
elif root_universe._id != 0:
|
||||
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
|
||||
self._root_universe = root_universe
|
||||
|
||||
|
||||
|
||||
class GeometryFile(object):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self):
|
||||
|
||||
# Initialize GeometryFile class attributes
|
||||
self._geometry = None
|
||||
self._geometry_file = ET.Element("geometry")
|
||||
# Initialize GeometryFile class attributes
|
||||
self._geometry = None
|
||||
self._geometry_file = ET.Element("geometry")
|
||||
|
||||
|
||||
def setGeometry(self, geometry):
|
||||
def setGeometry(self, geometry):
|
||||
|
||||
if not isinstance(geometry, Geometry):
|
||||
msg = 'Unable to set the Geometry to {0} for the GeometryFile ' \
|
||||
'since it is not a Geometry object'.format(geometry)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(geometry, Geometry):
|
||||
msg = 'Unable to set the Geometry to {0} for the GeometryFile ' \
|
||||
'since it is not a Geometry object'.format(geometry)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._geometry = geometry
|
||||
self._geometry = geometry
|
||||
|
||||
|
||||
def exportToXML(self):
|
||||
def exportToXML(self):
|
||||
|
||||
root_universe = self._geometry._root_universe
|
||||
root_universe.createXMLSubElement(self._geometry_file)
|
||||
root_universe = self._geometry._root_universe
|
||||
root_universe.createXMLSubElement(self._geometry_file)
|
||||
|
||||
# Clean the indentation in the file to be user-readable
|
||||
sort_xml_elements(self._geometry_file)
|
||||
clean_xml_indentation(self._geometry_file)
|
||||
# Clean the indentation in the file to be user-readable
|
||||
sort_xml_elements(self._geometry_file)
|
||||
clean_xml_indentation(self._geometry_file)
|
||||
|
||||
# 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")
|
||||
# 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")
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ MATERIAL_IDS = list()
|
|||
AUTO_MATERIAL_ID = 10000
|
||||
|
||||
def reset_auto_material_id():
|
||||
global AUTO_MATERIAL_ID, MATERIAL_IDS
|
||||
AUTO_MATERIAL_ID = 10000
|
||||
MATERIAL_IDS = list()
|
||||
global AUTO_MATERIAL_ID, MATERIAL_IDS
|
||||
AUTO_MATERIAL_ID = 10000
|
||||
MATERIAL_IDS = list()
|
||||
|
||||
|
||||
# Units for density supported by OpenMC
|
||||
|
|
@ -36,378 +36,381 @@ NO_DENSITY = 99999.
|
|||
|
||||
class Material(object):
|
||||
|
||||
def __init__(self, material_id=None, name=''):
|
||||
def __init__(self, material_id=None, name=''):
|
||||
|
||||
# Initialize class attributes
|
||||
self._id = None
|
||||
self._name = ''
|
||||
self._density = None
|
||||
self._density_units = ''
|
||||
# Initialize class attributes
|
||||
self._id = None
|
||||
self._name = ''
|
||||
self._density = None
|
||||
self._density_units = ''
|
||||
|
||||
# A dictionary of Nuclides
|
||||
# Keys - Nuclide names
|
||||
# Values - tuple (nuclide, percent, percent type)
|
||||
self._nuclides = dict()
|
||||
# A dictionary of Nuclides
|
||||
# Keys - Nuclide names
|
||||
# Values - tuple (nuclide, percent, percent type)
|
||||
self._nuclides = dict()
|
||||
|
||||
# A dictionary of Elements
|
||||
# Keys - Element names
|
||||
# Values - tuple (element, percent, percent type)
|
||||
self._elements = dict()
|
||||
# A dictionary of Elements
|
||||
# Keys - Element names
|
||||
# Values - tuple (element, percent, percent type)
|
||||
self._elements = dict()
|
||||
|
||||
# If specified, a list of tuples of (table name, xs identifier)
|
||||
self._sab = list()
|
||||
# If specified, a list of tuples of (table name, xs identifier)
|
||||
self._sab = list()
|
||||
|
||||
# Set the Material class attributes
|
||||
self.setId(material_id)
|
||||
self.setName(name)
|
||||
# Set the Material class attributes
|
||||
self.setId(material_id)
|
||||
self.setName(name)
|
||||
|
||||
|
||||
def setId(self, material_id=None):
|
||||
def setId(self, material_id=None):
|
||||
|
||||
global MATERIAL_IDS
|
||||
global MATERIAL_IDS
|
||||
|
||||
# If the Material already has an ID, remove it from global list
|
||||
if not self._id is None:
|
||||
MATERIAL_IDS.remove(self._id)
|
||||
# If the Material already has an ID, remove it from global list
|
||||
if not self._id is None:
|
||||
MATERIAL_IDS.remove(self._id)
|
||||
|
||||
if material_id is None:
|
||||
global AUTO_MATERIAL_ID
|
||||
self._id = AUTO_MATERIAL_ID
|
||||
MATERIAL_IDS.append(AUTO_MATERIAL_ID)
|
||||
AUTO_MATERIAL_ID += 1
|
||||
if material_id is None:
|
||||
global AUTO_MATERIAL_ID
|
||||
self._id = AUTO_MATERIAL_ID
|
||||
MATERIAL_IDS.append(AUTO_MATERIAL_ID)
|
||||
AUTO_MATERIAL_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(material_id):
|
||||
msg = 'Unable to set a non-integer Material ID {0}'.format(material_id)
|
||||
raise ValueError(msg)
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(material_id):
|
||||
msg = 'Unable to set a non-integer Material ' \
|
||||
'ID {0}'.format(material_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif material_id in MATERIAL_IDS:
|
||||
msg = 'Unable to set Material ID to {0} since a Material with ' \
|
||||
'this ID was already initialized'.format(material_id)
|
||||
raise ValueError(msg)
|
||||
elif material_id in MATERIAL_IDS:
|
||||
msg = 'Unable to set Material ID to {0} since a Material with ' \
|
||||
'this ID was already initialized'.format(material_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif material_id < 0:
|
||||
msg = 'Unable to set Material ID to {0} since it must be a ' \
|
||||
'non-negative integer'.format(material_id)
|
||||
raise ValueError(msg)
|
||||
elif material_id < 0:
|
||||
msg = 'Unable to set Material ID to {0} since it must be a ' \
|
||||
'non-negative integer'.format(material_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._id = material_id
|
||||
MATERIAL_IDS.append(material_id)
|
||||
else:
|
||||
self._id = material_id
|
||||
MATERIAL_IDS.append(material_id)
|
||||
|
||||
|
||||
def setName(self, name):
|
||||
def setName(self, name):
|
||||
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Material ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Material ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = name
|
||||
|
||||
|
||||
def setDensity(self, units, density=NO_DENSITY):
|
||||
def setDensity(self, units, density=NO_DENSITY):
|
||||
|
||||
if not is_float(density):
|
||||
msg = 'Unable to set the density for Material ID={0} to a ' \
|
||||
'non-floating point value {1}'.format(self._id, density)
|
||||
raise ValueError(msg)
|
||||
if not is_float(density):
|
||||
msg = 'Unable to set the density for Material ID={0} to a ' \
|
||||
'non-floating point value {1}'.format(self._id, density)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not units in DENSITY_UNITS:
|
||||
msg = 'Unable to set the density for Material ID={0} with ' \
|
||||
'units {1}'.format(self._id, units)
|
||||
raise ValueError(msg)
|
||||
elif not units in DENSITY_UNITS:
|
||||
msg = 'Unable to set the density for Material ID={0} with ' \
|
||||
'units {1}'.format(self._id, units)
|
||||
raise ValueError(msg)
|
||||
|
||||
if density == NO_DENSITY and units is not 'sum':
|
||||
msg = 'Unable to set the density Material ID={0} because '\
|
||||
'a density must be set when not using sum unit'.format(self._id)
|
||||
raise ValueError(msg)
|
||||
if density == NO_DENSITY and units is not 'sum':
|
||||
msg = 'Unable to set the density Material ID={0} ' \
|
||||
'because a density must be set when not using ' \
|
||||
'sum unit'.format(self._id)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._density = density
|
||||
self._density_units = units
|
||||
self._density = density
|
||||
self._density_units = units
|
||||
|
||||
|
||||
def addNuclide(self, nuclide, percent, percent_type='ao'):
|
||||
def addNuclide(self, nuclide, percent, percent_type='ao'):
|
||||
|
||||
if not isinstance(nuclide, openmc.Nuclide):
|
||||
msg = 'Unable to add an Nuclide to Material ID={0} with a ' \
|
||||
'non-Nuclide value {1}'.format(self._id, nuclide)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(nuclide, openmc.Nuclide):
|
||||
msg = 'Unable to add an Nuclide to Material ID={0} with a ' \
|
||||
'non-Nuclide value {1}'.format(self._id, nuclide)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not is_float(percent):
|
||||
msg = 'Unable to add an Nuclide to Material ID={0} with a non-floating ' \
|
||||
'non-floating point percent value {1}'.format(self._id, percent)
|
||||
raise ValueError(msg)
|
||||
elif not is_float(percent):
|
||||
msg = 'Unable to add an Nuclide to Material ID={0} with a ' \
|
||||
'non-floating point value {1}'.format(self._id, percent)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not percent_type in ['ao', 'wo', 'at/g-cm']:
|
||||
msg = 'Unable to add an Nuclide to Material ID={0} with a ' \
|
||||
'percent type {1}'.format(self._id, percent_type)
|
||||
raise ValueError(msg)
|
||||
elif not percent_type in ['ao', 'wo', 'at/g-cm']:
|
||||
msg = 'Unable to add an Nuclide to Material ID={0} with a ' \
|
||||
'percent type {1}'.format(self._id, percent_type)
|
||||
raise ValueError(msg)
|
||||
|
||||
# Copy this Nuclide to separate it from the same Nuclide in other Materials
|
||||
nuclide = deepcopy(nuclide)
|
||||
# Copy this Nuclide to separate it from the Nuclide in other Materials
|
||||
nuclide = deepcopy(nuclide)
|
||||
|
||||
self._nuclides[nuclide._name] = (nuclide, percent, percent_type)
|
||||
self._nuclides[nuclide._name] = (nuclide, percent, percent_type)
|
||||
|
||||
|
||||
def removeNuclide(self, nuclide):
|
||||
def removeNuclide(self, nuclide):
|
||||
|
||||
if not isinstance(nuclide, openmc.Nuclide):
|
||||
msg = 'Unable to remove a Nuclide {0} in Material ID={1} ' \
|
||||
'since it is not a Nuclide'.format(self._id, nuclide)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(nuclide, openmc.Nuclide):
|
||||
msg = 'Unable to remove a Nuclide {0} in Material ID={1} ' \
|
||||
'since it is not a Nuclide'.format(self._id, nuclide)
|
||||
raise ValueError(msg)
|
||||
|
||||
# If the Material contains the Nuclide, delete it
|
||||
if nuclide._name in self._nuclides:
|
||||
del self._nuclides[nuclide._name]
|
||||
# If the Material contains the Nuclide, delete it
|
||||
if nuclide._name in self._nuclides:
|
||||
del self._nuclides[nuclide._name]
|
||||
|
||||
|
||||
def addElement(self, element, percent, percent_type='ao'):
|
||||
def addElement(self, element, percent, percent_type='ao'):
|
||||
|
||||
if not isinstance(element, openmc.Element):
|
||||
msg = 'Unable to add an Element to Material ID={0} with a ' \
|
||||
'non-Element value {1}'.format(self._id, element)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(element, openmc.Element):
|
||||
msg = 'Unable to add an Element to Material ID={0} with a ' \
|
||||
'non-Element value {1}'.format(self._id, element)
|
||||
raise ValueError(msg)
|
||||
|
||||
if not is_float(percent):
|
||||
msg = 'Unable to add an Element to Material ID={0} with a non-floating ' \
|
||||
'point percent value {1}'.format(self._id, percent)
|
||||
raise ValueError(msg)
|
||||
if not is_float(percent):
|
||||
msg = 'Unable to add an Element to Material ID={0} with a ' \
|
||||
'non-floating point value {1}'.format(self._id, percent)
|
||||
raise ValueError(msg)
|
||||
|
||||
if not percent_type in ['ao', 'wo']:
|
||||
msg = 'Unable to add an Element to Material ID={0} with a percent ' \
|
||||
'percent type {1}'.format(self._id, percent_type)
|
||||
raise ValueError(msg)
|
||||
if not percent_type 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)
|
||||
|
||||
# Copy this Element to separate it from the same Element in other Materials
|
||||
element = deepcopy(element)
|
||||
# Copy this Element to separate it from same Element in other Materials
|
||||
element = deepcopy(element)
|
||||
|
||||
self._elements[element._name] = (element, percent, percent_type)
|
||||
self._elements[element._name] = (element, percent, percent_type)
|
||||
|
||||
|
||||
def removeElement(self, element):
|
||||
def removeElement(self, element):
|
||||
|
||||
# If the Material contains the Element, delete it
|
||||
if element._name in self._elements:
|
||||
del self._elements[element._name]
|
||||
# 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 addSAlphaBeta(self, name, xs):
|
||||
|
||||
if not is_string(name):
|
||||
msg = 'Unable to add an S(a,b) table to Material ID={0} with a ' \
|
||||
'non-string table name {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
if not is_string(name):
|
||||
msg = 'Unable to add an S(a,b) table to Material ID={0} with a ' \
|
||||
'non-string table name {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to add an S(a,b) table to Material ID={0} with a ' \
|
||||
'non-string cross-section identifier {1}'.format(self._id, xs)
|
||||
raise ValueError(msg)
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to add an S(a,b) table to Material ID={0} with a ' \
|
||||
'non-string cross-section identifier {1}'.format(self._id, xs)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._sab.append((name, xs))
|
||||
self._sab.append((name, xs))
|
||||
|
||||
|
||||
def getAllNuclides(self):
|
||||
def getAllNuclides(self):
|
||||
|
||||
nuclides = dict()
|
||||
nuclides = dict()
|
||||
|
||||
for nuclide_name, nuclide_tuple in self._nuclides.items():
|
||||
nuclide = nuclide_tuple[0]
|
||||
density = nuclide_tuple[1]
|
||||
nuclides[nuclide._name] = (nuclide, density)
|
||||
for nuclide_name, nuclide_tuple in self._nuclides.items():
|
||||
nuclide = nuclide_tuple[0]
|
||||
density = nuclide_tuple[1]
|
||||
nuclides[nuclide._name] = (nuclide, density)
|
||||
|
||||
return nuclides
|
||||
return nuclides
|
||||
|
||||
|
||||
def _repr__(self):
|
||||
def _repr__(self):
|
||||
|
||||
string = 'Material\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name)
|
||||
string = 'Material\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name)
|
||||
|
||||
string += '{0: <16}{1}{2}'.format('\tDensity', '=\t', self._density)
|
||||
string += ' [{0}]\n'.format(self._density_units)
|
||||
string += '{0: <16}{1}{2}'.format('\tDensity', '=\t', self._density)
|
||||
string += ' [{0}]\n'.format(self._density_units)
|
||||
|
||||
string += '{0: <16}'.format('\tS(a,b) Tables') + '\n'
|
||||
string += '{0: <16}'.format('\tS(a,b) Tables') + '\n'
|
||||
|
||||
for sab in self._sab:
|
||||
string += '{0: <16}{1}[{2}{3}]\n'.format('\tS(a,b)', '=\t', sab[0], sab[1])
|
||||
for sab in self._sab:
|
||||
string += '{0: <16}{1}[{2}{3}]\n'.format('\tS(a,b)', '=\t',
|
||||
sab[0], sab[1])
|
||||
|
||||
string += '{0: <16}'.format('\tNuclides') + '\n'
|
||||
string += '{0: <16}'.format('\tNuclides') + '\n'
|
||||
|
||||
for nuclide in self._nuclides:
|
||||
percent = self._nuclides[nuclide][1]
|
||||
percent_type = self._nuclides[nuclide][2]
|
||||
string += '{0: <16}'.format('\t{0}'.format(nuclide))
|
||||
string += '=\t{0: <12} [{1}]\n'.format(percent, percent_type)
|
||||
for nuclide in self._nuclides:
|
||||
percent = self._nuclides[nuclide][1]
|
||||
percent_type = self._nuclides[nuclide][2]
|
||||
string += '{0: <16}'.format('\t{0}'.format(nuclide))
|
||||
string += '=\t{0: <12} [{1}]\n'.format(percent, percent_type)
|
||||
|
||||
string += '{0: <16}\n'.format('\tElements')
|
||||
string += '{0: <16}\n'.format('\tElements')
|
||||
|
||||
for element in self._elements:
|
||||
percent = self._nuclides[element][1]
|
||||
percent_type = self._nuclides[element][2]
|
||||
string += '{0: >16}'.format('\t{0}'.format(element))
|
||||
string += '=\t{0: <12} [{1}]\n'.format(percent, percent_type)
|
||||
for element in self._elements:
|
||||
percent = self._nuclides[element][1]
|
||||
percent_type = self._nuclides[element][2]
|
||||
string += '{0: >16}'.format('\t{0}'.format(element))
|
||||
string += '=\t{0: <12} [{1}]\n'.format(percent, percent_type)
|
||||
|
||||
return string
|
||||
return string
|
||||
|
||||
|
||||
def getNuclideXML(self, nuclide):
|
||||
def getNuclideXML(self, nuclide):
|
||||
|
||||
xml_element = ET.Element("nuclide")
|
||||
xml_element.set("name", nuclide[0]._name)
|
||||
xml_element = ET.Element("nuclide")
|
||||
xml_element.set("name", nuclide[0]._name)
|
||||
|
||||
if nuclide[2] is 'ao':
|
||||
xml_element.set("ao", str(nuclide[1]))
|
||||
else:
|
||||
xml_element.set("wo", str(nuclide[1]))
|
||||
if nuclide[2] is 'ao':
|
||||
xml_element.set("ao", str(nuclide[1]))
|
||||
else:
|
||||
xml_element.set("wo", str(nuclide[1]))
|
||||
|
||||
if not nuclide[0]._xs is None:
|
||||
xml_element.set("xs", nuclide[0]._xs)
|
||||
if not nuclide[0]._xs is None:
|
||||
xml_element.set("xs", nuclide[0]._xs)
|
||||
|
||||
return xml_element
|
||||
return xml_element
|
||||
|
||||
|
||||
def getElementXML(self, element):
|
||||
def getElementXML(self, element):
|
||||
|
||||
xml_element = ET.Element("element")
|
||||
xml_element.set("name", str(element[0]._name))
|
||||
xml_element = ET.Element("element")
|
||||
xml_element.set("name", str(element[0]._name))
|
||||
|
||||
if element[2] is 'ao':
|
||||
xml_element.set("ao", str(element[1]))
|
||||
else:
|
||||
xml_element.set("wo", str(element[1]))
|
||||
if element[2] is 'ao':
|
||||
xml_element.set("ao", str(element[1]))
|
||||
else:
|
||||
xml_element.set("wo", str(element[1]))
|
||||
|
||||
return xml_element
|
||||
return xml_element
|
||||
|
||||
|
||||
def getNuclidesXML(self, nuclides):
|
||||
def getNuclidesXML(self, nuclides):
|
||||
|
||||
xml_elements = list()
|
||||
xml_elements = list()
|
||||
|
||||
for nuclide in nuclides.values():
|
||||
xml_elements.append(self.getNuclideXML(nuclide))
|
||||
for nuclide in nuclides.values():
|
||||
xml_elements.append(self.getNuclideXML(nuclide))
|
||||
|
||||
return xml_elements
|
||||
return xml_elements
|
||||
|
||||
|
||||
def getElementsXML(self, elements):
|
||||
def getElementsXML(self, elements):
|
||||
|
||||
xml_elements = list()
|
||||
xml_elements = list()
|
||||
|
||||
for element in elements.values():
|
||||
xml_elements.append(self.getElementXML(element))
|
||||
for element in elements.values():
|
||||
xml_elements.append(self.getElementXML(element))
|
||||
|
||||
return xml_elements
|
||||
return xml_elements
|
||||
|
||||
|
||||
def getMaterialXML(self):
|
||||
def getMaterialXML(self):
|
||||
|
||||
# Create Material XML element
|
||||
element = ET.Element("material")
|
||||
element.set("id", str(self._id))
|
||||
# Create Material XML element
|
||||
element = ET.Element("material")
|
||||
element.set("id", str(self._id))
|
||||
|
||||
# Create density XML subelement
|
||||
subelement = ET.SubElement(element, "density")
|
||||
if self._density_units is not 'sum':
|
||||
subelement.set("value", str(self._density))
|
||||
subelement.set("units", self._density_units)
|
||||
# Create density XML subelement
|
||||
subelement = ET.SubElement(element, "density")
|
||||
if self._density_units is not 'sum':
|
||||
subelement.set("value", str(self._density))
|
||||
subelement.set("units", self._density_units)
|
||||
|
||||
# Create nuclide XML subelements
|
||||
subelements = self.getNuclidesXML(self._nuclides)
|
||||
for subelement in subelements:
|
||||
element.append(subelement)
|
||||
# Create nuclide XML subelements
|
||||
subelements = self.getNuclidesXML(self._nuclides)
|
||||
for subelement in subelements:
|
||||
element.append(subelement)
|
||||
|
||||
# Create element XML subelements
|
||||
subelements = self.getElementsXML(self._elements)
|
||||
for subelement in subelements:
|
||||
element.append(subelement)
|
||||
# Create element XML subelements
|
||||
subelements = self.getElementsXML(self._elements)
|
||||
for subelement in subelements:
|
||||
element.append(subelement)
|
||||
|
||||
if len(self._sab) > 0:
|
||||
for sab in self._sab:
|
||||
subelement = ET.SubElement(element, "sab")
|
||||
subelement.set("name", sab[0])
|
||||
subelement.set("xs", sab[1])
|
||||
if len(self._sab) > 0:
|
||||
for sab in self._sab:
|
||||
subelement = ET.SubElement(element, "sab")
|
||||
subelement.set("name", sab[0])
|
||||
subelement.set("xs", sab[1])
|
||||
|
||||
return element
|
||||
return element
|
||||
|
||||
|
||||
class MaterialsFile(object):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self):
|
||||
|
||||
# Initialize MaterialsFile class attributes
|
||||
self._materials = list()
|
||||
self._default_xs = None
|
||||
self._materials_file = ET.Element("materials")
|
||||
# Initialize MaterialsFile class attributes
|
||||
self._materials = list()
|
||||
self._default_xs = None
|
||||
self._materials_file = ET.Element("materials")
|
||||
|
||||
|
||||
def addMaterial(self, material):
|
||||
def addMaterial(self, material):
|
||||
|
||||
if not isinstance(material, Material):
|
||||
msg = 'Unable to add a non-Material {0} to the ' \
|
||||
'MaterialsFile'.format(material)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(material, Material):
|
||||
msg = 'Unable to add a non-Material {0} to the ' \
|
||||
'MaterialsFile'.format(material)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._materials.append(material)
|
||||
self._materials.append(material)
|
||||
|
||||
|
||||
def addMaterials(self, materials):
|
||||
def addMaterials(self, materials):
|
||||
|
||||
if not isinstance(materials, (tuple, list, MappingView)):
|
||||
msg = 'Unable to create OpenMC materials.xml file from {0} which ' \
|
||||
'is not a Python tuple/list'.format(materials)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(materials, (tuple, list, MappingView)):
|
||||
msg = 'Unable to create OpenMC materials.xml file from {0} which ' \
|
||||
'is not a Python tuple/list'.format(materials)
|
||||
raise ValueError(msg)
|
||||
|
||||
for material in materials:
|
||||
self.addMaterial(material)
|
||||
for material in materials:
|
||||
self.addMaterial(material)
|
||||
|
||||
|
||||
def removeMaterial(self, material):
|
||||
def removeMaterial(self, material):
|
||||
|
||||
if not isinstance(material, Material):
|
||||
msg = 'Unable to remove a non-Material {0} from the ' \
|
||||
'MaterialsFile'.format(material)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(material, Material):
|
||||
msg = 'Unable to remove a non-Material {0} from the ' \
|
||||
'MaterialsFile'.format(material)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._materials.remove(material)
|
||||
self._materials.remove(material)
|
||||
|
||||
|
||||
def setDefaultXS(self, xs):
|
||||
def setDefaultXS(self, xs):
|
||||
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set default xs to a non-string value'.format(xs)
|
||||
raise ValueError(msg)
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set default xs to a non-string value'.format(xs)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._default_xs = xs
|
||||
self._default_xs = xs
|
||||
|
||||
|
||||
def createMaterialSubelements(self):
|
||||
def createMaterialSubelements(self):
|
||||
|
||||
subelement = ET.SubElement(self._materials_file, "default_xs")
|
||||
subelement = ET.SubElement(self._materials_file, "default_xs")
|
||||
|
||||
if not self._default_xs is None:
|
||||
subelement.text = self._default_xs
|
||||
if not self._default_xs is None:
|
||||
subelement.text = self._default_xs
|
||||
|
||||
for material in self._materials:
|
||||
xml_element = material.getMaterialXML()
|
||||
for material in self._materials:
|
||||
xml_element = material.getMaterialXML()
|
||||
|
||||
if len(material._name) > 0:
|
||||
self._materials_file.append(ET.Comment(material._name))
|
||||
if len(material._name) > 0:
|
||||
self._materials_file.append(ET.Comment(material._name))
|
||||
|
||||
self._materials_file.append(xml_element)
|
||||
self._materials_file.append(xml_element)
|
||||
|
||||
|
||||
def exportToXML(self):
|
||||
def exportToXML(self):
|
||||
|
||||
self.createMaterialSubelements()
|
||||
self.createMaterialSubelements()
|
||||
|
||||
# Clean the indentation in the file to be user-readable
|
||||
sort_xml_elements(self._materials_file)
|
||||
clean_xml_indentation(self._materials_file)
|
||||
# Clean the indentation in the file to be user-readable
|
||||
sort_xml_elements(self._materials_file)
|
||||
clean_xml_indentation(self._materials_file)
|
||||
|
||||
# Write the XML Tree to the materials.xml file
|
||||
tree = ET.ElementTree(self._materials_file)
|
||||
tree.write("materials.xml", xml_declaration=True,
|
||||
encoding='utf-8', method="xml")
|
||||
# Write the XML Tree to the materials.xml file
|
||||
tree = ET.ElementTree(self._materials_file)
|
||||
tree.write("materials.xml", xml_declaration=True,
|
||||
encoding='utf-8', method="xml")
|
||||
|
|
|
|||
|
|
@ -5,66 +5,66 @@ from openmc.checkvalue import *
|
|||
|
||||
class Nuclide(object):
|
||||
|
||||
def __init__(self, name='', xs=None):
|
||||
def __init__(self, name='', xs=None):
|
||||
|
||||
# Initialize class attributes
|
||||
self._name = ''
|
||||
self._xs = None
|
||||
# Initialize class attributes
|
||||
self._name = ''
|
||||
self._xs = None
|
||||
|
||||
# Set the Material class attributes
|
||||
self.setName(name)
|
||||
# Set the Material class attributes
|
||||
self.setName(name)
|
||||
|
||||
if not xs is None:
|
||||
self.setXS(xs)
|
||||
if not xs is None:
|
||||
self.setXS(xs)
|
||||
|
||||
|
||||
def __eq__(self, nuclide2):
|
||||
def __eq__(self, nuclide2):
|
||||
|
||||
# Check type
|
||||
if not isinstance(nuclide2, Nuclide):
|
||||
return False
|
||||
# Check type
|
||||
if not isinstance(nuclide2, Nuclide):
|
||||
return False
|
||||
|
||||
# Check name
|
||||
elif self._name != nuclide2._name:
|
||||
return False
|
||||
# Check name
|
||||
elif self._name != nuclide2._name:
|
||||
return False
|
||||
|
||||
# Check xs
|
||||
elif self._xs != nuclide2._xs:
|
||||
return False
|
||||
# Check xs
|
||||
elif self._xs != nuclide2._xs:
|
||||
return False
|
||||
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def __hash__(self):
|
||||
hashable = list()
|
||||
hashable.append(self._name)
|
||||
hashable.append(self._xs)
|
||||
return hash(tuple(hashable))
|
||||
def __hash__(self):
|
||||
hashable = list()
|
||||
hashable.append(self._name)
|
||||
hashable.append(self._xs)
|
||||
return hash(tuple(hashable))
|
||||
|
||||
|
||||
def setName(self, name):
|
||||
def setName(self, name):
|
||||
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Nuclide with a non-string ' \
|
||||
'value {0}'.format(name)
|
||||
raise ValueError(msg)
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Nuclide with a non-string ' \
|
||||
'value {0}'.format(name)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._name = name
|
||||
self._name = name
|
||||
|
||||
|
||||
def setXS(self, xs):
|
||||
def setXS(self, xs):
|
||||
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set cross-section identifier xs for Nuclide with ' \
|
||||
'a non-string value {0}'.format(xs)
|
||||
raise ValueError(msg)
|
||||
if not is_string(xs):
|
||||
msg = 'Unable to set cross-section identifier xs for Nuclide ' \
|
||||
'with a non-string value {0}'.format(xs)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._xs = xs
|
||||
self._xs = xs
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self):
|
||||
|
||||
string = 'Nuclide - {0}\n'.format(self._name)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tXS', '=\t', self._xs)
|
||||
return string
|
||||
string = 'Nuclide - {0}\n'.format(self._name)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tXS', '=\t', self._xs)
|
||||
return string
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -10,8 +10,8 @@ import numpy as np
|
|||
AUTO_PLOT_ID = 10000
|
||||
|
||||
def reset_auto_plot_id():
|
||||
global AUTO_PLOT_ID
|
||||
AUTO_PLOT_ID = 10000
|
||||
global AUTO_PLOT_ID
|
||||
AUTO_PLOT_ID = 10000
|
||||
|
||||
|
||||
BASES = ['xy', 'xz', 'yz']
|
||||
|
|
@ -19,416 +19,424 @@ BASES = ['xy', 'xz', 'yz']
|
|||
|
||||
class Plot(object):
|
||||
|
||||
def __init__(self, plot_id=None, name=''):
|
||||
def __init__(self, plot_id=None, name=''):
|
||||
|
||||
# Initialize Plot class attributes
|
||||
self._id = None
|
||||
self._name = ''
|
||||
self._width = [4.0, 4.0]
|
||||
self._pixels = [1000, 1000]
|
||||
self._origin = [0., 0., 0.]
|
||||
self._filename = 'plot'
|
||||
self._color = 'cell'
|
||||
self._type = 'slice'
|
||||
self._basis = 'xy'
|
||||
self._background = [0, 0, 0]
|
||||
self._mask_components = None
|
||||
self._mask_background = None
|
||||
self._col_spec = None
|
||||
# Initialize Plot class attributes
|
||||
self._id = None
|
||||
self._name = ''
|
||||
self._width = [4.0, 4.0]
|
||||
self._pixels = [1000, 1000]
|
||||
self._origin = [0., 0., 0.]
|
||||
self._filename = 'plot'
|
||||
self._color = 'cell'
|
||||
self._type = 'slice'
|
||||
self._basis = 'xy'
|
||||
self._background = [0, 0, 0]
|
||||
self._mask_components = None
|
||||
self._mask_background = None
|
||||
self._col_spec = None
|
||||
|
||||
self.setId(plot_id)
|
||||
self.setName(name)
|
||||
self.setId(plot_id)
|
||||
self.setName(name)
|
||||
|
||||
|
||||
def setId(self, plot_id=None):
|
||||
def setId(self, plot_id=None):
|
||||
|
||||
if plot_id is None:
|
||||
global AUTO_PLOT_ID
|
||||
self._id = AUTO_PLOT_ID
|
||||
AUTO_PLOT_ID += 1
|
||||
if plot_id is None:
|
||||
global AUTO_PLOT_ID
|
||||
self._id = AUTO_PLOT_ID
|
||||
AUTO_PLOT_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(plot_id):
|
||||
msg = 'Unable to set a non-integer Plot ID {0}'.format(plot_id)
|
||||
raise ValueError(msg)
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(plot_id):
|
||||
msg = 'Unable to set a non-integer Plot ID {0}'.format(plot_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif plot_id < 0:
|
||||
msg = 'Unable to set Plot ID to {0} since it must be a ' \
|
||||
'non-negative integer'.format(plot_id)
|
||||
raise ValueError(msg)
|
||||
elif plot_id < 0:
|
||||
msg = 'Unable to set Plot ID to {0} since it must be a ' \
|
||||
'non-negative integer'.format(plot_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._id = plot_id
|
||||
else:
|
||||
self._id = plot_id
|
||||
|
||||
|
||||
def setName(self, name):
|
||||
def setName(self, name):
|
||||
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Plot ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Plot ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = name
|
||||
|
||||
|
||||
def setWidth(self, width):
|
||||
def setWidth(self, width):
|
||||
|
||||
if not isinstance(width, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with width {1} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(width, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with width {1} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(width) != 2 and len(width) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with width {1} since only 2D ' \
|
||||
'and 3D plots are supported'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
elif len(width) != 2 and len(width) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with width {1} since only 2D ' \
|
||||
'and 3D plots are supported'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in width:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to create Plot ID={0} with width {1} since each ' \
|
||||
'element must be a floating point value or ' \
|
||||
'integer'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
for dim in width:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to create Plot ID={0} with width {1} since ' \
|
||||
'each element must be a floating point value or ' \
|
||||
'integer'.format(self._id, width)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._width = width
|
||||
self._width = width
|
||||
|
||||
|
||||
def setOrigin(self, origin):
|
||||
def setOrigin(self, origin):
|
||||
|
||||
if not isinstance(origin, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} which is not a ' \
|
||||
'Python tuple/list or NumPy array'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(origin, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(origin) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} since only a 3D ' \
|
||||
'coordinate must be input'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
elif len(origin) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} since only ' \
|
||||
'a 3D coordinate must be input'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
for dim in origin:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} since each ' \
|
||||
'element must be a floating point value or ' \
|
||||
'integer'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
for dim in origin:
|
||||
if not is_integer(dim) and not is_float(dim):
|
||||
msg = 'Unable to create Plot ID={0} with origin {1} since ' \
|
||||
'each element must be a floating point value or ' \
|
||||
'integer'.format(self._id, origin)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._origin = origin
|
||||
self._origin = origin
|
||||
|
||||
|
||||
def setPixels(self, pixels):
|
||||
def setPixels(self, pixels):
|
||||
|
||||
if not isinstance(pixels, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with pixels {1} which is not a ' \
|
||||
'Python tuple/list or NumPy array'.format(self._id, pixels)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(pixels, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with pixels {1} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(self._id, pixels)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(pixels) != 2 and len(pixels) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with pixels {1} since only 2D ' \
|
||||
'and 3D plots are supported'.format(self._id, pixels)
|
||||
raise ValueError(msg)
|
||||
elif len(pixels) != 2 and len(pixels) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with pixels {1} since ' \
|
||||
'only 2D and 3D plots are supported'.format(self._id, pixels)
|
||||
raise ValueError(msg)
|
||||
|
||||
for dim in pixels:
|
||||
for dim in pixels:
|
||||
|
||||
if not is_integer(dim):
|
||||
msg = 'Unable to create Plot ID={0} with pixel value {1} which is ' \
|
||||
'not an integer'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(dim):
|
||||
msg = 'Unable to create Plot ID={0} with pixel value {1} ' \
|
||||
'which is not an integer'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif dim < 0:
|
||||
msg = 'Unable to create Plot ID={0} with pixel value {1} which ' \
|
||||
'is less than 0'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
elif dim < 0:
|
||||
msg = 'Unable to create Plot ID={0} with pixel value {1} ' \
|
||||
'which is less than 0'.format(self._id, dim)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._pixels = pixels
|
||||
self._pixels = pixels
|
||||
|
||||
|
||||
def setFilename(self, filename):
|
||||
def setFilename(self, filename):
|
||||
|
||||
if not is_string(filename):
|
||||
msg = 'Unable to create Plot ID={0} with filename {1} which is ' \
|
||||
'not a string'.format(self._id, filename)
|
||||
raise ValueError(msg)
|
||||
if not is_string(filename):
|
||||
msg = 'Unable to create Plot ID={0} with filename {1} which is ' \
|
||||
'not a string'.format(self._id, filename)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._filename = filename
|
||||
self._filename = filename
|
||||
|
||||
|
||||
def setColor(self, color):
|
||||
def setColor(self, color):
|
||||
|
||||
if not is_string(color):
|
||||
msg = 'Unable to create Plot ID={0} with color {1} which is not ' \
|
||||
'a string'.format(self._id, color)
|
||||
raise ValueError(msg)
|
||||
if not is_string(color):
|
||||
msg = 'Unable to create Plot ID={0} with color {1} which is not ' \
|
||||
'a string'.format(self._id, color)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not color 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)
|
||||
elif not color 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)
|
||||
|
||||
self._color = color
|
||||
self._color = color
|
||||
|
||||
|
||||
def setType(self, type):
|
||||
def setType(self, type):
|
||||
|
||||
if not is_string(type):
|
||||
msg = 'Unable to create Plot ID={0} with type {1} which is not ' \
|
||||
'a string'.format(self._id, type)
|
||||
raise ValueError(msg)
|
||||
if not is_string(type):
|
||||
msg = 'Unable to create Plot ID={0} with type {1} which is not ' \
|
||||
'a string'.format(self._id, type)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not type 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)
|
||||
elif not type 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)
|
||||
|
||||
self._type = type
|
||||
self._type = type
|
||||
|
||||
|
||||
def setBasis(self, basis):
|
||||
def setBasis(self, basis):
|
||||
|
||||
if not is_string(basis):
|
||||
msg = 'Unable to create Plot ID={0} with basis {1} which is not ' \
|
||||
'a string'.format(self._id, basis)
|
||||
raise ValueError(msg)
|
||||
if not is_string(basis):
|
||||
msg = 'Unable to create Plot ID={0} with basis {1} which is not ' \
|
||||
'a string'.format(self._id, basis)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not basis 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)
|
||||
elif not basis 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)
|
||||
|
||||
self._basis = basis
|
||||
self._basis = basis
|
||||
|
||||
|
||||
def setBackground(self, background):
|
||||
def setBackground(self, background):
|
||||
|
||||
if not isinstance(background, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with background {1} which is not ' \
|
||||
'a Python tuple/list or NumPy array'.format(self._id, background)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(background, (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with background {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, background)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(background) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with background {1} which is ' \
|
||||
'not 3 integer RGB values'.format(self._id, background)
|
||||
raise ValueError(msg)
|
||||
elif len(background) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with background {1} ' \
|
||||
'which is not 3 integer RGB ' \
|
||||
'values'.format(self._id, background)
|
||||
raise ValueError(msg)
|
||||
|
||||
for rgb in background:
|
||||
for rgb in background:
|
||||
|
||||
if not is_integer(rgb):
|
||||
msg = 'Unable to create Plot ID={0} with background RGB value {1} ' \
|
||||
'which is not an integer'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(rgb):
|
||||
msg = 'Unable to create Plot ID={0} with background RGB ' \
|
||||
'value {1} which is not an integer'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif rgb < 0 or rgb > 255:
|
||||
msg = 'Unable to create Plot ID={0} with background RGB value {1} ' \
|
||||
'which is not between 0 and 255'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
elif rgb < 0 or rgb > 255:
|
||||
msg = 'Unable to create Plot ID={0} with background RGB value ' \
|
||||
'{1} which is not between 0 and 255'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._background = background
|
||||
self._background = background
|
||||
|
||||
|
||||
def setColSpec(self, col_spec):
|
||||
def setColSpec(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)
|
||||
raise ValueError(msg)
|
||||
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)
|
||||
raise ValueError(msg)
|
||||
|
||||
for key in col_spec:
|
||||
for key in col_spec:
|
||||
|
||||
if not is_integer(key):
|
||||
msg = 'Unable to create Plot ID={0} with col_spec ID {1} ' \
|
||||
'which is not an integer'.format(self._id, key)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(key):
|
||||
msg = 'Unable to create Plot ID={0} with col_spec ID {1} ' \
|
||||
'which is not an integer'.format(self._id, key)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif key < 0:
|
||||
msg = 'Unable to create Plot ID={0} with col_spec ID {1} which ' \
|
||||
'is less than 0'.format(self._id, key)
|
||||
raise ValueError(msg)
|
||||
elif key < 0:
|
||||
msg = 'Unable to create Plot ID={0} with col_spec ID {1} ' \
|
||||
'which is less than 0'.format(self._id, key)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not isinstance(col_spec[key], (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with col_spec RGB values {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, col_spec[key])
|
||||
raise ValueError(msg)
|
||||
elif not isinstance(col_spec[key], (tuple, list, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with col_spec RGB ' \
|
||||
'values {1} which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, col_spec[key])
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(col_spec[key]) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with col_spec RGB values of ' \
|
||||
'length {1} since 3 values must be ' \
|
||||
'input'.format(self._id, len(col_spec[key]))
|
||||
raise ValueError(msg)
|
||||
elif len(col_spec[key]) != 3:
|
||||
msg = 'Unable to create Plot ID={0} with col_spec RGB ' \
|
||||
'values of length {1} since 3 values must be ' \
|
||||
'input'.format(self._id, len(col_spec[key]))
|
||||
raise ValueError(msg)
|
||||
|
||||
self._col_spec = col_spec
|
||||
self._col_spec = col_spec
|
||||
|
||||
|
||||
def setMaskComponents(self, mask_components):
|
||||
def setMaskComponents(self, mask_components):
|
||||
|
||||
if not isinstance(mask_components, (list, tuple, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with mask components {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, mask_components)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(mask_components, (list, tuple, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with mask components {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, mask_components)
|
||||
raise ValueError(msg)
|
||||
|
||||
for component in mask_components:
|
||||
if not is_integer(component):
|
||||
msg = 'Unable to create Plot ID={0} with mask component {1} ' \
|
||||
'which is not an integer'.format(self._id, component)
|
||||
raise ValueError(msg)
|
||||
for component in mask_components:
|
||||
if not is_integer(component):
|
||||
msg = 'Unable to create Plot ID={0} with mask component {1} ' \
|
||||
'which is not an integer'.format(self._id, component)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif component < 0:
|
||||
msg = 'Unable to create Plot ID={0} with mask component {1} ' \
|
||||
'which is less than 0'.format(self._id, component)
|
||||
raise ValueError(msg)
|
||||
elif component < 0:
|
||||
msg = 'Unable to create Plot ID={0} with mask component {1} ' \
|
||||
'which is less than 0'.format(self._id, component)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._mask_components = mask_components
|
||||
self._mask_components = mask_components
|
||||
|
||||
|
||||
def setMaskBackground(self, mask_background):
|
||||
|
||||
if not isinstance(mask_background, (list, tuple, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with mask background {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, mask_background)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(mask_background) != 3 and len(mask_background) != 0:
|
||||
msg = 'Unable to create Plot ID={0} with mask background {1} since ' \
|
||||
'3 RGB values must be input'.format(self._id, mask_background)
|
||||
raise ValueError(msg)
|
||||
|
||||
for rgb in mask_background:
|
||||
|
||||
if not is_integer(rgb):
|
||||
msg = 'Unable to create Plot ID={0} with mask background RGB ' \
|
||||
'value {1} which is not an integer'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif rgb < 0 or rgb > 255:
|
||||
msg = 'Unable to create Plot ID={0} with mask bacground RGB ' \
|
||||
'value {1} which is not between 0 and 255'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._mask_background = mask_background
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
string = 'Plot\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tFilename', '=\t', self._filename)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tType', '=\t', self._type)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tBasis', '=\t', self._basis)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tWidth', '=\t', self._width)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tOrigin', '=\t', self._origin)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tPixels', '=\t', self._origin)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tColor', '=\t', self._color)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMask', '=\t', self._mask_components)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMask', '=\t', self._mask_background)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tCol Spec', '=\t', self._col_spec)
|
||||
return string
|
||||
|
||||
|
||||
def getPlotXML(self):
|
||||
|
||||
element = ET.Element("plot")
|
||||
element.set("id", str(self._id))
|
||||
element.set("filename", self._filename)
|
||||
element.set("color", self._color)
|
||||
element.set("type", self._type)
|
||||
|
||||
if self._type is 'slice':
|
||||
element.set("basis", self._basis)
|
||||
|
||||
subelement = ET.SubElement(element, "origin")
|
||||
text = ''
|
||||
for coord in self._origin:
|
||||
text += str(coord) + ' '
|
||||
subelement.text = text.rstrip(' ')
|
||||
|
||||
subelement = ET.SubElement(element, "width")
|
||||
text = ''
|
||||
for dim in self._width:
|
||||
text += str(dim) + ' '
|
||||
subelement.text = text.rstrip(' ')
|
||||
|
||||
subelement = ET.SubElement(element, "pixels")
|
||||
text = ''
|
||||
for dim in self._pixels:
|
||||
text += str(dim) + ' '
|
||||
subelement.text = text.rstrip(' ')
|
||||
|
||||
if not self._mask_background is None:
|
||||
subelement = ET.SubElement(element, "background")
|
||||
text = ''
|
||||
for rgb in self._background:
|
||||
text += str(rgb) + ' '
|
||||
subelement.text = text.rstrip(' ')
|
||||
|
||||
if not self._col_spec is None:
|
||||
|
||||
for key in self._col_spec:
|
||||
subelement = ET.SubElement(element, "col_spec")
|
||||
subelement.set("id", '{0}'.format(key))
|
||||
value = self._col_spec[key]
|
||||
subelement.set("rgb",'{0} {1} {2}'.format(value[0], value[1], value[2]))
|
||||
|
||||
if not self._mask_components is None:
|
||||
subelement = ET.SubElement(element, "mask")
|
||||
|
||||
text = ''
|
||||
for id in self._mask_components:
|
||||
text += str(id) + ' '
|
||||
subelement.set("components", text.rstrip(' '))
|
||||
|
||||
rgb = self._mask_background
|
||||
subelement.set("background", '{0} {1} {2}'.format(rgb[0], rgb[1], rgb[2]))
|
||||
|
||||
return element
|
||||
|
||||
def setMaskBackground(self, mask_background):
|
||||
|
||||
if not isinstance(mask_background, (list, tuple, np.ndarray)):
|
||||
msg = 'Unable to create Plot ID={0} with mask background {1} ' \
|
||||
'which is not a Python tuple/list or NumPy ' \
|
||||
'array'.format(self._id, mask_background)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif len(mask_background) != 3 and len(mask_background) != 0:
|
||||
msg = 'Unable to create Plot ID={0} with mask background ' \
|
||||
'{1} since 3 RGB values must be ' \
|
||||
'input'.format(self._id, mask_background)
|
||||
raise ValueError(msg)
|
||||
|
||||
for rgb in mask_background:
|
||||
|
||||
if not is_integer(rgb):
|
||||
msg = 'Unable to create Plot ID={0} with mask background RGB ' \
|
||||
'value {1} which is not an integer'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif rgb < 0 or rgb > 255:
|
||||
msg = 'Unable to create Plot ID={0} with mask bacground ' \
|
||||
'RGB value {1} which is not between 0 and ' \
|
||||
'255'.format(self._id, rgb)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._mask_background = mask_background
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
string = 'Plot\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tFilename', '=\t', self._filename)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tType', '=\t', self._type)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tBasis', '=\t', self._basis)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tWidth', '=\t', self._width)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tOrigin', '=\t', self._origin)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tPixels', '=\t', self._origin)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tColor', '=\t', self._color)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMask', '=\t',
|
||||
self._mask_components)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tMask', '=\t',
|
||||
self._mask_background)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tCol Spec', '=\t', self._col_spec)
|
||||
return string
|
||||
|
||||
|
||||
def getPlotXML(self):
|
||||
|
||||
element = ET.Element("plot")
|
||||
element.set("id", str(self._id))
|
||||
element.set("filename", self._filename)
|
||||
element.set("color", self._color)
|
||||
element.set("type", self._type)
|
||||
|
||||
if self._type is 'slice':
|
||||
element.set("basis", self._basis)
|
||||
|
||||
subelement = ET.SubElement(element, "origin")
|
||||
text = ''
|
||||
for coord in self._origin:
|
||||
text += str(coord) + ' '
|
||||
subelement.text = text.rstrip(' ')
|
||||
|
||||
subelement = ET.SubElement(element, "width")
|
||||
text = ''
|
||||
for dim in self._width:
|
||||
text += str(dim) + ' '
|
||||
subelement.text = text.rstrip(' ')
|
||||
|
||||
subelement = ET.SubElement(element, "pixels")
|
||||
text = ''
|
||||
for dim in self._pixels:
|
||||
text += str(dim) + ' '
|
||||
subelement.text = text.rstrip(' ')
|
||||
|
||||
if not self._mask_background is None:
|
||||
subelement = ET.SubElement(element, "background")
|
||||
text = ''
|
||||
for rgb in self._background:
|
||||
text += str(rgb) + ' '
|
||||
subelement.text = text.rstrip(' ')
|
||||
|
||||
if not self._col_spec is None:
|
||||
|
||||
for key in self._col_spec:
|
||||
subelement = ET.SubElement(element, "col_spec")
|
||||
subelement.set("id", '{0}'.format(key))
|
||||
value = self._col_spec[key]
|
||||
subelement.set("rgb",'{0} {1} {2}'.format(value[0],
|
||||
value[1], value[2]))
|
||||
|
||||
if not self._mask_components is None:
|
||||
subelement = ET.SubElement(element, "mask")
|
||||
|
||||
text = ''
|
||||
for id in self._mask_components:
|
||||
text += str(id) + ' '
|
||||
subelement.set("components", text.rstrip(' '))
|
||||
|
||||
rgb = self._mask_background
|
||||
subelement.set("background", '{0} {1} {2}'.format(rgb[0],
|
||||
rgb[1], rgb[2]))
|
||||
|
||||
return element
|
||||
|
||||
|
||||
class PlotsFile(object):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self):
|
||||
|
||||
# Initialize PlotsFile class attributes
|
||||
self._plots = list()
|
||||
self._plots_file = ET.Element("plots")
|
||||
# Initialize PlotsFile class attributes
|
||||
self._plots = list()
|
||||
self._plots_file = ET.Element("plots")
|
||||
|
||||
|
||||
def addPlot(self, plot):
|
||||
def addPlot(self, plot):
|
||||
|
||||
if not isinstance(plot, Plot):
|
||||
msg = 'Unable to add a non-Plot {0} to the PlotsFile'.format(plot)
|
||||
raise ValueError(msg)
|
||||
if not isinstance(plot, Plot):
|
||||
msg = 'Unable to add a non-Plot {0} to the PlotsFile'.format(plot)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._plots.append(plot)
|
||||
self._plots.append(plot)
|
||||
|
||||
|
||||
def removePlot(self, plot):
|
||||
self._plots.remove(plot)
|
||||
def removePlot(self, plot):
|
||||
self._plots.remove(plot)
|
||||
|
||||
|
||||
def createPlotSubelements(self):
|
||||
def createPlotSubelements(self):
|
||||
|
||||
for plot in self._plots:
|
||||
for plot in self._plots:
|
||||
|
||||
xml_element = plot.getPlotXML()
|
||||
xml_element = plot.getPlotXML()
|
||||
|
||||
if len(plot._name) > 0:
|
||||
self._plots_file.append(ET.Comment(plot._name))
|
||||
if len(plot._name) > 0:
|
||||
self._plots_file.append(ET.Comment(plot._name))
|
||||
|
||||
self._plots_file.append(xml_element)
|
||||
self._plots_file.append(xml_element)
|
||||
|
||||
|
||||
def exportToXML(self):
|
||||
def exportToXML(self):
|
||||
|
||||
self.createPlotSubelements()
|
||||
self.createPlotSubelements()
|
||||
|
||||
# Clean the indentation in the file to be user-readable
|
||||
clean_xml_indentation(self._plots_file)
|
||||
# Clean the indentation in the file to be user-readable
|
||||
clean_xml_indentation(self._plots_file)
|
||||
|
||||
# Write the XML Tree to the plots.xml file
|
||||
tree = ET.ElementTree(self._plots_file)
|
||||
tree.write("plots.xml", xml_declaration=True,
|
||||
encoding='utf-8', method="xml")
|
||||
# Write the XML Tree to the plots.xml file
|
||||
tree = ET.ElementTree(self._plots_file)
|
||||
tree.write("plots.xml", xml_declaration=True,
|
||||
encoding='utf-8', method="xml")
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -9,585 +9,587 @@ from xml.etree import ElementTree as ET
|
|||
AUTO_SURFACE_ID = 10000
|
||||
|
||||
def reset_auto_surface_id():
|
||||
global AUTO_SURFACE_ID
|
||||
AUTO_SURFACE_ID = 10000
|
||||
global AUTO_SURFACE_ID
|
||||
AUTO_SURFACE_ID = 10000
|
||||
|
||||
|
||||
|
||||
class Surface(object):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission', name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission', name=''):
|
||||
|
||||
# Initialize class attributes
|
||||
self._id = None
|
||||
self._name = ''
|
||||
self._type = ''
|
||||
self._bc_type = ''
|
||||
# Initialize class attributes
|
||||
self._id = None
|
||||
self._name = ''
|
||||
self._type = ''
|
||||
self._bc_type = ''
|
||||
|
||||
# A dictionary of the quadratic surface coefficients
|
||||
# Key - coefficeint name
|
||||
# Value - coefficient value
|
||||
self._coeffs = dict()
|
||||
# A dictionary of the quadratic surface coefficients
|
||||
# Key - coefficeint name
|
||||
# Value - coefficient value
|
||||
self._coeffs = dict()
|
||||
|
||||
# An ordered list of the coefficient names to export to XML in the
|
||||
# proper order
|
||||
self._coeff_keys = list()
|
||||
# An ordered list of the coefficient names to export to XML in the
|
||||
# proper order
|
||||
self._coeff_keys = list()
|
||||
|
||||
self.setId(surface_id)
|
||||
self.setBoundaryType(bc_type)
|
||||
self.setName(name)
|
||||
self.setId(surface_id)
|
||||
self.setBoundaryType(bc_type)
|
||||
self.setName(name)
|
||||
|
||||
|
||||
def setId(self, surface_id=None):
|
||||
def setId(self, surface_id=None):
|
||||
|
||||
if surface_id is None:
|
||||
global AUTO_SURFACE_ID
|
||||
self._id = AUTO_SURFACE_ID
|
||||
AUTO_SURFACE_ID += 1
|
||||
if surface_id is None:
|
||||
global AUTO_SURFACE_ID
|
||||
self._id = AUTO_SURFACE_ID
|
||||
AUTO_SURFACE_ID += 1
|
||||
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(surface_id):
|
||||
msg = 'Unable to set a non-integer Surface ID {0}'.format(surface_id)
|
||||
raise ValueError(msg)
|
||||
# Check that the ID is an integer and wasn't already used
|
||||
elif not is_integer(surface_id):
|
||||
msg = 'Unable to set a non-integer Surface ' \
|
||||
'ID {0}'.format(surface_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif surface_id < 0:
|
||||
msg = 'Unable to set Surface ID to {0} since it must be a ' \
|
||||
'non-negative integer'.format(surface_id)
|
||||
raise ValueError(msg)
|
||||
elif surface_id < 0:
|
||||
msg = 'Unable to set Surface ID to {0} since it must be a ' \
|
||||
'non-negative integer'.format(surface_id)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._id = surface_id
|
||||
else:
|
||||
self._id = surface_id
|
||||
|
||||
|
||||
def setName(self, name):
|
||||
def setName(self, name):
|
||||
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Surface ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
if not is_string(name):
|
||||
msg = 'Unable to set name for Surface ID={0} with a non-string ' \
|
||||
'value {1}'.format(self._id, name)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = name
|
||||
|
||||
|
||||
def setBoundaryType(self, bc_type):
|
||||
def setBoundaryType(self, bc_type):
|
||||
|
||||
if not is_string(bc_type):
|
||||
msg = 'Unable to set boundary type for Surface ID={0} with a ' \
|
||||
'non-string value {1}'.format(self._id, bc_type)
|
||||
raise ValueError(msg)
|
||||
if not is_string(bc_type):
|
||||
msg = 'Unable to set boundary type for Surface ID={0} with a ' \
|
||||
'non-string value {1}'.format(self._id, bc_type)
|
||||
raise ValueError(msg)
|
||||
|
||||
elif not bc_type in BC_TYPES.values():
|
||||
msg = 'Unable to set boundary type for Surface ID={0} to {1} which ' \
|
||||
'is not trasmission, vacuum or reflective'.format(bc_type)
|
||||
raise ValueError(msg)
|
||||
elif not bc_type in BC_TYPES.values():
|
||||
msg = 'Unable to set boundary type for Surface ID={0} to ' \
|
||||
'{1} which is not trasmission, vacuum or ' \
|
||||
'reflective'.format(bc_type)
|
||||
raise ValueError(msg)
|
||||
|
||||
else:
|
||||
self._bc_type = bc_type
|
||||
else:
|
||||
self._bc_type = bc_type
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self):
|
||||
|
||||
string = 'Surface\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t{0}', self._id)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tType', '=\t', self._type)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tBoundary', '=\t', self._bc_type)
|
||||
string = 'Surface\n'
|
||||
string += '{0: <16}{1}{2}\n'.format('\tID', '=\t{0}', self._id)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tName', '=\t', self._name)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tType', '=\t', self._type)
|
||||
string += '{0: <16}{1}{2}\n'.format('\tBoundary', '=\t', self._bc_type)
|
||||
|
||||
coeffs = '{0: <16}'.format('\tCoefficients') + '\n'
|
||||
coeffs = '{0: <16}'.format('\tCoefficients') + '\n'
|
||||
|
||||
for coeff in self._coeffs:
|
||||
coeffs += '{0: <16}{1}{2}\n'.format(coeff, '=\t', self._coeffs[coeff])
|
||||
for coeff in self._coeffs:
|
||||
coeffs += '{0: <16}{1}{2}\n'.format(coeff, '=\t', self._coeffs[coeff])
|
||||
|
||||
string += coeffs
|
||||
string += coeffs
|
||||
|
||||
return string
|
||||
return string
|
||||
|
||||
|
||||
def createXMLSubElement(self):
|
||||
def createXMLSubElement(self):
|
||||
|
||||
element = ET.Element("surface")
|
||||
element.set("id", str(self._id))
|
||||
element.set("type", self._type)
|
||||
element.set("boundary", self._bc_type)
|
||||
element = ET.Element("surface")
|
||||
element.set("id", str(self._id))
|
||||
element.set("type", self._type)
|
||||
element.set("boundary", self._bc_type)
|
||||
|
||||
coeffs = ''
|
||||
coeffs = ''
|
||||
|
||||
for coeff in self._coeff_keys:
|
||||
coeffs += '{0} '.format(self._coeffs[coeff])
|
||||
for coeff in self._coeff_keys:
|
||||
coeffs += '{0} '.format(self._coeffs[coeff])
|
||||
|
||||
element.set("coeffs", coeffs.rstrip(' '))
|
||||
element.set("coeffs", coeffs.rstrip(' '))
|
||||
|
||||
return element
|
||||
return element
|
||||
|
||||
|
||||
|
||||
class Plane(Surface):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
A=None, B=None, C=None, D=None, name='',):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
A=None, B=None, C=None, D=None, name='',):
|
||||
|
||||
# Initialize Plane class attributes
|
||||
super(Plane, self).__init__(surface_id, bc_type, name=name)
|
||||
# Initialize Plane class attributes
|
||||
super(Plane, self).__init__(surface_id, bc_type, name=name)
|
||||
|
||||
self._A = None
|
||||
self._B = None
|
||||
self._C = None
|
||||
self._D = None
|
||||
self._type = 'plane'
|
||||
self._coeff_keys = ['A', 'B', 'C', 'D']
|
||||
self._A = None
|
||||
self._B = None
|
||||
self._C = None
|
||||
self._D = None
|
||||
self._type = 'plane'
|
||||
self._coeff_keys = ['A', 'B', 'C', 'D']
|
||||
|
||||
if not A is None:
|
||||
self.setA(A)
|
||||
if not A is None:
|
||||
self.setA(A)
|
||||
|
||||
if not B is None:
|
||||
self.setB(B)
|
||||
if not B is None:
|
||||
self.setB(B)
|
||||
|
||||
if not C is None:
|
||||
self.setC(C)
|
||||
if not C is None:
|
||||
self.setC(C)
|
||||
|
||||
if not D is None:
|
||||
self.setD(D)
|
||||
if not D is None:
|
||||
self.setD(D)
|
||||
|
||||
|
||||
def setA(self, A):
|
||||
def setA(self, A):
|
||||
|
||||
if not is_integer(A) and not is_float(A):
|
||||
msg = 'Unable to set A coefficient for Plane ID={0} to a non-integer ' \
|
||||
'value {1}'.format(self._id, A)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(A) and not is_float(A):
|
||||
msg = 'Unable to set A coefficient for Plane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, A)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['A'] = A
|
||||
self._coeffs['A'] = A
|
||||
|
||||
|
||||
def setB(self, B):
|
||||
def setB(self, B):
|
||||
|
||||
if not is_integer(B) and not is_float(B):
|
||||
msg = 'Unable to set B coefficient for Plane ID={0} to a non-integer ' \
|
||||
'value {1}'.format(self._id, B)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(B) and not is_float(B):
|
||||
msg = 'Unable to set B coefficient for Plane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, B)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['B'] = B
|
||||
self._coeffs['B'] = B
|
||||
|
||||
|
||||
def setC(self, C):
|
||||
def setC(self, C):
|
||||
|
||||
if not is_integer(C) and not is_float(C):
|
||||
msg = 'Unable to set C coefficient for Plane ID={0} to a non-integer ' \
|
||||
'value {1}'.format(self._id, C)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(C) and not is_float(C):
|
||||
msg = 'Unable to set C coefficient for Plane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, C)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['C'] = C
|
||||
self._coeffs['C'] = C
|
||||
|
||||
|
||||
def setD(self, D):
|
||||
def setD(self, D):
|
||||
|
||||
if not is_integer(D) and not is_float(D):
|
||||
msg = 'Unable to set D coefficient for Plane ID={0} to a non-integer ' \
|
||||
'value {1}'.format(self._id, D)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(D) and not is_float(D):
|
||||
msg = 'Unable to set D coefficient for Plane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, D)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['D'] = D
|
||||
self._coeffs['D'] = D
|
||||
|
||||
|
||||
|
||||
class XPlane(Plane):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, name=''):
|
||||
|
||||
# Initialize XPlane class attributes
|
||||
super(XPlane, self).__init__(surface_id, bc_type, name=name)
|
||||
# Initialize XPlane class attributes
|
||||
super(XPlane, self).__init__(surface_id, bc_type, name=name)
|
||||
|
||||
self._x0 = None
|
||||
self._type = 'x-plane'
|
||||
self._coeff_keys = ['x0']
|
||||
self._x0 = None
|
||||
self._type = 'x-plane'
|
||||
self._coeff_keys = ['x0']
|
||||
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
|
||||
|
||||
def setX0(self, x0):
|
||||
def setX0(self, x0):
|
||||
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for XPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for XPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['x0'] = x0
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
|
||||
|
||||
class YPlane(Plane):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
y0=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
y0=None, name=''):
|
||||
|
||||
# Initialize YPlane class attributes
|
||||
super(YPlane, self).__init__(surface_id, bc_type, name=name)
|
||||
# Initialize YPlane class attributes
|
||||
super(YPlane, self).__init__(surface_id, bc_type, name=name)
|
||||
|
||||
self._y0 = None
|
||||
self._type = 'y-plane'
|
||||
self._coeff_keys = ['y0']
|
||||
self._y0 = None
|
||||
self._type = 'y-plane'
|
||||
self._coeff_keys = ['y0']
|
||||
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
|
||||
|
||||
def setY0(self, y0):
|
||||
def setY0(self, y0):
|
||||
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for XPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for XPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['y0'] = y0
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
|
||||
|
||||
class ZPlane(Plane):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
z0=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
z0=None, name=''):
|
||||
|
||||
# Initialize ZPlane class attributes
|
||||
super(ZPlane, self).__init__(surface_id, bc_type, name=name)
|
||||
# Initialize ZPlane class attributes
|
||||
super(ZPlane, self).__init__(surface_id, bc_type, name=name)
|
||||
|
||||
self._z0 = None
|
||||
self._type = 'z-plane'
|
||||
self._coeff_keys = ['z0']
|
||||
self._z0 = None
|
||||
self._type = 'z-plane'
|
||||
self._coeff_keys = ['z0']
|
||||
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
|
||||
|
||||
def setZ0(self, z0):
|
||||
def setZ0(self, z0):
|
||||
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for ZPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for ZPlane ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['z0'] = z0
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
|
||||
|
||||
class Cylinder(Surface):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
R=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
R=None, name=''):
|
||||
|
||||
# Initialize Cylinder class attributes
|
||||
super(Cylinder, self).__init__(surface_id, bc_type, name=name)
|
||||
# Initialize Cylinder class attributes
|
||||
super(Cylinder, self).__init__(surface_id, bc_type, name=name)
|
||||
|
||||
self._R = None
|
||||
self._coeff_keys = ['R']
|
||||
self._R = None
|
||||
self._coeff_keys = ['R']
|
||||
|
||||
if not R is None:
|
||||
self.setR(R)
|
||||
if not R is None:
|
||||
self.setR(R)
|
||||
|
||||
|
||||
def setR(self, R):
|
||||
def setR(self, R):
|
||||
|
||||
if not is_integer(R) and not is_float(R):
|
||||
msg = 'Unable to set R coefficient for Cylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, R)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(R) and not is_float(R):
|
||||
msg = 'Unable to set R coefficient for Cylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, R)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['R'] = R
|
||||
self._coeffs['R'] = R
|
||||
|
||||
|
||||
|
||||
class XCylinder(Cylinder):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
y0=None, z0=None, R=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
y0=None, z0=None, R=None, name=''):
|
||||
|
||||
# Initialize XCylinder class attributes
|
||||
super(XCylinder, self).__init__(surface_id, bc_type, R, name=name)
|
||||
# Initialize XCylinder class attributes
|
||||
super(XCylinder, self).__init__(surface_id, bc_type, R, name=name)
|
||||
|
||||
self._type = 'x-cylinder'
|
||||
self._y0 = None
|
||||
self._z0 = None
|
||||
self._coeff_keys = ['y0', 'z0', 'R']
|
||||
self._type = 'x-cylinder'
|
||||
self._y0 = None
|
||||
self._z0 = None
|
||||
self._coeff_keys = ['y0', 'z0', 'R']
|
||||
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
|
||||
|
||||
def setY0(self, y0):
|
||||
def setY0(self, y0):
|
||||
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for XCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for XCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['y0'] = y0
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
|
||||
def setZ0(self, z0):
|
||||
def setZ0(self, z0):
|
||||
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for XCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for XCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['z0'] = z0
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
|
||||
|
||||
class YCylinder(Cylinder):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, z0=None, R=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, z0=None, R=None, name=''):
|
||||
|
||||
# Initialize YCylinder class attributes
|
||||
super(YCylinder, self).__init__(surface_id, bc_type, R, name=name)
|
||||
# Initialize YCylinder class attributes
|
||||
super(YCylinder, self).__init__(surface_id, bc_type, R, name=name)
|
||||
|
||||
self._type = 'y-cylinder'
|
||||
self._x0 = None
|
||||
self._z0 = None
|
||||
self._coeff_keys = ['x0', 'z0', 'R']
|
||||
self._type = 'y-cylinder'
|
||||
self._x0 = None
|
||||
self._z0 = None
|
||||
self._coeff_keys = ['x0', 'z0', 'R']
|
||||
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
|
||||
|
||||
def setX0(self, x0):
|
||||
def setX0(self, x0):
|
||||
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for YCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for YCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['x0'] = x0
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
|
||||
def setZ0(self, z0):
|
||||
def setZ0(self, z0):
|
||||
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for YCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for YCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['z0'] = z0
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
|
||||
class ZCylinder(Cylinder):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, R=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, R=None, name=''):
|
||||
|
||||
# Initialize ZCylinder class attributes
|
||||
# Initialize YPlane class attributes
|
||||
super(ZCylinder, self).__init__(surface_id, bc_type, R, name=name)
|
||||
# Initialize ZCylinder class attributes
|
||||
# Initialize YPlane class attributes
|
||||
super(ZCylinder, self).__init__(surface_id, bc_type, R, name=name)
|
||||
|
||||
self._type = 'z-cylinder'
|
||||
self._x0 = None
|
||||
self._y0 = None
|
||||
self._coeff_keys = ['x0', 'y0', 'R']
|
||||
self._type = 'z-cylinder'
|
||||
self._x0 = None
|
||||
self._y0 = None
|
||||
self._coeff_keys = ['x0', 'y0', 'R']
|
||||
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
|
||||
|
||||
def setX0(self, x0):
|
||||
def setX0(self, x0):
|
||||
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for ZCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for ZCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['x0'] = x0
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
|
||||
def setY0(self, y0):
|
||||
def setY0(self, y0):
|
||||
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for ZCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for ZCylinder ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['y0'] = y0
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
|
||||
|
||||
class Sphere(Surface):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R=None, name=''):
|
||||
|
||||
# Initialize Sphere class attributes
|
||||
super(Sphere, self).__init__(surface_id, bc_type, name=name)
|
||||
# Initialize Sphere class attributes
|
||||
super(Sphere, self).__init__(surface_id, bc_type, name=name)
|
||||
|
||||
self._type = 'sphere'
|
||||
self._x0 = None
|
||||
self._y0 = None
|
||||
self._z0 = None
|
||||
self._R = None
|
||||
self._coeff_keys = ['x0', 'y0', 'z0', 'R']
|
||||
self._type = 'sphere'
|
||||
self._x0 = None
|
||||
self._y0 = None
|
||||
self._z0 = None
|
||||
self._R = None
|
||||
self._coeff_keys = ['x0', 'y0', 'z0', 'R']
|
||||
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
|
||||
if not R is None:
|
||||
self.setZ0(R)
|
||||
if not R is None:
|
||||
self.setZ0(R)
|
||||
|
||||
|
||||
def setX0(self, x0):
|
||||
def setX0(self, x0):
|
||||
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['x0'] = x0
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
|
||||
def setY0(self, y0):
|
||||
def setY0(self, y0):
|
||||
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['y0'] = y0
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
|
||||
def setZ0(self, z0):
|
||||
def setZ0(self, z0):
|
||||
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['z0'] = z0
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
|
||||
def setR(self, R):
|
||||
def setR(self, R):
|
||||
|
||||
if not is_integer(R) and not is_float(R):
|
||||
msg = 'Unable to set R coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, R)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(R) and not is_float(R):
|
||||
msg = 'Unable to set R coefficient for Sphere ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, R)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['R'] = R
|
||||
self._coeffs['R'] = R
|
||||
|
||||
|
||||
|
||||
class Cone(Surface):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R2=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R2=None, name=''):
|
||||
|
||||
# Initialize Cone class attributes
|
||||
super(Cone, self).__init__(surface_id, bc_type, name=name)
|
||||
# Initialize Cone class attributes
|
||||
super(Cone, self).__init__(surface_id, bc_type, name=name)
|
||||
|
||||
self._x0 = None
|
||||
self._y0 = None
|
||||
self._z0 = None
|
||||
self._R2 = None
|
||||
self._coeff_keys = ['x0', 'y0', 'z0', 'R2']
|
||||
self._x0 = None
|
||||
self._y0 = None
|
||||
self._z0 = None
|
||||
self._R2 = None
|
||||
self._coeff_keys = ['x0', 'y0', 'z0', 'R2']
|
||||
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
if not x0 is None:
|
||||
self.setX0(x0)
|
||||
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
if not y0 is None:
|
||||
self.setY0(y0)
|
||||
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
if not z0 is None:
|
||||
self.setZ0(z0)
|
||||
|
||||
if not R2 is None:
|
||||
self.setZ0(R2)
|
||||
if not R2 is None:
|
||||
self.setZ0(R2)
|
||||
|
||||
|
||||
def setX0(self, x0):
|
||||
def setX0(self, x0):
|
||||
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(x0) and not is_float(x0):
|
||||
msg = 'Unable to set x0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, x0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['x0'] = x0
|
||||
self._coeffs['x0'] = x0
|
||||
|
||||
|
||||
def setY0(self, y0):
|
||||
def setY0(self, y0):
|
||||
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(y0) and not is_float(y0):
|
||||
msg = 'Unable to set y0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, y0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['y0'] = y0
|
||||
self._coeffs['y0'] = y0
|
||||
|
||||
|
||||
def setZ0(self, z0):
|
||||
def setZ0(self, z0):
|
||||
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(z0) and not is_float(z0):
|
||||
msg = 'Unable to set z0 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, z0)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['z0'] = z0
|
||||
self._coeffs['z0'] = z0
|
||||
|
||||
|
||||
def setR2(self, R2):
|
||||
def setR2(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 ' \
|
||||
'non-integer value {1}'.format(self._id, R2)
|
||||
raise ValueError(msg)
|
||||
if not is_integer(R2) and not is_float(R2):
|
||||
msg = 'Unable to set R^2 coefficient for Cone ID={0} to a ' \
|
||||
'non-integer value {1}'.format(self._id, R2)
|
||||
raise ValueError(msg)
|
||||
|
||||
self._coeffs['R2'] = R2
|
||||
self._coeffs['R2'] = R2
|
||||
|
||||
|
||||
|
||||
class XCone(Cone):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R2=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R2=None, name=''):
|
||||
|
||||
# Initialize XCone class attributes
|
||||
super(XCone, self).__init__(surface_id, bc_type, x0, y0, z0, R2, name=name)
|
||||
# Initialize XCone class attributes
|
||||
super(XCone, self).__init__(surface_id, bc_type, x0, y0, z0, R2, name=name)
|
||||
|
||||
self._type = 'x-cone'
|
||||
self._type = 'x-cone'
|
||||
|
||||
|
||||
|
||||
class YCone(Cone):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R2=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R2=None, name=''):
|
||||
|
||||
# Initialize YCone class attributes
|
||||
super(YCone, self).__init__(surface_id, bc_type, x0, y0, z0, R2, name=name)
|
||||
# Initialize YCone class attributes
|
||||
super(YCone, self).__init__(surface_id, bc_type, x0, y0, z0, R2, name=name)
|
||||
|
||||
self._type = 'y-cone'
|
||||
self._type = 'y-cone'
|
||||
|
||||
|
||||
|
||||
class ZCone(Cone):
|
||||
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R2=None, name=''):
|
||||
def __init__(self, surface_id=None, bc_type='transmission',
|
||||
x0=None, y0=None, z0=None, R2=None, name=''):
|
||||
|
||||
# Initialize ZCone class attributes
|
||||
super(ZCone, self).__init__(surface_id, bc_type, x0, y0, z0, R2, name=name)
|
||||
# Initialize ZCone class attributes
|
||||
super(ZCone, self).__init__(surface_id, bc_type, x0, y0, z0, R2, name=name)
|
||||
|
||||
self._type = 'z-cone'
|
||||
self._type = 'z-cone'
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue