Create materials.xml from depletion results?

Hi everyone,

I would like to extract atom densities from a depletion_results.h5 file’s last time step for nuclides that have cross section data. Is there any easy way to do this through the python interface? I looked for a method like to_xml in both deplete.Results and deplete.ResultsList, but nothing particularly stood out as doing this. The internal materials.xml generation routine seems to only happen for creating the initial condition, and all nuclide densities are set through the C API thereafter.

This would be convenient for some profiling I’d like to do on cases using depleted materials, so that I’ve not got to run a full depletion step before doing transport calculations that are really XS lookup intensive.

Peace,

Gavin Ridley

Hey @gridley. Yeah, that’s a really good suggestion and I’ve come upon the same thought before. I could imagine both a fine-grained approach where you want to extract one specific material from a depletion results file as well as a more coarse-grained approach where you want to take an entire model and update all materials based on the state in the depletion results at a particular time. In any event, here’s how you could create a material based on what’s in the results file:

# Get final result
results = openmc.deplete.ResultsList.from_hdf5('depletion_results.h5')
last_result = results[-1]

# Create new Material object
new_mat = openmc.Material()
mat_id = 1  # ..or whatever your desired material is
new_mat.volume = last_result.volume[str(mat_id)]

# Add nuclides, skipping those with zero density
for nuc in last_result.nuc_to_ind.keys():
    atoms = last_result[0, str(mat_id), nuc]
    if atoms > 0.0:
        atoms_per_barn_cm = 1e-24 * atoms / new_mat.volume
        new_mat.add_nuclide(nuc, atoms_per_barn_cm)
2 Likes

Nice, that’ll do it! I had previously done something much more hacky and temporary in Operator, but this is very clean. There is also some filtering that has to be done to make sure you’re only adding ones available in your cross_sections.xml file, and Operator provides the facilities to do this checking. Do you think this would be helpful if added as a method to that class? I’ll make a PR if so.

1 Like

Ah yes, you’re right. Most of the nuclides would not have cross sections (if you’re using a large depletion chain). A PR on this front would be very welcome!

Fortunately, I have done this kind of function before. So may I create that PR for a try?
But my solution is a bit different, in which the “materials_n#.xml” will be printed out for each time step of depeltion if setting the option “print_materials=True” in openmc.deplete.operator(). Any comment is appreciated.

Hey Jiankai,

That sounds like a great idea. If you did submit that PR, I would be happy to help in any way if it’s not complete yet.

Cool. Thanks. The PR is submitted.

Following up, why close the PR? Not sure whether to discuss here or github.

There was a replacement PR that is still open (along with some discussion on it).

1 Like