# Simpler creation of RegularMesh with cube voxels

Hi all

Just posting a tiny idea in case anyone else has a similar need or a nice solution already.

I keep making RegularMesh tallies and am looking for a more convenient method of setting the number of voxels.

In this case I’m making voxels that are cubes with the same length width and height

Currently I calculate the height width and depth of the geometry and then I set a length for the voxel edge and calculate the number of voxels that fit in each axis of the geometry.

It is a bit messy (especially at the edges of the geometry where I round down) but it basically allows me to set a single “resolution” number for the mesh voxels which automatically finds the dimensions in x,y,z to set for the regular mesh.

Currently openmc allows

``````reg_mesh = openmc.RegularMesh().from_domain(
my_geometry,  # the corners of the mesh are being set automatically to surround the geometry
dimension=[200, 100, 25],  # needs a calculation to find number in each dimension for cubes
)
``````

With a bit of tinkering we could make the code accept a single “resolution” / voxel_edge_length

``````reg_mesh = openmc.RegularMesh().from_domain(
my_geometry,  # the corners of the mesh are being set automatically to surround the geometry
voxel_edge_length=5,  # sets the voxels to 5cm length, width, height and calculates dimension from this
)
``````

Interested on getting peoples feeback on this idea, also wondering if I am I the only one who spends time trying to set the regular mesh dimensions so that I end up with voxels that are cubes?

Cheers

Jon

Currently I am using this code snippet to make cubes fit in the geometry

``````voxel_edge_length = 20.

bb = self.geometry.bounding_box
bb_x_length = abs(bb[0][0] - bb[1][0])
bb_y_length = abs(bb[0][1] - bb[1][1])
bb_z_length = abs(bb[0][2] - bb[1][2])

ww_r_mesh = openmc.RegularMesh().from_domain(
self.geometry,  # the corners of the mesh are being set automatically to surround the geometry
dimension=[
int(bb_x_length/cube_length),
int(bb_y_length/cube_length),
int(bb_z_length/cube_length),
],
)
``````