import openmoc
import openmoc.plotter as plotter
import openmoc.process as process
from openmoc.materialize import materialize
import matplotlib
import matplotlib.pyplot as plt
plt.rcParams.update({'figure.figsize': (10,10)})
matplotlib.use('Agg')
%pylab inline
Populating the interactive namespace from numpy and matplotlib
num_threads = 8
track_spacing = 0.01
num_azim = 64
tolerance = 1E-7
max_iters = 50
materials = materialize('../../c5g7-materials.h5')
print materials.keys()
[u'UO2', u'MOX-8.7%', u'Fission Chamber', u'MOX-4.3%', u'Water', u'MOX-7%', u'Guide Tube']
# Create Circles for the fuel as well as to discretize the moderator into rings
fuel_radius = openmoc.Circle(x=0.0, y=0.0, radius=0.54)
moderator_inner_radius = openmoc.Circle(x=0.0, y=0.0, radius=0.62)
moderator_outer_radius = openmoc.Circle(x=0.0, y=0.0, radius=0.58)
# Create planes to bound the entire geometry
left = openmoc.XPlane(x=-10.71, name='left')
right = openmoc.XPlane(x=10.71, name='right')
top = openmoc.YPlane(y=10.71, name='top')
bottom = openmoc.YPlane(y=-10.71, name='bottom')
left.setBoundaryType(openmoc.REFLECTIVE)
right.setBoundaryType(openmoc.REFLECTIVE)
top.setBoundaryType(openmoc.REFLECTIVE)
bottom.setBoundaryType(openmoc.REFLECTIVE)
# 4.3% MOX pin cell
mox43_cell = openmoc.CellBasic(rings=3, sectors=8)
mox43_cell.setMaterial(materials['MOX-4.3%'])
mox43_cell.addSurface(-1, fuel_radius)
mox43 = openmoc.Universe(name='MOX-4.3%')
mox43.addCell(mox43_cell)
# 7% MOX pin cell
mox7_cell = openmoc.CellBasic(rings=3, sectors=8)
mox7_cell.setMaterial(materials['MOX-7%'])
mox7_cell.addSurface(-1, fuel_radius)
mox7 = openmoc.Universe(name='MOX-7%')
mox7.addCell(mox7_cell)
# 8.7% MOX pin cell
mox87_cell = openmoc.CellBasic(rings=3, sectors=8)
mox87_cell.setMaterial(materials['MOX-8.7%'])
mox87_cell.addSurface(-1, fuel_radius)
mox87 = openmoc.Universe(name='MOX-8.7%')
mox87.addCell(mox87_cell)
# Fission chamber pin cell
fission_chamber_cell = openmoc.CellBasic(rings=3, sectors=8)
fission_chamber_cell.setMaterial(materials['Fission Chamber'])
fission_chamber_cell.addSurface(-1, fuel_radius)
fission_chamber = openmoc.Universe(name='Fission Chamber')
fission_chamber.addCell(fission_chamber_cell)
# Guide tube pin cell
guide_tube_cell = openmoc.CellBasic(rings=3, sectors=8)
guide_tube_cell.setMaterial(materials['Guide Tube'])
guide_tube_cell.addSurface(-1, fuel_radius)
guide_tube = openmoc.Universe(name='Guide Tube')
guide_tube.addCell(guide_tube_cell)
# Moderator rings
moderator_ring1 = openmoc.CellBasic(sectors=8)
moderator_ring2 = openmoc.CellBasic(sectors=8)
moderator_ring3 = openmoc.CellBasic(sectors=8)
moderator_ring1.setMaterial(materials['Water'])
moderator_ring2.setMaterial(materials['Water'])
moderator_ring3.setMaterial(materials['Water'])
moderator_ring1.addSurface(+1, fuel_radius)
moderator_ring1.addSurface(-1, moderator_inner_radius)
moderator_ring2.addSurface(+1, moderator_inner_radius)
moderator_ring2.addSurface(-1, moderator_outer_radius)
moderator_ring3.addSurface(+1, moderator_outer_radius)
# Add moderator rings to each pin cell
pins = [mox43, mox7, mox87, fission_chamber, guide_tube]
for pin in pins:
pin.addCell(moderator_ring1)
pin.addCell(moderator_ring2)
pin.addCell(moderator_ring3)
# CellFills for the assembly
assembly1_cell = openmoc.CellFill(name='Assembly 1')
assembly1 = openmoc.Universe(name='Assembly 1')
assembly1.addCell(assembly1_cell)
# A mixed enrichment PWR MOX fuel assembly
assembly = openmoc.Lattice(name='MOX Assembly')
assembly.setWidth(width_x=1.26, width_y=1.26)
# Create a template to map to pin cell types
template = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1],
[1, 2, 2, 2, 2, 4, 2, 2, 4, 2, 2, 4, 2, 2, 2, 2, 1],
[1, 2, 2, 4, 2, 3, 3, 3, 3, 3, 3, 3, 2, 4, 2, 2, 1],
[1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1],
[1, 2, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 2, 1],
[1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1],
[1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1],
[1, 2, 4, 3, 3, 4, 3, 3, 5, 3, 3, 4, 3, 3, 4, 2, 1],
[1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1],
[1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1],
[1, 2, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4, 2, 1],
[1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1],
[1, 2, 2, 4, 2, 3, 3, 3, 3, 3, 3, 3, 2, 4, 2, 2, 1],
[1, 2, 2, 2, 2, 4, 2, 2, 4, 2, 2, 4, 2, 2, 2, 2, 1],
[1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
universes = {1 : mox43, 2 : mox7, 3 : mox87,
4 : guide_tube, 5 : fission_chamber}
for i in range(17):
for j in range(17):
template[i][j] = universes[template[i][j]]
assembly.setUniverses(template)
# Root Cell/Universe
root_cell = openmoc.CellFill(name='Full Geometry')
root_cell.setFill(assembly)
root_cell.addSurface(+1, left)
root_cell.addSurface(-1, right)
root_cell.addSurface(-1, top)
root_cell.addSurface(+1, bottom)
root_universe = openmoc.Universe(name='Root Universe')
root_universe.addCell(root_cell)
cmfd = openmoc.Cmfd()
cmfd.setMOCRelaxationFactor(0.6)
cmfd.setSORRelaxationFactor(1.5)
cmfd.setLatticeStructure(51,51)
cmfd.setGroupStructure([1,4,8])
geometry = openmoc.Geometry()
geometry.setRootUniverse(root_universe)
geometry.setCmfd(cmfd)
geometry.initializeFlatSourceRegions()
# Plot the geometry color-coded by materials
plotter.plot_materials(geometry, gridsize=500)
# Load the figure into Matplotlib
plt.imshow(plt.imread('plots/materials.png'))
plt.axis('off')
[ NORMAL ] Plotting the materials...
(-0.5, 259.5, 265.5, -0.5)
# Plot the geometry color-coded by cells
plotter.plot_cells(geometry, gridsize=500)
# Load the figure into Matplotlib
plt.imshow(plt.imread('plots/cells.png'))
plt.axis('off')
[ NORMAL ] Plotting the cells...
(-0.5, 259.5, 265.5, -0.5)
track_generator = openmoc.TrackGenerator(geometry, num_azim, track_spacing)
track_generator.setNumThreads(num_threads)
track_generator.generateTracks()
[ NORMAL ] Ray tracing for track segmentation... [ NORMAL ] Dumping tracks to file...
# Plot the geometry color-coded by flat source region
plotter.plot_flat_source_regions(geometry, gridsize=500)
# Load the figure into Matplotlib
plt.imshow(plt.imread('plots/flat-source-regions.png'))
plt.axis('off')
[ NORMAL ] Plotting the flat source regions...
(-0.5, 259.5, 265.5, -0.5)
# Plot the geometry color-coded by CMFD cells
plotter.plot_cmfd_cells(geometry, cmfd, gridsize=500)
# Load the figure into Matplotlib
plt.imshow(plt.imread('plots/cmfd-cells.png'))
plt.axis('off')
[ NORMAL ] Plotting the CMFD cells...
(-0.5, 259.5, 265.5, -0.5)
solver = openmoc.CPUSolver(track_generator)
solver.setConvergenceThreshold(tolerance)
solver.setNumThreads(num_threads)
solver.computeEigenvalue(max_iters)
[ NORMAL ] Computing the eigenvalue... [ NORMAL ] Iteration 0: k_eff = 1.464702 res = INF [ NORMAL ] Iteration 1: k_eff = 1.393566 res = 1.027E-01 [ NORMAL ] Iteration 2: k_eff = 1.298866 res = 2.483E-02 [ NORMAL ] Iteration 3: k_eff = 1.244139 res = 2.780E-02 [ NORMAL ] Iteration 4: k_eff = 1.215402 res = 1.348E-02 [ NORMAL ] Iteration 5: k_eff = 1.201086 res = 6.036E-03 [ NORMAL ] Iteration 6: k_eff = 1.193764 res = 2.430E-03 [ NORMAL ] Iteration 7: k_eff = 1.189951 res = 1.257E-03 [ NORMAL ] Iteration 8: k_eff = 1.187926 res = 8.746E-04 [ NORMAL ] Iteration 9: k_eff = 1.186843 res = 6.728E-04 [ NORMAL ] Iteration 10: k_eff = 1.186257 res = 4.890E-04 [ NORMAL ] Iteration 11: k_eff = 1.185935 res = 3.356E-04 [ NORMAL ] Iteration 12: k_eff = 1.185765 res = 2.166E-04 [ NORMAL ] Iteration 13: k_eff = 1.185663 res = 1.324E-04 [ NORMAL ] Iteration 14: k_eff = 1.185592 res = 7.679E-05 [ NORMAL ] Iteration 15: k_eff = 1.185551 res = 4.344E-05 [ NORMAL ] Iteration 16: k_eff = 1.185517 res = 2.626E-05 [ NORMAL ] Iteration 17: k_eff = 1.185502 res = 1.899E-05 [ NORMAL ] Iteration 18: k_eff = 1.185475 res = 1.593E-05 [ NORMAL ] Iteration 19: k_eff = 1.185466 res = 1.363E-05 [ NORMAL ] Iteration 20: k_eff = 1.185459 res = 1.131E-05 [ NORMAL ] Iteration 21: k_eff = 1.185469 res = 9.086E-06 [ NORMAL ] Iteration 22: k_eff = 1.185464 res = 7.032E-06 [ NORMAL ] Iteration 23: k_eff = 1.185461 res = 5.359E-06 [ NORMAL ] Iteration 24: k_eff = 1.185458 res = 3.917E-06 [ NORMAL ] Iteration 25: k_eff = 1.185456 res = 2.820E-06 [ NORMAL ] Iteration 26: k_eff = 1.185455 res = 1.998E-06 [ NORMAL ] Iteration 27: k_eff = 1.185454 res = 1.400E-06 [ NORMAL ] Iteration 28: k_eff = 1.185453 res = 9.736E-07 [ NORMAL ] Iteration 29: k_eff = 1.185453 res = 6.731E-07 [ NORMAL ] Iteration 30: k_eff = 1.185452 res = 4.639E-07 [ NORMAL ] Iteration 31: k_eff = 1.185452 res = 3.194E-07 [ NORMAL ] Iteration 32: k_eff = 1.185452 res = 2.200E-07 [ NORMAL ] Iteration 33: k_eff = 1.185452 res = 1.518E-07 [ NORMAL ] Iteration 34: k_eff = 1.185452 res = 1.051E-07 [ NORMAL ] Iteration 35: k_eff = 1.185452 res = 7.304E-08
plotter.plot_spatial_fluxes(solver, energy_groups=[1,3,7], gridsize=500)
# Load fast flux figure into Matplotlib
plt.imshow(plt.imread('plots/fsr-flux-group-1.png'))
plt.axis('off')
[ NORMAL ] Plotting the FSR scalar fluxes...
(-0.5, 325.5, 265.5, -0.5)
# Load epithermal flux figure into Matplotlib
plt.imshow(plt.imread('plots/fsr-flux-group-3.png'))
plt.axis('off')
(-0.5, 332.5, 265.5, -0.5)
# Load thermal flux figure into Matplotlib
plt.imshow(plt.imread('plots/fsr-flux-group-7.png'))
plt.axis('off')
(-0.5, 331.5, 265.5, -0.5)
plotter.plot_fission_rates(solver, gridsize=500)
# Load FSR fission rates figure into Matplotlib
plt.imshow(plt.imread('plots/fission-rates.png'))
plt.axis('off')
[ NORMAL ] Plotting the flat source region fission rates...
(-0.5, 325.5, 265.5, -0.5)