# Track multiple reaction\_domains with openmc.deplete.MicroXS.from\_model

**URL:** <https://openmc.discourse.group/t/track-multiple-reaction-domains-with-openmc-deplete-microxs-from-model/3479>\
**Category:** User Support\
**Created:** [October 2, 2023, 6:51pm UTC](https://openmc.discourse.group/t/track-multiple-reaction-domains-with-openmc-deplete-microxs-from-model/3479 "2023-10-02T18:51:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donald](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Donald](https://openmc.discourse.group/u/Donald)\
**Post date:** [October 2, 2023, 6:51pm UTC](https://openmc.discourse.group/t/track-multiple-reaction-domains-with-openmc-deplete-microxs-from-model/3479/1 "2023-10-02T18:51:43Z")

</div>

When using the openmc.deplete.MicroXS.from\_model method to generate one\_group cross sections is there a way to track multiple reaction\_domains for one transport calculations. Specifically I would like to generate cross sections for multiple materials in a reactor so it would be great to only need one instance of the openmc.deplete.MicroXS.from\_model for multiple reaction\_domains in this case multiple fuel materials?

---

<div class="post-metadata">

**Author:** ![Daedalus](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/daedalus/32/2928_2.png) [@Daedalus](https://openmc.discourse.group/u/Daedalus)\
**Post date:** [October 9, 2023, 7:38pm UTC](https://openmc.discourse.group/t/track-multiple-reaction-domains-with-openmc-deplete-microxs-from-model/3479/2 "2023-10-09T19:38:13Z")

</div>

## I’m not sure I’m understanding your question correctly, but if you want to take mgxs tallies on multiple materials across multiple reaction types I have the code for that. Small problem, the nuclides it is tallying have to be in the original compositions defined in the code, so it gets a little complicated during a depletion sim. Below is a small snippet that some of the setup. Essentially you provide a list of cells (any number of cells) and it will take tallies on the materials used to fill those cells according to the reactions you include in the for loop. You can choose energy groups (1 for you), macro or micro, ect. The data processed output is a folder of excel spreadsheets, one for each material for each reaction type which is sorted internally by nuclide (again, only the nuclides present in the original material definition) and by energy group. If this is what you are looking for, let me know.

cell\_set\_list = [fuel\_cell\_56\_9.id,fuel\_cell\_57\_9.id,borod\_46.id] # insert name of cell with ‘.id’

openmc\_cells = assembly.get\_all\_material\_cells().values()  
xs\_library = {}  
for cell in openmc\_cells:  
xs\_library[cell.id] = {}  
xs\_library[cell.id][‘total’] = mgxs.TotalXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘transport’] = mgxs.TransportXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘absorption’] = mgxs.AbsorptionXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘fission’] = mgxs.FissionXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘nu-fission’] = mgxs.FissionXS(energy\_groups=en\_groups, nu=True)  
xs\_library[cell.id][‘scatter’] = mgxs.ScatterXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘nu-scatter’] = mgxs.ScatterMatrixXS(energy\_groups=en\_groups, nu=True)  
xs\_library[cell.id][‘chi’] = mgxs.Chi(energy\_groups=en\_groups)

---

<div class="post-metadata">

**Author:** ![Donald](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Donald](https://openmc.discourse.group/u/Donald)\
**Post date:** [October 26, 2023, 5:39pm UTC](https://openmc.discourse.group/t/track-multiple-reaction-domains-with-openmc-deplete-microxs-from-model/3479/3 "2023-10-26T17:39:59Z")

</div>

I think this should work, will just need to add a method to add atom of all the nuclides that I need cross sections for. Basically what I want is one group cross sections for multiple materials that I can then give back to the transport independent depletion solver to carry out the Burnup calculations.

---

<div class="post-metadata">

**Author:** ![Daedalus](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/daedalus/32/2928_2.png) [@Daedalus](https://openmc.discourse.group/u/Daedalus)\
**Post date:** [October 26, 2023, 7:46pm UTC](https://openmc.discourse.group/t/track-multiple-reaction-domains-with-openmc-deplete-microxs-from-model/3479/4 "2023-10-26T19:46:16Z")

</div>

## List of energy group options, create one that you want to use

# “each energy group is 10x” group

magnitude\_group = mgxs.EnergyGroups([0., 0.0000000001e6, 0.000000001e6, 0.00000001e6, 0.0000001e6, 0.000001e6,   
0.00001e6, 0.0001e6, 0.001e6, 0.01e6, 0.1e6, 1e6, 10e6, 100e6])

# generic 8 group

eight\_group = mgxs.EnergyGroups([0., 0.058, 0.14, 0.28,0.625, 4.0, 5.53e3, 821.0e3, 20.0e6])

# This is the 4 group used in HAMMER

four\_group\_hammer = mgxs.EnergyGroups([0.004742,0.6552,5531,820900,14920000])

# This is the 2 group used in HAMMER

two\_group\_hammer = mgxs.EnergyGroups([0.004742,0.6552,14920000])

### Inputs

en\_groups = four\_group\_hammer # Set this variable to the energy group you want to run.  
outputxs\_type = ‘micro’ # choose micro or macro  
target\_folder = ‘/home/rmclem/openmc/NURAM/MCFNRv2.5/MG\_Working\_Outs’ # make sure this is correct for your system, MG\_Working\_Outs is output folder  
nuclide\_specific = True # turning this to false significantly increases computation time, tracks all nuclides in material for each cell specified

# list of cells to record data, tallies will only be recorded for these cells

cell\_set\_list = [fuel\_cell\_56\_9.id,reg\_water\_56.id,clad\_cell\_56\_9.id,L\_borod\_26.id] # insert name of cell with ‘.id’ at the end

### STOP (delicate, handle with care)

openmc\_cells = assembly.get\_all\_material\_cells().values()  
xs\_library = {}  
for cell in openmc\_cells:  
xs\_library[cell.id] = {}  
xs\_library[cell.id][‘total’] = mgxs.TotalXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘transport’] = mgxs.TransportXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘absorption’] = mgxs.AbsorptionXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘fission’] = mgxs.FissionXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘nu-fission’] = mgxs.FissionXS(energy\_groups=en\_groups, nu=True)  
xs\_library[cell.id][‘scatter’] = mgxs.ScatterXS(energy\_groups=en\_groups)  
xs\_library[cell.id][‘nu-scatter’] = mgxs.ScatterMatrixXS(energy\_groups=en\_groups, nu=True)  
xs\_library[cell.id][‘chi’] = mgxs.Chi(energy\_groups=en\_groups)

tally\_trigger = openmc.Trigger(‘std\_dev’, 1e-4) # sensitivity, change if needed

for cell in openmc\_cells:  
for mgxs\_type in xs\_library[cell.id]:  
xs\_library[cell.id][mgxs\_type].tally\_trigger = tally\_trigger

# Instantiate an empty Tallies object

tallies\_file = openmc.Tallies()

# Iterate over all cells and cross section types

for cell in openmc\_cells:  
for rxn\_type in xs\_library[cell.id]:  
xs\_library[cell.id][rxn\_type].domain = cell # not sure what happens if this is changed  
xs\_library[cell.id][rxn\_type].by\_nuclide = nuclide\_specific # turning this to false significantly increases computation time  
for tally in xs\_library[cell.id][rxn\_type].tallies.values():  
tallies\_file.append(tally, merge=True)

# Export to “tallies.xml”

tallies\_file.export\_to\_xml()

#####################################################################################################################  
###---------------------------------MGXS Advanced Tallies Post Processing (Section 8)------------------------------  
#####################################################################################################################

# This generates the output files for the advanced tallies. Make sure you have the correct settings before running.

‘’’

# Make sure this is turned off during tally taking

sp = openmc.StatePoint(‘statepoint\_100.h5’) # make sure this matches the statepoint output with your tallies

# Iterate over all cells and cross section types (creates our cross sections), doesn’t need editing

for cell in openmc\_cells:  
for rxn\_type in xs\_library[cell.id]:  
xs\_library[cell.id][rxn\_type].load\_from\_statepoint(sp)

for i in range(len(cell\_set\_list)): # careful adjusting order of cross sections, they have to be in a specific order or they won’t work  
cell\_set = cell\_set\_list[i]

```
total = xs_library[cell_set]['total']
df1 = total.get_pandas_dataframe(xs_type=outputxs_type)

transport = xs_library[cell_set]['transport']
df2 = transport.get_pandas_dataframe(xs_type=outputxs_type)

absorbtion = xs_library[cell_set]['absorption']
df3 = absorbtion.get_pandas_dataframe(xs_type=outputxs_type)

fission = xs_library[cell_set]['fission']
df4 = fission.get_pandas_dataframe(xs_type=outputxs_type)

nufission = xs_library[cell_set]['nu-fission']
df5 = nufission.get_pandas_dataframe(xs_type=outputxs_type)

scatter = xs_library[cell_set]['scatter']
df6 = scatter.get_pandas_dataframe(xs_type=outputxs_type)   

nuscatter = xs_library[cell_set]['nu-scatter']
df7 = nuscatter.get_pandas_dataframe(xs_type=outputxs_type)

chi = xs_library[cell_set]['chi']
df8 = chi.get_pandas_dataframe(xs_type=outputxs_type)

# These name and output our data into the target folder by cell ID and xs type

file_path_tot = f'{target_folder}/{cell_set}-total-xs.xlsx'
dftot = pd.DataFrame(df1)
writer = pd.ExcelWriter(file_path_tot)
dftot.to_excel(writer, index=False)
writer.save()

file_path_trans = f'{target_folder}/{cell_set}-transport-xs.xlsx'
dftrans = pd.DataFrame(df2)
writer = pd.ExcelWriter(file_path_trans)
dftrans.to_excel(writer, index=False)
writer.save()

file_path_abs = f'{target_folder}/{cell_set}-absorption-xs.xlsx'
dfabs = pd.DataFrame(df3)
writer = pd.ExcelWriter(file_path_abs)
dfabs.to_excel(writer, index=False)
writer.save()

file_path_fiss = f'{target_folder}/{cell_set}-fission-xs.xlsx'
dffiss = pd.DataFrame(df4)
writer = pd.ExcelWriter(file_path_fiss)
dffiss.to_excel(writer, index=False)
writer.save()

file_path_nufiss = f'{target_folder}/{cell_set}-nufission-xs.xlsx'
dfnufiss = pd.DataFrame(df5)
writer = pd.ExcelWriter(file_path_nufiss)
dfnufiss.to_excel(writer, index=False)
writer.save()

file_path_scat = f'{target_folder}/{cell_set}-scatter-xs.xlsx'
dfscat = pd.DataFrame(df6)
writer = pd.ExcelWriter(file_path_scat)
dfscat.to_excel(writer, index=False)
writer.save()

file_path_nuscat = f'{target_folder}/{cell_set}-nuscatter-xs.xlsx'
dfnuscat = pd.DataFrame(df7)
writer = pd.ExcelWriter(file_path_nuscat)
dfnuscat.to_excel(writer, index=False)
writer.save()

file_path_chi = f'{target_folder}/{cell_set}-chi.xlsx'
dfchi = pd.DataFrame(df8)
writer = pd.ExcelWriter(file_path_chi)
dfchi.to_excel(writer, index=False)
writer.save()

```

‘’’

---

<div class="post-metadata">

**Author:** ![Daedalus](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/daedalus/32/2928_2.png) [@Daedalus](https://openmc.discourse.group/u/Daedalus)\
**Post date:** [October 26, 2023, 7:50pm UTC](https://openmc.discourse.group/t/track-multiple-reaction-domains-with-openmc-deplete-microxs-from-model/3479/5 "2023-10-26T19:50:13Z")

</div>

Not sure why things are getting bolded, but this is the full code copy pasted. You don’t want the post-processing code active while you are taking tallies, so it is commented out. When the tallies are done, simply rerun the code with the post-processing active and the tallies section active (run the python script, not openmc simulation). The variables are setup for my stuff so you may need to change things like the target folder and path. This has nuclide\_specific = True, so it will track every nuclide that is present in the material definition. Let me know if you have trouble adapting it to your code. Also, the code at the bottom of the post-processing is sequestered into its own scroll for some reason, that is all part of the above for loop.
