def test_ycylinder(): x, z, r = 3, 5, 2 s = openmc.YCylinder(x0=x, z0=z, r=r) assert s.x0 == x assert s.z0 == z assert s.r == r # Check bounding box ll, ur = (+s).bounding_box assert np.all(np.isinf(ll)) assert np.all(np.isinf(ur)) ll, ur = (-s).bounding_box assert ll == pytest.approx((x - r, -np.inf, z - r)) assert ur == pytest.approx((x + r, np.inf, z + r)) # evaluate method assert s.evaluate((x, 0, z)) == pytest.approx(-r**2) # translate method st = s.translate((1.0, 1.0, 1.0)) assert st.x0 == s.x0 + 1 assert st.z0 == s.z0 + 1 assert st.r == s.r # rotate method sr = s.rotate((90, 90, 90)) R = np.array([[0, 0, 1], [0, 1, 0], [-1, 0, 0]]) assert sr._origin == pytest.approx(R @ s._origin) assert sr._axis == pytest.approx(R @ s._axis) # test passing in rotation matrix sr2 = s.rotate(R) assert sr2._get_base_coeffs() == pytest.approx(sr._get_base_coeffs()) # Make sure repr works repr(s)
def centers_y_cylinder(): cylinder = openmc.YCylinder(r=1, x0=1, z0=2) min_y = openmc.YPlane(0) max_y = openmc.YPlane(1) region = +min_y & -max_y & -cylinder return openmc.model.pack_spheres(radius=_RADIUS, region=region, pf=_PACKING_FRACTION, initial_pf=0.2)
def __init__(self, center_base, height, radius, axis='z', **kwargs): cx, cy, cz = center_base check_greater_than('cylinder height', height, 0.0) check_greater_than('cylinder radius', radius, 0.0) check_value('cylinder axis', axis, ('x', 'y', 'z')) if axis == 'x': self.cyl = openmc.XCylinder(y0=cy, z0=cz, r=radius, **kwargs) self.bottom = openmc.XPlane(x0=cx, **kwargs) self.top = openmc.XPlane(x0=cx + height, **kwargs) elif axis == 'y': self.cyl = openmc.YCylinder(x0=cx, z0=cz, r=radius, **kwargs) self.bottom = openmc.YPlane(y0=cy, **kwargs) self.top = openmc.YPlane(y0=cy + height, **kwargs) elif axis == 'z': self.cyl = openmc.ZCylinder(x0=cx, y0=cy, r=radius, **kwargs) self.bottom = openmc.ZPlane(z0=cz, **kwargs) self.top = openmc.ZPlane(z0=cz + height, **kwargs)
def test_ycylinder(): x, z, r = 3, 5, 2 s = openmc.YCylinder(x0=x, z0=z, r=r) assert s.x0 == x assert s.z0 == z assert s.r == r # Check bounding box ll, ur = (+s).bounding_box assert np.all(np.isinf(ll)) assert np.all(np.isinf(ur)) ll, ur = (-s).bounding_box assert ll == pytest.approx((x-r, -np.inf, z-r)) assert ur == pytest.approx((x+r, np.inf, z+r)) # evaluate method assert s.evaluate((x, 0, z)) == pytest.approx(-r**2) # translate method st = s.translate((1.0, 1.0, 1.0)) assert st.x0 == s.x0 + 1 assert st.z0 == s.z0 + 1 assert st.r == s.r
def get_openmc_surface(opencg_surface): """Return an OpenMC surface corresponding to an OpenCG surface. Parameters ---------- opencg_surface : opencg.Surface OpenCG surface Returns ------- openmc_surface : openmc.surface.Surface Equivalent OpenMC surface """ if not isinstance(opencg_surface, opencg.Surface): msg = 'Unable to create an OpenMC Surface from "{0}" which ' \ 'is not an OpenCG Surface'.format(opencg_surface) raise ValueError(msg) global openmc_surface 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 OpenCG Surface name = opencg_surface._name # Correct for OpenMC's syntax for Surfaces dividing Cells boundary = opencg_surface._boundary_type if boundary == 'interface': boundary = 'transmission' 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 opencg_surface._type == 'x-plane': x0 = opencg_surface._coeffs['x0'] openmc_surface = openmc.XPlane(surface_id, boundary, x0, name) elif opencg_surface._type == 'y-plane': y0 = opencg_surface._coeffs['y0'] openmc_surface = openmc.YPlane(surface_id, boundary, y0, name) elif opencg_surface._type == 'z-plane': z0 = opencg_surface._coeffs['z0'] openmc_surface = openmc.ZPlane(surface_id, boundary, z0, name) 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 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 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 OpenCG ' \ 'Surface of type "{0}" since it is not a compatible ' \ '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 OpenCG Surface to the global collection of all OpenCG Surfaces OPENCG_SURFACES[surface_id] = opencg_surface return openmc_surface
def generate_model(sol_temp=303., sol_conc=0.299, U_enrch=0.1467, cr_wd=0.1): sol_atom_densities = BoilerAtomDensities(enrich=U_enrch, temp=sol_temp, conc=sol_conc) sol = openmc.Material(name='sol') sol.add_element('H', sol_atom_densities['H'], percent_type='ao') sol.add_element('O', sol_atom_densities['O'], percent_type='ao') sol.add_element('S', sol_atom_densities['S'], percent_type='ao') sol.add_nuclide('U234', sol_atom_densities['U234'], percent_type='ao') sol.add_nuclide('U235', sol_atom_densities['U235'], percent_type='ao') sol.add_nuclide('U238', sol_atom_densities['U238'], percent_type='ao') sol.add_s_alpha_beta('c_H_in_H2O') ad_tot = 0. for key in sol_atom_densities: ad_tot += sol_atom_densities[key] sol.set_density('atom/b-cm', ad_tot) brass = openmc.Material(name='brass') brass.add_element('Fe', 0.001002) brass.add_element('Cu', 0.674918) brass.add_element('Zn', 0.320956) brass.add_element('Sn', 0.001451) brass.add_element('Pb', 0.001673) brass.set_density('g/cc', 8.070) cadmium = openmc.Material(name='cadmium') cadmium.add_element('Cd', 1.0) cadmium.set_density('g/cc', 8.65) shell = openmc.Material(name='shell') shell.add_element('C', 0.003659) shell.add_element('Si', 0.019559) shell.add_element('P', 0.000798) shell.add_element('S', 0.000514) shell.add_element('Cr', 0.179602) shell.add_element('Mn', 0.019998) shell.add_element('Fe', 0.669338) shell.add_element('Ni', 0.102952) shell.add_element('Nb', 0.002365) shell.add_element('Ta', 0.001214) shell.set_density('g/cc', 8.0) beryl_ref = openmc.Material(name='beryl_ref') beryl_ref.add_element('O', 6.6210e-2) beryl_ref.add_element('Be', 6.6210e-2) beryl_ref.add_element('B', 3.0637e-7) beryl_ref.add_element('Co', 5.6202e-7) beryl_ref.add_element('Ag', 3.0706e-8) beryl_ref.add_element('Cd', 7.3662e-8) beryl_ref.add_element('In', 1.4423e-8) beryl_ref.add_s_alpha_beta('c_Be_in_BeO') beryl_ref.set_density('g/cc', 2.75) grph = openmc.Material(name='grph') grph.add_element('C', 0.999999) grph.add_element('B', 0.000001) grph.set_density('g/cc', 1.7) grph.add_s_alpha_beta('c_Graphite') air = openmc.Material(name='air') air.add_element('C', 0.000150) air.add_element('N', 0.784431) air.add_element('O', 0.210748) air.add_element('Ar', 0.004671) air.set_density('g/cc', 0.001205) materials = openmc.Materials( [sol, shell, beryl_ref, grph, air, brass, cadmium]) rx_origin = [0., 76.3214, 0.] ref_sphere = openmc.Sphere(y0=rx_origin[1], r=47.4210) tank_o = openmc.Sphere(y0=rx_origin[1], r=15.3614) tank_i = openmc.Sphere(y0=rx_origin[1], r=15.282) graph_base_cyl = openmc.YCylinder(r=47.4210) #fill_drain_cav = openmc.YCylinder(r=4.445/2.); fill_drain_o = openmc.YCylinder(r=2.06375) fill_drain_i = openmc.YCylinder(r=1.905) plate_plane = openmc.YPlane(y0=0.) base_plane = openmc.YPlane(y0=34.4114) sphere_center_plane = openmc.YPlane(y0=rx_origin[1]) upper_plane = openmc.YPlane(y0=118.2314) bbox = openmc.model.RightCircularCylinder([0., -10., 0.], 230., 60., axis='y', boundary_type='vacuum') # surfaces for the control rod rod_channel_bottom = 118.2314 - 76.20 cr_cyl = openmc.YCylinder(x0=-18.891, z0=0., r=1.42875) cr_cyl_bottom = openmc.YPlane(y0=rod_channel_bottom) # surfaces for the safety rod sr_right = openmc.XPlane(x0=17.3664) sr_left = openmc.XPlane(x0=15.4614) sr_front = openmc.ZPlane(z0=7.62 / 2.) sr_back = openmc.ZPlane(z0=-7.62 / 2.) # top plane for cr/sr rod_channel_top = openmc.YPlane(y0=200.) rod_length = 76.20 #sr_wd = 76.20;# cm, distance from fully inserted cr_bottom = openmc.YPlane(y0=(rod_channel_bottom + cr_wd)) cr_top = openmc.YPlane(y0=(rod_channel_bottom + cr_wd + rod_length)) #sr_bottom = openmc.YPlane(y0=(rod_channel_bottom+sr_wd)); #sr_top = openmc.YPlane(y0=(rod_channel_bottom+sr_wd+rod_length)); cr_brass_o = openmc.YCylinder(x0=-18.891, z0=0., r=0.9525) cr_brass_i = openmc.YCylinder(x0=-18.891, z0=0., r=0.7000) cr_cd_o = openmc.YCylinder(x0=-18.891, z0=0.0, r=1.03375) core = openmc.Cell() core.fill = sol core.region = (-tank_i) | (-fill_drain_i) & -bbox steel_tank_and_pipe = openmc.Cell() steel_tank_and_pipe.fill = shell #steel_tank_and_pipe.region = (+tank_i & -tank_o & ~(-fill_drain_i)) | \ # (+fill_drain_i & -fill_drain_o & +tank_i) & -bbox steel_tank_and_pipe.region = (+tank_i & -tank_o & ~(-fill_drain_i)) | \ (+fill_drain_i & -fill_drain_o & +tank_i) & -bbox # make a universe for the control rod cr_brass = openmc.Cell() cr_brass.fill = brass cr_brass.region = +cr_brass_i & -cr_brass_o & +cr_bottom & -cr_top cr_cd = openmc.Cell() cr_cd.fill = cadmium cr_cd.region = +cr_brass_o & -cr_cd_o & +cr_bottom & -cr_top cr_air = openmc.Cell() cr_air.fill = air cr_air.region = +cr_cyl_bottom & -rod_channel_top & -cr_cyl & ~cr_cd.region & ~cr_brass.region cr_univ = openmc.Universe() cr_univ.add_cells([cr_brass, cr_cd, cr_air]) cr = openmc.Cell() cr.fill = cr_univ cr.region = -cr_cyl & +cr_cyl_bottom & -rod_channel_top sr = openmc.Cell() sr.fill = air sr.region = +sr_left & -sr_right & +cr_cyl_bottom & -upper_plane & -sr_front & +sr_back ref = openmc.Cell() ref.fill = beryl_ref ref.region = ((+tank_o & +fill_drain_o) & -ref_sphere & +base_plane & -upper_plane) & ~cr.region & ~sr.region outside = openmc.Cell() outside.fill = air outside.region = -bbox & (+graph_base_cyl | (+ref_sphere & -upper_plane) | (+upper_plane & +fill_drain_o & ~cr.region)) graph_base = openmc.Cell() graph_base.fill = grph graph_base.region = ( (-graph_base_cyl & +plate_plane & -base_plane & +fill_drain_o) | (-graph_base_cyl & +ref_sphere & +base_plane & -sphere_center_plane)) root = openmc.Universe() root.add_cells( [graph_base, ref, core, steel_tank_and_pipe, outside, cr, sr]) geometry = openmc.Geometry() geometry.root_universe = root cell_filter = openmc.CellFilter(core) N = 1001 energy_bins = np.logspace(-3, 7, num=N) energy_filter = openmc.EnergyFilter(values=energy_bins) abs_core = openmc.Tally(name='abs_core') abs_core.scores = ['absorption'] abs_core.filters = [cell_filter, energy_filter] fission = openmc.Tally(name='fission') fission.scores = ['fission'] fission.filters = [cell_filter, energy_filter] fission_by_nuclide = openmc.Tally(name='fission_by_nuclide') fission_by_nuclide.scores = ['fission'] fission_by_nuclide.nuclides = ['U234', 'U235', 'U238'] fission_by_nuclide.filters = [cell_filter, energy_filter] capture = openmc.Tally(name='capture') capture.scores = ['(n,gamma)'] capture.filters = [cell_filter, energy_filter] capture_by_nuclide = openmc.Tally(name='capture_by_nuclide') capture_by_nuclide.scores = ['(n,gamma)'] capture_by_nuclide.nuclides = ['U234', 'U238', 'H1', 'O16', 'S32'] capture_by_nuclide.filters = [cell_filter, energy_filter] flux = openmc.Tally(name='flux') flux.scores = ['flux'] flux.filters = [cell_filter, energy_filter] tallies = openmc.Tallies([ abs_core, flux, fission, capture, fission_by_nuclide, capture_by_nuclide ]) settings = openmc.Settings() settings.batches = 100 settings.inactive = 20 settings.particles = 5000 R = 15. y_org = 76.3214 bounds = [-R, -R + y_org, -R, R, R + y_org, R] uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:], only_fissionable=True) settings.source = openmc.source.Source(space=uniform_dist) #settings.temperature['method']='interpolation'; return materials, geometry, tallies, settings
def _read_surfaces(self): self.n_surfaces = self._f['geometry/n_surfaces'].value # Initialize dictionary for each Surface # Keys - Surface keys # Values - Surfacee objects self.surfaces = {} for key in self._f['geometry/surfaces'].keys(): if key == 'n_surfaces': continue surface_id = int(key.lstrip('surface ')) index = self._f['geometry/surfaces'][key]['index'].value name = self._f['geometry/surfaces'][key]['name'].value.decode() surf_type = self._f['geometry/surfaces'][key]['type'].value.decode( ) bc = self._f['geometry/surfaces'][key][ 'boundary_condition'].value.decode() coeffs = self._f['geometry/surfaces'][key]['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 self.surfaces[index] = surface
def get_openmc_surface(opencg_surface): """Return an OpenMC surface corresponding to an OpenCG surface. Parameters ---------- opencg_surface : opencg.Surface OpenCG surface Returns ------- openmc_surface : openmc.surface.Surface Equivalent OpenMC surface """ cv.check_type('opencg_surface', opencg_surface, opencg.Surface) 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 OpenCG Surface name = opencg_surface.name # Correct for OpenMC's syntax for Surfaces dividing Cells boundary = opencg_surface.boundary_type if boundary == 'interface': boundary = 'transmission' if opencg_surface.type == 'plane': A = opencg_surface.a B = opencg_surface.b C = opencg_surface.c D = opencg_surface.d openmc_surface = openmc.Plane(surface_id, boundary, A, B, C, D, name) elif opencg_surface.type == 'x-plane': x0 = opencg_surface.x0 openmc_surface = openmc.XPlane(surface_id, boundary, x0, name) elif opencg_surface.type == 'y-plane': y0 = opencg_surface.y0 openmc_surface = openmc.YPlane(surface_id, boundary, y0, name) elif opencg_surface.type == 'z-plane': z0 = opencg_surface.z0 openmc_surface = openmc.ZPlane(surface_id, boundary, z0, name) elif opencg_surface.type == 'x-cylinder': y0 = opencg_surface.y0 z0 = opencg_surface.z0 R = opencg_surface.r openmc_surface = openmc.XCylinder(surface_id, boundary, y0, z0, R, name) elif opencg_surface.type == 'y-cylinder': x0 = opencg_surface.x0 z0 = opencg_surface.z0 R = opencg_surface.r openmc_surface = openmc.YCylinder(surface_id, boundary, x0, z0, R, name) elif opencg_surface.type == 'z-cylinder': x0 = opencg_surface.x0 y0 = opencg_surface.y0 R = opencg_surface.r openmc_surface = openmc.ZCylinder(surface_id, boundary, x0, y0, R, name) else: 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(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 OpenCG Surface to the global collection of all OpenCG Surfaces OPENCG_SURFACES[surface_id] = opencg_surface return openmc_surface
import openmc # Geometry ground_sphere = openmc.Sphere(0, -100.5, 0, 100, boundary_type='vacuum') cyl = openmc.YCylinder(0, -1, 0.5, boundary_type='vacuum') ymax = openmc.YPlane(1.0, boundary_type='vacuum') ymin = openmc.YPlane(0.3, boundary_type='vacuum') top_cap = openmc.Sphere(0, 1.0, -1, 0.5, boundary_type='vacuum') bottom_cap = openmc.Sphere(0, 0.3, -1, 0.5, boundary_type='vacuum') ground_cell = openmc.Cell(region=-ground_sphere) pill = openmc.Cell(region=((-cyl & -ymax & +ymin) | -top_cap | -bottom_cap)) another_sphere = openmc.Sphere(-1.5, 0.5, -1.0, 0.5, boundary_type='vacuum') another_sphere_cell = openmc.Cell(region=-another_sphere) ycone = openmc.YCone(1.5, 1.0, -1, 0.5, boundary_type='vacuum') cone_cell = openmc.Cell(region=(-ycone & -ymax & +ymin)) geometry = openmc.Geometry([ground_cell, pill, another_sphere_cell, cone_cell]) geometry.export_to_xml() # Placeholder materials file openmc.Materials().export_to_xml() # Minimal settings settings = openmc.Settings() settings.particles = 500 settings.batches = 10 settings.inactive = 1
fuel.add_nuclide('U235', 1.2377e-4) fuel.add_nuclide('U236', 1.2085e-6) fuel.add_nuclide('U238', 2.3508e-3) fuel.set_density('atom/b-cm', 9.6726E-02) fuel.add_s_alpha_beta('c_H_in_H2O') fuel.temperature = 300 mats = openmc.Materials([ss304, air, fuel]) mats.export_to_xml() yp1 = openmc.YPlane(y0=-40.0) yp2 = openmc.YPlane(y0=-37.1425) yp3 = openmc.YPlane(y0=7.6575) yp4 = openmc.YPlane(y0=39.375) yp5 = openmc.YPlane(y0=41.28) yc6 = openmc.YCylinder(x0=0, z0=0, R=2.54) yc7 = openmc.YCylinder(x0=0, z0=0, R=3.175) yc8 = openmc.YCylinder(x0=0, z0=0, R=24.4475) yc9 = openmc.YCylinder(x0=0, z0=0, R=25.4) sph = openmc.Sphere(R=60.0) sph.boundary_type = 'vacuum' cell1 = openmc.Cell() cell1.region = +yp1 & -yp5 & -yc6 cell1.fill = air cell2 = openmc.Cell() cell2.region = +yc6 & +yp1 & -yp2 & -yc9 cell2.fill = ss304 cell3 = openmc.Cell()