mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Added OpenMOC region to OpenMC region compatibility
This commit is contained in:
parent
b74c6f065f
commit
a3cc60f4ed
1 changed files with 67 additions and 27 deletions
|
|
@ -227,14 +227,14 @@ def get_openmc_surface(openmoc_surface):
|
|||
|
||||
cv.check_type('openmoc_surface', openmoc_surface, openmoc.Surface)
|
||||
|
||||
surface_id = openmoc_surface.id
|
||||
surface_id = openmoc_surface.getId()
|
||||
|
||||
# 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 OpenMOC Surface
|
||||
name = openmoc_surface.name
|
||||
name = openmoc_surface.getName()
|
||||
|
||||
# Correct for OpenMC's syntax for Surfaces dividing Cells
|
||||
boundary = openmoc_surface.getBoundaryType()
|
||||
|
|
@ -248,6 +248,7 @@ def get_openmc_surface(openmoc_surface):
|
|||
boundary = 'transmission'
|
||||
|
||||
if openmoc_surface.getSurfaceType() == openmoc.PLANE:
|
||||
openmoc_surface = openmoc.castSurfaceToPlane(openmoc_surface)
|
||||
A = openmoc_surface.getA()
|
||||
B = openmoc_surface.getB()
|
||||
C = openmoc_surface.getC()
|
||||
|
|
@ -255,21 +256,25 @@ def get_openmc_surface(openmoc_surface):
|
|||
openmc_surface = openmc.Plane(surface_id, boundary, A, B, C, D, name)
|
||||
|
||||
elif openmoc_surface.getSurfaceType() == openmoc.XPLANE:
|
||||
openmoc_surface = openmoc.castSurfaceToXPlane(openmoc_surface)
|
||||
x0 = openmoc_surface.getX()
|
||||
openmc_surface = openmc.XPlane(surface_id, boundary, x0, name)
|
||||
|
||||
elif openmoc_surface.getSurfaceType() == openmoc.YPLANE:
|
||||
openmoc_surface = openmoc.castSurfaceToYPlane(openmoc_surface)
|
||||
y0 = openmoc_surface.getY()
|
||||
openmc_surface = openmc.YPlane(surface_id, boundary, y0, name)
|
||||
|
||||
elif openmoc_surface.getSurfaceType() == openmoc.ZPLANE:
|
||||
openmoc_surface = openmoc.castSurfaceToZPlane(openmoc_surface)
|
||||
z0 = openmoc_surface.getZ()
|
||||
openmc_surface = openmc.ZPlane(surface_id, boundary, z0, name)
|
||||
|
||||
elif openmoc_surface.getSurfaceType() == openmoc.ZCYLINDER:
|
||||
openmoc_surface = openmoc.castSurfaceToZCylinder(openmoc_surface)
|
||||
x0 = openmoc_surface.getX0()
|
||||
y0 = openmoc_surface.getY0()
|
||||
R = openmoc_surface.getR()
|
||||
R = openmoc_surface.getRadius()
|
||||
openmc_surface = openmc.ZCylinder(surface_id, boundary, x0, y0, R, name)
|
||||
|
||||
# Add the OpenMC Surface to the global collection of all OpenMC Surfaces
|
||||
|
|
@ -312,7 +317,6 @@ def get_openmoc_cell(openmc_cell):
|
|||
|
||||
if openmc_cell.fill_type == 'material':
|
||||
openmoc_cell.setFill(get_openmoc_material(fill))
|
||||
print('set fill to material {} {}'.format(fill.id, fill.name))
|
||||
elif openmc_cell.fill_type == 'universe':
|
||||
openmoc_cell.setFill(get_openmoc_universe(fill))
|
||||
else:
|
||||
|
|
@ -355,7 +359,7 @@ def get_openmoc_region(openmc_region):
|
|||
|
||||
cv.check_type('openmc_region', openmc_region, openmc.Region)
|
||||
|
||||
# Add surfaces to OpenMOC cell from OpenMC cell region
|
||||
# Recursively instantiate a region of the appropriate type
|
||||
if isinstance(openmc_region, openmc.Halfspace):
|
||||
surface = openmc_region.surface
|
||||
halfspace = -1 if openmc_region.side == '-' else 1
|
||||
|
|
@ -376,7 +380,6 @@ def get_openmoc_region(openmc_region):
|
|||
return openmoc_region
|
||||
|
||||
|
||||
# FIXME:
|
||||
def get_openmc_region(openmoc_region):
|
||||
"""Return an OpenMC region corresponding to an OpenMOC region.
|
||||
|
||||
|
|
@ -394,6 +397,30 @@ def get_openmc_region(openmoc_region):
|
|||
|
||||
cv.check_type('openmoc_region', openmoc_region, openmoc.Region)
|
||||
|
||||
# Recursively instantiate a region of the appropriate type
|
||||
if openmoc_region.getRegionType() == openmoc.HALFSPACE:
|
||||
openmoc_region = openmoc.castRegionToHalfspace(openmoc_region)
|
||||
surface = get_openmc_surface(openmoc_region.getSurface())
|
||||
side = '-' if openmoc_region.getHalfspace() == -1 else '+'
|
||||
openmc_region = openmc.Halfspace(surface, side)
|
||||
elif openmoc_region.getRegionType() == openmoc.INTERSECTION:
|
||||
openmc_region = openmc.Intersection()
|
||||
for openmoc_node in openmoc_region.getNodes():
|
||||
openmc_node = get_openmc_region(openmoc_node)
|
||||
openmc_region.nodes.append(openmc_node)
|
||||
elif openmoc_region.getRegionType() == openmoc.UNION:
|
||||
openmc_region = openmc.Union()
|
||||
for openmoc_node in openmoc_region.getNodes():
|
||||
openmc_node = get_openmc_region(openmoc_node)
|
||||
openmc_region.append(openmc_node)
|
||||
openmc_region.nodes.append(openmc_node)
|
||||
elif openmoc_region.getRegionType() == openmoc.COMPLEMENT:
|
||||
openmoc_nodes = openmoc_region.getNodes()
|
||||
openmc_node = get_openmc_region(openmoc_nodes[0])
|
||||
openmc_region = openmc.Complement(openmc_node)
|
||||
|
||||
return openmc_region
|
||||
|
||||
|
||||
def get_openmc_cell(openmoc_cell):
|
||||
"""Return an OpenMC cell corresponding to an OpenMOC cell.
|
||||
|
|
@ -427,24 +454,24 @@ def get_openmc_cell(openmoc_cell):
|
|||
openmc_cell.fill = get_openmc_material(fill)
|
||||
elif (openmoc_cell.getType() == openmoc.FILL):
|
||||
fill = openmoc_cell.getFillUniverse()
|
||||
if isinstance(fill, openmoc.Lattice):
|
||||
if fill.getType() == openmoc.LATTICE:
|
||||
fill = openmoc.castUniverseToLattice(fill)
|
||||
openmc_cell.fill = get_openmc_lattice(fill)
|
||||
else:
|
||||
openmc_cell.fill = get_openmc_universe(fill)
|
||||
|
||||
if openmoc_cell.isRotated():
|
||||
rotation = openmoc_cell.getRotation(3)
|
||||
rotation = openmoc_cell.retrieveRotation(3)
|
||||
openmc_cell.rotation = rotation
|
||||
if openmoc_cell.isTranslated():
|
||||
translation = openmoc_cell.getTranslation(3)
|
||||
translation = openmoc_cell.retrieveTranslation(3)
|
||||
openmc_cell.translation = translation
|
||||
|
||||
regions = []
|
||||
for surf_id, surf_halfspace in openmoc_cell.getSurfaces().values():
|
||||
halfspace = surf_halfspace._halfspace
|
||||
surface = get_openmc_surface(surf_halfspace._surface)
|
||||
regions.append(-surface if halfspace == -1 else +surface)
|
||||
openmc_cell.region = openmc.Intersection(*regions)
|
||||
|
||||
# Convert OpenMC's cell region to an equivalent OpenMOC region
|
||||
openmoc_region = openmoc_cell.getRegion()
|
||||
if openmoc_region is not None:
|
||||
openmc_cell.region = get_openmc_region(openmoc_region)
|
||||
|
||||
# Add the OpenMC Cell to the global collection of all OpenMC Cells
|
||||
OPENMC_CELLS[cell_id] = openmc_cell
|
||||
|
|
@ -526,7 +553,7 @@ def get_openmc_universe(openmoc_universe):
|
|||
openmc_universe = openmc.Universe(universe_id, name)
|
||||
|
||||
# Convert all OpenMOC Cells in this Universe to OpenMC Cells
|
||||
for openmoc_cell in openmoc_universe.getCells():
|
||||
for openmoc_cell in openmoc_universe.getCells().values():
|
||||
openmc_cell = get_openmc_cell(openmoc_cell)
|
||||
openmc_universe.add_cell(openmc_cell)
|
||||
|
||||
|
|
@ -562,6 +589,8 @@ def get_openmoc_lattice(openmc_lattice):
|
|||
if lattice_id in OPENMOC_LATTICES:
|
||||
return OPENMOC_LATTICES[lattice_id]
|
||||
|
||||
# FIXME: All of this must be fixed
|
||||
|
||||
# Create an OpenMOC Lattice to represent this OpenMC Lattice
|
||||
name = openmc_lattice.name
|
||||
dimension = openmc_lattice.shape
|
||||
|
|
@ -651,15 +680,23 @@ def get_openmc_lattice(openmoc_lattice):
|
|||
return OPENMC_LATTICES[lattice_id]
|
||||
|
||||
name = openmoc_lattice.getName()
|
||||
dimension = [1, openmoc_lattice.getNumY(), openmoc_lattice.getNumX()]
|
||||
width = [1, openmoc_lattice.getWidthY(), openmoc_lattice.getWidthX()]
|
||||
dimension = [openmoc_lattice.getNumX(),
|
||||
openmoc_lattice.getNumY(),
|
||||
openmoc_lattice.getNumZ()]
|
||||
width = [openmoc_lattice.getWidthX(),
|
||||
openmoc_lattice.getWidthY(),
|
||||
openmoc_lattice.getWidthZ()]
|
||||
offset = openmoc_lattice.getOffset()
|
||||
offset = [offset.getX(), offset.getY(), offset.getZ()]
|
||||
lower_left = np.array(offset, dtype=np.float64) + \
|
||||
((np.array(width, dtype=np.float64) *
|
||||
np.array(dimension, dtype=np.float64))) / -2.0
|
||||
|
||||
# FIXME
|
||||
# Initialize an empty array for the OpenMOC nested Universes in this Lattice
|
||||
universe_array = np.ndarray(tuple(np.array(dimension)[::-1]),
|
||||
# universe_array = np.ndarray(tuple(np.array(dimension)[::-1]),
|
||||
# dtype=openmoc.Universe)
|
||||
universe_array = np.ndarray(tuple(np.array(dimension)),
|
||||
dtype=openmoc.Universe)
|
||||
|
||||
# Create OpenMOC Universes for each unique nested Universe in this Lattice
|
||||
|
|
@ -667,19 +704,22 @@ def get_openmc_lattice(openmoc_lattice):
|
|||
|
||||
for universe_id, universe in unique_universes.items():
|
||||
unique_universes[universe_id] = get_openmc_universe(universe)
|
||||
|
||||
|
||||
# Build the nested Universe array
|
||||
for z in range(dimension[2]):
|
||||
for x in range(dimension[0]):
|
||||
for y in range(dimension[1]):
|
||||
for x in range(dimension[0]):
|
||||
universe = openmoc_lattice.getUniverse(x, y)
|
||||
for z in range(dimension[2]):
|
||||
universe = openmoc_lattice.getUniverse(x, y, z)
|
||||
universe_id = universe.getId()
|
||||
universe_array[z][dimension[1]-y-1][x] = unique_universes[universe_id]
|
||||
# universe_array[x][y][z] = \
|
||||
# unique_universes[universe_id]
|
||||
universe_array[x][dimension[1]-y-1][z] = \
|
||||
unique_universes[universe_id]
|
||||
|
||||
openmc_lattice = openmc.RectLattice(lattice_id=lattice_id, name=name)
|
||||
openmc_lattice.pitch = width
|
||||
openmc_lattice.lower_left = lower_left
|
||||
openmc_lattice.universes = universe_array
|
||||
openmc_lattice.universes = np.swapaxes(universe_array, 0, 2)
|
||||
|
||||
# Add the OpenMC Lattice to the global collection of all OpenMC Lattices
|
||||
OPENMC_LATTICES[lattice_id] = openmc_lattice
|
||||
|
|
@ -770,8 +810,8 @@ def get_openmc_geometry(openmoc_geometry):
|
|||
OPENMC_LATTICES.clear()
|
||||
OPENMOC_LATTICES.clear()
|
||||
|
||||
openmoc_root_universe = \
|
||||
openmoc_geometry.getRootUniverse(openmoc_root_universe)
|
||||
openmoc_root_universe = openmoc_geometry.getRootUniverse()
|
||||
openmc_root_universe = get_openmc_universe(openmoc_root_universe)
|
||||
|
||||
openmc_geometry = openmc.Geometry()
|
||||
openmc_geometry.root_universe = openmc_root_universe
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue