Skip to content
Merged
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
109 changes: 109 additions & 0 deletions tools/ALARAJOYWrapper/alarajoy_QA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import subprocess
from string import Template
from pathlib import Path

#--------------- Running Single Parent Element Simulation(s) -----------------

INPUT = 'alara.inp'

# Adapted from ALARA/examples/singleElement.ala
alara_input = Template(
'''
geometry rectangular
dimension x
0.0
1 5.0
end
mat_loading
inner_zone1 mix1
end
material_lib ../../data/matlib.sample
element_lib ../../data/nuclib.std
data_library alaralib $datalib
mixture mix1
element $element 1.0 1.00
end
flux flux_1 ../../examples/ref_flux_files/fluxfnsfIBfw_518MW.txt 1.0 0 default
schedule 2_year
2 y flux_1 steady_state 0 s
end
pulsehistory steady_state
1 0 s
end
dump_file dump_singleElement
cooling
1e-5 y
1e-2 y
1 y
100 y
10000 y
end
output interval
units Bq kg
number_density
specific_activity
total_heat
dose contact $datalib ../../data/ANS6_4_3
end
##
truncation 1e-7
'''
)

def fill_alara_template(element, datalib):
'''
Substitute in the specific single parent element and path to a
pre-converted ALARA binary library, such as that for either FENDL2 or
ALARAJOY-processed FENDL3, to a template containing a generalized
ALARA input file text for a simple single parent element simulation.
Arguments:
element (str): Single parent element to be irradiated.
datalib (str): Path to the binary library.

Returns:
alara_input (str): String template with appropriate variables
substituted in for Template identifiers.
'''

return alara_input.substitute(element=element, datalib=datalib)

def write_alara_input_file(template):
'''
Write out the ALARA input card from the prefilled template.
Arguments:
template (str): String template with appropriate variables substituted
in for Template identifiers.
Returns:
None
'''

with open(INPUT, 'w') as f:
f.write(template)

def run_alara(element, libname):
'''
Invoke subprocess.run() to run ALARA for the single parent element
irradiation simulation. Specify destination for ALARA tree file and
capture stdout to an output file to be read by
alara_pandas_parser.parse_tables().
Arguments:
element (str): Single parent element to be irradiated.
libname (str): Name of the source data library (i.e. fendl2, fendl3,
etc.)
Returns:
output (str): Path to the ALARA redirected ALARA stdout formatted as a
text file.
'''

filename_base = f'{element}_{libname}'
output = f'{filename_base}.out'
Path(output).unlink(missing_ok=True)
with open(output, 'w') as outfile:
subprocess.run(
['alara', '-t', f'{filename_base}.tree', '-v', '3', INPUT],
stdout=outfile,
stderr=subprocess.STDOUT,
check=True
)

return output
85 changes: 85 additions & 0 deletions tools/ALARAJOYWrapper/alarajoy_QA_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1112b209",
"metadata": {},
"source": [
"# **ALARAJOY Library Conversion QA Notebook**\n",
"\n",
"\n",
"This Jupyter Notebook is designed to enable comparisons for neutron activation responses of a given single parent element as calculated by ALARA for the purpose of validating ALARAJOY-processed data from the FENDL3.2x data sets."
]
},
{
"cell_type": "markdown",
"id": "3298730d",
"metadata": {},
"source": [
"**Import Packages**"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "57313772",
"metadata": {},
"outputs": [],
"source": [
"import alarajoy_QA as qa\n",
"import importlib"
]
},
{
"cell_type": "markdown",
"id": "d37d40a3",
"metadata": {},
"source": [
"**Run ALARA with each prepared binary data library**"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4eae0d85",
"metadata": {},
"outputs": [],
"source": [
"importlib.reload(qa)\n",
"data_soure = {\n",
" 'fendl2' : '/groupspace/shared/n/nukecode/ALARA/data/fendl2bin',\n",
" 'fendl3' : '../../examples/data/fendl3'\n",
"}\n",
"\n",
"element = input('Select single parent element to evaluate: ').lower()\n",
"\n",
"for libname, binary in data_soure.items():\n",
" alara_input = qa.fill_alara_template(element, binary)\n",
" qa.write_alara_input_file(alara_input)\n",
" output = qa.run_alara(element,libname)\n",
" data_soure[libname] = output"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you intend to overwrite the data_source here? Might make sense to store this in another dictionary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this intentionally, only because we would no longer need the actual binary paths anymore and I figured it would be cleaner to just overwrite them. I can still change it, though, if you think it would be best.

]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}