openmc icon indicating copy to clipboard operation
openmc copied to clipboard

Improve algorithmic complexity of sampling among multiple sources

Open paulromano opened this issue 1 year ago • 1 comments

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.

paulromano avatar Aug 01 '24 15:08 paulromano

Is this still available @johvincau ? @paulromano ? This looks like a nice first project for one of my students, if so....

gonuke avatar Oct 21 '24 21:10 gonuke

Steps:

  1. add a new "global" variable adjacent to external_sources that is of type DiscreteIndex
  2. initialize that discrete index after the external_sources are initialized src/settings.cpp#L560 using a vector of strengths (For s in external_sources s->strength()
  3. sample DiscreteIndex in sample_external_sources to get i

gonuke avatar Nov 06 '24 22:11 gonuke

@paulromano - any chance you can reassign this to @magnoxemo, since he's actively working on it?

gonuke avatar Nov 14 '24 20:11 gonuke

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!

paulromano avatar Nov 14 '24 20:11 paulromano