mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Fix bug when sampling multiple energy distributions
This commit is contained in:
parent
73f8400832
commit
0227f48230
1 changed files with 7 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue