# How to simulating series of materials without loading the cross-section data after every iteration?

**URL:** <https://openmc.discourse.group/t/how-to-simulating-series-of-materials-without-loading-the-cross-section-data-after-every-iteration/5501>\
**Category:** User Support\
**Created:** [May 13, 2025, 6:19am UTC](https://openmc.discourse.group/t/how-to-simulating-series-of-materials-without-loading-the-cross-section-data-after-every-iteration/5501 "2025-05-13T06:19:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjwiguna](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/cjwiguna/32/3728_2.png) [@cjwiguna](https://openmc.discourse.group/u/cjwiguna)\
**Post date:** [May 13, 2025, 6:19am UTC](https://openmc.discourse.group/t/how-to-simulating-series-of-materials-without-loading-the-cross-section-data-after-every-iteration/5501/1 "2025-05-13T06:19:09Z")

</div>

I have a series of materials to be simulated, based on previous depletion simulation:

```auto
depMaterials = [depResult.export_to_materials(m, path=join(loadDir, 'materials.xml')) 
                for m in range(0, timeslots+1, 2)]

```

I tried using this simple loop:

```auto
with change_directory(saveDir):
    for i, materials in enumerate(depMaterials):
        model = mc.Model(
                materials=depMaterials[i], geometry=geometry, settings=settings, tallies=tallies
        )

        model.export_to_xml(remove_surfs=True)
        
        with lib.run_in_memory():
            lib.reset()
            model.run()
            lib.statepoint_write(f"depletion_tallies_n{i}.h5")

```

and it’s working, but with one side-effect: the program initialize, load all the cross-sections data, and finalize, for every iteration. So it’s not very efficient.

I then tried to replace the code above with this:

```auto
with change_directory(saveDir):
    model.export_to_xml(remove_surfs=True)
    with lib.run_in_memory():
        for chainNuc in depChain.nuclides:
            nuclide = chainNuc.name
            if nuclide not in lib.nuclides and nuclide in xsNucs:
                lib.load_nuclide(nuclide)
                
        for i, materials in enumerate(depMaterials):
            lib.reset()
            model.run()
            lib.statepoint_write(f"depletion_tallies_n{i}.h5")
            print(lib.nuclides)

```

Now the data is load first based on the depletion chain used in all of those materials. However, it doesn’t correctly simulate other nuclides that didn’t present in the initial material. What did I do wrong in the code above?

Thanks in advance.

Cheers,  
Chris.

---

<div class="post-metadata">

**Author:** ![cjwiguna](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/cjwiguna/32/3728_2.png) [@cjwiguna](https://openmc.discourse.group/u/cjwiguna)\
**Post date:** [May 13, 2025, 12:32pm UTC](https://openmc.discourse.group/t/how-to-simulating-series-of-materials-without-loading-the-cross-section-data-after-every-iteration/5501/2 "2025-05-13T12:32:46Z")

</div>

Update: I realized I forgot to update the materials. My bad!

```auto
with change_directory(saveDir):
    model.export_to_xml(remove_surfs=True)
    with lib.run_in_memory():
        for chainNuc in depChain.nuclides:
            nuclide = chainNuc.name
            if nuclide not in lib.nuclides and nuclide in xsNucs:
                lib.load_nuclide(nuclide)
                
        for i, materials in enumerate(depMaterials):
            materials.export_to_xml()
            lib.reset()
            model.run()
            lib.statepoint_write(f"depletion_tallies_n{i}.h5")
            print(lib.nuclides)

```

Still doesn’t work. I bet it because I use the wrong methodology. Instead of the above I should directly change the composition of all the materials using the lib:

```auto
with change_directory(saveDir):
    model.export_to_xml(remove_surfs=True)
    with lib.run_in_memory():
        for chainNuc in depChain.nuclides:
            nuclide = chainNuc.name
            if nuclide not in lib.nuclides and nuclide in xsNucs:
                lib.load_nuclide(nuclide)
                
        for i, materials in enumerate(depMaterials):
            # Update the materials using something like this...
            ...
            lib.materials[i].set_densities(updatedNuclides, updatedDensities)
            ...

            # Continue the process
            lib.reset()
            model.run()
            lib.statepoint_write(f"depletion_tallies_n{i}.h5")
            print(lib.nuclides)

```

Probably.
