Athos branch and correction of dipole tilts (rad vs degree issues)
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
+44
-15
@@ -2,10 +2,10 @@ from containers import VariableContainer
|
||||
from elements import *
|
||||
|
||||
class Exporter:
|
||||
def __init__(self):
|
||||
self.path = 'onlinemodel/exportedlayouts/layout.py'
|
||||
def __init__(self,version='11.1.2'):
|
||||
self.path = '../Heilige Liste/Python_Code/onlinemodel/layout/layout.py'
|
||||
self.fid = None
|
||||
self.lattice='11.1.2'
|
||||
self.lattice=version
|
||||
|
||||
def openFile(self):
|
||||
print(self.path)
|
||||
@@ -38,7 +38,7 @@ class Exporter:
|
||||
fid.write('\t\t\treturn self.build_final()\n\n')
|
||||
|
||||
def buildCaseHeader(self,case):
|
||||
cases=['_current','_planned','_final']
|
||||
cases=['current','planned','final']
|
||||
self.fid.write('\tdef build_%s(self):\n' % cases[case])
|
||||
|
||||
|
||||
@@ -55,39 +55,55 @@ class Exporter:
|
||||
|
||||
|
||||
def writeSection(self,Name,Length):
|
||||
print('Write Line Container',Name)
|
||||
self.fid.write('\n\t\t%s=LineContainer("%s",%f)\n' % (Name,Name,Length))
|
||||
|
||||
def writeElement(self,Container,Element):
|
||||
def writeElement(self,Container,Element,varCont=None,idx=0):
|
||||
|
||||
prop, typename,off, relative= self.getProp(Element)
|
||||
if prop is None:
|
||||
return
|
||||
self.fid.write('\t\tprop=%s\n' % prop)
|
||||
self.fid.write('\t\t%s.append(%s(prop),%f,"%s")\n' % (Container,typename,off,relative))
|
||||
|
||||
if varCont:
|
||||
self.fid.write('\t\t%s.append(%s(prop),%d,%s)\n' % (Container,typename,idx,varCont))
|
||||
else:
|
||||
self.fid.write('\t\t%s.append(%s(prop),%f,"%s")\n' % (Container, typename, off, relative))
|
||||
|
||||
def getProp(self,Element):
|
||||
if isinstance(Element, Marker) or isinstance(Element, VariableContainer):
|
||||
if isinstance(Element, Marker):
|
||||
if not 'MKBR' in Element.Name:
|
||||
return None,1,1,1
|
||||
if isinstance(Element, VariableContainer):
|
||||
return None,1,1,1
|
||||
prop= '{"Tag":"%s","index":%d,"Baugruppe":"%s","Length":%f' % (Element.Tag,Element.index,Element.Baugruppe, Element.Length)
|
||||
if Element.LengthRes>Element.Length:
|
||||
prop+=',"LengthRes":%f' % Element.LengthRes
|
||||
if Element.Tilt>0:
|
||||
prop+=',"Tilt":%f' % (Element.Tilt*np.pi/180.)
|
||||
prop+=',"Tilt":%13.10f' % (Element.Tilt*np.pi/180.)
|
||||
if isinstance(Element,Alignment):
|
||||
prop = '{"Tag":"ALIG","index":%d,"dy":%f' % (Element.index,Element.dy)
|
||||
if isinstance(Element, RF):
|
||||
prop+=',"Band":%s' % Element.Band
|
||||
prop+=',"Band":"%s"' % Element.Band
|
||||
if isinstance(Element,Quadrupole):
|
||||
if Element.PSChannels > 1:
|
||||
prop+=',"corx":0,"cory":0'
|
||||
if isinstance(Element,Dipole):
|
||||
angD=Element.design_angle
|
||||
if Element.branching:
|
||||
ang=0
|
||||
else:
|
||||
ang=angD
|
||||
prop+=',"angle":%f,"design_angle":%f' % (ang,angD)
|
||||
prop+=',"e1":%f,"e2":%f' % (Element.e1,Element.e2)
|
||||
if Element.PSChannels > 1:
|
||||
prop+=',"cor":0"'
|
||||
prop+=',"cor":0'
|
||||
if isinstance(Element,Corrector):
|
||||
if Element.PSChannels >0:
|
||||
prop+=',"corx":0,"cory":0'
|
||||
if isinstance(Element, Diagnostic):
|
||||
if Element.Seval > 0:
|
||||
prop+=',"Seval":%f' % Element.seval
|
||||
if isinstance(Element,Undulator):
|
||||
prop+=',"K"=%f,"ku":%f' % (Element.K,2*np.pi/Element.lambdau)
|
||||
prop+=',"K":%f,"ku":%f' % (Element.K,2*np.pi/Element.lambdau)
|
||||
prop+='}'
|
||||
pos = 'absolute'
|
||||
if Element.relOff:
|
||||
@@ -97,11 +113,24 @@ class Exporter:
|
||||
return prop,typename,offs,pos
|
||||
|
||||
|
||||
|
||||
def writeVariableLine(self,count,Element):
|
||||
tag='varC%d' % count
|
||||
self.fid.write('\t\t%s=VariableContainer(%f,%f)\n' % (tag,Element.L,Element.Loff))
|
||||
return tag
|
||||
|
||||
def buildCaseFooter(self):
|
||||
|
||||
|
||||
self.fid.write('\t\tLinac = LineContainer("")\n')
|
||||
self.fid.write('\t\tLinac.append(Linac10, 0, "relative")\n')
|
||||
self.fid.write('\t\tLinac.append(Linac20, 0, "relative")\n')
|
||||
self.fid.write('\t\tLinac.append(Linac30, 0, "relative")\n\n')
|
||||
|
||||
|
||||
self.fid.write('\t\tPartsList = [[Injector, -1, 0, "SwissFEL Injector"],\n')
|
||||
self.fid.write('\t\t [InjectorDump, 0, 1, "SwissFEL Injector beam dump"]]\n')
|
||||
self.fid.write('\t\t [Linac, 0, -1, "SwissFEL Linac"],\n')
|
||||
self.fid.write('\t\t [Aramis, 1, -1, "Aramis beamline"],\n')
|
||||
self.fid.write('\t\t [Athos, 1, 2, "Athos beamline"]]\n')
|
||||
self.fid.write('\t\treturn PartsList\n\n')
|
||||
|
||||
# PartsList = [[Injector, -1, 0, 'SwissFEL Injector'], # 0
|
||||
|
||||
@@ -156,27 +156,88 @@ class BeamlineEditor(QtWidgets.QMainWindow, Ui_BeamlineGUI):
|
||||
|
||||
def exportOnlineModel(self):
|
||||
print('Exporting Online Model Layout File...')
|
||||
self.exporter= Exporter()
|
||||
version = str(self.UIOMVersion.text())
|
||||
self.exporter= Exporter(version=version)
|
||||
self.exporter.openFile()
|
||||
for alt in range(3):
|
||||
print('Writing lattice for Phase:',alt+1)
|
||||
self.exportOnlineModelCase(alt)
|
||||
self.exporter.closeFile()
|
||||
|
||||
def exportOnlineModelCase(self,alt):
|
||||
self.exporter.buildCaseHeader(alt)
|
||||
secs=['IN','SINBD01']
|
||||
references={'IN':'Injector','SINBD01':'InjectorDump'}
|
||||
secs=['IN','10','20','30','AR','AT']
|
||||
branches={'IN':'Injector','10':'Linac10','20':'Linac20','30':'Linac30','AR':'Aramis','AT':'Athos'}
|
||||
for sec in secs:
|
||||
# find element in database
|
||||
# find section element in database
|
||||
id0 = None
|
||||
for id in self.elementDB.keys():
|
||||
ele = self.elementDB[id]
|
||||
if isinstance(ele, LineContainer) and ele.Name == sec and ele.firstElementID in self.elementDB.keys():
|
||||
if isinstance(ele, LineContainer) and ele.Name == sec:
|
||||
id0=id
|
||||
if id0:
|
||||
print('Found Section',sec)
|
||||
print('Found Kingdom:','S'+sec)
|
||||
else:
|
||||
continue #skip to next entry
|
||||
# now loop through the subsections:
|
||||
kingEle=self.elementDB[id0]
|
||||
kingName=sec
|
||||
sectionList=[]
|
||||
if kingEle.firstElementID in self.elementDB.keys(): # start Marker, which holds all section of the kingdom
|
||||
tree = self.editor.flatten(kingEle.firstElementID, alt+1)
|
||||
for ele in tree.path:
|
||||
type = self.editor.getElementType(ele)
|
||||
if type =='Start':
|
||||
continue
|
||||
section = self.elementDB[ele]
|
||||
#print('Found Section:','S'+kingName+section.Name)
|
||||
if section.firstElementID in self.elementDB.keys():
|
||||
sectionList.append(section.Name)
|
||||
self.exportOnlineModelSection(section.Name,section.LengthRes,section.firstElementID,alt+1)
|
||||
if tree.primary:
|
||||
treeprimary=self.editor.flatten(tree.primary.node_id, alt+1)
|
||||
for ele in treeprimary.path:
|
||||
type = self.editor.getElementType(ele)
|
||||
if type == 'Start':
|
||||
continue
|
||||
section = self.elementDB[ele]
|
||||
#print('Found Section:','S'+kingName+section.Name)
|
||||
if section.firstElementID in self.elementDB.keys():
|
||||
sectionList.append(section.Name)
|
||||
self.exportOnlineModelSection(section.Name, section.LengthRes, section.firstElementID,
|
||||
alt + 1)
|
||||
self.exporter.writeDomain(branches[sec], sec, kingEle.LengthRes, sectionList)
|
||||
self.exporter.buildCaseFooter()
|
||||
return
|
||||
|
||||
def exportOnlineModelSection(self,Name: str, Lres:float,startID: str, alt:int):
|
||||
self.exporter.writeSection(Name, Lres)
|
||||
tree=self.editor.flatten(startID, alt+1)
|
||||
count=1
|
||||
nextVar=None
|
||||
refIdx=0
|
||||
for i,eleID in enumerate(tree.path[1:]):
|
||||
type = self.editor.getElementType(eleID)
|
||||
if type == 'Variable Line':
|
||||
nextVar=self.exporter.writeVariableLine(count,self.elementDB[eleID])
|
||||
refEle=self.elementDB[eleID].ID
|
||||
if refEle in tree.path:
|
||||
ct = 0
|
||||
refIdx=0
|
||||
for idscan in tree.path:
|
||||
if idscan == refEle:
|
||||
refIdx = ct
|
||||
ct += 1
|
||||
type = self.editor.getElementType(idscan)
|
||||
if type == 'Start' or type == 'Variable Line':
|
||||
ct -=1
|
||||
count+=1
|
||||
else:
|
||||
self.exporter.writeElement(Name,self.elementDB[eleID],nextVar,refIdx)
|
||||
nextVar=None
|
||||
return
|
||||
|
||||
if a > 2:
|
||||
root = self.elementDB[id0].firstElementID
|
||||
domain=self.elementDB[root]
|
||||
tree = self.editor.flatten(root, alt+1)
|
||||
|
||||
@@ -84,6 +84,17 @@ class Ui_BeamlineGUI(object):
|
||||
self.UITolerances.setSizePolicy(sizePolicy)
|
||||
self.UITolerances.setObjectName("UITolerances")
|
||||
self.gridLayout.addWidget(self.UITolerances, 1, 1, 1, 1)
|
||||
self.label = QtWidgets.QLabel(self.tab_4)
|
||||
self.label.setObjectName("label")
|
||||
self.gridLayout.addWidget(self.label, 2, 0, 1, 1)
|
||||
self.UIOMVersion = QtWidgets.QLineEdit(self.tab_4)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.UIOMVersion.sizePolicy().hasHeightForWidth())
|
||||
self.UIOMVersion.setSizePolicy(sizePolicy)
|
||||
self.UIOMVersion.setObjectName("UIOMVersion")
|
||||
self.gridLayout.addWidget(self.UIOMVersion, 2, 1, 1, 1)
|
||||
self.verticalLayout_3.addLayout(self.gridLayout)
|
||||
self.UIUnresolvedElements = QtWidgets.QCheckBox(self.tab_4)
|
||||
self.UIUnresolvedElements.setChecked(True)
|
||||
@@ -213,6 +224,8 @@ class Ui_BeamlineGUI(object):
|
||||
self.UIFlattenOffset.setText(_translate("BeamlineGUI", "-0.1"))
|
||||
self.lineEdit_2.setText(_translate("BeamlineGUI", "Tolerance"))
|
||||
self.UITolerances.setText(_translate("BeamlineGUI", "1e-5"))
|
||||
self.label.setText(_translate("BeamlineGUI", "Lattice Tag"))
|
||||
self.UIOMVersion.setText(_translate("BeamlineGUI", "11.1.4"))
|
||||
self.UIUnresolvedElements.setText(_translate("BeamlineGUI", "List Unresolved Elements"))
|
||||
self.groupBox.setTitle(_translate("BeamlineGUI", "Branching"))
|
||||
self.UISimpleBranch.setText(_translate("BeamlineGUI", "Simplified Branching"))
|
||||
|
||||
@@ -110,6 +110,26 @@ background-color: rgb(13, 15, 26);</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Lattice Tag</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="UIOMVersion">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>11.1.4</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
||||
Reference in New Issue
Block a user