A Funz plugin for CASMO5, Studsvik's advanced lattice physics code for Light Water Reactors.
This plugin enables parametric studies with CASMO5 using the fz framework.
- Variable syntax:
${variable_name} - Formula syntax:
@{formula} - Comment character:
*
The CASMO model extracts these output variables from output files:
When using depletion input files with DEP card, the following arrays are extracted from the summary table (one value per burnup step):
burnup: Burnup evolution [MWd/kgU]k_inf: Infinite multiplication factor evolutionm2: Migration area evolution [cm²]u235_wt_pct: U-235 weight percent evolutionfissile_pu_wt_pct: Fissile Pu weight percent evolutiontotal_pu_wt_pct: Total Pu weight percent evolutionpin_power_peak: Pin power peaking factor evolution
Depletion metadata (scalar values):
dep_target: Target burnup from DEP card [MWd/kgU]num_burnup_steps: Number of depletion steps performedhist_void: Historical (depletion-averaged) void fraction [%]hist_tfu: Historical fuel temperature [K]hist_tmo: Historical moderator temperature [K]hist_bor: Historical boron concentration [ppm]
For calculations without depletion, scalar values are extracted:
k_inf: Infinite multiplication factor (single value)m2: Migration area (single value)power_peak: Power peaking factorpin_power: 2D pin power distribution arraypin_exposure: 2D pin exposure distribution arraydecay_constants: Delayed neutron decay constantsbeta_eff: Effective delayed neutron fractionneutron_generation_time: Mean neutron generation time
This plugin requires the Funz/fz framework and a licensed copy of CASMO5.
pip install git+https://github.com/Funz/fz.gitSet the CASMO5 installation path:
export CASMO_PATH="/path/to/casmo5"import fz
# Example: Run calculation with varying enrichment
results = fz.fzr(
input_path="examples/CASMO/input.inp",
input_variables={
"enrichment": [3.0, 3.5, 4.0, 4.5],
"fuel_temp": 900,
"moderator_temp": 580
},
model="CASMO",
calculators="localhost_CASMO",
results_dir="my_results"
)
print(results[['enrichment', 'k_inf', 'm2']])import fz
import pandas as pd
# Example: Run depletion calculation with varying enrichment
results = fz.fzr(
input_path="examples/CASMO/input_dep.inp", # Input file with DEP card
input_variables={
"enrichment": [3.0, 3.5, 4.0],
"fuel_temp": 900,
"moderator_temp": 580
},
model="CASMO",
calculators="localhost_CASMO",
results_dir="depletion_results"
)
# Results contain arrays for each enrichment
for idx, row in results.iterrows():
print(f"\nEnrichment: {row['enrichment']}%")
print(f"Burnup points: {row['burnup']}")
print(f"K-infinity evolution: {row['k_inf']}")
print(f"U-235 depletion: {row['u235_wt_pct']}")
print(f"Pu buildup: {row['total_pu_wt_pct']}")your_project/
├── examples/
│ └── CASMO/
│ └── input.inp # Example input file
├── .fz/
│ ├── models/
│ │ └── CASMO.json # Model configuration
│ └── calculators/
│ ├── CASMO.sh # Calculator script
│ └── localhost_CASMO.json
├── tests/
│ └── test_plugin.py # Test suite
└── results/ # Generated by fz
* Example input file for CASMO plugin
* Variables are defined using ${variable_name} syntax
* Material definitions
FUE 1 10.42/${enrichment} * UO2 fuel with variable enrichment
MOD 3 ${moderator_temp}/1.0 * Water moderator
* State point definition
TFU=${fuel_temp} * Fuel temperature (K)
TMO=${moderator_temp} * Moderator temperature (K)
In this example:
${enrichment},${fuel_temp}, and${moderator_temp}are variable parameters that will be substituted by fz- Lines starting with
*are comments
The model JSON file defines variable syntax and output parsing:
{
"id": "CASMO",
"varprefix": "$",
"formulaprefix": "@",
"delim": "{}",
"commentline": "*",
"output": {
"burnup": "grep -A 1000 'BURNUP' output.txt | grep -E '^[[:space:]]*[0-9]' | awk '{print $1}'",
"k_inf": "grep -A 1000 'BURNUP' output.txt | grep -E '^[[:space:]]*[0-9]' | awk '{print $2}'",
"m2": "grep -A 1000 'BURNUP' output.txt | grep -E '^[[:space:]]*[0-9]' | awk '{print $3}'"
}
}Fields:
id: Unique identifier for the modelvarprefix: Character prefix for variables (e.g.,$for${x})formulaprefix: Character prefix for formulasdelim: Delimiter characters around variable namescommentline: Character(s) that start a comment lineoutput: Mapping of output variable names to shell commands that extract their values
The calculator JSON files define how to execute your code:
{
"uri": "sh://",
"models": {
"CASMO": "bash .fz/calculators/CASMO.sh"
}
}uri: Execution method (sh://for local shell,ssh://for remote)models: Mapping of model names to execution commands
To run calculations on a remote server:
results = fz.fzr(
input_path="examples/CASMO/input.inp",
input_variables={"enrichment": [3.0, 4.0, 5.0]},
model="CASMO",
calculators="ssh://[email protected]/bash /path/to/calculators/CASMO.sh",
results_dir="remote_results"
)Ensure CASMO_PATH environment variable is set:
export CASMO_PATH="/path/to/casmo5"Ensure the calculator script is executable:
chmod +x .fz/calculators/CASMO.shCheck the output section in your model JSON file. The shell commands must correctly parse your output files.
python tests/test_plugin.pyBSD 3-Clause License. See LICENSE file.