monte carlo sampling - university of st andrews

21
Monte Carlo Sampling Sampling from PDFs: given F(x) in analytic or tabulated form, generate a random number x in the range (0,1) and solve the equation to get the randomly sampled value X Solve this analytically, numerically, or by clever means… ξ = F ( x )dx = C ( X ) x min X X A F(x) x P(q) 1 q x i q i

Upload: others

Post on 07-Jul-2022

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Monte Carlo Sampling - University of St Andrews

Monte Carlo SamplingSampling from PDFs: given F(x) in analytic or tabulated form, generate a random number x in the range (0,1) and solve the equation to get the randomly sampled value X

Solve this analytically, numerically, or by clever means…

ξ = F(x)dx =C(X) ⇒xmin

X

∫ X

A

F(x)

x

P(q)

1q xiqi

Page 2: Monte Carlo Sampling - University of St Andrews

Power Law Spectrum• General power law spectrum: y = a xn + c• Choose random frequency nR from a power law

spectrum: F(n) ~ n-a with n1 < n < n2

Synchrotron spectrum from electrons spiraling in a magnetic field

Page 3: Monte Carlo Sampling - University of St Andrews

Power Law Spectrum• General power law spectrum: y = a xn + c• Choose random frequency nR from a power law

spectrum: F(n) ~ n-a with n1 < n < n2

ξ =

ν −α dνν 1

ν R

ν −α dνν 1

ν 2

∫=ν1−α[ ]

ν 1

ν R

ν1−α[ ]ν 1

ν 2⇒ νR = ν1

1−α + ξ ν 21−α −ν1

1−α[ ]( ) 1/(1−α )

Page 4: Monte Carlo Sampling - University of St Andrews

Neutron Interactions• Choose interaction event to be: absorption,

scattering, or fissionsT = sA + sS + sFran = xif (ran .lt. sA/sT) then

neutron absorbedelseif(ran .lt. (sA+sS)/sT) then

neutron scatteredelse

fission eventendif

AbsorptionScatteringFission

Page 5: Monte Carlo Sampling - University of St Andrews

Tabulated Spectrum• Solar spectrum: example of using numerical integration• Given arrays of wavelengths, l(i), and corresponding flux

values, F(i), with i = 1, 2,… N• Numerical integration by trapezoidal rule:

• Numerically compute and store the cumulative distribution function C(i):

F(λ)dλ ≈ 12Fi+1 + Fi( ) λi+1 − λi( )

i=1

N −1

∑∫

C(λ) = F(λ')λmin

λ

∫ dλ' / F(λ')λmin

λmax

∫ dλ'

sum = 0do i=1, N-1

sum = sum + 0.5*[F(i+1)+F(i)]*[lam(i+1)-lam(i)]end do

Page 6: Monte Carlo Sampling - University of St Andrews

xxi xi+1

F(x)

Area = [xi+1 – xi] [F(xi) + F(xi+1)] / 2

Trapezoidal Rule

Page 7: Monte Carlo Sampling - University of St Andrews

Tabulated Spectrum• Recall that C(l) increases monotonically from 0 to 1• Also recall Monte Carlo sampling:

• So, given a random number x, search C(i) to find C values that bracket x, and the corresponding indices i, i+1

• Interpolate to get wavelength and flux corresponding to x,e.g., linear interpolation:€

ξ = F(λ')dλ' =C(λ) ⇒λmin

λ

∫ λ

F = F(i) + F(i +1) − F(i)[ ] λ − λ(i)λ(i +1) − λ(i)

λ = λ(i) + λ(i +1) − λ(i)[ ] ξ −C(i)C(i +1) −C(i)

Page 8: Monte Carlo Sampling - University of St Andrews

Search an array by bisection

Nup = NNlow=1mid=(Nup+Nlow)/2do while(Nup – Nlow .gt. 1)

mid=(Nup+Nlow)/2)if (lam0 .gt. lam(mid)) then

Nup=NupNlow=mid

elseNup=midNlow=Nlow

endifend do

Given a wavelength, l0, search an array of wavelengths l(i), where i = 1, 2, … N, to find the ls and i-values that bracket l0

When exit the do-loop, l0 will be bracketed by the indices i = Nlow and i = Nlow + 1, l(Nlow) < l0 < l(Nlow + 1)

l(Nlow)

l(N)l(1) l0

l(Nlow+1)

Page 9: Monte Carlo Sampling - University of St Andrews

Setting the opacity• If Monte Carlo simulation has source emitting a spectrum,

then need to set optical properties (cross sections, opacities, etc) for the ensuing random walk for the wavelength randomly sampled from the spectrum

• Wavelength l randomly sampled from source spectrum, find bracketing location as above in array of wavelengths for cross sections, interpolate to get optical properties:

σ(λ) =σ (i) + σ (i +1) −σ(i)[ ] λ − λ(i)λ(i +1) − λ(i)

Page 10: Monte Carlo Sampling - University of St Andrews

Volume emission from uniform sphere• Choose x, y, z randomly in the range (-1, 1)• Reject if x2 + y2 + z2 > 1• Choose new random set of x, y, z until x2 + y2 + z2 < 1

• OR sample from volume element dV = r2 sinq dr dq df• Choose r, q, f from appropriate pdfs – group tutorial exercise

Can use this algorithm to select source locations for neutrons when computing critical mass of a Uranium sphere

Page 11: Monte Carlo Sampling - University of St Andrews

Cylinders or rods• Choose z using: z = x h• Choose x, y randomly in the range (-r, r)• Reject if x2 + y2 > r2

• Choose new random set of x, y until x2 + y2 < r2

• OR choose z as above, but sample r, q from appropriate pdfs for uniformly sampling points within a circle – group tutorial exercise

Page 12: Monte Carlo Sampling - University of St Andrews

Emission from a galaxy with stellar emission approximated as a smooth emissivity: j(r, z) ~ exp(- |z| / Z) exp(- r / R). Defined over 0 < r < Rmax, 0 < z < Zmax

Split into separate probabilities for r and z

( ))]/exp(1[1log

)]/exp(1[)]/exp(1[

d)/exp(

d)/exp(

max

max

0

0max

RRRr

RRRr

rRr

rRr

R

r

−−−−=⇒

−−−−

=

=

ξ

ξ

Page 13: Monte Carlo Sampling - University of St Andrews

Laser beams• Techniques for sampling from collimated laser beams, e.g.,

Gaussian beam profile…

Page 14: Monte Carlo Sampling - University of St Andrews

Launching from a collimated beam• For a circular beam of uniform intensity can use rejection

method to sample (x, y) launch positions of photons• Choose x, y randomly in the range (-R, R)• Reject if x2 + y2 > R2

• Choose new random set of x, y until x2 + y2 < R2

• Gaussian beam profile: exp[-(r/b)2] • Choose (r, f) by:

• See Jacques (2009) review eq 5.27• Use trigonometry to get (x, y)€

r = b −ln(ξ)φ = 2π ξ

Page 15: Monte Carlo Sampling - University of St Andrews

Clever techniques…

• Not as crucial now, but something still to consider when trying to speed up codes – be efficient!

• Cost of evaluating functions: addition < division < exponentials < trig functions, etc

• Cashwell & Carter (1977) – Third Monte Carlo Sampler, contains algorithms for sampling lots of functions

Page 16: Monte Carlo Sampling - University of St Andrews

Isotropic emission or scattering• Choosing isotropic direction cosines• Simple method:

• From John von Neumann, to avoid evaluating sin f, cos f:

• Efficiency = p / 4

µ = cosθ = 2ξ −1φ = 2π ξ

nx = 1− µ2 sinφ

ny = 1− µ2 cosφnz = µ

Choose x = 2x - 1, y = 2x – 1 (different xs!!)Reject if x2 + y2 > 1cos f = x/sqrt(x2 + y2), sin f = y/sqrt(x2 + y2)Double angle formula avoids taking square root:cos f = (x2 – y2)/(x2 + y2), sin f = 2xy/(x2 + y2)

Page 17: Monte Carlo Sampling - University of St Andrews

Energy of fission neutronsFission produced by an incident neutron of energy E0. Sample energy E from the normalised fission spectrum, which can be approximated by the Maxwell spectrum:

where T(E0) is the nuclear temperature (in energy units) which is tabulated as a function of energy in nuclear data tables. Use three random numbers to get:€

X(E) =2π1/ 2

T(E0)−3 / 2 E1/ 2 e−E /T (E0 )

E = T(E0) −lnξ1 − lnξ2( )cos2 π2 ξ3%

& '

(

) *

+

, -

.

/ 0

Page 18: Monte Carlo Sampling - University of St Andrews

U235 Fission Spectrum

Page 19: Monte Carlo Sampling - University of St Andrews

Blackbody RadiationSample frequency n from Planck function. Use the normalised Planck function with x = hn/kT

Set:

The notation {x; F(x)} means the set of all x satisfying F(x)

Then:

Bν (T ) =2hν 3

c21

ehν /kT −1; bx =

15x3

π 4 ex −1( )

L =min l ; j −4j=1

l

∑ ≥ξ0π 4

90

' ( )

* )

+ , )

- )

x = −L−1 ln ξ1ξ2 ξ3 ξ4( )

Page 20: Monte Carlo Sampling - University of St Andrews

Blackbody Radiation

Page 21: Monte Carlo Sampling - University of St Andrews

Scattering• Isotropic scattering: neutrons, photons• See later lectures for non-isotropic scattering, polarization,

and rotating angles from scattering to lab frame• Non-isotropic: electrons, dust, molecules, biological tissue• Rayleigh, Thompson/Compton, Klein-Nishina, Mie theory,

Heyney-Greenstein functions