Skip to content

Conversation

@shimwell
Copy link
Member

Description

When running a depletion simulation and then loading up the materials from a depletion_results.h5 file the material names are lost.

This makes depletion with DAGMC workflows a bit tricky as one typically knows the material name and not the ID in DAGMC workflows (this stems from material tags in the DAGMC file).

Anyway it would be super useful for me if we can preserve the material name when writing the depletion_results.h5 file so that I can easily find materials once again.

I have added tests but also manually tested with this script

I have also tried to keep this PR to the bare minimum and not cram in extra fixes or deviations from the objective.

"""Minimal OpenMC depletion example to test material name preservation."""

import openmc
import openmc.deplete
from pathlib import Path
openmc.config['cross_sections'] = Path.home() / 'nuclear_data'/ 'endf-b8.0-hdf5/' / 'cross_sections.xml'
openmc.config['chain_file'] = Path.home() / 'nuclear_data' / 'chain-endf-b8.0.xml'
fuel = openmc.Material(name="My Fuel Material", material_id=1)
fuel.add_nuclide("Fe56", 1)
fuel.set_density("g/cm3", 10.0)
fuel.depletable = True
fuel.volume = 4/3 * 3.14159 * 10**3  # sphere volume
materials = openmc.Materials()
sphere = openmc.Sphere(r=10, boundary_type="vacuum")
cell = openmc.Cell(fill=fuel, region=-sphere)
geometry = openmc.Geometry([cell])
settings = openmc.Settings()
settings.batches = 10
settings.run_mode  = 'fixed source'
settings.particles = 1000
settings.source = openmc.Source(
    space=openmc.stats.Point((0, 0, 0)),
    energy=openmc.stats.Discrete([14.0e6], [1.0])
)
model = openmc.Model(geometry, materials, settings)
model.deplete(
    method="predictor", 
    operator_kwargs={
        "normalization_mode": "source-rate",
        "chain_file": openmc.config['chain_file'],
        "reduce_chain_level": 5,
    },
    timesteps=[1,1,1,1],
    source_rates=[1e20,0,0,0],
)
results = openmc.deplete.Results("depletion_results.h5")
step = results[-1]
material = step.get_material('1')
assert material.name =="My Fuel Material"
print(material.name)

Fixes # (issue)

Checklist

  • I have followed the style guidelines for Python source files (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@shimwell shimwell requested a review from paulromano as a code owner January 16, 2026 10:43
@shimwell
Copy link
Member Author

Thanks for the improvements @GuySten

I also notice that when a user makes a material and sets density units to g/cm³ the returned materials come in units of sum regardless of the inital input density. I would be keen to try to keep the density units consistent with the original material. Naturally I could do this on a separate PR but it is somewhat releated to this and I'm keen to hear if it would be a popular change?

@GuySten
Copy link
Contributor

GuySten commented Jan 21, 2026

I think preserving density units should be in a separate PR.

Separately I do not think that it is very useful compared to the usefulness of preserving material names.

@shimwell
Copy link
Member Author

@paulromano if you have time to take a peak does this PR look ok to merge?

Refactor material name extraction and cleanup.
Copy link
Contributor

@GuySten GuySten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@GuySten GuySten added the Merging Soon PR will be merged in < 24 hrs if no further comments are made. label Jan 26, 2026
Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do see a few things that need changes here so putting a placeholder review for now. Sorry to hold this up but will really try to get to it this week.

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good now; thanks @shimwell!

@paulromano paulromano enabled auto-merge (squash) January 27, 2026 03:55
@paulromano paulromano merged commit db426b6 into openmc-dev:develop Jan 27, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merging Soon PR will be merged in < 24 hrs if no further comments are made.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants