Commit a9a927cb authored by reiche's avatar reiche
Browse files

Added support for dechirper modules in elegant

parent 0575f51e
......@@ -456,9 +456,9 @@ class SwissFEL:
TM.define('COL-TR-16',indict)
indict={'Type':'Diagnostic','Length':0.5,'Tag':'VCOL','Aperx':0,'Baugruppe': 'E-COL'}
TM.define('COL-Energy',indict)
indict={'Type':'Undulator','Length':1,'Tag':'UDCP','Aperx':0,'Baugruppe': 'DECHIRPER-V'}
indict={'Type':'Undulator','Length':1,'Tag':'UDCP','gap':20e-3,'Aperx':0,'Baugruppe': 'DECHIRPER-V'}
TM.define('COL-Dechirper-V',indict)
indict={'Type':'Undulator','Length':1,'Tag':'UDCP','Aperx':0,'Baugruppe': 'DECHIRPER-H'}
indict={'Type':'Undulator','Length':1,'Tag':'UDCP','gap':20e-3,'Aperx':0,'Baugruppe': 'DECHIRPER-H'}
TM.define('COL-Dechirper-H',indict)
indict={'Type':'Diagnostic','Length':0.01,'Tag':'DCOL','Aperx':0,'Baugruppe':'BC-SCRAPER'}
TM.define('COL-BC-Scraper',indict)
......@@ -1333,8 +1333,8 @@ class SwissFEL:
DI01.append(TM.generate('DBAM-FS16',70),0.1,'relative')
DI01.append(TM.generate('QFD',80),2.15-1.563-0.397,'relative')
DI01.append(TM.generate('DBPM-C16',90),0.063,'relative')
DI01.append(TM.generate('COL-Dechirper-H',100),0.5+0.087,'relative')
DI01.append(TM.generate('COL-Dechirper-V',200),0.5+0.35,'relative')
DI01.append(TM.generate('COL-Dechirper-H',100,{'gap':2e-3}),0.5+0.087,'relative')
DI01.append(TM.generate('COL-Dechirper-V',200,{'gap':2e-3}),0.5+0.35,'relative')
DI01.append(TM.generate('DBPM-C16',210),0.5+0.019+0.115+0.327-0.437,'relative')
DI01.append(TM.generate('QFD',230),0.081,'relative')
DI01.append(TM.generate('DBPM-C16',240),1.2-0.001-0.327,'relative')
......@@ -1376,17 +1376,17 @@ class SwissFEL:
CB01.append(TM.generate('DBPM-C16',420),0.099538,'relative')
CB01.append(TM.generate('QFD',430),0.049,'relative')
if self.alt>0:
CB02.append(TM.generate('COL-Dechirper-V',100),0.5+0.528-0.003,'relative')
CB02.append(TM.generate('COL-Dechirper-H',200),0.5-0.528+0.875+0.003,'relative')
CB02.append(TM.generate('COL-Dechirper-V',100,{'gap':2e-3}),0.5+0.528-0.003,'relative')
CB02.append(TM.generate('COL-Dechirper-H',200,{'gap':2e-3}),0.5-0.528+0.875+0.003,'relative')
CB02.append(TM.generate('DBPM-C16',220),0.080613+0.035+0.049387+0.085+1.015-0.875,'relative')
CB02.append(TM.generate('QFD',230),0.049,'relative')
CB02.append(TM.generate('COL-Dechirper-V',300),0.5+0.74208,'relative')
CB02.append(TM.generate('COL-Dechirper-H',400),0.5-0.74208+1.09208,'relative')
CB02.append(TM.generate('COL-Dechirper-V',300,{'gap':2e-3}),0.5+0.74208,'relative')
CB02.append(TM.generate('COL-Dechirper-H',400,{'gap':2e-3}),0.5-0.74208+1.09208,'relative')
CB02.append(TM.generate('DBPM-C16',420),0.099538+1.40146-1.09208,'relative')
CB02.append(TM.generate('QFD',430),0.049,'relative')
else:
CB02.append(TM.generate('COL-Dechirper-V',300),4.664+0.5+0.74208,'relative')
CB02.append(TM.generate('COL-Dechirper-H',400),0.5-0.74208+1.09208,'relative')
CB02.append(TM.generate('COL-Dechirper-V',300,{'gap':2e-3}),4.664+0.5+0.74208,'relative')
CB02.append(TM.generate('COL-Dechirper-H',400,{'gap':2e-3}),0.5-0.74208+1.09208,'relative')
CB02.append(TM.generate('DBPM-C16',420),0.099538+1.40146-1.09208,'relative')
CB02.append(TM.generate('QFD',430),0.049,'relative')
......@@ -1404,9 +1404,9 @@ class SwissFEL:
MA01.append(TM.generate('DSCR-OV16',30),1.78-0.037-0.051,'relative')
else:
MA01.append(TM.generate('DBPM-C8',10),0.293+0.102-0.257,'relative')
MA01.append(TM.generate('COL-Dechirper-V',15),0.5+0.257-0.202,'relative')
MA01.append(TM.generate('COL-Dechirper-V',15,{'gap':2e-3}),0.5+0.257-0.202,'relative')
MA01.append(TM.generate('DBPM-C8',20),0.5-0.051-0.1285+0.202,'relative')
MA01.append(TM.generate('COL-Dechirper-H',25),0.5+0.1285-0.2155,'relative')
MA01.append(TM.generate('COL-Dechirper-H',25,{'gap':2e-3}),0.5+0.1285-0.2155,'relative')
MA01.append(TM.generate('DSCR-HR8',30),0.28-0.037-0.051+0.2155,'relative')
MA01.append(TM.generate('DBPM-C8',40),0.12,'relative')
MA01.append(TM.generate('QFF',50),0.06,'relative')
......
import numpy as np
from scipy import special
import matplotlib.pyplot as plt
class Dechirper:
def __init__(self):
......@@ -20,10 +17,12 @@ class Dechirper:
def getWake(self,gap, writeSDDS=''):
def getWake(self,gap, element='', writeSDDS=''):
# emperical length of single particle wake
s0 = 0.5e-3
s0 = 0.5e-3
if 'SINSB05' in element:
s0 = 10e-3
self.s= np.linspace(0,s0,num=self.N)
# parameter for SwissFEL dechirper
a = gap/2
......@@ -49,13 +48,8 @@ class Dechirper:
if len(writeSDDS)>0:
self.writeSDDS(writeSDDS)
self.writeSDDS(element, 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]
......@@ -63,49 +57,22 @@ class Dechirper:
# write SDDS wakefile
def writeSDDS(self,path):
filename=path+'/wake_l_dechirper.sdds'
def writeSDDS(self,element, path):
filename=path+'/wake_%s.sdds' % element
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('&column name=WD, units=V/C/m, type=double, &end\n')
fid.write('&column name=WQ, units=V/C/m, type=double, &end\n')
fid.write('&column name=WQP, 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.twake[i],self.s[i]/self.c,self.twake[i]))
fid.write(' %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e \n' % (self.s[i],self.lwake[i],self.s[i]/self.c,self.twake[i],self.qwake[i],-self.qwake[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()
import math
from OMAppTemplate import ApplicationTemplate
from OMWakes import Wakes
from OMDWakes import Dechirper
# Elegant Interface
......@@ -261,6 +262,37 @@ class ElegantLattice(ApplicationTemplate):
if ele.K==0:
self.write("%s: LSCDRIFT, L=%f, LEFFECTIVE=%f, BINS=%d, SMOOTHING=1, LSC=%d\n" % (ele.Name,ele.getLength(),ele.getLength(),self.lscbins,self.lsc))
self.seq.append(ele.Name)
# add dechirper here
if 'UDCP' in ele.Name:
wake=Dechirper()
wake.getWake(ele.gap, ele.Name,self.path)
self.write('%s_LW : WAKE, INPUTFILE = "%s/wake_%s.sdds", &\n' % (ele.Name,self.path,ele.Name))
self.write('\t TCOLUMN="t",WCOLUMN="W", INTERPOLATE=1, FACTOR = %f, N_BINS=%d, SMOOTHING=1 \n'% (ele.getLength(),self.wakebins))
self.seq.append('%s_LW' % ele.Name)
if 'DECHIRPER-V' in ele.Baugruppe:
self.write('%s_DW : TRWAKE, INPUTFILE = "%s/wake_%s.sdds", &\n' % (ele.Name,self.path,ele.Name))
self.write('\t TCOLUMN="t",WXCOLUMN="WD", XFACTOR = %f, YFACTOR = %f, &\n' % (ele.getLength(),ele.getLength()))
self.write('\t INTERPOLATE=1, N_BINS=%d, SMOOTHING=1, & \n'% self.wakebins)
self.write('\t Y_DRIVE_EXPONENT = 0\n')
self.write('%s_QW : TRWAKE, INPUTFILE = "%s/wake_%s.sdds", &\n' % (ele.Name,self.path,ele.Name))
self.write('\t TCOLUMN="t",WXCOLUMN="WQ", WYCOLUMN="WQP", XFACTOR = %f, YFACTOR = %f, &\n' % (ele.getLength(),ele.getLength()))
self.write('\t INTERPOLATE=1, N_BINS=%d, SMOOTHING=1, & \n'% self.wakebins)
self.write('\t X_DRIVE_EXPONENT=0, Y_DRIVE_EXPONENT = 0, X_PROBE_EXPONENT = 1, Y_PROBE_EXPONENT = 1\n')
self.seq.append('%s_DW' % ele.Name)
self.seq.append('%s_QW' % ele.Name)
elif 'DECHIRPER-H' in ele.Baugruppe:
self.write('%s_DW : TRWAKE, INPUTFILE = "%s/wake_%s.sdds", &\n' % (ele.Name,self.path,ele.Name))
self.write('\t TCOLUMN="t",WYCOLUMN="WD", XFACTOR = %f, YFACTOR = %f, &\n' % (ele.getLength(),ele.getLength()))
self.write('\t INTERPOLATE=1, N_BINS=%d, SMOOTHING=1, & \n'% self.wakebins)
self.write('\t X_DRIVE_EXPONENT = 0\n')
self.write('%s_QW : TRWAKE, INPUTFILE = "%s/wake_%s.sdds", &\n' % (ele.Name,self.path,ele.Name))
self.write('\t TCOLUMN="t",WXCOLUMN="WQP", WYCOLUMN="WQ", XFACTOR = %f, YFACTOR = %f, &\n' % (ele.getLength(),ele.getLength()))
self.write('\t INTERPOLATE=1, N_BINS=%d, SMOOTHING=1, & \n'% self.wakebins)
self.write('\t X_DRIVE_EXPONENT=0, Y_DRIVE_EXPONENT = 0, X_PROBE_EXPONENT = 1, Y_PROBE_EXPONENT = 1\n')
self.seq.append('%s_DW' % ele.Name)
self.seq.append('%s_QW' % ele.Name)
ds=ele.getResLength()-ele.getLength()-ele.sRef
if ds>0:
self.writeDrift(ds)
......@@ -287,7 +319,7 @@ class ElegantLattice(ApplicationTemplate):
if ele.sRef>0:
self.writeDrift(ele.sRef)
if ele.Tag=="RACC":
if not (ele.Band in self.wakes):
if not (ele.Band in self.wakes.keys()):
wake=Wakes()
wake.getWake(ele.Band,self.path)
self.wakes[ele.Band]=1
......
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