Stafie Alex PSI de70d59ffd first files
2025-10-08 13:11:16 +02:00
2025-10-07 23:18:00 +02:00
2025-10-08 13:11:16 +02:00
2025-10-08 13:11:16 +02:00
2025-10-07 22:58:55 +02:00
2025-10-07 22:58:55 +02:00
2025-10-07 23:18:00 +02:00
2025-10-08 13:11:16 +02:00
2025-10-08 13:11:16 +02:00

OpenMC

Make your own env and compile it

My recomandation for the env:

  • install direnv --> hook

  • install pyen --> hook in bachrc

  • install python 3.12.0

  • install miniconda (not)

  • install conda (not)

  • install the api

Quick Install Guide

From the devs

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.

# ================================================================
#  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

OpenMC libraries

Nuclear library status

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 — its 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 dont 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

S
Description
No description provided
Readme MIT 153 KiB
Languages
Python 73.7%
Shell 26.3%