openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
699 stars 444 forks source link

implement contains for universes and geometry #2939

Open MicahGale opened 4 weeks ago

MicahGale commented 4 weeks ago

Description

It would be really convenient sometimes to be able to say: if cell in model.geometry: or if cell in universe.

I propose that openmc.Geometry and openmc.Universe implement __contains__ for openmc.Cell. We could also do so for openmc.Surfaces I'm not sure if the latter has as much utility though

Alternatives

Users could instead do:

if cell in model.geometry.get_all_cells().values() This just feels very verbose and not pythonic.

Compatibility

This would add features and should not impact any existing methods.