From 0227f4823080a686e8130df065762d8d855d6f3d Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 19 Feb 2016 07:07:46 -0600 Subject: [PATCH] Fix bug when sampling multiple energy distributions --- src/secondary_header.F90 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/secondary_header.F90 b/src/secondary_header.F90 index d858074129..7449a5793b 100644 --- a/src/secondary_header.F90 +++ b/src/secondary_header.F90 @@ -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