# Mesh trouble reading/producing data

**URL:** <https://openmc.discourse.group/t/mesh-trouble-reading-producing-data/2775>\
**Category:** User Support\
**Created:** [February 26, 2023, 11:43am UTC](https://openmc.discourse.group/t/mesh-trouble-reading-producing-data/2775 "2023-02-26T11:43:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhelpling1](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@bhelpling1](https://openmc.discourse.group/u/bhelpling1)\
**Post date:** [February 26, 2023, 11:43am UTC](https://openmc.discourse.group/t/mesh-trouble-reading-producing-data/2775/1 "2023-02-26T11:43:08Z")

</div>

I have a similar problem to another user but the fixes outlined in that post do not solve my issue. I am starting to use meshes to plot data in 2d and 3d forms. For CSG geometry I have had no problems at all but since I have begun working with CAD it has made it much more confusing. I am getting very strange results when plotting scattering, absorption and flux through my basic aluminum sphere (plots will be attached at the bottom) Essentially when using a regular mesh, my plots for scattering and absorption show values only at the source and nowhere else. When I use an unstructured mesh, my tallies are completely empty and I cannot find any data, although the simulation runs fine with a reasonable leakage fraction. I will post my code below and the plots; any help would be greatly appreciated.

I get the following message when running with unstructured mesh:

WARNING: Output for a MOAB mesh (mesh 24) was requested but will not be  
written. Please use the Python API to generated the desired VTK  
tetrahedral mesh.

```auto
import cadquery as cq
from cadquery import Assembly
from cad_to_dagmc import CadToDagmc
%matplotlib inline
import os
import openmc
import matplotlib.pyplot as plt
import openmc.lib
from stl_to_h5m import stl_to_h5m
assert(openmc.lib._dagmc_enabled())

Aluminum = openmc.Material(name='aluminum') 
Aluminum.add_element('Al', 1, percent_type='ao')
#Aluminum.set_density('g/cm3', 2.7)

mats = openmc.Materials()
mats.append(Aluminum)
mats.append(air)
mats.export_to_xml()

from cad_to_dagmc import CadToDagmc

my_model = CadToDagmc()
my_model.add_stp_file("Sphere.step", material_tags=["aluminum"])
my_model.export_dagmc_h5m_file()

dag_univ = openmc.DAGMCUniverse(filename = 'dagmc.h5m')

# creates an edge of universe boundary at a large radius
vac_surf = openmc.Sphere(r=10000, surface_id=9999, boundary_type="vacuum")

# specifies the region as below the universe boundary
region = -vac_surf

# creates a cell from the region and fills the cell with the dagmc geometry
containing_cell = openmc.Cell(cell_id=9999, region=region, fill=dag_univ)

model = openmc.Model()
model.geometry = openmc.Geometry(root=[containing_cell])
model.geometry.export_to_xml()

settings = openmc.Settings()
settings.batches = 10
settings.inactive = 0
settings.particles = 500
settings.run_mode = 'fixed source'

source = openmc.Source()
source.space = openmc.stats.Point((0,9,0))
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14e3], [1])
source.particle = 'neutron'

settings.source = source
settings.export_to_xml()

mesh = openmc.RegularMesh().from_domain(
    model.geometry, # the corners of the mesh are being set automatically to surround the geometry
    dimension=[100, 1, 100] # only 1 cell in the Y dimension (change to cube for vtk file)
)

#mesh = openmc.UnstructuredMesh("sphere.h5m", 'moab')

tallies = openmc.Tallies()

# Create mesh filter for tally
mesh_filter = openmc.MeshFilter(mesh)

mesh_tally_1 = openmc.Tally(name='absorption')
mesh_tally_1.filters = [mesh_filter]
mesh_tally_1.scores = ['absorption']
tallies.append(mesh_tally_1)

mesh_tally_2 = openmc.Tally(name='scattering')
mesh_tally_2.filters = [mesh_filter]
mesh_tally_2.scores = ['scatter']
tallies.append(mesh_tally_2)
tallies.export_to_xml()

mesh_tally_3 = openmc.Tally(name='flux')
mesh_tally_3.filters = [mesh_filter]
mesh_tally_3.scores = ['flux']
tallies.append(mesh_tally_3)
tallies.export_to_xml()

model = openmc.model.Model(model.geometry, mats, settings, tallies)

# deletes old files
!rm summary.h5
!rm statepoint.*.h5
!rm plot_14.png
# runs the simulation
sp_filename = model.run()

# open the results file
results = openmc.StatePoint(sp_filename)

my_tally = results.get_tally(scores=['absorption'])
my_slice = my_tally.get_slice(scores=['absorption'])
my_slice.mean.shape = (mesh.dimension[0], mesh.dimension[2]) # setting the resolution to the mesh dimensions

fig = plt.subplot()
plt.show(fig.imshow(my_slice.mean, extent=[-250,250,-250,250]))

```

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

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [February 26, 2023, 11:14pm UTC](https://openmc.discourse.group/t/mesh-trouble-reading-producing-data/2775/2 "2023-02-26T23:14:25Z")

</div>

This looks like something I should look into as I see a few familiar packages in this script.

Are you able to share the Sphere.stp so I can rerun the whole script.

Hope to get sometime this week

---

<div class="post-metadata">

**Author:** ![bhelpling1](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@bhelpling1](https://openmc.discourse.group/u/bhelpling1)\
**Post date:** [February 27, 2023, 12:58am UTC](https://openmc.discourse.group/t/mesh-trouble-reading-producing-data/2775/3 "2023-02-27T00:58:39Z")

</div>

Hello @Shimwell I have two files that I can share. They are both contained in the file in the link. The first is the .stp file for the CAD geometry. The second is a .h5m for a mesh of the geometry made in Cubit.

[https://file.io/oNc3jz7QNBrh](https://file.io/oNc3jz7QNBrh) (Please no one else download this as the files will be removed after download)

After the mesh was made, I used these lines in the Cubit Command Prompt; please let me know if this is correct:

group “mat:aluminum” add vol 1

export dagmc “sphere\_Mesh.h5m” faceting\_tolerance 1e-3 make\_watertight verbose

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [February 28, 2023, 12:15pm UTC](https://openmc.discourse.group/t/mesh-trouble-reading-producing-data/2775/4 "2023-02-28T12:15:38Z")

</div>

I think the vac\_surf is just too large so the sphere of Aluminum is showing up as a single pixel on your 100x100 regular mesh

First I used mbconvert to convert the h5m file into a vtk file I was able to see the sphere geometry is small

 ![Screenshot from 2023-02-28 12-13-05](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/4/426b287137e4cf5e2171aa442590537432383020.png)

So then I changed this line

```auto
vac_surf = openmc.Sphere(r=10000, surface_id=9999, boundary_type="vacuum")

```

to

```auto
vac_surf = openmc.Sphere(r=100, surface_id=9999, boundary_type="vacuum")

```

I was then able to get a better pixel map  
 ![Screenshot from 2023-02-28 12-12-01](https://global.discourse-cdn.com/free1/uploads/openmc/original/2X/6/6edab9ad7499eeae4386ef885a44efca44982e90.png)
