Voxel file generating problem

Dear experts @pshriwise @paulromano , I want to create a voxel image on a simple model in OpenMC. Even though I added the voxel creation scripts to my Python code, the voxel.h5 file does not appear among my output files. How can I solve this problem?

%matplotlib inline
import math
import openmc
import vtk
fuel = openmc.Material(name="uo2")
fuel.add_element("U", 1, percent_type="ao", enrichment=4.25)
fuel.add_element("O", 2)
fuel.set_density("g/cc", 10.4)

clad = openmc.Material(name="clad")
clad.add_element("Zr", 1)
clad.set_density("g/cc", 6)

water = openmc.Material(name="water")
water.add_element("O", 1)
water.add_element("H", 2)
water.set_density("g/cc", 1.0)
water.add_s_alpha_beta("c_H_in_H2O")
materials = openmc.Materials([fuel, clad, water])
materials.export_to_xml()
radii = [0.42, 0.45]
pin_surfaces = [openmc.ZCylinder(r=r) for r in radii]
pin_univ = openmc.model.pin(pin_surfaces, materials)
bound_box = openmc.model.rectangular_prism(1.24, 1.24, boundary_type="reflective")
root_cell = openmc.Cell(fill=pin_univ, region=bound_box)
geometry = openmc.Geometry([root_cell])
geometry.export_to_xml()
vox_plot = openmc.Plot()
vox_plot.type = 'voxel'
vox_plot.filename= 'voxel.h5'
vox_plot.width = (100., 100., 50.)
vox_plot.pixels = (400, 400, 200)
plots.append(vox_plot)
plots= openmc.Plots()
plots.export_to_xml()
settings = openmc.Settings()
settings.particles = 1000
settings.inactive = 10
settings.batches = 50
settings.export_to_xml()
openmc.run()
1 Like

Hiya @pfproton,

To produce a voxel file, you’ll need to run OpenMC in “plotting mode”. You can do this by replacing the openmc.run() line in your script with openmc.plot_geometry().

2 Likes

It created a voxel.h5 file, but I got an error when I ran this script.

import openmc
import vtk
!openmc-voxel-to-vtk voxel.h5 --output
Traceback (most recent call last):
  File "/home/user/.local/bin/openmc-voxel-to-vtk", line 4, in <module>
    __import__('pkg_resources').run_script('openmc==0.14.0', 'openmc-voxel-to-vtk')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 656, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1441, in run_script
    raise ResolutionError(
pkg_resources.ResolutionError: Script 'scripts/openmc-voxel-to-vtk' not found in metadata at '/home/user/.local/lib/python3.10/site-packages/openmc-0.14.0.dist-info'

You need to set the path of the code script correctly.Example

user@DESKTOP: $HOME/openmc/scripts/openmc-voxel-to-vtk   voxel.h5
1 Like