Preserve user material names in convert_to_multigroup and avoid overwriting material with same name bug fix#3984
Merged
jtramm merged 2 commits intoJun 30, 2026
Conversation
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.
34498bd to
75699d4
Compare
convert_to_multigroup now keeps the user's original material name in the
exported materials.xml and keys each macroscopic / MGXS-library entry by
sanitize(name) + "_{id}". Regenerate the inputs_true.dat references for the
random_ray_auto_convert* and random_ray_diagonal_stabilization tests to match.
Only dataset labels change; the MGXS values and results are unaffected.
b86ff79 to
dc8af9b
Compare
Member
Author
|
I just updated the regression test files to accommodate the new names in the mgxs and now the CI is green. What do you think @jtramm is this PR small and contained enough to merge in before the next release |
jtramm
approved these changes
Jun 30, 2026
jtramm
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Thanks for putting this together!
jon-proximafusion
pushed a commit
to shimwell/openmc
that referenced
this pull request
Jun 30, 2026
Add method="material_cell_wise" to Model.convert_to_multigroup: like material_wise, but it tallies multigroup cross sections per CELL instead of per material, so each material-filled cell gets its own spatially-resolved cross sections (each cell is assigned a distinct macroscopic). This captures intra-material spectral variation that material_wise averages away when one material spans a strong gradient (e.g. a thick shield modeled as one material). Reuses the entire material_wise run/tally/collapse path via a domain_type parameter threaded through _auto_generate_mgxs_lib and _isothermal_materialwise_mgxs (openmc.mgxs.Library already supports domain_type="cell"); the only genuinely new code is the per-cell macroscopic assignment in convert_to_multigroup. A shared _mgxs_domain_key helper keys each cell by sanitized name + id. Stacked on openmc-dev#3984 (name+id library keying): per-cell macroscopics for cells that share a material would otherwise collide in the library. Retarget to develop once openmc-dev#3984 merges. Adds a unit test that two cells sharing a material get distinct macroscopics.
jon-proximafusion
pushed a commit
to shimwell/openmc
that referenced
this pull request
Jun 30, 2026
Add method="material_cell_wise" to Model.convert_to_multigroup: like material_wise, but it tallies multigroup cross sections per CELL instead of per material, so each material-filled cell gets its own spatially-resolved cross sections (each cell is assigned a distinct macroscopic). This captures intra-material spectral variation that material_wise averages away when one material spans a strong gradient (e.g. a thick shield modeled as one material). Reuses the entire material_wise run/tally/collapse path via a domain_type parameter threaded through _auto_generate_mgxs_lib and _isothermal_materialwise_mgxs (openmc.mgxs.Library already supports domain_type="cell"); the only genuinely new code is the per-cell macroscopic assignment in convert_to_multigroup. A shared _mgxs_domain_key helper keys each cell by sanitized name + id. Stacked on openmc-dev#3984 (name+id library keying): per-cell macroscopics for cells that share a material would otherwise collide in the library. Retarget to develop once openmc-dev#3984 merges. Adds a unit test that two cells sharing a material get distinct macroscopics.
jon-proximafusion
pushed a commit
to shimwell/openmc
that referenced
this pull request
Jun 30, 2026
Add method="material_cell_wise" to Model.convert_to_multigroup: like material_wise, but gives each cell its own multigroup cross sections. The material in every material-filled cell is cloned (each clone gets a unique id), then the standard per-material generation runs, so per material becomes per cell. This captures the intra-material spatial-spectrum variation that material_wise averages away when one material spans a strong gradient. The implementation reuses the material_wise path entirely; the only new code is the per-cell cloning step in convert_to_multigroup plus the dispatch entry. Adds a unit test (two cells sharing a material get distinct macroscopics) and a user guide entry in the MGXS methods table. Builds on the name+id library keying from openmc-dev#3984 (now in develop).
jon-proximafusion
pushed a commit
to shimwell/openmc
that referenced
this pull request
Jun 30, 2026
Add method="material_cell_wise" to Model.convert_to_multigroup: like material_wise, but gives each cell its own multigroup cross sections. The material in every material-filled cell is cloned (each clone gets a unique id), then the standard per-material generation runs, so per material becomes per cell. This captures the intra-material spatial-spectrum variation that material_wise averages away when one material spans a strong gradient. The implementation reuses the material_wise path entirely; the only new code is the per-cell cloning step in convert_to_multigroup plus the dispatch entry. Adds a unit test (two cells sharing a material get distinct macroscopics) and a user guide entry in the MGXS methods table. Builds on the name+id library keying from openmc-dev#3984 (now in develop).
jon-proximafusion
added a commit
to shimwell/openmc
that referenced
this pull request
Jun 30, 2026
Add method="material_cell_wise" to Model.convert_to_multigroup: like material_wise, but gives each cell its own multigroup cross sections. The material in every material-filled cell is cloned (each clone gets a unique id), then the standard per-material generation runs, so per material becomes per cell. This captures the intra-material spatial-spectrum variation that material_wise averages away when one material spans a strong gradient. The implementation reuses the material_wise path entirely; the only new code is the per-cell cloning step in convert_to_multigroup plus the dispatch entry. Adds a unit test (two cells sharing a material get distinct macroscopics) and a user guide entry in the MGXS methods table. Builds on the name+id library keying from openmc-dev#3984 (now in develop). Co-authored-by: jon-proxima <jon@proximafusion.com>
jon-proximafusion
added a commit
to shimwell/openmc
that referenced
this pull request
Jul 1, 2026
Add method="cell_wise" to Model.convert_to_multigroup: like material_wise, but gives each cell its own multigroup cross sections. The material in every material-filled cell is cloned (each clone gets a unique id), then the standard per-material generation runs, so per material becomes per cell. This captures the intra-material spatial-spectrum variation that material_wise averages away when one material spans a strong gradient. The implementation reuses the material_wise path entirely; the only new code is the per-cell cloning step in convert_to_multigroup plus the dispatch entry. Adds unit tests (CSG and DAGMC: two cells sharing a material get distinct macroscopics) and a user guide entry in the MGXS methods table. Builds on the name+id library keying from openmc-dev#3984 (now in develop). Co-authored-by: jon-proxima <jon@proximafusion.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
convert_to_multigroupoverwrote each material'snamewith a sanitised, HDF5-safe version, because the name was used both as the key for the material'sXSdataentry 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.nameuntouched and instead keys the library by a separatename + idstring (sanitised to alphanumeric/underscore; unique because the material ID is unique). The macroscopic reads its data under that library name. As a result: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