예제 #1
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')
예제 #2
0
파일: demo1.py 프로젝트: archman/beamline
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)
elesim.setInputfiles(ltefile=latfile, elefile=elefile)

elesim.doSimulation()

# data columns could be extracted from simulation output files, to memory or h5 files.
data_tp = elesim.getOutput(file='test.out', data=('t', 'p'))  #, dump = h5out)
data_sSx = elesim.getOutput(file='test.sig', data=('s', 'Sx'))
data_setax = elesim.getOutput(file='test.twi', data=('s', 'etax'))

# #### visualize data