Modifying the source code to reduce the amount of tracking

Hi all,

I am trying to track all the generated particles in the simulation but only in certain cell_ids and material_ids.
It seems that for now, when you set tracks=True in the run, it saves all the tracks without any filtering option.
Could anyone please point me in the right direction where I can modify to save tracks in certain cells and materials?
I believe this could reduce the tracks.h5 file size drastically (depending on the situation of course).

Thank you!
Best,

I don’t think this is currently an option to save only specific tracks that go through a certain material.

The default is to save all particle tracks are to the h5 file and this can result in a large file.

It is possible to save particular particle id numbers to the with the max_tracks and track attribute of openmc.Settings

Filtering of tracks by material can be done as a post process with commands like this line of code from this example

tracks_in_water_material = tracks.filter(state_filter=lambda s:s['material_id'] == 42)

Hi Shimwell,

Thanks for the reply!

Right. So, I am trying to modify the source code.
It would be helpful if you or someone could point to the right files or directions.

Thank you.

Hi everyone,

I wanted to follow up on this thread to see if anyone could offer some guidance.

I’m currently working on a project that involves modifying the source code.
My aim is to record the tracks that pass through a specific material_id or cell_id.
The ultimate goal is to trace these tracks back to their origins, which I believe would be valuable for characterizing neutron detector properties.

As mentioned by Shimwell earlier, recording all tracks, as currently available, results in a large output that is both time-consuming to generate and process.
Therefore, I’m looking to implement a more targeted approach.

Could anyone advise me on which part of the source code I should modify to achieve this functionality?
Any pointers or insights would be greatly appreciated.

Thanks in advance for your help!

For source code modifications this is the file that would need changing.

You could alternatively filter tracks from the larger track file with this example

tracks_in_zirconium_material = tracks.filter(state_filter=lambda s:s['material_id'] == 82)
# writing a separate vtk file for the tracks that go through the zirconium material 
tracks_in_zirconium_material.write_to_vtk('tracks_in_zirconium_material.vtp')

tracks_in_water_material = tracks.filter(state_filter=lambda s:s['material_id'] == 42)
# writing a separate vtk file for the tracks that go through the water material 
tracks_in_water_material.write_to_vtk('tracks_in_water_material.vtp')

print(f'{len(tracks_in_water_material)} tracks in water and {len(tracks_in_zirconium_material)}')

Hi Shimwell,

Thank you so much for the suggestion!
Let me try this and come back!

Best,