# Geometry plotting not working as expected

**URL:** <https://openmc.discourse.group/t/geometry-plotting-not-working-as-expected/3218>\
**Category:** User Support\
**Created:** [July 20, 2023, 10:56pm UTC](https://openmc.discourse.group/t/geometry-plotting-not-working-as-expected/3218 "2023-07-20T22:56:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbehne](https://avatars.discourse-cdn.com/v4/letter/p/e495f1/32.png) [@pbehne](https://openmc.discourse.group/u/pbehne)\
**Post date:** [July 20, 2023, 10:56pm UTC](https://openmc.discourse.group/t/geometry-plotting-not-working-as-expected/3218/1 "2023-07-20T22:56:00Z")

</div>

Hello,

I am trying to plot my cylindrical geometry for the simple input below. I am following the instructions [here](https://docs.openmc.org/en/stable/usersguide/plots.html). When I open the vti file in paraview, I only see a cube of side length 50 instead of my cylindrical geometry. I am running the file with python, then running openmc --plot, then running openmc-voxel-to-vtk plot\_1.h5 What am I doing wrong? Thanks!

> import numpy as np
> 
> import openmc  
> import openmc.mgxs as mgxs
> 
> # create a model object to tie geometry, materials, settings, and tallies together  
> model = openmc.Model()
> 
> # Instantiate a Material and register the Nuclides  
> inf\_medium = openmc.Material(name=‘moderator’)  
> inf\_medium.set\_density(‘g/cc’, 5.)  
> inf\_medium.add\_nuclide(‘C12’, 0.01450188)  
> inf\_medium.add\_nuclide(‘U235’, 0.000114142)  
> inf\_medium.add\_nuclide(‘U238’, 0.006886019)
> 
> # Instantiate a Materials collection and export to XML  
> model.materials = openmc.Materials([inf\_medium])  
> model.materials.export\_to\_xml()
> 
> # Lengths in cm  
> thickness = 1.27  
> inner\_radius = 36.83  
> inner\_height = 251.46
> 
> outer\_radius = inner\_radius + thickness  
> total\_height = 2 \* thickness + inner\_height
> 
> # Instantiate boundary Planes  
> #inner\_tube = openmc.ZCylinder(r=inner\_radius)  
> outer\_tube = openmc.ZCylinder(r=outer\_radius, boundary\_type=‘vacuum’)
> 
> bottom = openmc.ZPlane(z0=0.0, boundary\_type=‘vacuum’)  
> #cavity\_start = openmc.ZPlane(z0=thickness)  
> #cavity\_end = openmc.ZPlane(z0=thickness + inner\_height)  
> top = openmc.ZPlane(z0=total\_height, boundary\_type=‘vacuum’)
> 
> # Instantiate a Cell  
> cell = openmc.Cell(cell\_id=1, name=‘cell’)
> 
> # Register bounding Surfaces with the Cell  
> cell.region = +bottom & -top & -outer\_tube
> 
> # Fill the Cell with the Material  
> cell.fill = inf\_medium
> 
> # Create root universe  
> root\_universe = openmc.Universe(name=‘root universe’, cells=[cell])
> 
> # Create Geometry and set root Universe  
> model.geometry = openmc.Geometry(root\_universe)  
> model.geometry.export\_to\_xml()
> 
> # OpenMC simulation parameters  
> batches = 50  
> inactive = 10  
> particles = 2500  
> #generations\_per\_batch = 1
> 
> # Instantiate a Settings object  
> settings = openmc.Settings()  
> settings.batches = batches  
> settings.inactive = inactive  
> settings.particles = particles  
> #settings.generations\_per\_batch = generations\_per\_batch  
> settings.output = {‘tallies’: True}
> 
> # Create an initial uniform spatial source distribution over fissionable zones  
> r\_dist = openmc.stats.Uniform(0, inner\_radius)  
> phi\_dist = openmc.stats.Uniform(0, 2\*np.pi)  
> z\_dist = openmc.stats.Uniform(thickness, thickness + inner\_height)  
> uniform\_dist = openmc.stats.CylindricalIndependent(r\_dist, phi\_dist, z\_dist)  
> settings.source = openmc.Source(space=uniform\_dist)
> 
> model.settings = settings  
> settings.export\_to\_xml()
> 
> # Instantiate a 2-group EnergyGroups object  
> groups = mgxs.EnergyGroups(group\_edges=np.array([0., 0.625, 20.0e6]))
> 
> # Instantiate a few different sections  
> total = mgxs.TotalXS(domain=cell, energy\_groups=groups)  
> absorption = mgxs.AbsorptionXS(domain=cell, energy\_groups=groups)  
> scattering = mgxs.ScatterXS(domain=cell, energy\_groups=groups)
> 
> # Note that if we wanted to incorporate neutron multiplication in the  
> # scattering cross section we would write the previous line as:  
> # scattering = mgxs.ScatterXS(domain=cell, energy\_groups=groups, nu=True)
> 
> # Instantiate an empty Tallies object  
> tallies = openmc.Tallies()
> 
> # Add total tallies to the tallies file  
> tallies += total.tallies.values()
> 
> # Add absorption tallies to the tallies file  
> tallies += absorption.tallies.values()
> 
> # Add scattering tallies to the tallies file  
> tallies += scattering.tallies.values()
> 
> model.tallies = tallies
> 
> tallies.export\_to\_xml()
> 
> # Geometry plot  
> vox\_plot = openmc.Plot()  
> vox\_plot.type = ‘voxel’  
> vox\_plot.width = (100., 100., 100.)  
> vox\_plot.pixels = (400, 400, 400)
> 
> plots = openmc.Plots([vox\_plot])  
> plots.export\_to\_xml()

---

<div class="post-metadata">

**Author:** ![Pranto](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pranto/32/489_2.png) [@Pranto](https://openmc.discourse.group/u/Pranto)\
**Post date:** [July 21, 2023, 4:24am UTC](https://openmc.discourse.group/t/geometry-plotting-not-working-as-expected/3218/2 "2023-07-21T04:24:16Z")

</div>

@pbehne Paraview automatically shows all geometry cells specified in OpenMC, including **vacuum cells**. The IDs of these cells might start from negative values. To visualize only your desired cylindrical geometry, you can use the `Threshold` filter in Paraview. This filter allows you to select a specific range of cell IDs to display. By setting the threshold to exclude the vacuum cells, you should be able to see your cylindrical geometry correctly.

 ![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/4/41bb3fffcaf5ae7044dea35865ac9586272e2bae.png)

---

<div class="post-metadata">

**Author:** ![pbehne](https://avatars.discourse-cdn.com/v4/letter/p/e495f1/32.png) [@pbehne](https://openmc.discourse.group/u/pbehne)\
**Post date:** [July 21, 2023, 3:15pm UTC](https://openmc.discourse.group/t/geometry-plotting-not-working-as-expected/3218/3 "2023-07-21T15:15:55Z")

</div>

Thank you, @Pranto! Now that I can see my cylindrical geometry, I have a follow-up question. In the input file, I specified a cylinder of radius ~38 cm and height ~254 cm. However, it looks like I am getting a cylinder with the correct radius, but only half the expected height. When I look at a slice through entire geometry, I see the correct height, but the cylinder ends halfway down:

 ![image](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/9/965ad994289c244d812dd427f4d859bf9626c0ee.jpeg)

Do you know what is going on here?

---

<div class="post-metadata">

**Author:** ![Pranto](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pranto/32/489_2.png) [@Pranto](https://openmc.discourse.group/u/Pranto)\
**Post date:** [July 21, 2023, 6:02pm UTC](https://openmc.discourse.group/t/geometry-plotting-not-working-as-expected/3218/4 "2023-07-21T18:02:48Z")

</div>

The issue you are facing with the height of the cylinder is due to the default origin used in the plot. In OpenMC, the width of the voxels gets halved in each direction from the origin. As a result, when you visualize the cylindrical geometry with the default origin (0, 0, 0), it leads to the widths of the voxels being divided in half, resulting in a cylinder with only half the expected height. To get the full height, you can change the origin of the plot to (0, 0, H/2), where H is the height of the cylinder. This will ensure that the cylinder is centered correctly and spans the entire height.

A modified code snippet below that incorporates this suggested change:

```python
vox_plot = openmc.Plot()
vox_plot.type = 'voxel'
vox_plot.origin = (0., 0., total_height/2)
vox_plot.width = (outer_radius*2, outer_radius*2, total_height)

```

I hope this helps! Please let me know if you have any questions.
