Depletion post processing error

Dear experts, I encounter this error when I add the post processing script to my depletion code. How can I solve this error?
My Script

# Instantiate the Tally
tally = openmc.Tally(name='mesh tally')
tally.filters = [mesh_filter]
tally.scores = ['fission']

# Add tally to collection
tallies.append(tally)

model.tallies = tallies
chain_file = '/home/pfelectron/srpopenmc/test2/test/depletion/data/depletion/chain_casl_.xml'
op = openmc.deplete.CoupledOperator(model, chain_file)

# Perform simulation using the predictor algorithm
time_steps = [30] * 6
# Depletion Post-Processing
previous_results = openmc.deplete.Results('depletion_results.h5')
materials_dep = previous_results.export_to_materials(time_steps)
materials_dep.export_to_xml()  # extracts and replaces original materials.xml file
power = 174  # W/cm, for 2D simulations only (use W for 3D)
integrator = openmc.deplete.PredictorIntegrator(op, time_steps, power, timestep_units='d')
integrator.integrate()

Error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[11], line 212
    210 # Depletion Post-Processing
    211 previous_results = openmc.deplete.Results('depletion_results.h5')
--> 212 materials_dep = previous_results.export_to_materials(time_steps)
    213 materials_dep.export_to_xml()  # extracts and replaces original materials.xml file
    214 power = 174  # W/cm, for 2D simulations only (use W for 3D)

File ~/.local/lib/python3.10/site-packages/openmc/deplete/results.py:560, in Results.export_to_materials(self, burnup_index, nuc_with_data, path)
    526 def export_to_materials(
    527     self,
    528     burnup_index: int,
    529     nuc_with_data: Optional[Iterable[str]] = None,
    530     path: PathLike = 'materials.xml'
    531 ) -> Materials:
    532     """Return openmc.Materials object based on results at a given step
    533 
    534     .. versionadded:: 0.12.1
   (...)
    558         and original isotopic compositions of non-depletable materials
    559     """
--> 560     result = self[burnup_index]
    562     # Only materials found in the original materials.xml file will be
    563     # updated. If for some reason you have modified OpenMC to produce
    564     # new materials as depletion takes place, this method will not
    565     # work as expected and leave out that material.
    566     mat_file = Materials.from_xml(path)

TypeError: list indices must be integers or slices, not list
1 Like
materials_dep = previous_results.export_to_materials(time_steps)

This will return the materials at a given time step, so rather than give the whole list you have to specify the time step index. If you want it at each time step you can loop over the length of the time_steps list?

1 Like

How should I specify the time steps? Can you show an example? What do you mean by step index?

Time step is specified by its list index, so in your case:

time_step = [30] * 6 # [30,30,30,30,30,30] <-- List of length 6 

The equivalent burnup step indices are then 0,1,2,3,4,5 - these are python list indices, the error youre getting is because you are giving a list and not a single value EQUATING to a burnup step.

So, the direct fix to the error would be (using the last time step as an example):

materials_dep = previous_results.export_to_materials(burnup_index = 5)

If you do this does it run?

EDIT: -1 would also work for the last time step (I would actually recommend this instead)

1 Like