SF+ matching and support for ELegant lattice export

This commit is contained in:
reiche committed 2026-10-13 09:39:40 +02:00
1 parent 85b8e89917
commit 4e9a35b0e7
8 files changed
+818 -323

No files matched your search

+10 -3
View File
@@ -148,7 +148,11 @@ class Model:
def loadSettingsGroup(self,group,fields,normalized=False):
for key in group.keys():
ele = self.om.getElement(key)
if ele is None: # entry in settings file, which doe snot exist in lattice
continue
for field in fields:
if 'design' in field:
print(ele.Name,group[key][field])
ele.__dict__[field]=group[key][field]
if normalized:
ele.__dict__[field]/=ele.Length
@@ -164,7 +168,7 @@ class Model:
self.loadSettingsGroup(settings['RF'], ['Gradient'],normalized=True)
self.loadSettingsGroup(settings['RF'], ['Phase'])
self.loadSettingsGroup(settings['Undulator'], ['K','kx','ky'])
self.loadSettingsGroup(settings['Kicker'], ['cory','design_kick'])
self.loadSettingsGroup(settings['Kicker'], ['design_kick'])
self.startEnergy = settings['Energy']['energy']
self.energyReference = settings['Energy']['location']
self.startTwiss = settings['InitialCondition']
@@ -213,11 +217,12 @@ class Model:
refloc = start.upper()
if self.startEnergy is None:
self.startEnergy = self.om.EnergyAt(self.energyReference)[0]*1e-6
twiss0['energy'] = self.startEnergy*1e-3 # convert to GeV for madx
start, end = self.checkRange(start, end, refloc[0:7])
if start is None:
return
print('Tracking from',start,'to',end)
print('Tracking from',start,'to',end, '(Reference Location:',refloc,')')
self.doTrack(start,end,refloc,twiss0)
@@ -225,11 +230,12 @@ class Model:
#print(twiss_in)
twiss0 = {converttwiss[key]:twiss_in[key] for key in twiss_in.keys()} # follows the madx format
self.setBranch(end.upper())
print("Tracking:",refloc[0:7],start)
if not refloc[0:7] == start:
print("Back tracking from", refloc, start)
twiss0 = self.doBackTrack(refloc,start,twiss0) # track backwards to get new initial twiss values
twiss = self.madx.track('swissfel',start+'$START',end+'$END',twiss0)
energy = self.calcEnergyProfile(twiss)
exit
if plot:
self.parent.plot.newData(twiss,energy)
@@ -285,6 +291,7 @@ class Model:
destination = 'ATHOS'
elif 'S10BD' in end or 'SIN' in end:
destination = 'INJECTOR'
print('Setting Branch in online model:', destination)
self.om.setBranch(destination,'SINLH01')
self.order=self.om.getBranchElements()
self.madx.updateLattice(self.om,destination,self.forceLat)