Included missing CAPI wappers and unit tests for test_math.py

This commit is contained in:
Andrew Davis 2018-12-13 16:51:47 +00:00
parent e1cdd5a5c2
commit 32674887e5
2 changed files with 41 additions and 0 deletions

View file

@ -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) ...

View file

@ -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