Example #1
0
def test1():
    latticePath = "/home/tong/Programming/projects/vFEL/simulation/SXFEL"
    infilename = os.path.join(latticePath, 'sxfel_v14b.lte')
    pins = beamline.LteParser(infilename)
    lins = beamline.Lattice(pins.file2json())

    print(lins.dumpAllElements())
Example #2
0
def testfun():
    latticePath = os.path.join(os.getcwd(), '../lattice')
    infilename = os.path.join(latticePath, 'linac.lte')
    pins = beamline.LteParser(infilename)
    lins = beamline.Lattice(pins.file2json())

    #latticefile = os.path.join(os.getcwd(), 'tracking/newlat.lte')
    #lins.generateLatticeFile('bl', latticefile, format = 'elegant')

    #    tl = lins.manipulateLattice('bl')
    #    print tl

    #    print lins.orderLattice('chi')

    #    for (ename,etype,eid) in lins.orderLattice('chi'):
    #        print('{x:10s}:{y:10s}:{z:3d}'.format(x=ename,y=etype,z=eid))
    #    print lins.getFullBeamline('bl')
    #    print lins.getFullBeamline('a1', extend = True)
    #    print lins.getFullBeamline('l1')
    #    print lins.getFullBeamline('2l1', extend = True)
    #    print lins.getFullBeamline('bltest')
    #    print lins.getFullBeamline('bltest', extend = True)

    #    print lins.getFullBeamline('chi', extend = True)
    #    print lins.getElementByName('chi','dbll2')
    #    # single index
    #    print lins.getElementByOrder('chi','lscdrif', -1)
    #    # multi index
    #    print lins.getElementByOrder('chi','lscdrif', '0,1,2')
    #    # index range
    #    print lins.getElementByOrder('chi','lscdrif', '1:5:2')
    #    print lins.getElementByOrder('chi','lscdrif', 'all')

    #    lins.manipulateLattice('chi', type = 'quad', irange = 0, opstr = '+100%')
    #    for ename, etype, eid in lins.getElementByOrder('chi', type = 'quad', irange = 0):
    #        print lins.getElementProperties(ename)['properties']

    #    print lins.getElementProperties('q01')['properties']

    # double quad k1 in chi
    latticefile1 = os.path.join(os.getcwd(), 'tracking/newlat1.lte')
    latticefile2 = os.path.join(os.getcwd(), 'tracking/newlat2.lte')
    lins.generateLatticeFile('bl', latticefile1, format='elegant')
    lins.manipulateLattice('chi',
                           type='quad',
                           property='k1',
                           irange='all',
                           opstr='+100%')
    lins.generateLatticeFile('bl', latticefile2, format='elegant')

    # use datautils and simulation modules
    simpath = os.path.join(os.getcwd(), 'tracking')
    ltefile = latticefile1
    elefile = os.path.join(simpath, 'test.ele')
    A = beamline.Simulator()
    A.setMode('elegant')
    A.setScript('runElegant.sh')
    A.setExec('elegant')
    A.setPath(simpath)
    A.setInputfiles(ltefile=ltefile, elefile=elefile)
    A.doSimulation()
    data = A.getOutput(file='test.out', data=('t', 'p'), dump='test.h5')
Example #3
0
eleQ1.printConfig(type='all')

# update Q1's EPICS PV value
latline_online.putCtrlConf(eleQ1, 'k1', 2.5, type='real')
eleQ1.printConfig(type='all')

latline_online.getAllConfig(fmt='dict')

# ### Section 2: Lattice modeling

# #### STEP 4: create Lattice instance, make simulation required input files

eleb1.setConf('angle=0.1', type='simu')

# e.g. '.lte' for elegant tracking, require all configurations
latins = beamline.Lattice(latline_online.getAllConfig())
latfile = os.path.join(os.getcwd(), 'tracking/test.lte')
latins.generateLatticeFile(latline_online.name, latfile)

latins.dumpAllElements()

# #### STEP 5: simulation with generated lattice file

simpath = os.path.join(os.getcwd(), 'tracking')
elefile = os.path.join(simpath, 'test.ele')
h5out = os.path.join(simpath, 'tpout.h5')
elesim = beamline.Simulator()
elesim.setMode('elegant')
elesim.setScript('runElegant.sh')
elesim.setExec('elegant')
elesim.setPath(simpath)
Example #4
0
 def setUp(self):
     latticePath = os.path.join(os.getcwd(), '../lattice')
     infilename = os.path.join(latticePath, 'linac.lte')
     pins = beamline.LteParser(infilename)
     self.lins = beamline.Lattice(pins.file2json())
Example #5
0
import os
import matplotlib.pyplot as plt

### STEP 0: global configurations
beamline.MagBlock.setStyleConfig(
        config={'drift':{'lw':2}}
        )

### STEP 1: read lattice configurations from .lte file
ltefile = os.path.join(os.getcwd(), 'dcls/dcls.lte')
lpins   = beamline.LteParser(ltefile)

# generate lte file with all the element-definitions regarding to beamline
blname = 'bl'
newltefile = os.path.join(os.getcwd(), 'dcls/om.lte')
latins = beamline.Lattice(lpins.file2json())
latins.generateLatticeFile(blname, newltefile)

# use the concise version of lte file
newlpins = beamline.LteParser(newltefile)
newlatins = beamline.Lattice(newlpins.file2json())
# 
## print all keywords and types
#allkws = newlpins.detectAllKws()
#for kw in allkws:
#    print("{k:<10s}: {t:>10s}".format(k=kw.upper(),
#                                      t=newlpins.getKwType(kw)))

# demonstrate to create a new element from keyword name,
# there are two approaches to create:
#   1: use element classes from element module