Skip to content

Add Detectors and Dose tallies #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,14 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Compiled objects and modules
*.a
*.o
*.log
*.out
*.pkl
summary.*
statepoint.*
*.vtk
*.xml
101 changes: 76 additions & 25 deletions analysis/neutron/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import math
import openmc

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from typing import Iterable

def get_exp_cllif_density(temp, LiCl_frac=0.695):
"""Calculates density of ClLiF [g/cc] from temperature in Celsius
Expand Down Expand Up @@ -32,28 +35,76 @@ def calculate_cylinder_volume(radius, height):
volume = math.pi * radius**2 * height
return volume

def calculate_circle_surface(radius):
area = math.pi * radius**2
return area

def rescale_to_lethargy(df: pd.DataFrame, normalize_over: Iterable = None) -> pd.DataFrame:
"""Rescale the mean and std. dev. of a DataFrame to lethargy values.
Useful when it comes to plot a particle energy spectrum in lethargy scale.

Parameters
----------
df : pd.DataFrame
DataFrame containing an energy spectrum tally. it needs to contain
'mean' and 'std. dev.' columns, as well as 'energy low [eV]' and
'energy high [eV]' columns.
normalize_over : Iterable, optional
Some openmc tallies (e.g. cell tally, surface tally) need to be normalized
by their filter dimension (e.g cell volume, surface area), by default None

Returns
-------
pd.DataFrame
DataFrame with the mean and std. dev. rescaled to lethargy values.
"""
# Copy the DataFrame to avoid modifying the original
df_lethargy = df.copy()

# Calculate the lethargy of the energy bins
lethargy = np.log(
df_lethargy['energy high [eV]'] / df_lethargy['energy low [eV]'])

# normalize tally over tally filter dimension (e.g. cell volume, surface area etc.)
if normalize_over is not None:
df_lethargy['mean'] = df_lethargy['mean'] / normalize_over
df_lethargy['std. dev.'] = df_lethargy['std. dev.'] / normalize_over

# Rescale the mean and std. dev. to lethargy
df_lethargy['mean'] = df_lethargy['mean'] / lethargy
df_lethargy['std. dev.'] = df_lethargy['std. dev.'] / lethargy

return df_lethargy

def plot_results(df, ylabel, label, color):

figsize = (10, 5)

fig, ax = plt.subplots(nrows=1, ncols=2, figsize=figsize, constrained_layout=True)

ax[0].set_xscale('log')
ax[1].set_xscale('linear')

for i in range(2):
ax[i].set_yscale('log')
ax[i].tick_params(axis='both', which='both', direction='in', labelsize=12)
ax[i].set_xlabel('Energy (eV)', fontsize=12)

ax[0].set_ylabel(ylabel, fontsize=12)

ax[0].annotate("Log scale on x", [0.05, 0.01], xycoords='axes fraction',
horizontalalignment='left', verticalalignment='bottom', fontsize=12)
ax[1].annotate("Lin scale on x", [0.05, 0.01], xycoords='axes fraction',
horizontalalignment='left', verticalalignment='bottom', fontsize=12)

# Plot

ax[0].step(df['energy low [eV]'], df["mean"], linestyle='-', label=label, color=color)
ax[0].fill_between(df['energy low [eV]'], df["mean"] - df["std. dev."], df["mean"] + df["std. dev."], color='gray', step='pre', alpha=0.5)

ax[1].step(df['energy low [eV]'], df["mean"], linestyle='-', label=label, color=color)
ax[1].fill_between(df['energy low [eV]'], df["mean"] - df["std. dev."], df["mean"] + df["std. dev."], color='gray', step='pre', alpha=0.5)

def translate_surface(
surface: (
openmc.XPlane | openmc.YPlane | openmc.ZPlane | openmc.Plane | openmc.Sphere
),
dx: float,
dy: float,
dz: float,
) -> openmc.Surface:
"""Translate an OpenMC surface by dx, dy, dz."""
if isinstance(surface, openmc.XPlane):
surface.x0 += dx
elif isinstance(surface, openmc.YPlane):
surface.y0 += dy
elif isinstance(surface, openmc.ZPlane):
surface.z0 += dz
elif isinstance(surface, openmc.Plane):
surface.d += surface.a * dx + surface.b * dy + surface.c * dz
elif isinstance(surface, openmc.Sphere):
surface.x0 += dx
surface.y0 += dy
surface.z0 += dz
else:
raise TypeError(f"Unsupported surface type: {type(surface)}")
return surface
ax[0].legend()

plt.show()
Empty file.
45 changes: 45 additions & 0 deletions analysis/neutron/irdff2_xs/dos-irdff2-4025.acef
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
40090.34y 89.132400 2.5300E-08 12/09/20
IRDFF-II dosimetry data for MAT 4025 in ace format mat4025
0 0. 0 0. 0 0. 0 0.
0 0. 0 0. 0 0. 0 0.
0 0. 0 0. 0 0. 0 0.
0 0. 0 0. 0 0. 0 0.
130 40090 0 1 0 0 0 0
0 0 0 0 0 0 0 0
1 0 1 0 0 2 3 0
0 0 0 0 0 0 0 0
0 0 0 0 0 130 0 0
0 0 0 0 0 0 0 0
16 1 0 63
1.21040000000E+01 1.22000000000E+01 1.22500000000E+01 1.23000000000E+01
1.23500000000E+01 1.24000000000E+01 1.24500000000E+01 1.25000000000E+01
1.25500000000E+01 1.26000000000E+01 1.27000000000E+01 1.28000000000E+01
1.29000000000E+01 1.30000000000E+01 1.33000000000E+01 1.34000000000E+01
1.35000000000E+01 1.36000000000E+01 1.37000000000E+01 1.38000000000E+01
1.39000000000E+01 1.40000000000E+01 1.41000000000E+01 1.43000000000E+01
1.45100000000E+01 1.47000000000E+01 1.49000000000E+01 1.51000000000E+01
1.54000000000E+01 1.57000000000E+01 1.60000000000E+01 1.64000000000E+01
1.68000000000E+01 1.73000000000E+01 1.78000000000E+01 1.84000000000E+01
1.90000000000E+01 1.97000000000E+01 2.00001000000E+01 2.10000000000E+01
2.20000000000E+01 2.30000000000E+01 2.40000000000E+01 2.50000000000E+01
2.60000000000E+01 2.70000000000E+01 2.80000000000E+01 2.90000000000E+01
3.00000000000E+01 3.20000000000E+01 3.40000000000E+01 3.60000000000E+01
3.80000000000E+01 4.00000000000E+01 4.20000000000E+01 4.40000000000E+01
4.80000000000E+01 5.00000000000E+01 5.20000000000E+01 5.40000000000E+01
5.60000000000E+01 5.80000000000E+01 6.00000000000E+01 0.00000000000E+00
1.02949000000E-02 1.56070000000E-02 2.25531000000E-02 3.10396000000E-02
4.09663000000E-02 5.22282000000E-02 6.47171000000E-02 7.83233000000E-02
9.29366000000E-02 1.24754000000E-01 1.59333000000E-01 1.95905000000E-01
2.33779000000E-01 3.49715000000E-01 3.87743000000E-01 4.24968000000E-01
4.61196000000E-01 4.96287000000E-01 5.30146000000E-01 5.62715000000E-01
5.93964000000E-01 6.23888000000E-01 6.79822000000E-01 7.33174000000E-01
7.77037000000E-01 8.19073000000E-01 8.57270000000E-01 9.08212000000E-01
9.52580000000E-01 9.91391000000E-01 1.03593000000E+00 1.07365000000E+00
1.11300000000E+00 1.14519000000E+00 1.17589000000E+00 1.19901000000E+00
1.21713000000E+00 1.22203000000E+00 1.21543000000E+00 1.19705000000E+00
1.16953000000E+00 1.11825000000E+00 1.02980000000E+00 9.03038000000E-01
7.64678000000E-01 6.47938000000E-01 5.57368000000E-01 4.89432000000E-01
4.02659000000E-01 3.55297000000E-01 3.32784000000E-01 3.19328000000E-01
3.09996000000E-01 3.02136000000E-01 2.95414000000E-01 2.74556000000E-01
2.66168000000E-01 2.56521000000E-01 2.51667000000E-01 2.48072000000E-01
2.45168000000E-01 2.37592000000E-01
Loading