Export to OpenMC - KeithSloan/GDML GitHub Wiki
Export to OpenMC
⚠️ ALPHA — This feature is under active development and is not yet stable.
The OpenMC export is an early alpha release. It has been tested on a limited set of geometries and materials. You will encounter cases where the export produces incorrect or incomplete results. Please test any exported geometry carefully in OpenMC before using it for simulation, and report any issues on the GDML Workbench issue tracker.
The interface, file format, and behaviour may change in future releases without notice.
OpenMC is an open-source Monte Carlo program for simulating neutron and photon transport. It is widely used in nuclear engineering and reactor physics, and is an increasingly popular alternative to GEANT4 for users who work primarily in the neutron transport domain.
The GDML Workbench can export a FreeCAD GDML document to the geometry and materials XML files read by OpenMC.
To export the geometry and materials to the xml files needed by openMC select the OpenMC (.xml) format when exporting the root volume:
The export will create three files:
docname-root.xml
docname-root_geometry.xml
docname-root_materials.xml
The docname-root.xml contains both the geometry and materials in one xml file.
I usually use this bash code to link the geometry.xml and materials.xml files to the exported file:
file=$1
rm geometry.xml
rm materials.xml
baseName="${file%.*}"
ln -s $baseName"_materials.xml" materials.xml
ln -s $baseName"_geometry.xml" geometry.xml
Geometry export
All the native GDML and Part Workbench solids can be exported as CSG of the surface regions supported by OpenMC. As in gdml export, booleans and arrays of solids, as well as revolves and extrusions of sketches are supported. Please refer to the GDML Wiki to see examples of the types of Solids that can be exported by the Workbench.
The geometry.xml file includes only three types of surfaces: planes, spheres and quadratics. Cones and cylinders are exported as quadratics to accommodate arbitrary orientation of the axis of these surfaces. To repeat: cones and cylinders in the document do not have to be constructed along the main x, y, z axes; they can be oriented and placed arbitrarily.
More complicated shapes are surface meshed by the exporting code and the resulting boundaries exported as CSG of the surrounding planes. This works well for convex surfaces of genus 0 (i.e., no holes). Relatively simple concave surfaces usually work, but some complex surfaces with twisted surfaces might not. You should double check the exported geometry to make sure it reflects the FreeCAD geometry! We are working on algorithms to deal with genus > 0 surfaces and have some preliminary code, but it is still under developement.
Please let us know in the forum if you encounter any problems.
Materials export
In geant4 materials are constructed in terms of elements. One can define elements in terms of isotopes, to specify, for example, a specific enrichment of Uranium, or to use heavy water. For OpenMC all materials are specified in terms of isotopes (in the python API one can specify elements and openmc will retrieve the natural isotopic abundances for the specified element, but in the materials.xml file, as of OpenMC version 0.15.3, the materials.xml file does not support the element tag). The github source code for the OpenMC export includes a file
freecad/gdml/Resources/Isotopic_abundances.csv that has the natural isotopic abundances of the elements, as tabulated recently by various outlets. That file is read when the export is executed. You can edit it to modiy, remove, or add any entries, but you should not change its name. But of course, be aware that any changes to the file will be overwritten if the GDML installation is updated, so make sure to save a copy under a different name for backup.
Newly created GDML documents will have a group called ReactorMaterials under the Materials group; this group includes (as of 2026-01-18) a limited number of some reactor materials. These can be found in the file freecad/gdml/Resources/ReactorMaterials.xml; again, as above you can edit that file, with the same caveats.
The Elements group also includes isotopically-enriched uranium elements. These are named enriched_U1, enriched_U2, ...enriched_U20. The xx after the Uxx refers to the percent enrichment in U235. These are provided for quick selection in the Materials assignment GUI, but you can always create any enrichment that is needed using the materials creation GUI under the GDML workbench.