Skip to content

Commit 812577f

Browse files
authored
Merge pull request #66 from SteSeg/benchmark_results_class
Implemented `BenchmarkResult` class for postprocessing
2 parents 50e1a99 + b80cf77 commit 812577f

File tree

11 files changed

+184
-36
lines changed

11 files changed

+184
-36
lines changed

.readthedocs.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ version: 2
88
build:
99
os: ubuntu-24.04
1010
tools:
11-
python: "3.13"
12-
jobs:
13-
pre_build:
14-
- "jupyter-book config sphinx docs/source"
11+
python: "3.12"
1512

1613
python:
1714
install:
1815
- requirements: requirements.txt
1916

20-
# Build documentation in the "docs/source" directory with Sphinx
17+
# Build documentation with Sphinx
2118
sphinx:
22-
builder: html
23-
configuration: docs/source/_config.yml
19+
configuration: docs/source/conf.py

docs/source/_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Book settings
22
# Learn more at https://jupyterbook.org/customize/config.html
33

4+
# Jupyter Book version
5+
# This is required for jupyter-book < 1.0
6+
version: 0.15.1
7+
48
title: OpenMC Fusion Benchmarks
59
logo: images/logo.svg
610

docs/source/_toc.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@
33

44
format: jb-book
55
root: intro
6-
parts:
7-
- caption: Installation
8-
chapters:
9-
- file: user_installation
10-
- file: dev_installation
11-
- caption: FNG
12-
chapters:
13-
- file: fng_readme
14-
- file: fng_str_benchmark
15-
- file: fng_w_benchmark
16-
- caption: FNS
17-
chapters:
18-
- file: fns_readme
19-
- file: fns_clean_w_benchmark
20-
- file: fns_duct_benchmark
21-
- caption: Oktavian
22-
chapters:
23-
- file: oktavian_readme
24-
- file: oktavian_al_benchmark
6+
chapters:
7+
- file: user_installation
8+
- file: oktavian_readme
9+
- file: oktavian_al_benchmark

docs/source/conf.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
# This file replaces jupyter-book build system
3+
4+
import os
5+
import sys
6+
7+
# -- Project information -----------------------------------------------------
8+
project = 'OpenMC Fusion Benchmarks'
9+
copyright = '2025, OpenMC Fusion Benchmarks Contributors'
10+
author = 'OpenMC Fusion Benchmarks Contributors'
11+
12+
# -- General configuration ---------------------------------------------------
13+
extensions = [
14+
'myst_parser',
15+
'sphinxcontrib.bibtex',
16+
]
17+
18+
# Bibliography files
19+
bibtex_bibfiles = ['references.bib']
20+
bibtex_reference_style = 'label'
21+
22+
# Add any paths that contain templates here, relative to this directory.
23+
templates_path = ['_templates']
24+
25+
# List of patterns, relative to source directory, that match files and
26+
# directories to ignore when looking for source files.
27+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
28+
29+
# -- Options for HTML output -------------------------------------------------
30+
html_theme = 'sphinx_book_theme'
31+
html_logo = 'images/logo.svg'
32+
html_title = 'OpenMC Fusion Benchmarks'
33+
34+
html_theme_options = {
35+
'repository_url': 'https://github.com/eepeterson/openmc_fusion_benchmarks',
36+
'use_repository_button': True,
37+
'use_issues_button': True,
38+
'path_to_docs': 'docs/source',
39+
'repository_branch': 'develop',
40+
}
41+
42+
# -- MyST options ------------------------------------------------------------
43+
myst_enable_extensions = [
44+
'colon_fence',
45+
'deflist',
46+
'dollarmath',
47+
]
48+
49+
# Don't execute notebooks (set to 'off' to disable)
50+
# This is equivalent to jupyter-book's execute_notebooks: false
51+
jupyter_execute_notebooks = 'off'

docs/source/index.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
OpenMC Fusion Benchmarks
2+
=========================
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
:caption: Contents:
7+
8+
intro
9+
user_installation
10+
oktavian_readme
11+
oktavian_al_benchmark
12+
13+
References
14+
----------
15+
16+
.. bibliography::

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
jupyter-book
1+
sphinx>=7.0.0
2+
myst-parser
3+
sphinx-book-theme
4+
sphinxcontrib-bibtex

src/openmc_fusion_benchmarks/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from openmc_fusion_benchmarks.benchmark import *
2+
from openmc_fusion_benchmarks.benchmark_results import *
23
from openmc_fusion_benchmarks.validate import *
34
import openmc_fusion_benchmarks.uq
45

src/openmc_fusion_benchmarks/benchmark.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,8 @@ def run(self, uq: bool = False, *args, **kwargs):
446446
self._uncertainty_quantification(*args, **kwargs)
447447
else:
448448
# Run the OpenMC model
449-
# self._run_model(*args, **kwargs)
450-
# Run the OpenMC model
451-
statepoint = self.model.run(*args, **kwargs)
449+
sp = self.model.run(*args, **kwargs)
450+
statepoint = openmc.StatePoint(sp)
452451
# Post-process the results
453452
self._postprocess(statepoint=statepoint)
454453

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import h5py
2+
import xarray as xr
3+
import numpy as np
4+
5+
6+
class BenchmarkResults:
7+
def __init__(self, filepath: str):
8+
self.filepath = filepath
9+
10+
@property
11+
def tallies(self):
12+
with h5py.File(self.filepath, 'r') as f:
13+
tallies = list(f.keys())
14+
return tallies
15+
16+
def get_tally(self, name: str) -> xr.DataArray:
17+
return xr.load_dataarray(self.filepath, group=name)
18+
19+
20+
# # Some utilities for data analysis
21+
# def get_means(tally: xr.DataArray) -> xr.DataArray:
22+
# """Extract tally means from the tally DataArray."""
23+
# return tally.sel(column='mean').squeeze()
24+
25+
# def get_stds(tally: xr.DataArray) -> xr.DataArray:
26+
# """Extract tally standard deviations from the tally DataArray."""
27+
# return tally.sel(column='std. dev.').squeeze()
28+
29+
# def get_rstds(tally: xr.DataArray) -> xr.DataArray:
30+
# """Compute tally relative standard deviations from the tally DataArray."""
31+
# mean_vals = get_means(tally)
32+
# std_vals = get_stds(tally)
33+
# return std_vals / mean_vals
34+
35+
36+
# # UQ-TMC base analysis functions - Move in uq/ ?
37+
# def mean_of_means(tally: xr.DataArray) -> xr.DataArray:
38+
# """Compute the mean of the means across realizations."""
39+
# means = get_means(tally)
40+
# return means.mean(dim='realization')
41+
42+
# def std_of_means(tally: xr.DataArray) -> xr.DataArray:
43+
# """Compute the standard deviation of the means across realizations."""
44+
# means = get_means(tally)
45+
# return means.std(dim='realization')
46+
47+
# def rstd_of_means(tally: xr.DataArray) -> xr.DataArray:
48+
# """Compute the relative standard deviation of the means across realizations."""
49+
# mean_vals = mean_of_means(tally)
50+
# std_vals = std_of_means(tally)
51+
# return std_vals / mean_vals
52+
53+
# # UQ-TMC dynamic realization analysis functions - Move in uq/ ?
54+
# def dynamic_mean_of_means(tally: xr.DataArray) -> np.ndarray:
55+
# """Compute the dynamic mean of the means across realizations."""
56+
# means = get_means(tally)
57+
# return np.array([means[:i].mean(dim='realization') for i in range(2, len(means.realization) + 1)])
58+
59+
# def dynamic_std_of_means(tally: xr.DataArray) -> np.ndarray:
60+
# """Compute the dynamic standard deviation of the means across realizations."""
61+
# means = get_means(tally)
62+
# return np.array([
63+
# means[:i].std(dim='realization') for i in range(2, len(means.realization) + 1)
64+
# ])
65+
66+
# def dynamic_rstd_of_means(tally: xr.DataArray) -> np.ndarray:
67+
# """Compute the dynamic relative standard deviation of the means across realizations."""
68+
# means = get_means(tally)
69+
# return np.array([
70+
# means[:i].std(dim='realization') / means[:i].mean(dim='realization')
71+
# for i in range(2, len(means.realization) + 1)
72+
# ])
73+
74+
# def dynamic_rstd_of_rstds(tally: xr.DataArray) -> np.ndarray:
75+
# """Compute the dynamic relative standard deviation of the relative standard deviations across realizations."""
76+
# rstds = dynamic_rstd_of_means(tally)
77+
# return np.array([
78+
# rstds[:i].std() / rstds[:i].mean() for i in range(2, len(rstds) + 1)
79+
# ])
80+
81+
# def derivative_of_dynamic_rstds(tally: xr.DataArray) -> np.ndarray:
82+
# """Compute the derivative of the dynamic relative standard deviations."""
83+
# dynamic_rstds = dynamic_rstd_of_means(tally)
84+
# return np.gradient(dynamic_rstds, axis=0)

src/openmc_fusion_benchmarks/uq/tmc_engine.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,23 @@ def tmc_engine(model: openmc.Model, realizations: int, lib_name: str, nuclide,
7777
tally = sp.get_tally(id=t)
7878
df = tally.get_pandas_dataframe()
7979

80+
df = df.drop(columns=['surface', 'cell', 'particle', 'nuclide',
81+
'score', 'energyfunction'], errors='ignore')
82+
8083
# Convert to xarray and add dimensions
81-
t = xr.DataArray(
84+
da = xr.DataArray(
8285
df.values[np.newaxis, :, :], # shape: (1, r, c)
8386
dims=["realization", "row", "column"],
8487
coords={
8588
"realization": [realization_label],
8689
"column": df.columns,
8790
"row": np.arange(df.shape[0]),
8891
},
89-
name=t.name
92+
name=tally.name
9093
)
9194

92-
_save_result(new_result=t, filename="tmc_results.h5",
93-
group=t.name, realization_label=f'{nuclide}_{n}_{lib_name}')
95+
_save_result(new_result=da, filename="tmc_results.h5",
96+
group=tally.name, realization_label=f'{nuclide}_{n}_{lib_name}')
9497

9598
Path('summary.h5').unlink(missing_ok=True)
9699
Path(statepoint).unlink(missing_ok=True)

0 commit comments

Comments
 (0)