openmc-dev / openmc

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

Add convenience function for openmc.stats.Discrete for single values or multiple equal probability values #2961

Open MicahGale opened 2 weeks ago

MicahGale commented 2 weeks ago

Description

I find myself writing openmc.stats.Discrete([1.23], [1]). The probabilities here just seem silly. Also sometimes selecting multiple values with equal probability is a bit clunky too:

values = [1,2,3]
openmc.stats.Discrete(values, [1/len(values)]*len(values))

Name for this is TBD:

@staticmethod
def equal_probability(values):
   return openmc.stats.Discrete(values, [1/len(values)]*len(values))

Alternatives

Let the user continue to do as they currently do.

Compatibility

This would only add a new method.