# Pincell visualisation

**URL:** <https://openmc.discourse.group/t/pincell-visualisation/4231>\
**Category:** User Support\
**Created:** [May 3, 2024, 10:19am UTC](https://openmc.discourse.group/t/pincell-visualisation/4231 "2024-05-03T10:19:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariemm](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@mariemm](https://openmc.discourse.group/u/mariemm)\
**Post date:** [May 3, 2024, 10:19am UTC](https://openmc.discourse.group/t/pincell-visualisation/4231/1 "2024-05-03T10:19:56Z")

</div>

why i can’t visualize the plenume and the top or bottom nozzle here

from math import log10  
import openmc.mgxs  
from IPython.display import Image  
import numpy as np  
import matplotlib.pyplot as plt  
import openmc

# Create materials for the problem

uo2 = openmc.Material(name=‘UO2 fuel at 4.95% wt enrichment’)  
uo2.set\_density(‘g/cm3’, 10.53)  
uo2.add\_element(‘U’, 1., enrichment=4.95)  
uo2.add\_element(‘O’, 2.)

# Create Helium gas material for fuel pin gap

helium = openmc.Material(name=‘Helium for gap’)  
helium.set\_density(‘g/cm3’, 0.0015981 )  
helium.add\_element(‘He’, 2.4044e-4)

# Create air material for instrument tubes

air\_instrument = openmc.Material(name=‘Air’)  
air\_instrument.set\_density(‘g/cc’, 0.00616)  
air\_instrument.add\_element(‘O’, 0.2095, ‘ao’)  
air\_instrument.add\_element(‘N’, 0.7809, ‘ao’)  
air\_instrument.add\_element(‘Ar’, 0.00933, ‘ao’)  
air\_instrument.add\_element(‘C’, 0.00027, ‘ao’)

# Create M5 alloy material

m5\_niobium = 0.01 # [http://publications.jrc.ec.europa.eu/repository/bitstream/JRC100644/lcna28366enn.pdf](http://publications.jrc.ec.europa.eu/repository/bitstream/JRC100644/lcna28366enn.pdf)  
m5\_oxygen = 0.00135 # [http://publications.jrc.ec.europa.eu/repository/bitstream/JRC100644/lcna28366enn.pdf](http://publications.jrc.ec.europa.eu/repository/bitstream/JRC100644/lcna28366enn.pdf)  
m5\_density = 6.494 # 10.1039/C5DT03403E  
m5\_alloy = openmc.Material(name=‘M5’)  
m5\_alloy.add\_element(‘Zr’, 1.0 - m5\_niobium - m5\_oxygen)  
m5\_alloy.add\_element(‘Nb’, m5\_niobium)  
m5\_alloy.add\_element(‘O’, m5\_oxygen)  
m5\_alloy.set\_density(‘g/cm3’, m5\_density)

# Create inconel 718 material

inconel\_718 = openmc.Material(name=‘Inconel’)  
inconel\_718.set\_density(‘g/cc’, 8.2)  
inconel\_718.add\_element(‘Si’, 0.0035, ‘wo’)  
inconel\_718.add\_element(‘Cr’, 0.1896, ‘wo’)  
inconel\_718.add\_element(‘Mn’, 0.0087, ‘wo’)  
inconel\_718.add\_element(‘Fe’, 0.2863, ‘wo’)  
inconel\_718.add\_element(‘Ni’, 0.5119, ‘wo’)

# Create light water for coolant / moderator

coolant = openmc.Material(name=‘Coolant’)  
coolant.set\_density(‘g/cm3’, 0.997)  
coolant.add\_element(‘H’, 2.0)  
coolant.add\_element(‘O’, 1.0)  
coolant.add\_s\_alpha\_beta(‘c\_H\_in\_H2O’)

# Create stainless steel material

SS304 = openmc.Material(name=‘SS304’)  
SS304.set\_density(‘g/cc’, 8.03)  
SS304.add\_element(‘Si’, 0.0060, ‘wo’)  
SS304.add\_element(‘Cr’, 0.1900, ‘wo’)  
SS304.add\_element(‘Mn’, 0.0200, ‘wo’)  
SS304.add\_element(‘Fe’, 0.6840, ‘wo’)  
SS304.add\_element(‘Ni’, 0.1000, ‘wo’)

# Create Ag-In-Cd control rod material

AIC= openmc.Material(name=‘Ag-In-Cd’)  
AIC.set\_density(‘g/cc’, 10.16)  
AIC.add\_element(‘Ag’, 0.80, ‘wo’)  
AIC.add\_element(‘In’, 0.15, ‘wo’)  
AIC.add\_element(‘Cd’, 0.05, ‘wo’)

# Create stainless steel 302

SS302= openmc.Material(name=‘SS302’)  
SS302.set\_density(‘g/cm3’, 7.86)  
SS302.add\_element(‘Si’, 0.01, ‘wo’)  
SS302.add\_element(‘Cr’, 0.18, ‘wo’)  
SS302.add\_element(‘Mn’, 0.02, ‘wo’)  
SS302.add\_element(‘Fe’, 0.70, ‘wo’)  
SS302.add\_element(‘Ni’, 0.09, ‘wo’)

# Create zircaloy 4 material

zircaloy\_4 = openmc.Material(name=‘Zircaloy-4’)  
zircaloy\_4.set\_density(‘g/cc’, 6.55)  
zircaloy\_4.add\_element(‘O’, 0.00125, ‘wo’)  
zircaloy\_4.add\_element(‘Cr’, 0.0010, ‘wo’)  
zircaloy\_4.add\_element(‘Fe’, 0.0021, ‘wo’)  
zircaloy\_4.add\_element(‘Zr’, 0.98115, ‘wo’)  
zircaloy\_4.add\_element(‘Sn’, 0.0145, ‘wo’)

materials = openmc.Materials([uo2, helium, inconel\_718, m5\_alloy, coolant, SS304, SS302, zircaloy\_4, AIC, air\_instrument])  
materials.export\_to\_xml()

# Define problem geometry

INCHES=2.54

h\_fuel=200  
plenum\_length = 13.4899  
h\_fuel\_rod = 215.9  
h\_lower\_end\_cap = 1.4606  
pitch = 1.2598  
h\_total=230

top\_nozzle\_height = 3.551\*INCHES  
top\_nozzle\_width = 0.25

bottom\_lower\_nozzle = h\_fuel + plenum\_length  
top\_lower\_nozzle = bottom\_lower\_nozzle +top\_nozzle\_height

bottom\_upper\_nozzle = h\_fuel + plenum\_length  
top\_upper\_nozzle = bottom\_upper\_nozzle +top\_nozzle\_height

# Create cylindrical surfaces

fuel\_or = openmc.ZCylinder(r=0.405765, name=‘Fuel OR’)  
fuel\_t\_plan = openmc.ZPlane(z0=h\_fuel/2)  
fuel\_b\_plan = openmc.ZPlane(z0=-h\_fuel/2)

clad\_ir = openmc.ZCylinder( r=0.41402, name=‘Clad IR’)  
clad\_or = openmc.ZCylinder(r=0.47498, name=‘Clad OR’)

plenum\_or = openmc.ZCylinder(r=0.06459 , name=‘Plenum OR’)  
plenum\_t\_plan = openmc.ZPlane(z0=h\_fuel+plenum\_length)

top\_nozzle = openmc.ZCylinder(r=top\_nozzle\_height /2 , name=‘Top nozzle’)  
top\_upper\_nozzle\_plane = openmc.ZPlane(z0=top\_upper\_nozzle )  
bottom\_upper\_nozzle\_plane = openmc.ZPlane(z0=bottom\_upper\_nozzle)

top\_lower\_nozzle\_plane = openmc.ZPlane(z0= -top\_lower\_nozzle )  
bottom\_lower\_nozzle\_plane = openmc.ZPlane(z0= -bottom\_lower\_nozzle)

# Create cells, mapping materials to regions

def fuel\_pin():  
“”“Returns a fuel pin universe.”“”  
fuel\_cell = openmc.Cell(name=‘Fuel’, fill=uo2, region=-fuel\_or & -fuel\_t\_plan & +fuel\_b\_plan)  
gap\_cell = openmc.Cell(name=‘Gap’, fill=helium, region=+fuel\_or & -clad\_ir & -fuel\_t\_plan & +fuel\_b\_plan)  
clad\_cell = openmc.Cell(name=‘Clad’, fill=m5\_alloy, region=+clad\_ir & -clad\_or& -fuel\_t\_plan & +fuel\_b\_plan)  
moderator\_cell = openmc.Cell(name=‘Moderator’, fill=coolant, region=+clad\_or & -fuel\_t\_plan & +fuel\_b\_plan )

```
univ = openmc.Universe(name='Fuel Pin')
univ.add_cells([fuel_cell, gap_cell, clad_cell, moderator_cell])
return univ

```

def plenum():  
“”“Returns a plenum part universe.”“”  
plenum\_cell = openmc.Cell(fill=SS302, region= -plenum\_or )  
pl\_gap\_cell = openmc.Cell(fill=helium, region= +plenum\_or & -clad\_ir)  
pl\_clad\_cell = openmc.Cell(fill=m5\_alloy, region=+clad\_ir & -clad\_or)  
pl\_moderator\_cell = openmc.Cell(fill=coolant,region=+clad\_or & +fuel\_t\_plan & -plenum\_t\_plan )

```
univ = openmc.Universe(name='Plenum Part')
univ.add_cells([plenum_cell, pl_gap_cell, pl_clad_cell, pl_moderator_cell])
return univ

```

def Top\_nozzle():  
“”“Returns a top nozzle part universe.”“”  
t\_nozz\_cell = openmc.Cell(fill=SS304, region= -top\_nozzle )  
t\_n\_moderator\_cell = openmc.Cell(fill=coolant,region= +top\_nozzle & -top\_upper\_nozzle\_plane & +bottom\_upper\_nozzle\_plane )

```
univ = openmc.Universe(name='Top nozzle part')
univ.add_cells([t_nozz_cell, t_n_moderator_cell])
return univ

```

def Bot\_nozzle():  
“”“Returns a bot nozzle part universe.”“”  
b\_nozz\_cell = openmc.Cell(fill=SS304, region= -top\_nozzle )  
b\_n\_moderator\_cell = openmc.Cell( fill = coolant, region= +top\_nozzle & +top\_lower\_nozzle\_plane & -bottom\_lower\_nozzle\_plane)

```
univ = openmc.Universe(name='Bot nozzle part')
univ.add_cells([b_nozz_cell, b_n_moderator_cell])
return univ

```

def setup\_root\_universe():  
fuel\_pin\_universe = fuel\_pin()  
plenum\_universe = plenum()  
top\_nozzle\_universe = Top\_nozzle()  
bot\_nozzle\_universe = Bot\_nozzle()

```
container_universe = openmc.Universe(name='Container Universe')
fuel_pin_cell = openmc.Cell(name='Fuel Pin Cell', fill=fuel_pin_universe)
plenum_cell = openmc.Cell(name='Plenum Cell', fill=plenum_universe)
T_noz_cell = openmc.Cell(name='Top nozzle', fill=top_nozzle_universe)
B_noz_cell = openmc.Cell(name='Bot nozzle', fill=bot_nozzle_universe)

container_universe.add_cells([fuel_pin_cell, plenum_cell, T_noz_cell, B_noz_cell])

root_cell = openmc.Cell(name='Root Cell', fill=container_universe)

# Boundary planes
min_x = openmc.XPlane(x0=-pitch/2, boundary_type='reflective')
max_x = openmc.XPlane(x0=pitch/2, boundary_type='reflective')
min_y = openmc.YPlane(y0=-pitch/2, boundary_type='reflective')
max_y = openmc.YPlane(y0=pitch/2, boundary_type='reflective')
min_z = openmc.ZPlane(z0=-300/2, boundary_type='reflective')
max_z = openmc.ZPlane(z0=300/2, boundary_type='reflective')

root_cell.region = +min_x & -max_x & +min_y & -max_y & +min_z & -max_z

root_universe = openmc.Universe(name='Root Universe')
root_universe.add_cell(root_cell)

geometry = openmc.Geometry(root_universe)
geometry.export_to_xml()

```

setup\_root\_universe()

##################################################################################################

# Plot in the XY-plane

plot\_xy = openmc.Plot()  
plot\_xy.filename = ‘plot\_xy’  
plot\_xy.origin = [0, 0, 0] # Centered at the origin  
plot\_xy.width = [pitch, pitch] # Width in X and Y  
plot\_xy.pixels = [200, 200]  
plot\_xy.basis = ‘xy’  
plot\_xy.color\_by = ‘material’  
plot\_xy.colors = {uo2: ‘yellow’, coolant: ‘blue’, helium:‘pink’ , SS302:‘red’}

# Plot in the XZ-plane

plot\_xz = openmc.Plot()  
plot\_xz.filename = ‘plot\_xz’  
plot\_xz.origin = [0, 0, -35] # Centered along the XZ-plane at y=0  
plot\_xz.width = [2, 350] # Width in X and Z  
plot\_xz.pixels = [200, 2000]  
plot\_xz.basis = ‘xz’  
plot\_xz.color\_by = ‘material’  
plot\_xz.colors = {uo2: ‘yellow’, coolant: ‘blue’,helium:‘pink’ , SS302:‘red’}

# Plot in the YZ-plane

plot\_yz = openmc.Plot()  
plot\_yz.filename = ‘plot\_yz’  
plot\_yz.origin = [0, 0, -35]  
plot\_yz.width = [2., 350]  
plot\_yz.basis = ‘yz’  
plot\_yz.pixels = [200, 2000]  
plot\_yz.color\_by = ‘material’  
plot\_yz.colors = {uo2: ‘yellow’, coolant: ‘blue’, helium:‘pink’ , SS302:‘red’}

# Instantiate a Plots collection, add plots, and export to XML

plot\_file = openmc.Plots([plot\_xy, plot\_xz, plot\_yz])  
plot\_file.export\_to\_xml()

openmc.plot\_inline(plot\_file)

settings = openmc.Settings()  
settings.batches = 100  
settings.inactive = 10  
settings.particles = 1000

# Create an initial uniform spatial source distribution over fissionable zones

lower\_left = (-pitch/2, -pitch/2, -1)  
upper\_right = (pitch/2, pitch/2, 1)  
uniform\_dist = openmc.stats.Box(lower\_left, upper\_right, only\_fissionable=True)  
settings.source = openmc.IndependentSource(space=uniform\_dist)  
settings.export\_to\_xml()

---

<div class="post-metadata">

**Author:** ![JustAnotherNeutron](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@JustAnotherNeutron](https://openmc.discourse.group/u/JustAnotherNeutron)\
**Post date:** [May 3, 2024, 10:43am UTC](https://openmc.discourse.group/t/pincell-visualisation/4231/2 "2024-05-03T10:43:25Z")

</div>

Not sure if this will answer your question, Im exclusively looking at the plotting portion of the code and im not sure what the output of this is (If this doesnt answer your question, you could add an attachment to show)

The origin is the middle of your plot, so if you wanted a topdown slice of the bottom nozzle you would have to adjust the z axis (for example).

I tend to try remove ambiguity for my width and just use (same principle can be applied for the origin):

```auto
bbox = geometry.bounding_box
plot_xy.width = (
    bbox [1][0] - bbox [0][0],
    bbox [1][1] - bbox [0][1],
)

```

Then just change the index as you need to. However, I dont see anything glaringly wrong with the plotting part of the code
