Commit 0575f51e authored by reiche's avatar reiche
Browse files

Adding dechirper module and lattice 10.3.3

parent 06babe9d
This diff is collapsed.
OMLayout-10.3.3.py
\ No newline at end of file
import numpy as np
from scipy import special
import matplotlib.pyplot as plt
class Dechirper:
def __init__(self):
self.Z0 = 377
self.c = 299792458
self.eps=8.854e-12
self.mks=1./4/np.pi/self.eps
self.N=1000
# OK for python2 and python3
self.lwake=list(range(self.N))
self.twake=list(range(self.N))
self.qwake=list(range(self.N))
self.s=list(range(self.N))
def getWake(self,gap, writeSDDS=''):
# emperical length of single particle wake
s0 = 0.5e-3
self.s= np.linspace(0,s0,num=self.N)
# parameter for SwissFEL dechirper
a = gap/2
p = 0.500e-3
delta = 0.250e-3 # h in paper SwisSFEL 250 micron
g = 0.250e-3 # t in paper
alfa = 1-0.465*np.sqrt(g/p)-0.07*g/p
s0r = a*a*g/2/np.pi/alfa/alfa/p/p
s0l = s0r*9./4.
s0q = s0r*(15./16)**2
s0d = s0r*(15./14)**2
sl=self.s/s0l
sq=self.s/s0q
sd=self.s/s0d
# longitudinal wake
self.lwake=np.pi*np.pi/a/a/4*np.exp(-np.sqrt(sl))*self.mks
# quadrupole wake
self.qwake=(np.pi/2/a)**4*s0q*(1-(1+np.sqrt(sq))*np.exp(-np.sqrt(sq)))*self.mks
# dipole wake
self.twake=(np.pi/2/a)**4*s0d*(1-(1+np.sqrt(sd))*np.exp(-np.sqrt(sd)))*self.mks
if len(writeSDDS)>0:
self.writeSDDS(writeSDDS)
# plotting the wake to cross check with bolkos matlab scripts
# plt.plot(self.s,self.lwake)
# plt.xlabel('Test')
# plt.xlim(0,0.01)
# plt.show()
return [self.s, self.lwake, self.twake, self.qwake]
#--------------------------------------
# write SDDS wakefile
def writeSDDS(self,path):
filename=path+'/wake_l_dechirper.sdds'
fid=open(filename,'w')
fid.write('SDDS1\n')
fid.write('&column name=z, units=m, type=double, &end\n')
fid.write('&column name=W, units=V/C, type=double, &end\n')
fid.write('&column name=t, units=s, type=double, &end\n')
fid.write('&column name=WL, units=V/C/m, type=double, &end\n')
fid.write('&data mode=ascii, &end\n')
fid.write('! page number 1\n')
fid.write('%i\n' % len(self.s))
for i in range(len(self.s)):
fid.write(' %12.6e %12.6e %12.6e %12.6e\n' % (self.s[i],self.lwake[i],self.s[i]/self.c,self.lwake[i]))
fid.close()
filename=path+'/wake_t_dechirper.sdds'
fid=open(filename,'w')
fid.write('SDDS1\n')
fid.write('&column name=z, units=m, type=double, &end\n')
fid.write('&column name=W, units=V/C/m, type=double, &end\n')
fid.write('&column name=t, units=s, type=double, &end\n')
fid.write('&column name=WT, units=V/C/m$a2$n, type=double, &end\n')
fid.write('&data mode=ascii, &end\n')
fid.write('! page number 1\n')
fid.write('%i\n' % len(self.s))
for i in range(len(self.s)):
fid.write(' %12.6e %12.6e %12.6e %12.6e\n' % (self.s[i],self.twake[i],self.s[i]/self.c,self.twake[i]))
fid.close()
filename=path+'/wake_q_dechirper.sdds'
fid=open(filename,'w')
fid.write('SDDS1\n')
fid.write('&column name=z, units=m, type=double, &end\n')
fid.write('&column name=W, units=V/C/m, type=double, &end\n')
fid.write('&column name=t, units=s, type=double, &end\n')
fid.write('&column name=WT, units=V/C/m$a2$n, type=double, &end\n')
fid.write('&data mode=ascii, &end\n')
fid.write('! page number 1\n')
fid.write('%i\n' % len(self.s))
for i in range(len(self.s)):
fid.write(' %12.6e %12.6e %12.6e %12.6e\n' % (self.s[i],self.qwake[i],self.s[i]/self.c,self.qwake[i]))
fid.close()
......@@ -72,18 +72,12 @@ class Dist:
return self.litrackfile
def importSDDS(self,filename,printout=0):
def importSDDS(self,filename,path, printout=0):
print('Importing SDDS Particle Distribution:', filename)
self.sddsfile=filename
call(["sddsanalyzebeam",filename,"dist.analyse"])
fid=open('dummy','w')
call(["sdds2stream","dist.analyse","-col=enx,eny,betax,betay,alphax,alphay,St,Sdelta,pCentral,Charge"],stdout=fid)
fid.close()
fid=open('dummy','r')
self.sddsfile=path+'/'+filename
fid=open(path+'/dist.txt','r')
line=fid.readline()
fid.close()
col=line.strip().split()
......@@ -99,9 +93,6 @@ class Dist:
self.p0=float(col[8])
self.q=float(col[9])
call(["rm","dummy"])
call(["rm","dist.analyse"])
self.loaded=True
if printout==0:
......
......@@ -37,7 +37,7 @@ class Elegant(ElegantLattice):
self.fid=open(filename,'w')
self.fid.write('&run_setup\n')
self.fid.write('\tlattice\t\t=%s/%s.lat,\n' % (path,name))
self.fid.write('\tuse_beamline\t= %s,\n' % name)
self.fid.write('\tuse_beamline\t= SwissFEL,\n')
self.fid.write('\trootname\t= %s,\n' % name)
self.fid.write('\toutput\t\t= %s.out,\n')
self.fid.write('\tcentroid\t\t= %s.cen,\n')
......
......@@ -255,7 +255,7 @@ class ElegantLattice(ApplicationTemplate):
ele.K=0
if 'Power' in ele.__dict__:
if ele.Power>0:
LaserHeater=1
LaserHeater=0 ######## disable laser modulator, since energy spread is not correct anyhow
if ele.sRef>0:
self.writeDrift(ele.sRef)
if ele.K==0:
......
Layout/OMLayout_10_3_2.py
\ No newline at end of file
Layout/OMLayout-10.3.3.py
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment