activity and decay heat as dictionary of arrays
Description
While experimenting with the depletion module, I observed a consistent need to modify the format of certain results, particularly with the get_activity() and get_decay_heat() functions. This is particularly noticeable when setting the by_nuclide argument to True, causing the functions to return a list of elements. The first element in the list is an array of times, while the second element is a list of dictionaries corresponding to the depletion timesteps. Each dictionary contains all the nuclides present in the material at that specific timestep.
This pull request suggests a slight adjustment: alongside the times object, these two functions should now return a single dictionary of arrays. The dictionary contains all the elements present in the material across all timesteps, and the arrays are as long as the number of timesteps.
The aim is to simplify the process of plotting activity and heat against time for most users. Here it is as easy as:
results = openmc.deplete.Results("depletion_results.h5")
timesteps, activity = results.get_activity(mat='1', by_nuclide=True)
plt.plot(timesteps, activity['U238'])
Additionally, if this PR is of interest, I would like to propose a couple of additional modifications I would like to implement along the way:
-
I suggest replacing the by_element:bool argument with a by:str argument that accepts 'nuclide' or 'element'. This is because, in complex materials, I usually prefer to filter by element first and then pick. I can implement this quickly.
-
To avoid all functions in Results returning the times object alongside the main object (e.g., (times, activities), (times, k_eff), (times, decay_heat), etc.), we can use the method
Results.get_timesto obtain that information. However, I acknowledge that this may cause some structural issues elsewhere. (suggested by @eepeterson ) -
Currently, the argument for choosing materials is
mat:Union[Material, str], which accepts the ID of the material as a string. Would it be better to allow for eithermat_id:intormat_name:str?
ps. I just realized I had an automatic formatter on. The lines that actually changed are 22-33, 165-166 and and 287-288.