-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPLB_acc_NoSTCApril.py
72 lines (62 loc) · 3.08 KB
/
RPLB_acc_NoSTCApril.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
from numba import jit
@jit(nopython=True)
def RPLB_acc_NoSTCApril(lambda_0, s, a, P, Psi_0, t_0, z_0, beta_0):
# initialize constants (SI units)
c = 2.99792458e8 # speed of light
m_e = 9.10938356e-31
q_e = 1.60217662e-19
e_0 = 8.85418782e-12
# calculate frequency properties
omega_0 = 2*np.pi*c/lambda_0
tau_0 = s*np.sqrt(np.exp(2/(s+1))-1)/omega_0
# amplitude factor
Amp = -1*np.sqrt(8*P/(np.pi*e_0*c))*a*c/(2*omega_0)
t_start = t_0 + z_0/(c*(1-beta_0))
t_end = +1e5*tau_0
# number of time steps per laser period
n = (lambda_0/(0.8e-6))*100 # np.maximum(50, np.round(np.sqrt(P/(w_0**2))/(5e10))) # empirically chosen resolution based on field strength
num_t = np.int_(np.round(n*(t_end-t_start)/(lambda_0/c)))
time = np.linspace(t_start, t_end, num_t)
dt = time[1]-time[0]
# initialize empty arrays
z = np.zeros(shape=(len(time)))
beta = np.zeros(shape=(len(time)))
deriv2 = np.zeros(shape=(len(time)))
KE = np.zeros(shape=(len(time)))
# Set initial conditions
beta[0] = beta_0
z[0] = beta[0]*c*time[0]+z_0
k_stop = -1
#do 5th order Adams-Bashforth finite difference method
for k in range(0, len(time)-1):
t_p = time[k] + np.sqrt((z[k]/c + 1j*a/c)**2) + 1j*a/c
t_m = time[k] - np.sqrt((z[k]/c + 1j*a/c)**2) + 1j*a/c
f_zero_p = (1-1j*omega_0*t_p/s)**(-(s+1))
f_zero_m = (1-1j*omega_0*t_m/s)**(-(s+1))
f_one_p = (s+1)*(1j*omega_0/s)*(1-1j*omega_0*t_p/s)**(-(s+2))
f_one_m = (s+1)*(1j*omega_0/s)*(1-1j*omega_0*t_m/s)**(-(s+2))
Gm_zero = f_zero_p - f_zero_m
Gp_one = f_one_p + f_one_m
field_total = np.real(np.exp(1j*(Psi_0+np.pi/2))*(2*Amp/(z[k]+1j*a)**2)*(Gm_zero/(z[k]+1j*a)-Gp_one/c))
deriv2[k] = (-q_e*np.real(field_total)*((1-beta[k]**2)**(3/2))/(m_e*c))
if k==0:
z[k+1] = z[k] + dt*c*beta[k]
beta[k+1] = beta[k] + dt*deriv2[k]
elif k==1:
z[k+1] = z[k] + dt*c*(1.5*beta[k]-0.5*beta[k-1])
beta[k+1] = beta[k] + dt*(1.5*deriv2[k]-0.5*deriv2[k-1])
elif k==2:
z[k+1] = z[k] + dt*c*((23/12)*beta[k]-(4/3)*beta[k-1]+(5/12)*beta[k-2])
beta[k+1] = beta[k] + dt*((23/12)*deriv2[k]-(4/3)*deriv2[k-1]+(5/12)*deriv2[k-2])
elif k==3:
z[k+1] = z[k] + dt*c*((55/24)*beta[k]-(59/24)*beta[k-1]+(37/24)*beta[k-2]-(3/8)*beta[k-3])
beta[k+1] = beta[k] + dt*((55/24)*deriv2[k]-(59/24)*deriv2[k-1]+(37/24)*deriv2[k-2]-(3/8)*deriv2[k-3])
else:
z[k+1] = z[k] + dt*c*((1901/720)*beta[k]-(1387/360)*beta[k-1]+(109/30)*beta[k-2]-(637/360)*beta[k-3]+(251/720)*beta[k-4])
beta[k+1] = beta[k] + dt*((1901/720)*deriv2[k]-(1387/360)*deriv2[k-1]+(109/30)*deriv2[k-2]-(637/360)*deriv2[k-3]+(251/720)*deriv2[k-4])
KE[k+1] = ((1/np.sqrt(1-beta[k+1]**2))-1)*m_e*c**2/q_e
if (time[k] > 300*tau_0 and np.mean(np.abs(np.diff(KE[k-np.int(10*n):k+1]))/(KE[k+1]*dt)) < 1e7):
k_stop = k+1
break
return time[:k_stop], z[:k_stop], beta[:k_stop], KE[:k_stop]