Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
Arquivo: a.py Projeto: mpyliyj/sqmat
def cirDist(k2s):
	'''
	circle distortion
	'''
	npass = 64

	norder = 7
	tol = 1e-12

	sexts = ring.matchElements('sh1.*')
	for s in sexts:
		ring[s,'K2'] = k2s[0]
	sexts = ring.matchElements('sh3.*')
	for s in sexts:
		ring[s,'K2'] = k2s[1]
	sexts = ring.matchElements('sh4.*')
	for s in sexts:
		ring[s,'K2'] = k2s[2]
	sexts = ring.matchElements('sl3.*')
	for s in sexts:
		ring[s,'K2'] = k2s[3]
	sexts = ring.matchElements('sl2.*')
	for s in sexts:
		ring[s,'K2'] = k2s[4]
	sexts = ring.matchElements('sl1.*')
	for s in sexts:
		ring[s,'K2'] = k2s[5]
		
        # six phase space varialbe, 4 independent, expand to n'rd order.
	m = tesla.TPSMap(6,4,norder)
	m.c = [0, 0, 0, 0, 0, 0]
	m.m = [[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1], [0,0,0,0],[0,0,0,0]]
	ms = ring.trackTPSMaps(m, 0, ring.elements()) #ms has the maps of all elements around the ring, m is one turn map
	tw, ml = tesla.calcLinearTwiss(ring)

        #4. Construct map matrix mm
	mf,powerindex = sqdf.mfunction(m,norder) # m is one turn map
        #This program only applies when x[0]=0,xp[0]=0,y[0]=0, yp[0]=0. If not, then the map matrix mm is no longer semi-triangular
	mf[0][0] = 0
	mf[1][0] = 0
	mf[2][0] = 0
	mf[3][0] = 0
	mf = np.array(mf)

	mlen=len(powerindex)

        # sequencenumber[i1,i2,i3,i4] gives the sequence number in power index for power of x^i1*xp^i2*y^i3*yp^i4
	sequencenumber = np.zeros((norder+1,norder+1,norder+1,norder+1),'i')
	powerindex = sqdf.powerindex4(norder)
	powerindex = np.array(powerindex,'i')
	mlen = len(powerindex)

	for i in range(mlen):
		ip = powerindex[i]
		sequencenumber[ip[0]][ip[1]][ip[2]][ip[3]] = i

	betax0,phix0,alphax0,betay0,phiy0,alphay0 = sqdf.extracttwiss(mf)
	gammax0 = (1+alphax0**2)/betax0
	mlix = [np.cos(phix0)+alphax0*np.sin(phix0), betax0*np.sin(phix0)],\
	    [-gammax0*np.sin(phix0), np.cos(phix0)-alphax0*np.sin(phix0)]
	gammay0 = (1+alphay0**2)/betay0
	mliy = [np.cos(phiy0)+alphay0*np.sin(phiy0), betay0*np.sin(phiy0)],\
	    [-gammay0*np.sin(phiy0), np.cos(phiy0)-alphay0*np.sin(phiy0)]

	elemtx = np.zeros((4,4))
	elemtx[0:2,0:2] = mlix #Replace linear part of elegant, which is accurate only to 8 digits, 
        #by the twiss matrix obtained from the twiss parameters extract from the tpsa linear part of matrix
	elemtx[2:4,2:4] = mliy #Notice that mlix and mliy is accurate simplex to machine precision, so their determinantes are closer to zero.

	mf[:,1:5] = elemtx #Now replace the linear part of map matrix by the more accurate twiss matrix

	sqrtbetax = np.sqrt(betax0)
	sqrtbetay = np.sqrt(betay0)

        #5. Construct the BK square matrix using the first 5 rows.
	bK,bKi = sqdf.BKmatrix(betax0,phix0,alphax0,\
			       betay0,phiy0,alphay0,
			       0,0,norder,powerindex,sequencenumber,tol)

        #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) 

	Bi = np.array([[1/sqrtbetax,0,0,0],[alphax0/sqrtbetax,sqrtbetax,0,0],
		       [0,0,1/sqrtbetay,0],[0,0,alphay0/sqrtbetay,sqrtbetay]])
	Ki = np.array([[1,-1j,0,0],[1,1j,0,0],[0,0,1,-1j],[0,0,1,1j]]) 
	bKi4b4 = np.dot(Ki,Bi)

	try:
	    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 [1e8]*8

	# --- particle 1
	x0 = 2.5e-2
	y0 = 5e-3
	xxpyyp = np.zeros((4,npass+1))
	xxpyyp[:,0] = np.array([x0,0,y0,0])
	for i in xrange(1,npass+1):
		xxpyyp[:,i] = np.dot(elemtx,xxpyyp[:,i-1])
	xybar = np.dot(Bi,xxpyyp)
	xy = zip(*xybar)
	section = []
	for row in xy:
		section.append(normalcoordinate(*row))
	st = zip(*section)
        #11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
	section1 = [] #section1 is without joined blocks
	xy = zip(*xxpyyp)
	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 ''
	
	# --- particle 2
	x0 = 1.0e-2
	y0 = 2e-3
	xxpyyp = np.zeros((4,npass+1))
	xxpyyp[:,0] = np.array([x0,0,y0,0])
	for i in xrange(1,npass+1):
		xxpyyp[:,i] = np.dot(elemtx,xxpyyp[:,i-1])
	xybar = np.dot(Bi,xxpyyp)
	xy = zip(*xybar)
	section = []
	for row in xy:
		section.append(normalcoordinate(*row))
	st = zip(*section)
        #11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
	section1 = [] #section1 is without joined blocks
	xy = zip(*xxpyyp)
	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])
	zx2 = (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])
	zy2 = (zmax-zmin)/zav
	#print "for wy1 without resonance block,  (zmax-zmin)/zmean = ", zy1
	#print ''

	# --- particle 3
	x0 = 3.5e-2
	y0 = 3.0e-3
	xxpyyp = np.zeros((4,npass+1))
	xxpyyp[:,0] = np.array([x0,0,y0,0])
	for i in xrange(1,npass+1):
		xxpyyp[:,i] = np.dot(elemtx,xxpyyp[:,i-1])
	xybar = np.dot(Bi,xxpyyp)
	xy = zip(*xybar)
	section = []
	for row in xy:
		section.append(normalcoordinate(*row))
	st = zip(*section)
        #11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
	section1 = [] #section1 is without joined blocks
	xy = zip(*xxpyyp)
	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])
	zx3 = (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])
	zy3 = (zmax-zmin)/zav
	#print "for wy1 without resonance block,  (zmax-zmin)/zmean = ", zy1
	#print ''

	xlist = np.linspace(-3e-2,3e-2,30) #a list of theta0
	ylist = np.arange(1e-6,1.0e-2,10) #a list of theta0
	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]
	
	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]))
	return [zx1,zy1,zx2,zy2,zx3,zy3,dnuxda,dnuyda,dax,day]
Exemplo n.º 4
0
def cirDist(k2s):
    '''
	circle distortion
	'''
    npass = 64

    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]
        '''
    # ---fast but not general, only for nsls2-II chrom+7/+7
    sm12 = [-26.21867845, 30.69679902, -28.01658206]
    K2 = np.hstack((k2s[:3], sm12, k2s[3:], k2s[-1:-4:-1], sm12, k2s[-4::-1]))

    temp = copy.deepcopy(unit)
    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, truncate=norder)
    temp = sm.lmPass(nsls2.ring.mlist[-1][:nv, :nv], temp)
    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)
    '''
	Bi = np.array([[1/sqrtbetax,0,0,0],[alphax0/sqrtbetax,sqrtbetax,0,0],
		       [0,0,1/sqrtbetay,0],[0,0,alphay0/sqrtbetay,sqrtbetay]])
	Ki = np.array([[1,-1j,0,0],[1,1j,0,0],[0,0,1,-1j],[0,0,1,1j]]) 
	bKi4b4 = np.dot(Ki,Bi)
        '''

    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 [1e8] * 8

    # --- particle 1
    x0 = 2.5e-2
    y0 = 5e-3
    xxpyyp = np.zeros((4, npass + 1))
    xxpyyp[:, 0] = np.array([x0, 0, y0, 0])
    for i in xrange(1, npass + 1):
        xxpyyp[:, i] = np.dot(elemtx, xxpyyp[:, i - 1])
    xybar = np.dot(Bi, xxpyyp)
    xy = zip(*xybar)
    section = []
    for row in xy:
        section.append(normalcoordinate(*row))
    st = zip(*section)
    #11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
    section1 = []  #section1 is without joined blocks
    xy = zip(*xxpyyp)
    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 ''

    # --- particle 2
    x0 = 1.0e-2
    y0 = 2e-3
    xxpyyp = np.zeros((4, npass + 1))
    xxpyyp[:, 0] = np.array([x0, 0, y0, 0])
    for i in xrange(1, npass + 1):
        xxpyyp[:, i] = np.dot(elemtx, xxpyyp[:, i - 1])
    xybar = np.dot(Bi, xxpyyp)
    xy = zip(*xybar)
    section = []
    for row in xy:
        section.append(normalcoordinate(*row))
    st = zip(*section)
    #11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
    section1 = []  #section1 is without joined blocks
    xy = zip(*xxpyyp)
    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)
    return st1
    #print 'K2s = %.2f:'%k2s
    zmax = max(st1[0])
    zmin = min(st1[0])
    zav = np.mean(st1[0])
    zx2 = (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])
    zy2 = (zmax - zmin) / zav
    #print "for wy1 without resonance block,  (zmax-zmin)/zmean = ", zy1
    #print ''

    # --- particle 3
    x0 = 3.5e-2
    y0 = 3.0e-3
    xxpyyp = np.zeros((4, npass + 1))
    xxpyyp[:, 0] = np.array([x0, 0, y0, 0])
    for i in xrange(1, npass + 1):
        xxpyyp[:, i] = np.dot(elemtx, xxpyyp[:, i - 1])
    xybar = np.dot(Bi, xxpyyp)
    xy = zip(*xybar)
    section = []
    for row in xy:
        section.append(normalcoordinate(*row))
    st = zip(*section)
    #11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
    section1 = []  #section1 is without joined blocks
    xy = zip(*xxpyyp)
    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])
    zx3 = (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])
    zy3 = (zmax - zmin) / zav
    #print "for wy1 without resonance block,  (zmax-zmin)/zmean = ", zy1
    #print ''

    xlist = np.linspace(-3e-2, 3e-2, 30)  #a list of theta0
    ylist = np.arange(1e-6, 1.0e-2, 10)  #a list of theta0
    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]

    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]))
    return [zx1, zy1, zx2, zy2, zx3, zy3, dnuxda, dnuyda, dax, day]
Exemplo n.º 5
0
    phib0x = cmath.phase(b0x)
    wy = np.dot(uy, Zys)
    b0y = wy[0]
    dmu00y = -1j * (wy[1]) / b0y
    ab0y = abs(b0y)
    phib0y = cmath.phase(b0y)
    return ab0x, ab0y, phib0x, phib0y


#11. Prepare data for |wx|,thetax,|wy|,thetay to plot Poincare section of thetax,|wy|,thetay
#ux1,uxbar,Jx,scalex,Ms,As2x,Asm2x = jfdf.UMsUbarexpJ(Ms,phix0,1,powerindex,scalemf,ypowerorder=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,Ms,As2y,Asm2y = jfdf.UMsUbarexpJ(Ms,phiy0,1,powerindex,scalemf,ypowerorder=norder)
uy1, uybar, Jy, scaley, Msy, As2y, Asm2y = jfdf.UMsUbarexpJ(Ms,
                                                            phiy0,
                                                            1,
                                                            powerindex,
                                                            scalemf,
                                                            sequencenumber[0,
                                                                           0,
                                                                           1,
                                                                           0],
                                                            ypowerorder=norder)