openmc icon indicating copy to clipboard operation
openmc copied to clipboard

material IDs conflict caused by depletion

Open azimgivron opened this issue 2 years ago • 2 comments

Bug Description

When you run a depletion, the ids of several classes, including openmc.Material, are reset after the depletion. This causes a conflict of IDs if you create a new material after the depletion. It is mentioned that the reset is used to reset the tallies ids and avoid warnings but it does not only affect the tallies.

Steps to Reproduce

import openmc, math

openmc.config["cross_sections"] = "/data/nuclear_data/jeff33/HDF5/cross_sections.xml"
chain_file = "/data/nuclear_data/jeff33/chain-jeff33-short.xml"

class SiC(openmc.Material):
    def __init__(self, T: float=293.15):
        super(SiC, self).__init__(name="sic", temperature=T)
        self.set_density(units="g/cm3", density=3.15)
        self.add_nuclide("C0", .5)
        self.add_nuclide("Si28", .5)
        
class U(openmc.Material):
    def __init__(self, T: float=293.15):
        super(U, self).__init__(name="U", temperature=T)
        self.set_density(units="g/cm3", density=19.5)
        self.add_nuclide("U235", 1)

s1 = openmc.Sphere(r=8.5, boundary_type="transmission")
s2 = openmc.Sphere(r=15, boundary_type="vacuum")

u = U()
sic = SiC()

u.volume = 4/3 * math.pi * s1.r**3
sic.volume =  (4/3 * math.pi * s2.r**3) - u.volume

cells = {
    "internal sphere": openmc.Cell(region=-s1, fill=u),
    "external sphere": openmc.Cell(region=-s2 & +s1, fill=sic),
}

settings_args = {
    "source": openmc.Source(space=openmc.stats.Point((0, 0, 0))),
    "batches": 100,
    "inactive": 10,
    "particles": int(1e3),
    "output": {"path": "."},
    "temperature": {"method": "interpolation"},
}
settings = openmc.Settings(**settings_args)

geo = openmc.Geometry(root=openmc.Universe(cells=list(cells.values())))
model = openmc.Model(materials=openmc.Materials([u, sic]), geometry=geo, settings=settings)

next_id = openmc.Material.next_id
used_ids = openmc.Material.used_ids.copy()

model.export_to_xml()
model.deplete(timesteps=[10, 10], method="predictor", output=False, power=80e6, timestep_units="s", operator_kwargs={"chain_file": chain_file})

next_id_after = openmc.Material.next_id
used_ids_after = openmc.Material.used_ids
set_to_print=lambda s: list(dict.fromkeys(s))
print(
    "next ID : {}".format(next_id),
    "set of IDs : {}".format(set_to_print(used_ids)),
    "next ID POST DEPLETION : {}".format(next_id_after),
    "set of IDs POST DEPLETION : {}".format(set_to_print(used_ids_after)),
    sep="\n"
)

#if you create a material now, the export_to_xml is going to produce a conflict
u2= U()
cells["external sphere"] = openmc.Cell(region=-s2 & +s1, fill=u2)
model.geometry= openmc.Geometry(root=openmc.Universe(cells=list(cells.values())))
model.materials.append(u2)
model.export_to_xml()
model.run() #won't work

TERMINAL OUTPUT:

RuntimeError: Two materials have the same ID: 1

Environment

docker image openmc/openmc:latest, openmc version='0.14.0', Python 3.9.2

azimgivron avatar Dec 01 '23 10:12 azimgivron

Hi azimgivron, I have had the same problem...

Nicolas-ReyTornero avatar Dec 05 '23 14:12 Nicolas-ReyTornero

Hello,

i have had the same problem as both of you before. I "fixed" by redoing my script after each depletion and manually adding the material but it's very time consuming and inneficient so i would gladly welcome a fix on this one!

choclocklate avatar Dec 08 '23 07:12 choclocklate