Skip to content

Preserve user material names in convert_to_multigroup#3984

Open
shimwell wants to merge 1 commit into
openmc-dev:developfrom
shimwell:convert-mgxs-preserve-material-names
Open

Preserve user material names in convert_to_multigroup#3984
shimwell wants to merge 1 commit into
openmc-dev:developfrom
shimwell:convert-mgxs-preserve-material-names

Conversation

@shimwell

Copy link
Copy Markdown
Member

Summary

convert_to_multigroup overwrote each material's name with a sanitised, HDF5-safe version, because the name was used both as the key for the material's XSdata entry in the MGXS library and as the macroscopic the material reads back. This silently changed user-assigned names, and two distinct materials whose names collided were written as a single cross section (one overwriting the other).

This keeps material.name untouched and instead keys the library by a separate name + id string (sanitised to alphanumeric/underscore; unique because the material ID is unique). The macroscopic reads its data under that library name. As a result:

  • user material names are preserved (a material with no name stays unnamed),
  • distinct materials that share a name no longer collapse — each gets its own cross section.

Verified end-to-end: a model with two distinct same-named materials converts and runs in multigroup mode, the library containing one entry per material.

Tests

Added a unit test asserting names are preserved and same-named materials map to distinct library entries.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

convert_to_multigroup overwrote each material's name with a sanitised,
HDF5-safe version, because the name is used as the key for the material's
XSdata entry in the MGXS library and for the macroscopic that reads it back.
This silently changed user-assigned names, and two distinct materials whose
names collided were written as a single cross section (one overwriting the
other).

Use a unique library name (the sanitised name plus the material ID) for the
library entry and macroscopic, then restore each material's original name at
the end, so the user's names are preserved and same-named materials no longer
collapse.
@shimwell shimwell requested a review from jtramm June 25, 2026 16:22
@jon-proximafusion jon-proximafusion force-pushed the convert-mgxs-preserve-material-names branch 2 times, most recently from 34498bd to 75699d4 Compare June 25, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant