diff --git a/openmc/capi/math.py b/openmc/capi/math.py index 34beb585fd..126638c9aa 100644 --- a/openmc/capi/math.py +++ b/openmc/capi/math.py @@ -37,6 +37,8 @@ _dll.broaden_wmp_polynomials_c.restype = None _dll.broaden_wmp_polynomials_c.argtypes = [c_double, c_double, c_int, ndpointer(c_double)] +_dll.normal_variate.restype = c_double +_dll.normal_variate.argtypes = [c_double, c_double] def t_percentile(p, df): """ Calculate the percentile of the Student's t distribution with a @@ -253,6 +255,26 @@ def watt_spectrum(a, b): return _dll.watt_spectrum(a, b) +def normal_variate(mean_value, std_dev): + """ Samples an energy from the Normal distribution. + + Parameters + ---------- + mean_value : float + Mean of the Normal distribution + std_dev : float + Standard deviation of the normal distribution + + Returns + ------- + float + Sampled outgoing normally distributed value + + """ + + return _dll.normal_variate(mean_value, std_dev) + + def broaden_wmp_polynomials(E, dopp, n): """ Doppler broadens the windowed multipole curvefit. The curvefit is a polynomial of the form a/E + b/sqrt(E) + c + d sqrt(E) ... diff --git a/tests/unit_tests/test_math.py b/tests/unit_tests/test_math.py index 7ef749dece..c891d97e3e 100644 --- a/tests/unit_tests/test_math.py +++ b/tests/unit_tests/test_math.py @@ -205,6 +205,25 @@ def test_watt_spectrum(): assert ref_val == test_val +def test_normal_dist(): + settings = openmc.capi.settings + settings.seed = 1 + a = 14.08 + b = 0.0 + ref_val = 14.08 + test_val = openmc.capi.math.normal_variate(a, b) + + assert ref_val == test_val + + settings.seed = 1 + a = 14.08 + b = 1.0 + ref_val = 16.436645416691427 + test_val = openmc.capi.math.normal_variate(a, b) + + assert ref_val == test_val + + def test_broaden_wmp_polynomials(): # Two branches of the code to worry about, beta > 6 and otherwise # beta = sqrtE * dopp