Merge pull request #588 from paulromano/applicability-bug

Fix bug when sampling multiple energy distributions
This commit is contained in:
Sterling Harper 2016-02-19 11:38:34 -05:00
commit 642f6a946e

View file

@ -1,5 +1,6 @@
module secondary_header
use constants, only: ZERO
use endf_header, only: Tab1
use interpolation, only: interpolate_tab1
use random_lcg, only: prn
@ -54,16 +55,19 @@ contains
real(8), intent(out) :: mu ! sampled scattering cosine
integer :: n ! number of angle-energy distributions
real(8) :: p_valid ! probability that given distribution is valid
real(8) :: prob ! cumulative probability
real(8) :: c ! sampled cumulative probability
n = size(this%applicability)
if (n > 1) then
prob = ZERO
c = prn()
do i = 1, n
! Determine probability that i-th energy distribution is sampled
p_valid = interpolate_tab1(this%applicability(i), E_in)
prob = prob + interpolate_tab1(this%applicability(i), E_in)
! If i-th distribution is sampled, sample energy from the distribution
if (prn() <= p_valid) then
if (c <= prob) then
call this%distribution(i)%obj%sample(E_in, E_out, mu)
exit
end if