Improve algorithmic complexity of sampling among multiple sources
Bug Description
If you have multiple Source objects specified for settings.source, OpenMC will sample among them based on the relative strengths of the sources (see the sample_external_source function). Currently, the algorithm for sampling is just a linear table search over the CDF, which means it is O(n) where n is the number of Source objects. We could make this O(1) by using alias sampling, which can be provided by the DiscreteIndex class.
Is this still available @johvincau ? @paulromano ? This looks like a nice first project for one of my students, if so....
Steps:
- add a new "global" variable adjacent to
external_sourcesthat is of typeDiscreteIndex - initialize that discrete index after the
external_sourcesare initialized src/settings.cpp#L560 using a vector of strengths (Forsinexternal_sourcess->strength() - sample
DiscreteIndexinsample_external_sourcesto geti
@paulromano - any chance you can reassign this to @magnoxemo, since he's actively working on it?
I can't assign him since he's not a member on the openmc-dev organization, but for now I left the assignee blank. @gonuke Thanks for letting us know, and thanks @magnoxemo for working on this!