mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-25 12:35:29 -04:00
Create Mesh.from_hdf5() and Surface.from_hdf5() methods
This commit is contained in:
parent
4729754ce5
commit
8f2efa19dd
4 changed files with 104 additions and 93 deletions
|
|
@ -160,6 +160,33 @@ class Mesh(EqualityMixin):
|
|||
string += '{0: <16}{1}{2}\n'.format('\tPixels', '=\t', self._width)
|
||||
return string
|
||||
|
||||
@classmethod
|
||||
def from_hdf5(cls, group):
|
||||
"""Create mesh from HDF5 group
|
||||
|
||||
Parameters
|
||||
----------
|
||||
group : h5py.Group
|
||||
Group in HDF5 file
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc.Mesh
|
||||
Mesh instance
|
||||
|
||||
"""
|
||||
mesh_id = int(group.name.split('/')[-1].lstrip('mesh '))
|
||||
|
||||
# Read and assign mesh properties
|
||||
mesh = cls(mesh_id)
|
||||
mesh.type = group['type'].value.decode()
|
||||
mesh.dimension = group['dimension'].value
|
||||
mesh.lower_left = group['lower_left'].value
|
||||
mesh.upper_right = group['upper_right'].value
|
||||
mesh.width = group['width'].value
|
||||
|
||||
return mesh
|
||||
|
||||
def cell_generator(self):
|
||||
"""Generator function to traverse through every [i,j,k] index
|
||||
of the mesh.
|
||||
|
|
|
|||
|
|
@ -261,19 +261,9 @@ class StatePoint(object):
|
|||
mesh_group = self._f['tallies/meshes']
|
||||
|
||||
# Iterate over all Meshes
|
||||
for key, group in mesh_group.items():
|
||||
mesh_id = int(key.lstrip('mesh '))
|
||||
|
||||
# Read and assign mesh properties
|
||||
mesh = openmc.Mesh(mesh_id)
|
||||
mesh.type = group['type'].value.decode()
|
||||
mesh.dimension = group['dimension'].value
|
||||
mesh.lower_left = group['lower_left'].value
|
||||
mesh.upper_right = group['upper_right'].value
|
||||
mesh.width = group['width'].value
|
||||
|
||||
# Add mesh to the global dictionary of all Meshes
|
||||
self._meshes[mesh_id] = mesh
|
||||
for group in mesh_group.values():
|
||||
mesh = openmc.Mesh.from_hdf5(group)
|
||||
self._meshes[mesh.id] = mesh
|
||||
|
||||
self._meshes_read = True
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class Summary(object):
|
|||
self._read_materials()
|
||||
surfaces = self._read_surfaces()
|
||||
cells, cell_fills = self._read_cells(surfaces)
|
||||
universes = self._read_universes(cells, cell_fills)
|
||||
universes = self._read_universes(cells)
|
||||
lattices = self._read_lattices(universes)
|
||||
self._finalize_geometry(cells, cell_fills, universes, lattices)
|
||||
|
||||
|
|
@ -121,78 +121,8 @@ class Summary(object):
|
|||
|
||||
def _read_surfaces(self):
|
||||
surfaces = {}
|
||||
|
||||
for key, group in self._f['geometry/surfaces'].items():
|
||||
surface_id = int(key.lstrip('surface '))
|
||||
name = group['name'].value.decode()
|
||||
surf_type = group['type'].value.decode()
|
||||
bc = group['boundary_condition'].value.decode()
|
||||
coeffs = group['coefficients'][...]
|
||||
|
||||
# Create the Surface based on its type
|
||||
if surf_type == 'x-plane':
|
||||
x0 = coeffs[0]
|
||||
surface = openmc.XPlane(surface_id, bc, x0, name)
|
||||
|
||||
elif surf_type == 'y-plane':
|
||||
y0 = coeffs[0]
|
||||
surface = openmc.YPlane(surface_id, bc, y0, name)
|
||||
|
||||
elif surf_type == 'z-plane':
|
||||
z0 = coeffs[0]
|
||||
surface = openmc.ZPlane(surface_id, bc, z0, name)
|
||||
|
||||
elif surf_type == 'plane':
|
||||
A = coeffs[0]
|
||||
B = coeffs[1]
|
||||
C = coeffs[2]
|
||||
D = coeffs[3]
|
||||
surface = openmc.Plane(surface_id, bc, A, B, C, D, name)
|
||||
|
||||
elif surf_type == 'x-cylinder':
|
||||
y0 = coeffs[0]
|
||||
z0 = coeffs[1]
|
||||
R = coeffs[2]
|
||||
surface = openmc.XCylinder(surface_id, bc, y0, z0, R, name)
|
||||
|
||||
elif surf_type == 'y-cylinder':
|
||||
x0 = coeffs[0]
|
||||
z0 = coeffs[1]
|
||||
R = coeffs[2]
|
||||
surface = openmc.YCylinder(surface_id, bc, x0, z0, R, name)
|
||||
|
||||
elif surf_type == 'z-cylinder':
|
||||
x0 = coeffs[0]
|
||||
y0 = coeffs[1]
|
||||
R = coeffs[2]
|
||||
surface = openmc.ZCylinder(surface_id, bc, x0, y0, R, name)
|
||||
|
||||
elif surf_type == 'sphere':
|
||||
x0 = coeffs[0]
|
||||
y0 = coeffs[1]
|
||||
z0 = coeffs[2]
|
||||
R = coeffs[3]
|
||||
surface = openmc.Sphere(surface_id, bc, x0, y0, z0, R, name)
|
||||
|
||||
elif surf_type in ['x-cone', 'y-cone', 'z-cone']:
|
||||
x0 = coeffs[0]
|
||||
y0 = coeffs[1]
|
||||
z0 = coeffs[2]
|
||||
R2 = coeffs[3]
|
||||
|
||||
if surf_type == 'x-cone':
|
||||
surface = openmc.XCone(surface_id, bc, x0, y0, z0, R2, name)
|
||||
if surf_type == 'y-cone':
|
||||
surface = openmc.YCone(surface_id, bc, x0, y0, z0, R2, name)
|
||||
if surf_type == 'z-cone':
|
||||
surface = openmc.ZCone(surface_id, bc, x0, y0, z0, R2, name)
|
||||
|
||||
elif surf_type == 'quadric':
|
||||
a, b, c, d, e, f, g, h, j, k = coeffs
|
||||
surface = openmc.Quadric(surface_id, bc, a, b, c, d, e, f,
|
||||
g, h, j, k, name)
|
||||
|
||||
# Add Surface to global dictionary of all Surfaces
|
||||
for group in self._f['geometry/surfaces'].values():
|
||||
surface = openmc.Surface.from_hdf5(group)
|
||||
surfaces[surface.id] = surface
|
||||
|
||||
return surfaces
|
||||
|
|
@ -261,10 +191,7 @@ class Summary(object):
|
|||
|
||||
return cells, cell_fills
|
||||
|
||||
def _read_universes(self, cells, cell_fills):
|
||||
# Initialize dictionary for each Universe
|
||||
# Keys - Universe keys
|
||||
# Values - Universe objects
|
||||
def _read_universes(self, cells):
|
||||
universes = {}
|
||||
|
||||
for key in self._f['geometry/universes'].keys():
|
||||
|
|
@ -284,9 +211,6 @@ class Summary(object):
|
|||
return universes
|
||||
|
||||
def _read_lattices(self, universes):
|
||||
# Initialize lattices for each Lattice
|
||||
# Keys - Lattice keys
|
||||
# Values - Lattice objects
|
||||
lattices = {}
|
||||
|
||||
for key, group in self._f['geometry/lattices'].items():
|
||||
|
|
|
|||
|
|
@ -186,6 +186,76 @@ class Surface(object):
|
|||
|
||||
return element
|
||||
|
||||
@staticmethod
|
||||
def from_hdf5(group):
|
||||
"""Create surface from HDF5 group
|
||||
|
||||
Parameters
|
||||
----------
|
||||
group : h5py.Group
|
||||
Group in HDF5 file
|
||||
|
||||
Returns
|
||||
-------
|
||||
openmc.Surface
|
||||
Instance of surface subclass
|
||||
|
||||
"""
|
||||
surface_id = int(group.name.split('/')[-1].lstrip('surface '))
|
||||
name = group['name'].value.decode()
|
||||
surf_type = group['type'].value.decode()
|
||||
bc = group['boundary_condition'].value.decode()
|
||||
coeffs = group['coefficients'][...]
|
||||
|
||||
# Create the Surface based on its type
|
||||
if surf_type == 'x-plane':
|
||||
x0 = coeffs[0]
|
||||
surface = XPlane(surface_id, bc, x0, name)
|
||||
|
||||
elif surf_type == 'y-plane':
|
||||
y0 = coeffs[0]
|
||||
surface = YPlane(surface_id, bc, y0, name)
|
||||
|
||||
elif surf_type == 'z-plane':
|
||||
z0 = coeffs[0]
|
||||
surface = ZPlane(surface_id, bc, z0, name)
|
||||
|
||||
elif surf_type == 'plane':
|
||||
A, B, C, D = coeffs
|
||||
surface = Plane(surface_id, bc, A, B, C, D, name)
|
||||
|
||||
elif surf_type == 'x-cylinder':
|
||||
y0, z0, R = coeffs
|
||||
surface = XCylinder(surface_id, bc, y0, z0, R, name)
|
||||
|
||||
elif surf_type == 'y-cylinder':
|
||||
x0, z0, R = coeffs
|
||||
surface = YCylinder(surface_id, bc, x0, z0, R, name)
|
||||
|
||||
elif surf_type == 'z-cylinder':
|
||||
x0, y0, R = coeffs
|
||||
surface = ZCylinder(surface_id, bc, x0, y0, R, name)
|
||||
|
||||
elif surf_type == 'sphere':
|
||||
x0, y0, z0, R = coeffs
|
||||
surface = Sphere(surface_id, bc, x0, y0, z0, R, name)
|
||||
|
||||
elif surf_type in ['x-cone', 'y-cone', 'z-cone']:
|
||||
x0, y0, z0, R2 = coeffs
|
||||
if surf_type == 'x-cone':
|
||||
surface = XCone(surface_id, bc, x0, y0, z0, R2, name)
|
||||
elif surf_type == 'y-cone':
|
||||
surface = YCone(surface_id, bc, x0, y0, z0, R2, name)
|
||||
elif surf_type == 'z-cone':
|
||||
surface = ZCone(surface_id, bc, x0, y0, z0, R2, name)
|
||||
|
||||
elif surf_type == 'quadric':
|
||||
a, b, c, d, e, f, g, h, j, k = coeffs
|
||||
surface = Quadric(surface_id, bc, a, b, c, d, e, f, g,
|
||||
h, j, k, name)
|
||||
|
||||
return surface
|
||||
|
||||
|
||||
class Plane(Surface):
|
||||
"""An arbitrary plane of the form :math:`Ax + By + Cz = D`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue