Created
September 29, 2017 21:00
-
-
Save pshriwise/c24a58dba1d36b004fd9f2ff4a5ab52a to your computer and use it in GitHub Desktop.
PyNE script for collapsing MCNP materials to nuclides with multi-group xs's only
This file contains 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
# coding: utf-8 | |
# USE: python mats_to_mg.py <mcnp_input_file> | |
from pyne import mcnp, nucname | |
from pyne.material import MaterialLibrary, Material | |
from sys import argv | |
# load library from | |
original_library = MaterialLibrary(mcnp.mats_from_inp(argv[1])) | |
# create exception list | |
exception_file = open('multigroup_ids.txt', 'r') | |
exception_list = [nucname.id(nucname.name(int(line))) for line in exception_file] | |
# collapse elements in library to elemental types except those with multigroup xs | |
new_library = MaterialLibrary() | |
for m in original_library: | |
mat = original_library[m].collapse_elements(exception_list) | |
new_library[m] = mat | |
# remove any elemental types that aren't in the list of multigroup xs types | |
for m in new_library: | |
mat = new_library[m] | |
new_comp = {key: value for key, value in mat.comp.items() if key in exception_list} | |
mat.metadata['table_ids'] = {} | |
mat.comp = new_comp | |
new_library[m] = mat | |
# replace all material metadata with multigroup xs identifier (.50m) | |
for m in new_library: | |
mat = new_library[m] | |
table_ids = {str(nucname.zzzaaa(key)): "50m" for key, value in mat.comp.items()} | |
mat.metadata['table_ids'] = table_ids | |
mat.metadata['mat_number'] = int(mat.metadata['mat_number']) | |
new_library[m] = mat | |
# test print of new mcnp materials | |
for m in new_library.keys(): | |
print new_library[m].mcnp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment