A Funz plugin for running parametric studies with the Serpent Monte Carlo reactor physics code.
This plugin enables you to:
- Define input parameters in Serpent input files using
${variable}syntax - Run parametric sweeps and sensitivity analyses
- Automatically extract key results (k-effective, etc.) using serpentTools
- Variable syntax:
${variable_name}(e.g.,${enrichment}) - Formula syntax:
@{formula}(e.g.,@{1-enrichment}) - Comment character:
%(Serpent's native comment character)
The plugin automatically extracts these output variables from Serpent result files (*_res.m). All outputs are formatted as JSON arrays/matrices for easy parsing.
| Variable | Description |
|---|---|
absKeff |
Absorption-based k-effective [value, rel_error] per burnup step |
anaKeff |
Analog k-effective estimate [value, rel_error, ...] per burnup step |
colKeff |
Collision-based k-effective [value, rel_error] per burnup step |
impKeff |
Implicit k-effective estimate [value, rel_error] per burnup step |
burnup |
Burnup values [MWd/kgU, ...] per burnup step (empty for non-depletion) |
burnDays |
Burnup time [days] per burnup step (empty for non-depletion) |
- Funz/fz framework
- Serpent 2 Monte Carlo code (for actual calculations)
- serpentTools Python package (for result parsing)
- Install the fz framework:
pip install git+https://github.com/Funz/fz.git- Install serpentTools for result parsing:
pip install serpentTools- Clone this repository:
git clone https://github.com/Funz/fz-Serpent.git
cd fz-Serpentimport fz
# Example: Run parametric study varying fuel enrichment
results = fz.fzr(
input_path="examples/Serpent/input.inp",
input_variables={
"enrichment": [0.03, 0.04, 0.05],
"u238_fraction": [0.8515, 0.8415, 0.8315],
"water_density": [0.72],
"water_temp": [600],
"fuel_radius": [0.41],
"clad_inner_radius": [0.42],
"clad_outer_radius": [0.475],
"pitch_half": [0.63],
"neutrons_per_cycle": [50000],
"active_cycles": [200],
"inactive_cycles": [20],
"seed": [12345]
},
model="Serpent",
calculators="localhost_Serpent",
results_dir="my_results"
)
print(results[['enrichment', 'absKeff', 'absKeff_err']])fz-Serpent/
├── .fz/
│ ├── models/
│ │ └── Serpent.json # Model configuration
│ └── calculators/
│ ├── Serpent.sh # Calculator script
│ └── localhost_Serpent.json
├── examples/
│ └── Serpent/
│ ├── input.inp # Example Serpent input file
│ └── input_res.m # Example result file (for testing)
├── tests/
│ └── test_plugin.py # Test suite
├── README.md
├── LICENSE
└── .gitignore
% UOX Fuel Pin Cell - fz Parametric Study
% Variables are defined using ${variable_name} syntax
% --- UOX fuel material ---
mat fuel -10.5 tmp 900
92235.09c -${enrichment}
92238.09c -${u238_fraction}
8016.09c -0.1185
% --- Water moderator/coolant ---
mat water -${water_density} moder lwtr 1001 tmp ${water_temp}
1001.06c 2
8016.06c 1
% --- Geometry ---
surf 1 cyl 0.0 0.0 ${fuel_radius}
surf 2 cyl 0.0 0.0 ${clad_inner_radius}
surf 3 cyl 0.0 0.0 ${clad_outer_radius}
surf 4 sqc 0.0 0.0 ${pitch_half}
% --- Run settings ---
set pop ${neutrons_per_cycle} ${active_cycles} ${inactive_cycles}
set seed ${seed}
This plugin uses serpentTools to parse Serpent output files. The *_res.m files contain all criticality results.
Example of manually reading results:
import serpentTools
# Read Serpent result file
res = serpentTools.read('input_res.m')
# Access k-effective values
keff = res.resdata['absKeff'][0, 0] # value
keff_err = res.resdata['absKeff'][0, 1] # relative error
print(f"k-eff = {keff:.5f} ± {keff * keff_err:.5f}")The calculator script looks for Serpent in the following locations:
sss2command in PATHserpentcommand in PATH/opt/serpent/bin/sss2$HOME/serpent/bin/sss2
To use a custom Serpent installation, modify .fz/calculators/Serpent.sh.
To run calculations on a remote server with Serpent installed:
results = fz.fzr(
input_path="input.inp",
input_variables={"enrichment": [0.03, 0.04, 0.05]},
model="Serpent",
calculators="ssh://user@hpc-server.edu/bash /path/to/calculators/Serpent.sh",
results_dir="remote_results"
)# Install test dependencies
pip install serpentTools
# Run tests
python tests/test_plugin.py- Serpent Monte Carlo Code
- Serpent Documentation
- serpentTools Documentation
- serpentTools ResultsReader Example
- Funz/fz Framework
BSD 3-Clause License. See LICENSE file.
- Funz/fz - Main framework
- Funz/fz-Model - Plugin template
- Funz/fz-Scale - SCALE code plugin