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

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

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:

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:

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.

1 Like

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

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:

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.

1 Like