Skip to content

Fix convert mgxs to avoid duplicate material names bug#3982

Closed
jon-proximafusion wants to merge 2 commits into
openmc-dev:developfrom
shimwell:fix-convert-mgxs-duplicate-material-names
Closed

Fix convert mgxs to avoid duplicate material names bug#3982
jon-proximafusion wants to merge 2 commits into
openmc-dev:developfrom
shimwell:fix-convert-mgxs-duplicate-material-names

Conversation

@jon-proximafusion

@jon-proximafusion jon-proximafusion commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Model.convert_to_multigroup() generates one MGXS per material, keyed by material name. Two distinct materials that share a name would be silently written as a single cross section — one material's data overwrites the other's, dropping a material. This is easy to hit because Material.clone() (used by Model.differentiate_mats()) preserves the original name, and because names are sanitised to alphanumeric + underscore, which can make otherwise-distinct names collide.

Conversion now raises a ValueError instead of silently producing an incorrect library; material names are left unchanged. The per-material granularity is also noted in the convert_to_multigroup docstring.

Tests

Added a unit test asserting that two distinct materials sharing a name raise ValueError.

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)

shimwell and others added 2 commits June 25, 2026 16:34
convert_to_multigroup generates one MGXS per material, keyed by material
name. Two distinct materials that share a name (for example the same-named
clones from Model.differentiate_mats(), since Material.clone() preserves
the name) cannot be written as separate cross sections -- one would
silently overwrite the other, dropping a material's data. Names are also
sanitised to alphanumeric plus underscore, which can make otherwise
distinct names collide.

Raise a ValueError instead of silently producing an incorrect library,
leaving user-assigned names unchanged.
@shimwell shimwell requested a review from jtramm June 25, 2026 15:45
@shimwell

Copy link
Copy Markdown
Member

closing as we can make a unique name for all materials

@shimwell shimwell closed this Jun 25, 2026
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.

2 participants