Merge IEPC2025 #54

Merged
JorgeGonz merged 19 commits from IEPC2025 into development 2025-09-23 18:42:06 +02:00
2 changed files with 12 additions and 11 deletions
Showing only changes of commit 4b040c35c3 - Show all commits

Fixes to random variables

After reading some works and reviewing what I had, I've done some
corrections to how the randomb velicities in Maxwellian distributions
are calculated. These should be correct now.
Jorge Gonzalez 2025-08-02 13:25:48 +02:00

View file

@ -47,22 +47,23 @@ MODULE moduleRandom
END FUNCTION randomIntAB END FUNCTION randomIntAB
!Returns a random number in a Maxwellian distribution of mean 0 and width 1 !Returns a random number in a Maxwellian distribution of mean 0 and width 1 with the Box-Muller Method
FUNCTION randomMaxwellian() RESULT(rnd) FUNCTION randomMaxwellian() RESULT(rnd)
USE moduleConstParam, ONLY: PI USE moduleConstParam, ONLY: PI
IMPLICIT NONE IMPLICIT NONE
REAL(8):: rnd REAL(8):: rnd
REAL(8):: x, y REAL(8):: v1, v2, Rsquare
rnd = 0.D0 Rsquare = 1.D0
x = 0.D0 do while (Rsquare >= 1.D0 .and. Rsquare > 0.D0)
DO WHILE (x == 0.D0) v1 = 2.D0 * random() - 1.D0
CALL RANDOM_NUMBER(x) v2 = 2.D0 * random() - 1.D0
END DO Rsquare = v1**2 + v2**2
CALL RANDOM_NUMBER(y)
rnd = DSQRT(-2.D0*DLOG(x))*DCOS(2.D0*PI*y) end do
rnd = v2 * sqrt(-2.D0 * log(Rsquare) / Rsquare)
END FUNCTION randomMaxwellian END FUNCTION randomMaxwellian

View file

@ -289,7 +289,7 @@ MODULE moduleInject
REAL(8):: v REAL(8):: v
v = 0.D0 v = 0.D0
v = self%vTh*randomMaxwellian() v = sqrt(2.0)*self%vTh*randomMaxwellian()
END FUNCTION randomVelMaxwellian END FUNCTION randomVelMaxwellian
@ -302,7 +302,7 @@ MODULE moduleInject
REAL(8):: v REAL(8):: v
v = 0.D0 v = 0.D0
v = self%vTh*randomHalfMaxwellian() v = sqrt(2.0)*self%vTh*randomHalfMaxwellian()
END FUNCTION randomVelHalfMaxwellian END FUNCTION randomVelHalfMaxwellian