-
Notifications
You must be signed in to change notification settings - Fork 24
Comparison Tool Part 1: Simulation Tools for Single Element Comparison Tool #142
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } | ||
| ], | ||
| "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 | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_sourcehere? Might make sense to store this in another dictionary.There was a problem hiding this comment.
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.