Beispiel #1
0
def cirDist(k2s):
	'''
	circle distortion
	'''
	norder = 7

        # slow but general ---
	sext = nsls2.ring.getElements('sext','sh1')[0]
        sext.put('K2',k2s[0])
	sext = nsls2.ring.getElements('sext','sh3')[0]
        sext.put('K2',k2s[1])
	sext = nsls2.ring.getElements('sext','sh4')[0]
        sext.put('K2',k2s[2])
	sext = nsls2.ring.getElements('sext','sl3')[0]
        sext.put('K2',k2s[3])
	sext = nsls2.ring.getElements('sext','sl2')[0]
        sext.put('K2',k2s[4])
	sext = nsls2.ring.getElements('sext','sl1')[0]
        sext.put('K2',k2s[5])

        K2 = [nsls2.ring.bl[k].K2 for k in nsls2.ring.klist]
        
        temp = [CTPS(0,i) for i in xrange(1,nv+1)]
        for i,k in enumerate(nsls2.ring.klist):
            temp = sm.lmPass(nsls2.ring.mlist[i][:nv,:nv],temp)
            temp = sm.thickSextPass(L[i],K2[i],2,temp)
            # --- attach thin octupole to sext
            temp = sm.thinOctPass(K2[i]/abs(K2[i])*10.,temp)
        temp = sm.lmPass(nsls2.ring.mlist[-1][:nv,:nv],temp)
        mf = np.array([[temp[i].element(jj) for jj in xrange(mlen)] for i in xrange(nv)])
        #mf = np.array([sm.aline(temp[i],powerindex) for i in xrange(nv)])

        elemtx = mf[:,1:5]
        
        #6. Derive normalized map M=(BK)^(-1).mm.BK, see my notes 'Relation to Normal Form' of Wednesday, March 30, 2011 10:34 PM
        #   here #mfbk is the first 4 rows of M, it is 

	mfbk = jfdf.d3(bKi[1:5,1:5],mf,bK) 

	mfbk,scalemf,As,Asm = scalingmf(mfbk,powerindex)

	Ms = sqdf.squarematrix(mfbk,norder,powerindex,sequencenumber,tol)

	try:
            #print Ms[-1],Ms.shape,phix0,1,powerindex,scalemf,sequencenumber[1,0,0,0],norder
	    ux1,uxbar,Jx,scalex,Msx,As2x,Asm2x = \
		jfdf.UMsUbarexpJ(Ms,phix0,1,powerindex,scalemf,sequencenumber[1,0,0,0],ypowerorder=norder)
	    uy1,uybar,Jy,scaley,Msy,As2y,Asm2y = \
		jfdf.UMsUbarexpJ(Ms,phiy0,1,powerindex,scalemf,sequencenumber[0,0,1,0],ypowerorder=norder)
	except:
            return [1.0e8]*12

	# --- particle one by one
        zx,zy = [],[]
        for xy in xylist:
            #11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
            section1 = [] #section1 is without joined blocks
            for row in xy:
                    row1 = row+(ux1,uy1)
                    section1.append(tuneshift(row1[0],row1[1],row1[2],row1[3],row1[4],row1[5],
                                              bKi4b4,scalex,scaley,powerindex,norder))
            st1 = zip(*section1)
            #print 'K2s = %.2f:'%k2s
            zmax = max(st1[0])
            zmin = min(st1[0])
            zav = np.mean(st1[0])
            zx1 = (zmax-zmin)/zav
            #print "for wx1 without resonance block,  (zmax-zmin)/zmean = ", zx1
            zmax = max(st1[1])
            zmin = min(st1[1])
            zav = np.mean(st1[1])
            zy1 = (zmax-zmin)/zav
            #print "for wy1 without resonance block,  (zmax-zmin)/zmean = ", zy1
            #print ''
            zx.append(zx1)
            zy.append(zy1)

	xlist = np.linspace(-3e-2, 3e-2,30) # a list of x
	ylist = np.linspace( 1e-6, 1e-2,10) # a list of y
	xyplane = [[i,j] for i in xlist for j in ylist]

	nu,da = [],[]
	for x,y in xyplane:
		t1,t2,t3,t4,t5,t6,t7,t8 = tuneshift(x,0,y,0,ux1,uy1,
						    bKi4b4,scalex,scaley,powerindex,norder)
		nu.append([t5,t6])
		da.append([t7,t8])

	da = np.array(da)
	nux = [i[0].real/2/np.pi for i in nu]
	nuy = [i[1].real/2/np.pi for i in nu]
	#nux = [i[0].imag/2/np.pi for i in nu]
	#nuy = [i[1].imag/2/np.pi for i in nu]
	
	dnuxda = np.max(np.abs(nux))
	dnuyda = np.max(np.abs(nuy))
	dax = np.max(np.abs(da[:,0]))
	day = np.max(np.abs(da[:,1]))

        #k2c = [sc.K2 for sc in chsext]
	return zx+zy+[dnuxda,dnuyda,dax,day]#+k2c
Beispiel #2
0
def cirDist():
    '''
	circle distortion
	'''
    norder = 7

    K2 = [nsls2.ring.bl[k].K2 for k in nsls2.ring.klist]

    temp = [CTPS(0, i) for i in xrange(1, nv + 1)]
    for i, k in enumerate(nsls2.ring.klist):
        temp = sm.lmPass(nsls2.ring.mlist[i][:nv, :nv], temp)
        temp = sm.thickSextPass(L[i], K2[i], 1, temp)
    temp = sm.lmPass(nsls2.ring.mlist[-1][:nv, :nv], temp)
    mf = np.array([[temp[i].element(jj) for jj in xrange(mlen)]
                   for i in xrange(nv)])
    #mf = np.array([sm.aline(temp[i],powerindex) for i in xrange(nv)])

    elemtx = mf[:, 1:5]

    #6. Derive normalized map M=(BK)^(-1).mm.BK, see my notes 'Relation to Normal Form' of Wednesday, March 30, 2011 10:34 PM
    #   here #mfbk is the first 4 rows of M, it is

    mfbk = jfdf.d3(bKi[1:5, 1:5], mf, bK)

    mfbk, scalemf, As, Asm = scalingmf(mfbk, powerindex)

    Ms = sqdf.squarematrix(mfbk, norder, powerindex, sequencenumber, tol)

    try:
        #print Ms[-1],Ms.shape,phix0,1,powerindex,scalemf,sequencenumber[1,0,0,0],norder
        ux1,uxbar,Jx,scalex,Msx,As2x,Asm2x = \
     jfdf.UMsUbarexpJ(Ms,phix0,1,powerindex,scalemf,sequencenumber[1,0,0,0],ypowerorder=norder)
        uy1,uybar,Jy,scaley,Msy,As2y,Asm2y = \
     jfdf.UMsUbarexpJ(Ms,phiy0,1,powerindex,scalemf,sequencenumber[0,0,1,0],ypowerorder=norder)
    except:
        return [1.0e8] * 12

    # --- particle one by one
    zxy = []
    for xy in xylist:
        #11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
        section1 = []  #section1 is without joined blocks
        for row in xy:
            row1 = row + (ux1, uy1)
            section1.append(
                tuneshift(row1[0], row1[1], row1[2], row1[3], row1[4], row1[5],
                          bKi4b4, scalex, scaley, powerindex, norder))
        st1 = zip(*section1)
        #print 'K2s = %.2f:'%k2s
        #zmax = max(st1[0])
        #zmin = min(st1[0])
        #zav = np.mean(st1[0])
        #zx1 = (zmax-zmin)/zav
        #print "for wx1 without resonance block,  (zmax-zmin)/zmean = ", zx1
        #zmax = max(st1[1])
        #zmin = min(st1[1])
        #zav = np.mean(st1[1])
        #zy1 = (zmax-zmin)/zav
        #print "for wy1 without resonance block,  (zmax-zmin)/zmean = ", zy1
        #print ''
        zxy.append(st1)
    return zxy