Issues Fetching Nuclide Concentration from Depleted Results

I’ve been trying to use the .get_atoms function from the depletion module, but I haven’t managed to get it working. I’ve tried dozens of versions of the code to fetch the data, but all of them fail. The error changes, but always has to do with the specifications being passed within the parenthesis. It also seems to think something is out of place or simply returns a “KeyError” otherwise. The snippet of the code is included below.

results = openmc.deplete.Results(‘depletion_results.h5’)

time, u235 = results.get_atoms(“1”, ‘U235’, nuc_units=‘atom/b-cm’, time_units=‘d’)

print(u235)

There is a part of the source code where it looks up the mat_id and nuc in the results object and if not found it would return a key error.

Are you able to post the whole error message so I can check

I suspect it is this line of the source code raises the keyerror, when it does not find the nuc or the material id

File “core.py”, line 3592, in
time, u235 = results.get_atoms(“1”, ‘U235’, nuc_units=‘atom/b-cm’, time_units=‘d’)
File “/home/rmclem/miniconda3/envs/openmc-py3.7/lib/python3.7/site-packages/openmc/deplete/results.py”, line 147, in get_atoms
concentrations[i] = result[0, mat_id, nuc]
File “/home/rmclem/miniconda3/envs/openmc-py3.7/lib/python3.7/site-packages/openmc/deplete/stepresult.py”, line 104, in getitem
mat = self.index_mat[mat]
KeyError: ‘1’

For anyone reading this in the future, an alternative if you can’t get this to work either is to use the following code:

results = openmc.deplete.Results(‘depletion_results.h5’)

materials_dep = results.export_to_materials(1) # 1 is for 1 step depletion, 0 would be fresh

materials_dep.export_to_xml()

This generates a new materials.xml file containing the depleted materials which can be used to check compositions. There are some quirks to using this though, primarily the “atomic percents” listed in the compositions don’t add to 1 or anything close to it for the depleted materials. The values are consistently arbitrary.

1 Like

A more helpful error messages merged into openmc. Should help identify the available keys instead of just a keyerror messages

1 Like

Correction: The units in the exported materials.xml file are in units of atoms/barn-cm.