diff --git a/src/utils/openmc/__init__.py b/src/utils/openmc/__init__.py index 3508543d83..5e5ec08b99 100644 --- a/src/utils/openmc/__init__.py +++ b/src/utils/openmc/__init__.py @@ -9,10 +9,11 @@ from openmc.settings import * from openmc.surface import * from openmc.universe import * from openmc.tallies import * +from openmc.cmfd import * from openmc.executor import * #from statepoint import * try: - from openmc.opencsg_compatible import * + from openmc.opencg_compatible import * except ImportError: pass diff --git a/src/utils/openmc/cmfd.py b/src/utils/openmc/cmfd.py new file mode 100644 index 0000000000..4b7802ba3d --- /dev/null +++ b/src/utils/openmc/cmfd.py @@ -0,0 +1,586 @@ +#!/usr/bin/env python + +from openmc.checkvalue import * +from openmc.clean_xml import * +from xml.etree import ElementTree as ET +import numpy as np + + +class CMFDMesh(object): + + def __init__(self): + + self._lower_left = None + self._upper_right = None + self._dimension = None + self._width = None + self._energy = None + self._albedo = None + self._map = None + + + def set_lower_left(self, lower_left): + + if not isinstance(lower_left, (tuple, list, np.ndarray)): + msg = 'Unable to set CMFD Mesh with lower_left {0} which is ' \ + 'not a Python list, tuple or NumPy array'.format(lower_left) + raise ValueError(msg) + + elif len(lower_left) != 2 and len(lower_left) != 3: + msg = 'Unable to set CMFD Mesh with lower_left {0} since it ' \ + 'must include 2 or 3 dimensions'.format(lower_left) + raise ValueError(msg) + + for coord in lower_left: + + if not is_integer(coord) and not is_float(coord): + msg = 'Unable to set CMFD Mesh with lower_left {0} which is ' \ + 'not an integer or a floating point value'.format(coord) + raise ValueError(msg) + + self._lower_left = lower_left + + + def set_upper_right(self, upper_right): + + if not isinstance(upper_right, (tuple, list, np.ndarray)): + msg = 'Unable to set CMFD Mesh with upper_right {0} which is ' \ + 'not a Python list, tuple or NumPy array'.format(upper_right) + raise ValueError(msg) + + if len(upper_right) != 2 and len(upper_right) != 3: + msg = 'Unable to set CMFD Mesh with upper_right {0} since it ' \ + 'must include 2 or 3 dimensions'.format(upper_right) + raise ValueError(msg) + + for coord in upper_right: + + if not is_integer(coord) and not is_float(coord): + msg = 'Unable to set CMFD Mesh with upper_right {0} which ' \ + 'is not an integer or floating point value'.format(coord) + raise ValueError(msg) + + self._upper_right = upper_right + + + def set_dimension(self, dimension): + + if not isinstance(dimension, (tuple, list, np.ndarray)): + msg = 'Unable to set CMFD Mesh with dimension {0} which is ' \ + 'not a Python list, tuple or NumPy array'.format(dimension) + raise ValueError(msg) + + elif len(dimension) != 2 and len(dimension) != 3: + msg = 'Unable to set CMFD Mesh with dimension {0} since it ' \ + 'must include 2 or 3 dimensions'.format(dimension) + raise ValueError(msg) + + for dim in dimension: + + if not is_integer(dim): + msg = 'Unable to set CMFD Mesh with dimension {0} which ' \ + 'is a non-integer'.format(dim) + raise ValueError(msg) + + self._dimension = dimension + + + def set_width(self, width): + + if not width is None: + + if not isinstance(width, (tuple, list, np.ndarray)): + msg = 'Unable to set CMFD Mesh with width {0} which ' \ + 'is not a Python list, tuple or NumPy array'.format(width) + raise ValueError(msg) + + if len(width) != 2 and len(width) != 3: + msg = 'Unable to set CMFD Mesh with width {0} since it must ' \ + 'include 2 or 3 dimensions'.format(width) + raise ValueError(msg) + + for dim in width: + + if not is_integer(dim) and not is_float(dim): + msg = 'Unable to set CMFD Mesh with width {0} which is ' \ + 'not an integer or floating point value'.format(width) + raise ValueError(msg) + + self._width = width + + + def set_energy(self, energy): + + if not isinstance(energy, (tuple, list, np.ndarray)): + msg = 'Unable to set CMFD Mesh energy to {0} which is not ' \ + 'a Python tuple/list or NumPy array'.format(energy) + raise ValueError(msg) + + for e in energy: + + if not is_integer(e) and not is_float(e): + msg = 'Unable to set CMFD Mesh energy to {0} which is not ' \ + 'an integer or floating point value'.format(e) + raise ValueError(msg) + + elif e < 0: + msg = 'Unable to set CMFD Mesh energy to {0} which is ' \ + 'is a negative integer'.format(e) + raise ValueError(msg) + + self._energy = energy + + + def set_albedo(self, albedo): + + if not isinstance(albedo, (tuple, list, np.ndarray)): + msg = 'Unable to set CMFD Mesh albedo to {0} which is not ' \ + 'a Python tuple/list or NumPy array'.format(albedo) + raise ValueError(msg) + + if not len(albedo) == 6: + msg = 'Unable to set CMFD Mesh albedo to {0} which is not ' \ + 'length 6 for +/-x,y,z'.format(albedo) + raise ValueError(msg) + + for a in albedo: + + if not is_integer(a) and not is_float(a): + msg = 'Unable to set CMFD Mesh albedo to {0} which is not ' \ + 'an integer or floating point value'.format(a) + raise ValueError(msg) + + elif a < 0 or a > 1: + msg = 'Unable to set CMFD Mesh albedo to {0} which is ' \ + 'is not in [0,1]'.format(a) + raise ValueError(msg) + + self._albedo = albedo + + + def set_map(self, map): + + if not isinstance(map, (tuple, list, np.ndarray)): + msg = 'Unable to set CMFD Mesh map to {0} which is not ' \ + 'a Python tuple/list or NumPy array'.format(map) + raise ValueError(msg) + + for m in map: + + if m != 1 and m != 2: + msg = 'Unable to set CMFD Mesh map to {0} which is ' \ + 'is not 1 or 2'.format(m) + raise ValueError(msg) + + self._map = map + + + def get_mesh_xml(self): + + element = ET.Element("mesh") + + if len(self._lower_left) == 2: + subelement = ET.SubElement(element, "lower_left") + subelement.text = '{0} {1}'.format(self._lower_left[0], + self._lower_left[1]) + else: + subelement = ET.SubElement(element, "lower_left") + subelement.text = '{0} {1} {2}'.format(self._lower_left[0], + self._lower_left[1], + self._lower_left[2]) + + if not self._upper_right is None: + if len(self._upper_right) == 2: + subelement = ET.SubElement(element, "upper_right") + subelement.text = '{0} {1}'.format(self._upper_right[0], + self._upper_right[1]) + else: + subelement = ET.SubElement(element, "upper_right") + subelement.text = '{0} {1} {2}'.format(self._upper_right[0], + self._upper_right[1], + self._upper_right[2]) + + if len(self._dimension) == 2: + subelement = ET.SubElement(element, "dimension") + subelement.text = '{0} {1}'.format(self._dimension[0], + self._dimension[1]) + else: + subelement = ET.SubElement(element, "dimension") + subelement.text = '{0} {1} {2}'.format(self._dimension[0], + self._dimension[1], + self._dimension[2]) + + if not self._width is None: + if len(self._width) == 2: + subelement = ET.SubElement(element, "width") + subelement.text = '{0} {1}'.format(self._width[0], + self._width[1]) + else: + subelement = ET.SubElement(element, "width") + subelement.text = '{0} {1} {2}'.format(self._width[0], + self._width[1], + self._width[2]) + + if not self._energy is None: + + subelement = ET.SubElement(element, "energy") + + energy = '' + for e in self._energy: + energy += '{0} '.format(e) + + subelement.set("energy", energy.rstrip(' ')) + + if not self._albedo is None: + + subelement = ET.SubElement(element, "albedo") + + albedo = '' + for a in self._albedo: + albedo += '{0} '.format(a) + + subelement.set("albedo", albedo.rstrip(' ')) + + if not self._map is None: + + subelement = ET.SubElement(element, "map") + + map = '' + for m in self._map: + map += '{0} '.format(m) + + subelement.set("map", map.rstrip(' ')) + + return element + + +class CMFDFile(object): + + def __init__(self): + + self._active_flush = None + self._begin = None + self._display = None + self._feedback = None + self._inactive = None + self._inactive_flush = None + self._ksp_monitor = None + self._cmfd_mesh = None + self._norm = None + self._num_flushes = None + self._power_monitor = None + self._run_adjoint = None + self._snes_monitor = None + self._solver = None + self._write_matrices = None + + self._cmfd_file = ET.Element("cmfd") + self._cmfd_mesh_element = None + + + def set_active_flush(self, active_flush): + + if not is_integer(active_flush): + msg = 'Unable to set CMFD active flush batch to a non-integer ' \ + 'value {0}'.format(active_flush) + raise ValueError(msg) + + if active_flush < 0: + msg = 'Unable to set CMFD active flush batch to a negative ' \ + 'value {0}'.format(active_flush) + raise ValueError(msg) + + self._active_flush = active_flush + + + def set_begin(self, begin): + + if not is_integer(begin): + msg = 'Unable to set CMFD begin batch to a non-integer ' \ + 'value {0}'.format(begin) + raise ValueError(msg) + + if begin <= 0: + msg = 'Unable to set CMFD begin batch batch to a negative ' \ + 'value {0}'.format(begin) + raise ValueError(msg) + + self._begin = begin + + + def set_display(self, display): + + if not is_string(display): + msg = 'Unable to set CMFD display to a non-string ' \ + 'value'.format(display) + raise ValueError(msg) + + if display not in ['balance', 'dominance', 'entropy', 'source']: + msg = 'Unable to set CMFD display to {0} which is ' \ + 'not an accepted value'.format(display) + raise ValueError(msg) + + self._display = display + + + def set_feedback(self, feedback): + + if not isinstance(feedback, bool): + msg = 'Unable to set CMFD feedback to {0} which is ' \ + 'a non-boolean value'.format(feedback) + raise ValueError(msg) + + self._feedback = feedback + + + def set_inactive(self, inactive): + + if not isinstance(inactive, bool): + msg = 'Unable to set CMFD inactive batch to {0} which is ' \ + ' a non-boolean value'.format(inactive) + raise ValueError(msg) + + self._inactive = inactive + + + def set_inactive_flush(self, inactive_flush): + + if not is_integer(inactive_flush): + msg = 'Unable to set CMFD inactive flush batch to {0} which is ' \ + 'a non-integer value'.format(inactive_flush) + raise ValueError(msg) + + if inactive_flush <= 0: + msg = 'Unable to set CMFD inactive flush batch to {0} which is ' \ + 'a negative value {0}'.format(inactive_flush) + raise ValueError(msg) + + self._inactive_flush = inactive_flush + + + def set_ksp_monitor(self, ksp_monitor): + + if not isinstance(ksp_monitor, bool): + msg = 'Unable to set CMFD ksp monitor to {0} which is a ' \ + 'non-boolean value'.format(ksp_monitor) + raise ValueError(msg) + + self._ksp_monitor = ksp_monitor + + + def set_mesh(self, mesh): + + if not isinstance(mesh, CMFDMesh): + msg = 'Unable to set CMFD mesh to {0} which is not a ' \ + 'CMFDMesh object'.format(mesh) + raise ValueError(msg) + + self._mesh = mesh + + + def set_norm(self, norm): + + if not is_integer(norm) and not is_float(norm): + msg = 'Unable to set the CMFD norm to {0} which is not ' \ + 'an integer or floating point value'.format(norm) + raise ValueError(msg) + + self._norm = norm + + + + def set_num_flushes(self, num_flushes): + + if not is_integer(num_flushes): + msg = 'Unable to set the CMFD number of flushes to {0} ' \ + 'which is not an integer value'.format(num_flushes) + raise ValueError(msg) + + if num_flushes < 0: + msg = 'Unable to set CMFD number of flushes to a negative ' \ + 'value {0}'.format(num_flushes) + raise ValueError(msg) + + self._num_flushes = num_flushes + + + def set_power_monitor(self, power_monitor): + + if not isinstance(power_monitor, bool): + msg = 'Unable to set CMFD power monitor to {0} which is a ' \ + 'non-boolean value'.format(power_monitor) + raise ValueError(msg) + + self._power_monitor = power_monitor + + + def set_run_adjoint(self, run_adjoint): + + if not isinstance(run_adjoint, bool): + msg = 'Unable to set CMFD run adjoint to {0} which is a ' \ + 'non-boolean value'.format(run_adjoint) + raise ValueError(msg) + + self._run_adjoint = run_adjoint + + + def set_snes_monitor(self, snes_monitor): + + if not isinstance(snes_monitor, bool): + msg = 'Unable to set CMFD snes monitor to {0} which is a ' \ + 'non-boolean value'.format(snes_monitor) + raise ValueError(msg) + + self._snes_monitor = snes_monitor + + + def set_solver(self, solver): + + if not solver in ['power', 'jfnk']: + msg = 'Unable to set CMFD solver to {0} which is not ' \ + '"power" or "jfnk"'.format(solver) + raise ValueError(msg) + + self._solver = solver + + + def set_write_matrices(self, write_matrices): + + if not isinstance(write_matrices, bool): + msg = 'Unable to set CMFD write matrices to {0} which is a ' \ + 'non-boolean value'.format(write_matrices) + raise ValueError(msg) + + self._write_matrices = write_matrices + + + def create_active_flush_subelement(self): + + if not self._active_flush is None: + element = ET.SubElement(self._cmfd_file, "active_flush") + element.text = '{0}'.format(str(self._active_flush)) + + + def create_begin_subelement(self): + + if not self._begin is None: + element = ET.SubElement(self._cmfd_file, "begin") + element.text = '{0}'.format(str(self._begin)) + + + def create_display_subelement(self): + + if not self._display is None: + element = ET.SubElement(self._cmfd_file, "display") + element.text = '{0}'.format(str(self._display)) + + + def create_feedback_subelement(self): + + if not self._feedback is None: + element = ET.SubElement(self._cmfd_file, "feeback") + element.text = '{0}'.format(str(self._feedback).lower()) + + + def create_inactive_subelement(self): + + if not self._inactive is None: + element = ET.SubElement(self._cmfd_file, "inactive") + element.text = '{0}'.format(str(self._inactive).lower()) + + + def create_inactive_flush_subelement(self): + + if not self._inactive_flush is None: + element = ET.SubElement(self._cmfd_file, "inactive_flush") + element.text = '{0}'.format(str(self._inactive_flush)) + + + def create_ksp_monitor_subelement(self): + + if not self._ksp_monitor is None: + element = ET.SubElement(self._cmfd_file, "ksp_monitor") + element.text = '{0}'.format(str(self._ksp_monitor).lower()) + + + def create_mesh_subelement(self): + + if not self._mesh is None: + xml_element = self._mesh.get_mesh_xml() + self._cmfd_file.append(xml_element) + + + def create_norm_subelement(self): + + if not self._num_flushes is None: + element = ET.SubElement(self._cmfd_file, "norm") + element.text = '{0}'.format(str(self._norm)) + + + def create_num_flushes_subelement(self): + + if not self._num_flushes is None: + element = ET.SubElement(self._cmfd_file, "num_flushes") + element.text = '{0}'.format(str(self._num_flushes)) + + + def create_power_monitor_subelement(self): + + if not self._power_monitor is None: + element = ET.SubElement(self._cmfd_file, "power_monitor") + element.text = '{0}'.format(str(self._power_monitor).lower()) + + + def create_run_adjoint_subelement(self): + + if not self._run_adjoint is None: + element = ET.SubElement(self._cmfd_file, "run_adjoint") + element.text = '{0}'.format(str(self._run_adjoint).lower()) + + + def create_snes_monitor_subelement(self): + + if not self._snes_monitor is None: + element = ET.SubElement(self._cmfd_file, "snes_monitor") + element.text = '{0}'.format(str(self._snes_monitor).lower()) + + + def create_solver_subelement(self): + + if not self._solver is None: + element = ET.SubElement(self._cmfd_file, "solver") + element.text = '{0}'.format(str(self._solver)) + + + def create_write_matrices_subelement(self): + + if not self._write_matrices is None: + element = ET.SubElement(self._cmfd_file, "write_matrices") + element.text = '{0}'.format(str(self._write_matrices).lower()) + + + def export_to_xml(self): + + self.create_active_flush_subelement() + self.create_begin_subelement() + self.create_display_subelement() + self.create_feedback_subelement() + self.create_inactive_subelement() + self.create_inactive_flush_subelement() + self.create_ksp_monitor_subelement() + self.create_mesh_subelement() + self.create_norm_subelement() + self.create_num_flushes_subelement() + self.create_power_monitor_subelement() + self.create_run_adjoint_subelement() + self.create_snes_monitor_subelement() + self.create_solver_subelement() + self.create_write_matrices_subelement() + + # Clean the indentation in the file to be user-readable + clean_xml_indentation(self._cmfd_file) + + # Write the XML Tree to the cmfd.xml file + tree = ET.ElementTree(self._cmfd_file) + tree.write("cmfd.xml", xml_declaration=True, + encoding='utf-8', method="xml") \ No newline at end of file diff --git a/src/utils/openmc/opencsg_compatible.py b/src/utils/openmc/opencg_compatible.py similarity index 57% rename from src/utils/openmc/opencsg_compatible.py rename to src/utils/openmc/opencg_compatible.py index 52845b956f..300f269a96 100644 --- a/src/utils/openmc/opencsg_compatible.py +++ b/src/utils/openmc/opencg_compatible.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import openmc -import opencsg +import opencg import copy import numpy as np @@ -11,7 +11,7 @@ import numpy as np # Values - Materials OPENMC_MATERIALS = dict() -# A dictionary of all OpenCSG Materials created +# A dictionary of all OpenCG Materials created # Keys - Material IDs # Values - Materials OPENCSG_MATERIALS = dict() @@ -21,7 +21,7 @@ OPENCSG_MATERIALS = dict() # Values - Surfaces OPENMC_SURFACES = dict() -# A dictionary of all OpenCSG Surfaces created +# A dictionary of all OpenCG Surfaces created # Keys - Surface IDs # Values - Surfaces OPENCSG_SURFACES = dict() @@ -31,7 +31,7 @@ OPENCSG_SURFACES = dict() # Values - Cells OPENMC_CELLS = dict() -# A dictionary of all OpenCSG Cells created +# A dictionary of all OpenCG Cells created # Keys - Cell IDs # Values - Cells OPENCSG_CELLS = dict() @@ -41,7 +41,7 @@ OPENCSG_CELLS = dict() # Values - Universes OPENMC_UNIVERSES = dict() -# A dictionary of all OpenCSG Universes created +# A dictionary of all OpenCG Universes created # Keys - Universes IDs # Values - Universes OPENCSG_UNIVERSES = dict() @@ -51,17 +51,17 @@ OPENCSG_UNIVERSES = dict() # Values - Lattices OPENMC_LATTICES = dict() -# A dictionary of all OpenCSG Lattices created +# A dictionary of all OpenCG Lattices created # Keys - Lattice IDs # Values - Lattices OPENCSG_LATTICES = dict() -def get_opencsg_material(openmc_material): +def get_opencg_material(openmc_material): if not isinstance(openmc_material, openmc.Material): - msg = 'Unable to create an OpenCSG Material from {0} ' \ + msg = 'Unable to create an OpenCG Material from {0} ' \ 'which is not an OpenMC Material'.format(openmc_material) raise ValueError(msg) @@ -72,64 +72,64 @@ def get_opencsg_material(openmc_material): if material_id in OPENCSG_MATERIALS: return OPENCSG_MATERIALS[material_id] - # Create an OpenCSG Material to represent this OpenMC Material + # Create an OpenCG Material to represent this OpenMC Material name = openmc_material._name - opencsg_material = opencsg.Material(material_id=material_id, name=name) + opencg_material = opencg.Material(material_id=material_id, name=name) # Add the OpenMC Material to the global collection of all OpenMC Materials OPENMC_MATERIALS[material_id] = openmc_material - # Add the OpenCSG Material to the global collection of all OpenCSG Materials - OPENCSG_MATERIALS[material_id] = opencsg_material + # Add the OpenCG Material to the global collection of all OpenCG Materials + OPENCSG_MATERIALS[material_id] = opencg_material - return opencsg_material + return opencg_material -def get_openmc_material(opencsg_material): +def get_openmc_material(opencg_material): - if not isinstance(opencsg_material, opencsg.Material): + if not isinstance(opencg_material, opencg.Material): msg = 'Unable to create an OpenMC Material from {0} ' \ - 'which is not an OpenCSG Material'.format(opencsg_material) + 'which is not an OpenCG Material'.format(opencg_material) raise ValueError(msg) global OPENMC_MATERIALS - material_id = opencsg_material._id + material_id = opencg_material._id # If this Material was already created, use it if material_id in OPENMC_MATERIALS: return OPENMC_MATERIALS[material_id] - # Create an OpenMC Material to represent this OpenCSG Material - name = opencsg_material._name + # Create an OpenMC Material to represent this OpenCG Material + name = opencg_material._name openmc_material = openmc.Material(material_id=material_id, name=name) # Add the OpenMC Material to the global collection of all OpenMC Materials OPENMC_MATERIALS[material_id] = openmc_material - # Add the OpenCSG Material to the global collection of all OpenCSG Materials - OPENCSG_MATERIALS[material_id] = opencsg_material + # Add the OpenCG Material to the global collection of all OpenCG Materials + OPENCSG_MATERIALS[material_id] = opencg_material return openmc_material -def is_opencsg_surface_compatible(opencsg_surface): +def is_opencg_surface_compatible(opencg_surface): - if not isinstance(opencsg_surface, opencsg.Surface): - msg = 'Unable to check if OpenCSG Surface is compatible' \ - 'since {0} is not a Surface'.format(opencsg_surface) + if not isinstance(opencg_surface, opencg.Surface): + msg = 'Unable to check if OpenCG Surface is compatible' \ + 'since {0} is not a Surface'.format(opencg_surface) raise ValueError(msg) - if opencsg_surface._type in ['x-squareprism', + if opencg_surface._type in ['x-squareprism', 'y-squareprism', 'z-squareprism']: return False else: return True -def get_opencsg_surface(openmc_surface): +def get_opencg_surface(openmc_surface): if not isinstance(openmc_surface, openmc.Surface): - msg = 'Unable to create an OpenCSG Surface from {0} ' \ + msg = 'Unable to create an OpenCG Surface from {0} ' \ 'which is not an OpenMC Surface'.format(openmc_surface) raise ValueError(msg) @@ -140,7 +140,7 @@ def get_opencsg_surface(openmc_surface): if surface_id in OPENCSG_SURFACES: return OPENCSG_SURFACES[surface_id] - # Create an OpenCSG Surface to represent this OpenMC Surface + # Create an OpenCG Surface to represent this OpenMC Surface name = openmc_surface._name # Correct for OpenMC's syntax for Surfaces dividing Cells @@ -148,205 +148,205 @@ def get_opencsg_surface(openmc_surface): if boundary == 'transmission': boundary = 'interface' - opencsg_surface = None + opencg_surface = None if openmc_surface._type == 'plane': A = openmc_surface._coeffs['A'] B = openmc_surface._coeffs['B'] C = openmc_surface._coeffs['C'] D = openmc_surface._coeffs['D'] - opencsg_surface = opencsg.Plane(surface_id, name, boundary, A, B, C, D) + opencg_surface = opencg.Plane(surface_id, name, boundary, A, B, C, D) elif openmc_surface._type == 'x-plane': x0 = openmc_surface._coeffs['x0'] - opencsg_surface = opencsg.XPlane(surface_id, name, boundary, x0) + opencg_surface = opencg.XPlane(surface_id, name, boundary, x0) elif openmc_surface._type == 'y-plane': y0 = openmc_surface._coeffs['y0'] - opencsg_surface = opencsg.YPlane(surface_id, name, boundary, y0) + opencg_surface = opencg.YPlane(surface_id, name, boundary, y0) elif openmc_surface._type == 'z-plane': z0 = openmc_surface._coeffs['z0'] - opencsg_surface = opencsg.ZPlane(surface_id, name, boundary, z0) + opencg_surface = opencg.ZPlane(surface_id, name, boundary, z0) elif openmc_surface._type == 'x-cylinder': y0 = openmc_surface._coeffs['y0'] z0 = openmc_surface._coeffs['z0'] R = openmc_surface._coeffs['R'] - opencsg_surface = opencsg.XCylinder(surface_id, name, + opencg_surface = opencg.XCylinder(surface_id, name, boundary, y0, z0, R) elif openmc_surface._type == 'y-cylinder': x0 = openmc_surface._coeffs['x0'] z0 = openmc_surface._coeffs['z0'] R = openmc_surface._coeffs['R'] - opencsg_surface = opencsg.YCylinder(surface_id, name, + opencg_surface = opencg.YCylinder(surface_id, name, boundary, x0, z0, R) elif openmc_surface._type == 'z-cylinder': x0 = openmc_surface._coeffs['x0'] y0 = openmc_surface._coeffs['y0'] R = openmc_surface._coeffs['R'] - opencsg_surface = opencsg.ZCylinder(surface_id, name, + opencg_surface = opencg.ZCylinder(surface_id, name, boundary, x0, y0, R) # Add the OpenMC Surface to the global collection of all OpenMC Surfaces OPENMC_SURFACES[surface_id] = openmc_surface - # Add the OpenCSG Surface to the global collection of all OpenCSG Surfaces - OPENCSG_SURFACES[surface_id] = opencsg_surface + # Add the OpenCG Surface to the global collection of all OpenCG Surfaces + OPENCSG_SURFACES[surface_id] = opencg_surface - return opencsg_surface + return opencg_surface -def get_openmc_surface(opencsg_surface): +def get_openmc_surface(opencg_surface): - if not isinstance(opencsg_surface, opencsg.Surface): + if not isinstance(opencg_surface, opencg.Surface): msg = 'Unable to create an OpenMC Surface from {0} which ' \ - 'is not an OpenCSG Surface'.format(opencsg_surface) + 'is not an OpenCG Surface'.format(opencg_surface) raise ValueError(msg) global openmc_surface - surface_id = opencsg_surface._id + surface_id = opencg_surface._id # If this Surface was already created, use it if surface_id in OPENMC_SURFACES: return OPENMC_SURFACES[surface_id] - # Create an OpenMC Surface to represent this OpenCSG Surface - name = opencsg_surface._name + # Create an OpenMC Surface to represent this OpenCG Surface + name = opencg_surface._name # Correct for OpenMC's syntax for Surfaces dividing Cells - boundary = opencsg_surface._boundary_type + boundary = opencg_surface._boundary_type if boundary == 'interface': boundary = 'transmission' - if opencsg_surface._type == 'plane': - A = opencsg_surface._coeffs['A'] - B = opencsg_surface._coeffs['B'] - C = opencsg_surface._coeffs['C'] - D = opencsg_surface._coeffs['D'] + if opencg_surface._type == 'plane': + A = opencg_surface._coeffs['A'] + B = opencg_surface._coeffs['B'] + C = opencg_surface._coeffs['C'] + D = opencg_surface._coeffs['D'] openmc_surface = openmc.Plane(surface_id, boundary, A, B, C, D, name) - elif opencsg_surface._type == 'x-plane': - x0 = opencsg_surface._coeffs['x0'] + elif opencg_surface._type == 'x-plane': + x0 = opencg_surface._coeffs['x0'] openmc_surface = openmc.XPlane(surface_id, boundary, x0, name) - elif opencsg_surface._type == 'y-plane': - y0 = opencsg_surface._coeffs['y0'] + elif opencg_surface._type == 'y-plane': + y0 = opencg_surface._coeffs['y0'] openmc_surface = openmc.YPlane(surface_id, boundary, y0, name) - elif opencsg_surface._type == 'z-plane': - z0 = opencsg_surface._coeffs['z0'] + elif opencg_surface._type == 'z-plane': + z0 = opencg_surface._coeffs['z0'] openmc_surface = openmc.ZPlane(surface_id, boundary, z0, name) - elif opencsg_surface._type == 'x-cylinder': - y0 = opencsg_surface._coeffs['y0'] - z0 = opencsg_surface._coeffs['z0'] - R = opencsg_surface._coeffs['R'] + elif opencg_surface._type == 'x-cylinder': + y0 = opencg_surface._coeffs['y0'] + z0 = opencg_surface._coeffs['z0'] + R = opencg_surface._coeffs['R'] openmc_surface = openmc.XCylinder(surface_id, boundary, y0, z0, R, name) - elif opencsg_surface._type == 'y-cylinder': - x0 = opencsg_surface._coeffs['x0'] - z0 = opencsg_surface._coeffs['z0'] - R = opencsg_surface._coeffs['R'] + elif opencg_surface._type == 'y-cylinder': + x0 = opencg_surface._coeffs['x0'] + z0 = opencg_surface._coeffs['z0'] + R = opencg_surface._coeffs['R'] openmc_surface = openmc.YCylinder(surface_id, boundary, x0, z0, R, name) - elif opencsg_surface._type == 'z-cylinder': - x0 = opencsg_surface._coeffs['x0'] - y0 = opencsg_surface._coeffs['y0'] - R = opencsg_surface._coeffs['R'] + elif opencg_surface._type == 'z-cylinder': + x0 = opencg_surface._coeffs['x0'] + y0 = opencg_surface._coeffs['y0'] + R = opencg_surface._coeffs['R'] openmc_surface = openmc.ZCylinder(surface_id, boundary, x0, y0, R, name) else: - msg = 'Unable to create an OpenMC Surface from an OpenCSG ' \ + msg = 'Unable to create an OpenMC Surface from an OpenCG ' \ 'Surface of type {0} since it is not a compatible ' \ - 'Surface type in OpenMC'.format(opencsg_surface._type) + 'Surface type in OpenMC'.format(opencg_surface._type) raise ValueError(msg) # Add the OpenMC Surface to the global collection of all OpenMC Surfaces OPENMC_SURFACES[surface_id] = openmc_surface - # Add the OpenCSG Surface to the global collection of all OpenCSG Surfaces - OPENCSG_SURFACES[surface_id] = opencsg_surface + # Add the OpenCG Surface to the global collection of all OpenCG Surfaces + OPENCSG_SURFACES[surface_id] = opencg_surface return openmc_surface -def get_compatible_opencsg_surfaces(opencsg_surface): +def get_compatible_opencg_surfaces(opencg_surface): - if not isinstance(opencsg_surface, opencsg.Surface): + if not isinstance(opencg_surface, opencg.Surface): msg = 'Unable to create an OpenMC Surface from {0} which ' \ - 'is not an OpenCSG Surface'.format(opencsg_surface) + 'is not an OpenCG Surface'.format(opencg_surface) raise ValueError(msg) global OPENMC_SURFACES - surface_id = opencsg_surface._id + surface_id = opencg_surface._id # If this Surface was already created, use it if surface_id in OPENMC_SURFACES: return OPENMC_SURFACES[surface_id] - # Create an OpenMC Surface to represent this OpenCSG Surface - name = opencsg_surface._name - boundary = opencsg_surface._boundary_type + # Create an OpenMC Surface to represent this OpenCG Surface + name = opencg_surface._name + boundary = opencg_surface._boundary_type - if opencsg_surface._type == 'x-squareprism': - y0 = opencsg_surface._coeffs['y0'] - z0 = opencsg_surface._coeffs['z0'] - R = opencsg_surface._coeffs['R'] + if opencg_surface._type == 'x-squareprism': + y0 = opencg_surface._coeffs['y0'] + z0 = opencg_surface._coeffs['z0'] + R = opencg_surface._coeffs['R'] # Create a list of the four planes we need - left = opencsg.YPlane(name=name, boundary=boundary, y0=y0-R) - right = opencsg.YPlane(name=name, boundary=boundary, y0=y0+R) - bottom = opencsg.ZPlane(name=name, boundary=boundary, z0=z0-R) - top = opencsg.ZPlane(name=name, boundary=boundary, z0=z0+R) + left = opencg.YPlane(name=name, boundary=boundary, y0=y0-R) + right = opencg.YPlane(name=name, boundary=boundary, y0=y0+R) + bottom = opencg.ZPlane(name=name, boundary=boundary, z0=z0-R) + top = opencg.ZPlane(name=name, boundary=boundary, z0=z0+R) surfaces = [left, right, bottom, top] - elif opencsg_surface._type == 'y-squareprism': - x0 = opencsg_surface._coeffs['x0'] - z0 = opencsg_surface._coeffs['z0'] - R = opencsg_surface._coeffs['R'] + elif opencg_surface._type == 'y-squareprism': + x0 = opencg_surface._coeffs['x0'] + z0 = opencg_surface._coeffs['z0'] + R = opencg_surface._coeffs['R'] # Create a list of the four planes we need - left = opencsg.XPlane(name=name, boundary=boundary, x0=x0-R) - right = opencsg.XPlane(name=name, boundary=boundary, x0=x0+R) - bottom = opencsg.ZPlane(name=name, boundary=boundary, z0=z0-R) - top = opencsg.ZPlane(name=name, boundary=boundary, z0=z0+R) + left = opencg.XPlane(name=name, boundary=boundary, x0=x0-R) + right = opencg.XPlane(name=name, boundary=boundary, x0=x0+R) + bottom = opencg.ZPlane(name=name, boundary=boundary, z0=z0-R) + top = opencg.ZPlane(name=name, boundary=boundary, z0=z0+R) surfaces = [left, right, bottom, top] - elif opencsg_surface._type == 'z-squareprism': - x0 = opencsg_surface._coeffs['x0'] - y0 = opencsg_surface._coeffs['y0'] - R = opencsg_surface._coeffs['R'] + elif opencg_surface._type == 'z-squareprism': + x0 = opencg_surface._coeffs['x0'] + y0 = opencg_surface._coeffs['y0'] + R = opencg_surface._coeffs['R'] # Create a list of the four planes we need - left = opencsg.XPlane(name=name, boundary=boundary, x0=x0-R) - right = opencsg.XPlane(name=name, boundary=boundary, x0=x0+R) - bottom = opencsg.YPlane(name=name, boundary=boundary, y0=y0-R) - top = opencsg.YPlane(name=name, boundary=boundary, y0=y0+R) + left = opencg.XPlane(name=name, boundary=boundary, x0=x0-R) + right = opencg.XPlane(name=name, boundary=boundary, x0=x0+R) + bottom = opencg.YPlane(name=name, boundary=boundary, y0=y0-R) + top = opencg.YPlane(name=name, boundary=boundary, y0=y0+R) surfaces = [left, right, bottom, top] else: - msg = 'Unable to create a compatible OpenMC Surface an OpenCSG ' \ + msg = 'Unable to create a compatible OpenMC Surface an OpenCG ' \ 'Surface of type {0} since it already a compatible ' \ - 'Surface type in OpenMC'.format(opencsg_surface._type) + 'Surface type in OpenMC'.format(opencg_surface._type) raise ValueError(msg) # Add the OpenMC Surface(s) to the global collection of all OpenMC Surfaces OPENMC_SURFACES[surface_id] = surfaces - # Add the OpenCSG Surface to the global collection of all OpenCSG Surfaces - OPENCSG_SURFACES[surface_id] = opencsg_surface + # Add the OpenCG Surface to the global collection of all OpenCG Surfaces + OPENCSG_SURFACES[surface_id] = opencg_surface return surfaces -def get_opencsg_cell(openmc_cell): +def get_opencg_cell(openmc_cell): if not isinstance(openmc_cell, openmc.Cell): - msg = 'Unable to create an OpenCSG Cell from {0} which ' \ + msg = 'Unable to create an OpenCG Cell from {0} which ' \ 'is not an OpenMC Cell'.format(openmc_cell) raise ValueError(msg) @@ -357,45 +357,45 @@ def get_opencsg_cell(openmc_cell): if cell_id in OPENCSG_CELLS: return OPENCSG_CELLS[cell_id] - # Create an OpenCSG Cell to represent this OpenMC Cell + # Create an OpenCG Cell to represent this OpenMC Cell name = openmc_cell._name - opencsg_cell = opencsg.Cell(cell_id, name) + opencg_cell = opencg.Cell(cell_id, name) fill = openmc_cell._fill if (openmc_cell._type == 'normal'): - opencsg_cell.setFill(get_opencsg_material(fill)) + opencg_cell.setFill(get_opencg_material(fill)) elif (openmc_cell._type == 'fill'): - opencsg_cell.setFill(get_opencsg_universe(fill)) + opencg_cell.setFill(get_opencg_universe(fill)) else: - opencsg_cell.setFill(get_opencsg_lattice(fill)) + opencg_cell.setFill(get_opencg_lattice(fill)) surfaces = openmc_cell._surfaces for surface_id in surfaces: surface = surfaces[surface_id][0] halfspace = surfaces[surface_id][1] - opencsg_cell.addSurface(get_opencsg_surface(surface), halfspace) + opencg_cell.addSurface(get_opencg_surface(surface), halfspace) # Add the OpenMC Cell to the global collection of all OpenMC Cells OPENMC_CELLS[cell_id] = openmc_cell - # Add the OpenCSG Cell to the global collection of all OpenCSG Cells - OPENCSG_CELLS[cell_id] = opencsg_cell + # Add the OpenCG Cell to the global collection of all OpenCG Cells + OPENCSG_CELLS[cell_id] = opencg_cell - return opencsg_cell + return opencg_cell -def get_compatible_opencsg_cells(opencsg_cell, opencsg_surface, halfspace): +def get_compatible_opencg_cells(opencg_cell, opencg_surface, halfspace): - if not isinstance(opencsg_cell, opencsg.Cell): + if not isinstance(opencg_cell, opencg.Cell): msg = 'Unable to create compatible OpenMC Cell from {0} which ' \ - 'is not an OpenCSG Cell'.format(opencsg_cell) + 'is not an OpenCG Cell'.format(opencg_cell) raise ValueError(msg) - elif not isinstance(opencsg_surface, opencsg.Surface): + elif not isinstance(opencg_surface, opencg.Surface): msg = 'Unable to create compatible OpenMC Cell since {0} is ' \ - 'not an OpenCSG Surface'.format(opencsg_surface) + 'not an OpenCG Surface'.format(opencg_surface) raise ValueError(msg) elif not halfspace in [-1, +1]: @@ -407,21 +407,21 @@ def get_compatible_opencsg_cells(opencsg_cell, opencsg_surface, halfspace): compatible_cells = list() # SquarePrism Surfaces - if opencsg_surface._type in ['x-squareprism', + if opencg_surface._type in ['x-squareprism', 'y-squareprism', 'z-squareprism']: # Get the compatible Surfaces (XPlanes and YPlanes) - compatible_surfaces = get_compatible_opencsg_surfaces(opencsg_surface) + compatible_surfaces = get_compatible_opencg_surfaces(opencg_surface) - opencsg_cell.removeSurface(opencsg_surface) + opencg_cell.removeSurface(opencg_surface) # If Cell is inside SquarePrism, add "inside" of Surface halfspaces if halfspace == -1: - opencsg_cell.addSurface(compatible_surfaces[0], +1) - opencsg_cell.addSurface(compatible_surfaces[1], -1) - opencsg_cell.addSurface(compatible_surfaces[2], +1) - opencsg_cell.addSurface(compatible_surfaces[3], -1) - compatible_cells.append(opencsg_cell) + opencg_cell.addSurface(compatible_surfaces[0], +1) + opencg_cell.addSurface(compatible_surfaces[1], -1) + opencg_cell.addSurface(compatible_surfaces[2], +1) + opencg_cell.addSurface(compatible_surfaces[3], -1) + compatible_cells.append(opencg_cell) # If Cell is outside SquarePrism, add "outside" of Surface halfspaces else: @@ -432,8 +432,8 @@ def get_compatible_opencsg_cells(opencsg_cell, opencsg_surface, halfspace): for clone_id in range(num_clones): - # Create a cloned OpenCSG Cell with Surfaces compatible with OpenMC - clone = opencsg_cell.clone() + # Create a cloned OpenCG Cell with Surfaces compatible with OpenMC + clone = opencg_cell.clone() compatible_cells.append(clone) # Top left subcell - add left XPlane, top YPlane @@ -484,81 +484,81 @@ def get_compatible_opencsg_cells(opencsg_cell, opencsg_surface, halfspace): for cell in compatible_cells: cell.removeRedundantSurfaces() - # Return the list of OpenMC compatible OpenCSG Cells + # Return the list of OpenMC compatible OpenCG Cells return compatible_cells -def make_opencsg_cells_compatible(opencsg_universe): +def make_opencg_cells_compatible(opencg_universe): - if not isinstance(opencsg_universe, opencsg.Universe): - msg = 'Unable to make compatible OpenCSG Cells for {0} which ' \ - 'is not an OpenCSG Universe'.format(opencsg_universe) + if not isinstance(opencg_universe, opencg.Universe): + msg = 'Unable to make compatible OpenCG Cells for {0} which ' \ + 'is not an OpenCG Universe'.format(opencg_universe) raise ValueError(msg) - # Check all OpenCSG Cells in this Universe for compatibility with OpenMC - opencsg_cells = opencsg_universe._cells + # Check all OpenCG Cells in this Universe for compatibility with OpenMC + opencg_cells = opencg_universe._cells - for cell_id, opencsg_cell in opencsg_cells.items(): + for cell_id, opencg_cell in opencg_cells.items(): - # Check each of the OpenCSG Surfaces for OpenMC compatibility - surfaces = opencsg_cell._surfaces + # Check each of the OpenCG Surfaces for OpenMC compatibility + surfaces = opencg_cell._surfaces for surface_id in surfaces: surface = surfaces[surface_id][0] halfspace = surfaces[surface_id][1] # If this Surface is not compatible with OpenMC, create compatible - # OpenCSG cells with a compatible version of this OpenCSG Surface - if not is_opencsg_surface_compatible(surface): + # OpenCG cells with a compatible version of this OpenCG Surface + if not is_opencg_surface_compatible(surface): - # Get one or more OpenCSG Cells that are compatible with OpenMC - # NOTE: This does not necessarily make OpenCSG fully compatible. + # Get one or more OpenCG Cells that are compatible with OpenMC + # NOTE: This does not necessarily make OpenCG fully compatible. # It only removes the incompatible Surface and replaces it with - # compatible OpenCSG Surface(s). The recursive call at the end + # compatible OpenCG Surface(s). The recursive call at the end # of this block is necessary in the event that there are more # incompatible Surfaces in this Cell that are not accounted for. - cells = get_compatible_opencsg_cells(opencsg_cell, + cells = get_compatible_opencg_cells(opencg_cell, surface, halfspace) - # Remove the non-compatible OpenCSG Cell from the Universe - opencsg_universe.removeCell(opencsg_cell) + # Remove the non-compatible OpenCG Cell from the Universe + opencg_universe.removeCell(opencg_cell) - # Add the compatible OpenCSG Cells to the Universe - opencsg_universe.addCells(cells) + # Add the compatible OpenCG Cells to the Universe + opencg_universe.addCells(cells) # Make recursive call to look at the updated state of the - # OpenCSG Universe and return - return make_opencsg_cells_compatible(opencsg_universe) + # OpenCG Universe and return + return make_opencg_cells_compatible(opencg_universe) - # If all OpenCSG Cells in the OpenCSG Universe are compatible, return + # If all OpenCG Cells in the OpenCG Universe are compatible, return return -def get_openmc_cell(opencsg_cell): +def get_openmc_cell(opencg_cell): - if not isinstance(opencsg_cell, opencsg.Cell): + if not isinstance(opencg_cell, opencg.Cell): msg = 'Unable to create an OpenMC Cell from {0} which ' \ - 'is not an OpenCSG Cell'.format(opencsg_cell) + 'is not an OpenCG Cell'.format(opencg_cell) raise ValueError(msg) global OPENMC_CELLS - cell_id = opencsg_cell._id + cell_id = opencg_cell._id # If this Cell was already created, use it if cell_id in OPENMC_CELLS: return OPENMC_CELLS[cell_id] - # Create an OpenCSG Cell to represent this OpenMC Cell - name = opencsg_cell._name + # Create an OpenCG Cell to represent this OpenMC Cell + name = opencg_cell._name openmc_cell = openmc.Cell(cell_id, name) - fill = opencsg_cell._fill - rot = opencsg_cell._rotation + fill = opencg_cell._fill + rot = opencg_cell._rotation - if (opencsg_cell._type == 'universe'): + if (opencg_cell._type == 'universe'): openmc_cell.set_fill(get_openmc_universe(fill)) - elif (opencsg_cell._type == 'lattice'): + elif (opencg_cell._type == 'lattice'): openmc_cell.set_fill(get_openmc_lattice(fill)) else: openmc_cell.set_fill(get_openmc_material(fill)) @@ -566,7 +566,7 @@ def get_openmc_cell(opencsg_cell): if rot: openmc_cell.set_rotation(rot) - surfaces = opencsg_cell._surfaces + surfaces = opencg_cell._surfaces for surface_id in surfaces: surface = surfaces[surface_id][0] @@ -576,17 +576,17 @@ def get_openmc_cell(opencsg_cell): # Add the OpenMC Cell to the global collection of all OpenMC Cells OPENMC_CELLS[cell_id] = openmc_cell - # Add the OpenCSG Cell to the global collection of all OpenCSG Cells - OPENCSG_CELLS[cell_id] = opencsg_cell + # Add the OpenCG Cell to the global collection of all OpenCG Cells + OPENCSG_CELLS[cell_id] = opencg_cell return openmc_cell -def get_opencsg_universe(openmc_universe): +def get_opencg_universe(openmc_universe): if not isinstance(openmc_universe, openmc.Universe): - msg = 'Unable to create an OpenCSG Universe from {0} which ' \ + msg = 'Unable to create an OpenCG Universe from {0} which ' \ 'is not an OpenMC Universe'.format(openmc_universe) raise ValueError(msg) @@ -597,67 +597,67 @@ def get_opencsg_universe(openmc_universe): if universe_id in OPENCSG_UNIVERSES: return OPENCSG_UNIVERSES[universe_id] - # Create an OpenCSG Universe to represent this OpenMC Universe + # Create an OpenCG Universe to represent this OpenMC Universe name = openmc_universe._name - opencsg_universe = opencsg.Universe(universe_id, name) + opencg_universe = opencg.Universe(universe_id, name) - # Convert all OpenMC Cells in this Universe to OpenCSG Cells + # Convert all OpenMC Cells in this Universe to OpenCG Cells openmc_cells = openmc_universe._cells for cell_id, openmc_cell in openmc_cells.items(): - opencsg_cell = get_opencsg_cell(openmc_cell) - opencsg_universe.addCell(opencsg_cell) + opencg_cell = get_opencg_cell(openmc_cell) + opencg_universe.addCell(opencg_cell) # Add the OpenMC Universe to the global collection of all OpenMC Universes OPENMC_UNIVERSES[universe_id] = openmc_universe - # Add the OpenCSG Universe to the global collection of all OpenCSG Universes - OPENCSG_UNIVERSES[universe_id] = opencsg_universe + # Add the OpenCG Universe to the global collection of all OpenCG Universes + OPENCSG_UNIVERSES[universe_id] = opencg_universe - return opencsg_universe + return opencg_universe -def get_openmc_universe(opencsg_universe): +def get_openmc_universe(opencg_universe): - if not isinstance(opencsg_universe, opencsg.Universe): + if not isinstance(opencg_universe, opencg.Universe): msg = 'Unable to create an OpenMC Universe from {0} which ' \ - 'is not an OpenCSG Universe'.format(opencsg_universe) + 'is not an OpenCG Universe'.format(opencg_universe) raise ValueError(msg) global OPENMC_UNIVERSES - universe_id = opencsg_universe._id + universe_id = opencg_universe._id # If this Universe was already created, use it if universe_id in OPENMC_UNIVERSES: return OPENMC_UNIVERSES[universe_id] - # Make all OpenCSG Cells and Surfaces in this Universe compatible with OpenMC - make_opencsg_cells_compatible(opencsg_universe) + # Make all OpenCG Cells and Surfaces in this Universe compatible with OpenMC + make_opencg_cells_compatible(opencg_universe) # Create an OpenMC Universe to represent this OpenCSg Universe - name = opencsg_universe._name + name = opencg_universe._name openmc_universe = openmc.Universe(universe_id, name) - # Convert all OpenCSG Cells in this Universe to OpenMC Cells - opencsg_cells = opencsg_universe._cells + # Convert all OpenCG Cells in this Universe to OpenMC Cells + opencg_cells = opencg_universe._cells - for cell_id, opencsg_cell in opencsg_cells.items(): - openmc_cell = get_openmc_cell(opencsg_cell) + for cell_id, opencg_cell in opencg_cells.items(): + openmc_cell = get_openmc_cell(opencg_cell) openmc_universe.add_cell(openmc_cell) # Add the OpenMC Universe to the global collection of all OpenMC Universes OPENMC_UNIVERSES[universe_id] = openmc_universe - # Add the OpenCSG Universe to the global collection of all OpenCSG Universes - OPENCSG_UNIVERSES[universe_id] = opencsg_universe + # Add the OpenCG Universe to the global collection of all OpenCG Universes + OPENCSG_UNIVERSES[universe_id] = opencg_universe return openmc_universe -def get_opencsg_lattice(openmc_lattice): +def get_opencg_lattice(openmc_lattice): if not isinstance(openmc_lattice, openmc.Lattice): - msg = 'Unable to create an OpenCSG Lattice from {0} which ' \ + msg = 'Unable to create an OpenCG Lattice from {0} which ' \ 'is not an OpenMC Lattice'.format(openmc_lattice) raise ValueError(msg) @@ -668,22 +668,22 @@ def get_opencsg_lattice(openmc_lattice): if lattice_id in OPENCSG_LATTICES: return OPENCSG_LATTICES[lattice_id] - # Create an OpenCSG Lattice to represent this OpenMC Lattice + # Create an OpenCG Lattice to represent this OpenMC Lattice name = openmc_lattice._name dimension = openmc_lattice._dimension width = openmc_lattice._width lower_left = openmc_lattice._lower_left universes = openmc_lattice._universes - # Initialize an empty array for the OpenCSG nested Universes in this Lattice + # Initialize an empty array for the OpenCG nested Universes in this Lattice universe_array = np.ndarray(tuple(np.array(dimension)[::-1]), \ - dtype=opencsg.Universe) + dtype=opencg.Universe) - # Create OpenCSG Universes for each unique nested Universe in this Lattice + # Create OpenCG Universes for each unique nested Universe in this Lattice unique_universes = openmc_lattice.get_unique_universes() for universe_id, universe in unique_universes.items(): - unique_universes[universe_id] = get_opencsg_universe(universe) + unique_universes[universe_id] = get_opencg_universe(universe) # Build the nested Universe array for z in range(dimension[2]): @@ -695,50 +695,50 @@ def get_opencsg_lattice(openmc_lattice): # Reverse y-dimension in array for appropriate ordering in OpenCG universe_array = universe_array[:,::-1,:] - opencsg_lattice = opencsg.Lattice(lattice_id, name) - opencsg_lattice.setDimension(dimension) - opencsg_lattice.setWidth(width) - opencsg_lattice.setUniverses(universe_array) + opencg_lattice = opencg.Lattice(lattice_id, name) + opencg_lattice.setDimension(dimension) + opencg_lattice.setWidth(width) + opencg_lattice.setUniverses(universe_array) offset = np.array(lower_left, dtype=np.float64) - \ ((np.array(width, dtype=np.float64) * \ np.array(dimension, dtype=np.float64))) / -2.0 - opencsg_lattice.setOffset(offset) + opencg_lattice.setOffset(offset) # Add the OpenMC Lattice to the global collection of all OpenMC Lattices OPENMC_LATTICES[lattice_id] = openmc_lattice - # Add the OpenCSG Lattice to the global collection of all OpenCSG Lattices - OPENCSG_LATTICES[lattice_id] = opencsg_lattice + # Add the OpenCG Lattice to the global collection of all OpenCG Lattices + OPENCSG_LATTICES[lattice_id] = opencg_lattice - return opencsg_lattice + return opencg_lattice -def get_openmc_lattice(opencsg_lattice): +def get_openmc_lattice(opencg_lattice): - if not isinstance(opencsg_lattice, opencsg.Lattice): + if not isinstance(opencg_lattice, opencg.Lattice): msg = 'Unable to create an OpenMC Lattice from {0} which ' \ - 'is not an OpenCSG Lattice'.format(opencsg_lattice) + 'is not an OpenCG Lattice'.format(opencg_lattice) raise ValueError(msg) global OPENMC_LATTICES - lattice_id = opencsg_lattice._id + lattice_id = opencg_lattice._id # If this Lattice was already created, use it if lattice_id in OPENMC_LATTICES: return OPENMC_LATTICES[lattice_id] - dimension = opencsg_lattice._dimension - width = opencsg_lattice._width - offset = opencsg_lattice._offset - universes = opencsg_lattice._universes + dimension = opencg_lattice._dimension + width = opencg_lattice._width + offset = opencg_lattice._offset + universes = opencg_lattice._universes # Initialize an empty array for the OpenMC nested Universes in this Lattice universe_array = np.ndarray(tuple(np.array(dimension)), \ dtype=openmc.Universe) # Create OpenMC Universes for each unique nested Universe in this Lattice - unique_universes = opencsg_lattice.getUniqueUniverses() + unique_universes = opencg_lattice.getUniqueUniverses() for universe_id, universe in unique_universes.items(): unique_universes[universe_id] = get_openmc_universe(universe) @@ -767,12 +767,12 @@ def get_openmc_lattice(opencsg_lattice): OPENMC_LATTICES[lattice_id] = openmc_lattice # Add the OpenCG Lattice to the global collection of all OpenCG Lattices - OPENCSG_LATTICES[lattice_id] = opencsg_lattice + OPENCSG_LATTICES[lattice_id] = opencg_lattice return openmc_lattice -def get_opencsg_geometry(openmc_geometry): +def get_opencg_geometry(openmc_geometry): if not isinstance(openmc_geometry, openmc.Geometry): msg = 'Unable to get OpenCG geometry from {0} which is ' \ @@ -789,31 +789,31 @@ def get_opencsg_geometry(openmc_geometry): OPENMC_LATTICES.clear() OPENCSG_LATTICES.clear() - opencsg.geometry.reset_auto_ids() + opencg.geometry.reset_auto_ids() openmc_root_universe = openmc_geometry._root_universe - opencsg_root_universe = get_opencsg_universe(openmc_root_universe) + opencg_root_universe = get_opencg_universe(openmc_root_universe) - opencsg_geometry = opencsg.Geometry() - opencsg_geometry.setRootUniverse(opencsg_root_universe) - opencsg_geometry.initializeCellOffsets() + opencg_geometry = opencg.Geometry() + opencg_geometry.setRootUniverse(opencg_root_universe) + opencg_geometry.initializeCellOffsets() - return opencsg_geometry + return opencg_geometry -def get_openmc_geometry(opencsg_geometry): +def get_openmc_geometry(opencg_geometry): - if not isinstance(opencsg_geometry, opencsg.Geometry): + if not isinstance(opencg_geometry, opencg.Geometry): msg = 'Unable to get OpenMC geometry from {0} which is ' \ - 'not an OpenCSG Geometry object'.format(opencsg_geometry) + 'not an OpenCG Geometry object'.format(opencg_geometry) raise ValueError(msg) # Deep copy the goemetry since it may be modified to make all Surfaces # compatible with OpenMC's specifications - opencsg_geometry = copy.deepcopy(opencsg_geometry) + opencg_geometry = copy.deepcopy(opencg_geometry) # Update Cell bounding boxes in Geometry - opencsg_geometry.updateBoundingBoxes() + opencg_geometry.updateBoundingBoxes() # Clear dictionaries and auto-generated ID OPENMC_SURFACES.clear() @@ -827,8 +827,8 @@ def get_openmc_geometry(opencsg_geometry): openmc.reset_auto_ids() - opencsg_root_universe = opencsg_geometry._root_universe - openmc_root_universe = get_openmc_universe(opencsg_root_universe) + opencg_root_universe = opencg_geometry._root_universe + openmc_root_universe = get_openmc_universe(opencg_root_universe) openmc_geometry = openmc.Geometry() openmc_geometry.set_root_universe(openmc_root_universe) diff --git a/src/utils/openmc/universe.py b/src/utils/openmc/universe.py index f758c84aa3..36727e927d 100644 --- a/src/utils/openmc/universe.py +++ b/src/utils/openmc/universe.py @@ -716,7 +716,7 @@ class Lattice(object): def set_outside(self, outside): - if not isinstance(outside, Universe): + if not isinstance(outside, (Universe, openmc.Material)): msg = 'Unable to set Lattice ID={0} outside universe to {1} ' \ 'since it is not a Universe object'.format(self._id, outside) raise ValueError(msg)