Skip to content

Conversation

@RemDelaporteMathurin
Copy link
Contributor

@RemDelaporteMathurin RemDelaporteMathurin commented Aug 15, 2025

Description

Recently, we accidentally added the same Material object to a Model twice which made the simulation crash because there were duplicate IDs in the XML. Consider the following MWE:

import openmc

my_mat = openmc.Material(name="my_mat")
my_mat2 = openmc.Material(name="my_mat2")

materials = openmc.Materials([my_mat, my_mat2, my_mat])

materials.export_to_xml("materials.xml")

materials_in = openmc.Materials.from_xml("materials.xml")
assert len(materials_in) == 2

A simple way to get rid of this is to only export unique entities to XML.

@pshriwise

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) 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)

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.

@paulromano paulromano enabled auto-merge (squash) August 18, 2025 11:48
@paulromano paulromano merged commit c5a7173 into openmc-dev:develop Aug 18, 2025
14 checks passed
@RemDelaporteMathurin RemDelaporteMathurin deleted the avoid-duplicate-materials branch August 18, 2025 15:02
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