How to create unstructured meshes for tallying

Hello,

I am using openmc to model fixed sources. I am just starting out so keeping it simple.

I am able to run simulations using CAD that I made in FreeCAD and then turned into .h5m-files using cad_to_dagmc (GitHub - fusion-energy/cad_to_dagmc: Convert CAD geometry (STP files) and Cadquery shapes to DAGMC h5m files). I can analyse the results like I normally would using structured meshes.

My question is how to best create an unstructured mesh to be used for tallying? I can’t find much information online so I would appreciate any help!

1 Like

Welcome to the community Maarten

Great to hear that cad-to-dagmc is useful for the triangular surface meshes. I wrote that recently and am delighted to hear of people using it.

Patrick is the expert here but I can give some pointers while the US is asleep. There are examples on using an unstructured mesh here GitHub - openmc-dev/openmc-notebooks: Example Jupyter notebooks for OpenMC but these do start from a mesh file.

There are two routes for making the unstructured mesh.

Option one.
Produce a tetrahedral mesh using Cubit, save as a h5 file, make sure dagmc is included in the openmc binary (either via conda or compilation), use the h5 file as shown by the example notebooks.
openmc.UnstructuredMesh(“filename.h5”, library=‘moab’)

Option two
Produce a mesh in Exodus and save it in .exo format. Make sure libmesh is included in the openmc binary (not currently available with conda, possible via the compile route). Use the exo file as shown in the notebooks.
openmc.UnstructuredMesh(“filename.exo”, library=‘libmesh’)

To make this easier we should look into including libmesh in the conda package. Otherwise I would suggest making use of the dockerfile with libmesh as it takes a while to compile.
https://hub.docker.com/r/openmc/openmc/tags

1 Like

Hello, I’m interested in the topic.

I have a CAD file (in .stp format). If I have correctly understood, I have to first assign the materials/boundary conditions to the CAD file and then, using the “cad_to_openmc” package, export it in “.h5m”.

My question is: how should I assign the materials/BC to the CAD file?

Thanks

The making of a h5m file for use in DAGMC can also be done in a variety of ways, essentially one needs triangle sets and their connectivity to make the geometry:

Here are some methods of the top of my head, but we maintain a complete list here

  • openmc-to-cad link
  • Cubit and the DAGMC-plugin [link] [link]
  • cad-to-h5m (a Cubit wrapper) [link]
  • stl-to-h5m (requires non overlapping stl files) [link]
  • vertices-to-h5m (requires mesh info) [link]
  • brep-to-h5m (requires brep cad file) [link]
  • cad-to-dagmc (my latest creation and new personal favorite) [link]

Assigning the outer vacuum boundary conditions to the h5m DAGMC geometry was recently discussed on this thread.

There are a few options but in summary the boundary condition can be made automatically by using the bounded_universe introduced by an awesome PR in version 0.13.1

dagunv = openmc.DAGMCUniverse("dagmc.h5m").bounded_universe()

Assigning materials to a DAGMC Universe can be done in two steps.

First, identify the material names within the universe

This can now be done with another awesome PR in openmc 0.13.1 and above using the material_names property

dagunv = openmc.DAGMCUniverse("dagmc.h5m").bounded_universe()
dagunv.material_names
>>> ["openmc_is_great", "especially_with_dagmc"]

Assuming this returns two materials called “openmc_is_great” and another one called “especially_with_dagmc” which I would imaging are ever ones first choice of material names :wink:

Secondly, make use of these material names when making materials

mat1 = openmc.Material(name="openmc_is_great")
mat1.add_element('Li', 1)
...
mat2 = openmc.Material(name="especially_with_dagmc")
mat1.add_element('Pb', 1)
...

Hi Shimwell,

Instead of opening another forum post I figure I’d ask in this forum since the subject matter is similar. In Cubit Coreform I meshed my geometry, simple sphere, as a Tetmesh and exported the file as a dagmc .h5m. I run the simulation and it converges nicely, expect that openmc cannot read the mesh as seen below:

Moreover, when I go to post-process the results I see no data in my tallies…

Here is my code for the meshed geometry and tallies :

Geometry input

mesh_library = ‘moab’ # change to ‘libmesh’ to use libMesh instead

Import Tetmesh’d Geometry

mesh_file = ‘NeutronBall.h5m’ # Import h5m files (mesh)

Create DAGMC universes out of h5m files

NeutronBall= openmc.DAGMCUniverse(filename=mesh_file)

Create regions

Fuel_region = NeutronBall.bounding_region()

Create openmc Cells

Fuel_cell = openmc.Cell(region=Fuel_region , fill=plutonium)

Read Mesh

umesh = openmc.UnstructuredMesh(mesh_file, library=mesh_library)
mesh_filter = openmc.MeshFilter(umesh)

Create openmc Geometry object

geo = openmc.Geometry([Fuel_cell,])

geo.export_to_xml()

Tallies

tally = openmc.Tally(name=‘NeutronFlux’)
tally.filters = [openmc.MeshFilter(umesh)]
tally.scores = [“flux”]
tallies_file.append(tally)

It seems settings.dagmc = True is not creating an element in the settings xml file

settings.dagmc=True has been deprecated.

The current version of openmc has an improved method of making dagmc geometries.

# makes a bounding box around the CAD geometry with vacuum surfaces
bound_dag_univ = openmc.DAGMCUniverse(filename='dagmc.h5m').bounded_universe() 

Just to mention we also have a DAGMC discussion forum over here which could be a good source of DAGMC knowledge (especially Cubit related workflow).

Thank you, I am very new to all of this so my apologies. Thank you for this link I will discuss there! :slight_smile:

Happy to answer questions here or on the DAGMC discussions. A few of us are on both forums but not all the DAGMC developers are here on the openmc forum.

The dagmc=True was a fairly recent change

Hello @Shimwell

Could you please tell me how to export mesh files created in cubit in format of h5 or h5m? Cause I cannot find the file format in the list.

@Jacob unfortunately the export is not in the menu but can be achieved with the Cubit terminal command

export dagmc dagmc.h5m

For this to work you will need the Cubit plugin installing

There are also a few other steps like imprinting and merging

I wrote a package for automating the loading, merging, imprinting and exporting all with python if that helps

Okay,thank you so much! @Shimwell

Hi, I have a question about unstructured grids. My computer configuration and plugin (dagmc cubit) have been installed. Can be done the case “https://nbviewer.org/github/openmc-dev/openmc-notebooks/blob/main/unstructured-mesh-part-i.ipynb”, However, for my simple geometry, I built the mesh in cubit, export dagmc “test.h5m” and took .h5m file as umesh. The whole process can be calculated, but the tallies.out file is empty and cannot identify and loading my mesh file .This question diffuse me.

I have got the same problem as you. If you have got the solution please suggest me how can I create tetrahedral mesh in cubit and then export it into dagmc file.