forked from slaclab/zfel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsase_regression_test.py
48 lines (43 loc) · 2.13 KB
/
sase_regression_test.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
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#%matplotlib inline
import scipy.io
import random
import datetime
import time
from zfel import sase1d
Nruns=1 # Number of runs
npart = 512 # n-macro-particles per bucket
s_steps = 200#31 # n-sample points along bunch length
z_steps = 200#20 # n-sample points along undulator
energy = 4313.34e6 # electron energy [eV]
eSpread = 0#1.0e-4 # relative rms energy spread [ ]
emitN = 1.2e-6 # normalized transverse emittance [m-rad]
currentMax = 3900 # peak current [Ampere]
beta = 26 # mean beta [meter]
unduPeriod = 0.03 # undulator period [meter]
unduK = 3.5 # undulator parameter, K [ ]
unduL = 70#30 # length of undulator [meter]
radWavelength = 1.5e-9 # seed wavelength? [meter], used only in single-freuqency runs
dEdz = 0 # rate of relative energy gain or taper [keV/m], optimal~130
iopt = 5 # 5=SASE, 4=seeded
P0 = 10000*0.0 # small seed input power [W]
constseed = 1 # whether we want to use constant random seed for reproducibility, 1 Yes, 0 No
'''
Put input parameters into a inp_struct dict, for 1D FEL run
'''
inp_struct={'Nruns':Nruns,'npart':npart,'s_steps':s_steps,'z_steps':z_steps,'energy':energy,'eSpread':eSpread,\
'emitN':emitN,'currentMax':currentMax,'beta':beta,'unduPeriod':unduPeriod,'unduK':unduK,'unduL':\
unduL,'radWavelength':radWavelength,'dEdz':dEdz,'iopt':iopt,'P0':P0,'constseed':constseed}
#%load_ext autoreload
#%autoreload
'''
Use sase function in sase1d.py to run 1D FEL
'''
z,power_z,s,power_s,rho,detune,field,\
field_s,gainLength,resWavelength,\
thet_out,gam_out,bunching,history=sase1d.sase(inp_struct)
result_A=np.round(z,2)
result_B=np.round(power_z,2)
np.savetxt('test/z_and_power_z.now',np.column_stack((result_A,result_B)),delimiter=",", header="z,power_z")