1

I am currently attempting to map and show the path of a photon from the center of the sun until it reaches the surface and is emitted. I also want to show the time taken for this to happen.

So far all I have done is set the parameters (density of sun, Thompson cross-section, mass of electron, mass of proton) and using these I was able find the mean free path in the sun for a photon. I know that I will have to set an array of some sorts, and create random numbers for each random walk. I do not know what to do to make the random walk so that the photon can go in any direction in the x, y or z values.

I also do not know what I should loop in order to create this random walk. I need it so that the random walk will stop when d is equal to or greater than the radius of the sun. I know that d=l*sqrt(N), where l is the average size of each step, or mean free path, and N is the number of steps taken.

Lastly, I would not know where to start with plotting the results. I would like to show an animation of the photon travelling through a sphere from the center, where the sphere would resemble the sun.

Below is the only code I have so far, any help would be much appreciated.

from random import random, seed, randint
import numpy as np
import matplotlib.pyplot as plt

N=100000
rho=1408.6 #the mass density of the sun
thompson=6.65*10**-29 #Thompson cross-section for an electro 
proton=1.67*10**-27 #mass of a proton
electron=9.11*10**-31 #mass of an electron
radius=6.9634*10**8 #radius of a sun
c=2.99*10**8

mfp=(electron+proton)/(rho*thompson*np.sqrt(2))
timestep=mfp/c
sek1996
  • 11
  • 1

1 Answers1

1

You have the pseudocode in your head. Just translate into equations.

For the random walk in 3d, the simplest way I can think of is, instead of making the photon travel in any direction, call a random number in each step to decide in which direction it will move (x, y or z) and which direction (positive or negative). In a simple form, something like this.

import numpy as np

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

mfp = 1
num_steps=10000

walks = [[0,0,0]]
for step in range(num_steps):
    walk = np.zeros(3)
    move_in_direct = np.random.choice(3)
    move_pos_or_neg = np.random.choice([-1,1])
    walk[move_in_direct] = move_pos_or_neg*mfp
    walks.append(np.array(walks[-1])+walk)

walks = np.transpose(walks)

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(*walks, label='parametric curve')
ax.legend()
plt.show()

Try to understand it and improve/adapt it.

j_bio
  • 25
  • 5