Example #1
0
class StatLatsSetMember:
	"""
	This class delivers the statistical twiss parameters
	"""
	def __init__(self, file):
		self.file_out = file
		self.bunchtwissanalysis = BunchTwissAnalysis()
	
	def writeStatLats(self, s, bunch, lattlength = 0):
		
		self.bunchtwissanalysis.analyzeBunch(bunch)
		emitx = self.bunchtwissanalysis.getEmittance(0)
		betax = self.bunchtwissanalysis.getBeta(0)
		alphax = self.bunchtwissanalysis.getAlpha(0)
		betay = self.bunchtwissanalysis.getBeta(1)
		alphay = self.bunchtwissanalysis.getAlpha(1)
		emity = self.bunchtwissanalysis.getEmittance(1)
		dispersionx = self.bunchtwissanalysis.getDispersion(0)
		ddispersionx = self.bunchtwissanalysis.getDispersionDerivative(0)
		#dispersiony = self.bunchtwissanalysis.getDispersion(1, bunch)
		#ddispersiony = self.bunchtwissanalysis.getDispersionDerivative(1, bunch)
		
		sp = bunch.getSyncParticle()
		time = sp.time()

		if lattlength > 0:
			time = sp.time()/(lattlength/(sp.beta() * speed_of_light))

		# if mpi operations are enabled, this section of code will
		# determine the rank of the present node
		rank = 0  # default is primary node
		mpi_init = orbit_mpi.MPI_Initialized()
		comm = orbit_mpi.mpi_comm.MPI_COMM_WORLD
		if (mpi_init):
			rank = orbit_mpi.MPI_Comm_rank(comm)

		# only the primary node needs to output the calculated information
		if (rank == 0):
			self.file_out.write(str(s) + "\t" +  str(time) + "\t" + str(emitx)+ "\t" + str(emity)+ "\t" + str(betax)+ "\t" + str(betay)+ "\t" + str(alphax)+ "\t" + str(alphay) + "\t" + str(dispersionx) + "\t" + str(ddispersionx) +"\n")
	
	def closeStatLats(self):
		self.file_out.close()

	def resetFile(self, file):
		self.file_out = file
Example #2
0
    if i % 100 == 0:
        lostbunch.dumpBunch(pre_list + "/lost_data/turn_" + str(i) + ".dat")

    if 1:
        k = 0
        while k < b.getSize():
            if check_bucket(b.z(k), b.dE(k)) is False:
                b.deleteParticle(k)
            else:
                k += 1

    if i < 200:
        b.macroSize(num_charge_max / 200 * (i + 1))

ana.analyzeBunch(b)
curr_emitx = ana.getEmittance(0)
curr_betax = ana.getBeta(0)
curr_sx = sqrt(curr_betax * curr_emitx)

if rank == 0:
    if not os.path.exists(pre_list + "/test_particles_" + str(test_name)):
        os.mkdir(pre_list + "/test_particles_" + str(test_name))

    p_list = []
    count = 1
    for ang in np.linspace(0, pi / 2, 30):
        for r in np.linspace(0, 10 * curr_sx, 100):

            x = cos(ang) * r
            px = 0
            if x == 0:
Example #3
0
                b.deleteParticle(k)
            else:
                k += 1

        if rank == 0:
            f2.flush()

    # slow initialization for the first 200 turns
    if i < 200:
        b.macroSize(num_charge_max / 200 * (i + 1))

b.dumpBunch(pre_list + "/ready_bunch_" + str(test_name) + ".dat")
"""----------------------add test particles----------------------"""

ana.analyzeBunch(b)
curr_emitx = ana.getEmittance(0)
curr_betax = ana.getBeta(0)
curr_alphax = ana.getAlpha(0)

curr_emity = ana.getEmittance(1)
curr_betay = ana.getBeta(1)
curr_alphay = ana.getAlpha(1)

if rank == 0:

    count = 1

    for n_factor in np.linspace(0, 3, 51)[1:]:

        for theta in np.linspace(0, 2 * pi, 101)[:-1]:
Example #4
0
        ), matrix_lattice.getRingTwissDataY()
        print("{} {}".format(TwissDataX[0][-1][1], TwissDataY[0][-1][1]))

        twissX = TwissContainer(alpha=TwissDataX[1][0][1],
                                beta=TwissDataX[2][0][1],
                                emittance=emitx)
        twissY = TwissContainer(alpha=TwissDataY[1][0][1],
                                beta=TwissDataY[2][0][1],
                                emittance=emity)
        dist = GaussDist3D(twissX, twissY, twissZ)

        for i in range(n_particles):
            b.addParticle(*dist.getCoordinates())

        print("tracking")
        for i in range(n_turns):
            lattice.trackBunch(b, trackDict)
        bunchtwissanalysis.analyzeBunch(b)
        Ex = bunchtwissanalysis.getEmittance(0)
        Ey = bunchtwissanalysis.getEmittance(1)
        w.write("{},{},{},{}\n".format(TwissDataX[0][-1][1],
                                       TwissDataY[0][-1][1], Ex, Ey))

        b.deleteAllParticles()

        print("we are at the {}-th position".format(k))
    else:
        print("the problem occured: {}-th position".format(k))

w.close()