@vzn sorry, I forgot to tag you in the response about the thesis. I'll copypaste it real quick: So there is this astro simulation code RAMSES that my professor wrote (bitbucket.org/rteyssie/ramses).
For dark matter particle simulations, it had a segmentation tool to find density clumps. My job was to implement a tool that checks if the particles are energetically bound to those clumps. It gets a bit more complicated than that, but that's the main outline.