OpenMC
- OpenMC
- Making OpenMC work on WSL/LCLRS/MERLIN via Apptainer
- Making OpenMC work on WSL/LCLRS/MERLIN via Apptainer coverted from Docker Image
- OpenMC libraries
- Tutorial alternatives
- Goodies!
Make your own env and compile it
(Not finished) My recomandation for the env:
-
install direnv --> hook
-
install pyen --> hook in bachrc
-
install python 3.12.0
-
install/compile openmc
-
install the api
Quick Install Guide
Making OpenMC work on WSL/LCLRS/MERLIN via Apptainer
Even though the website says to use the docker, we'll make use of apptainer, because is more friendly and is available on all platforms (LCLRS and MERLIN). Docker works as well, but I find it cumbersome.
This will make a sif image for the container to run from, localy in the folder
apptainer pull openmc.sif docker://openmc/openmc:latest
To run use this script to call apptainer opemnc container scripts/openmc_run.sh. NOTE: Update SIF and LIB_DIR paths as needed !
# ================================================================
# OpenMC + Python Runner (Apptainer-based)
# ================================================================
# Description:
# This script runs either:
# (1) OpenMC directly inside an Apptainer container, or
# (2) a Python script using the same container environment.
#
# Usage:
# ./run_openmc.sh → Run OpenMC in the container
# ./run_openmc.sh script.py args → Run Python script with args
# ./run_openmc.sh -h | --help → Show help
#
# Behavior:
# - The current working directory is mounted into /workspace inside the container.
# - The OpenMC library directory is mounted into /libs.
# - The output log is saved in the same directory as the run:
# * openmc_run.log for OpenMC runs
# * <scriptname>.log for Python runs
#
# Example:
# ./run_openmc.sh # Run OpenMC normally
# ./run_openmc.sh input.py # API can be called inside the script
Making OpenMC work on WSL/LCLRS/MERLIN via Apptainer coverted from Docker Image
You can do it on your own machine (WSL)
The long way
docker pull -it --name=develop-dagmc-libmesh openmc/openmc:develop-dagmc-libmesh
docker save openmc/openmc:develop-dagmc-libmesh -o openmc_develop_dagmc_libmesh_docker_img.tar
apptainer build openmc_from_tar.sif docker-archive:openmc_develop_dagmc_libmesh_docker_img.tar
The short way
apptainer build openmc_develop_dagmc_libmesh_from_docker_img.sif docker://openmc/openmc:develop-dagmc-libmesh
LCLRS
# use the scratch disk so apptainer does not throw errors
BUILDROOT=/scratch/$USER/apptainer_openmc_build
mkdir -p "$BUILDROOT"/{tmp,cache}
export APPTAINER_TMPDIR="$BUILDROOT/tmp"
export APPTAINER_CACHEDIR="$BUILDROOT/cache"
# build
apptainer build openmc_develop_dagmc_libmesh_from_docker_img.sif docker://openmc/openmc:develop-dagmc-libmesh
Merlin 7
nope
Tests
Use these test files here Tests If you need a quick lib, I left one on the scrach at S:\stafie_c\openmc_libs.
OpenMC libraries
NOTE: this is a work in progress, and currently not hosted on a public folder.
Setting the Cross Section Library in OpenMC
By default, OpenMC locates the cross section library using the environment variable OPENMC_CROSS_SECTIONS. But avoid doing this inside long-term scripts — it’s better to keep the path explicit in your model setup.
import os
os.environ['OPENMC_CROSS_SECTIONS'] = f"/libs/e80_hdf5/cross_sections.xml"
However, you can specify the library path directly in your Python script or XML files — no need to rely on environment variables.
Option 1 — Use Materials.cross_sections
You can embed the path into your exported materials.xml file:
materials.cross_sections = '/absolute/path/to/cross_sections.xml'
materials.export_to_xml()
This adds the following line inside your generated XML:
<cross_sections>/absolute/path/to/cross_sections.xml</cross_sections>
Option 2 — Use openmc.config
For newer OpenMC versions, you can configure the cross-section file at runtime:
openmc.config['cross_sections'] = '/absolute/path/to/cross_sections.xml'
This temporarily overrides any environment variable and is useful for workflows or notebooks where you don’t want to modify global settings.
NOTE: Depending on the OpenMC version, openmc.config['cross_sections'] may not be automatically written to XML, in that case, use option 1 to ensure reproducibility.
Find more here
OpenMC Documentation – Using Cross Section Data
Python API: openmc.Materials.cross_sections
Tutorial alternatives
The tutorial on the website is nice but there are some alternatives:
-
Hands-on OpenMC introduction by ICTP Science, Technology and Innovation. It has 4 videos that are quite useful, you can find the workshop resources here:
-
OpenMC demonstration by the Centre for Energy Research & Institute of Nuclear Techniques.