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
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
file_writer.close() b.dumpBunch(pre_list + "/initial_bunch_" + str(test_name) + ".dat") ana = BunchTwissAnalysis() f = open(pre_list + "/tracking_" + str(test_name) + ".txt", 'w') for i in range(1000): ana.analyzeBunch(b) if rank == 0: f.write( str(i) + " " + str(ana.getEmittanceNormalized(0)) + " " + str(ana.getEmittanceNormalized(1)) + " " + str(ana.getBeta(0)) + " " + str(ana.getBeta(1)) + " " + str(lostbunch.getSize()) + "\n") lattice.trackBunch(b, paramsDict) if rank == 0: print("==========================") print("turn: " + str(i)) print("lost: " + str(lostbunch.getSize())) print("remain: " + str(b.getSize())) print("charge: " + str(b.macroSize())) print("intensity: " + str(b.macroSize() * b.getSize() * size)) print( str(ana.getEmittanceNormalized(0)) + " " + str(ana.getEmittanceNormalized(1))) print("==========================")
get_bunch_length = lambda b, bta: 4 * np.sqrt(bta.getCorrelation(4,4)) / (speed_of_light*b.getSyncParticle().beta()) get_eps_z = lambda b, bta: 1e9 * 4 * pi * bta.getEmittance(2) / (speed_of_light*b.getSyncParticle().beta()) output_file = 'output/output.mat' output = Output_dictionary() output.addParameter('turn', lambda: turn) output.addParameter('epsn_x', lambda: bunchtwissanalysis.getEmittanceNormalized(0)) output.addParameter('epsn_y', lambda: bunchtwissanalysis.getEmittanceNormalized(1)) output.addParameter('eps_z', lambda: get_eps_z(bunch, bunchtwissanalysis)) output.addParameter('intensity', lambda: bunchtwissanalysis.getGlobalMacrosize()) output.addParameter('n_mp', lambda: bunchtwissanalysis.getGlobalCount()) output.addParameter('D_x', lambda: bunchtwissanalysis.getDispersion(0)) output.addParameter('D_y', lambda: bunchtwissanalysis.getDispersion(1)) output.addParameter('bunchlength', lambda: get_bunch_length(bunch, bunchtwissanalysis)) output.addParameter('dpp_rms', lambda: get_dpp(bunch, bunchtwissanalysis)) output.addParameter('beta_x', lambda: bunchtwissanalysis.getBeta(0)) output.addParameter('beta_y', lambda: bunchtwissanalysis.getBeta(1)) output.addParameter('alpha_x', lambda: bunchtwissanalysis.getAlpha(0)) output.addParameter('alpha_y', lambda: bunchtwissanalysis.getAlpha(1)) output.addParameter('mean_x', lambda: bunchtwissanalysis.getAverage(0)) output.addParameter('mean_xp', lambda: bunchtwissanalysis.getAverage(1)) output.addParameter('mean_y', lambda: bunchtwissanalysis.getAverage(2)) output.addParameter('mean_yp', lambda: bunchtwissanalysis.getAverage(3)) output.addParameter('mean_z', lambda: bunchtwissanalysis.getAverage(4)) output.addParameter('mean_dE', lambda: bunchtwissanalysis.getAverage(5)) output.addParameter('eff_beta_x', lambda: bunchtwissanalysis.getEffectiveBeta(0)) output.addParameter('eff_beta_y', lambda: bunchtwissanalysis.getEffectiveBeta(1)) output.addParameter('eff_epsn_x', lambda: bunchtwissanalysis.getEffectiveEmittance(0)) output.addParameter('eff_epsn_y', lambda: bunchtwissanalysis.getEffectiveEmittance(1)) output.addParameter('eff_alpha_x', lambda: bunchtwissanalysis.getEffectiveAlpha(0)) output.addParameter('eff_alpha_y', lambda: bunchtwissanalysis.getEffectiveAlpha(1))
f = open(pre_list + "/tracking_" + str(test_name) + ".txt", 'w') f2 = open(pre_list + "/z_loss_" + str(test_name) + ".txt", 'w') # create folder to store lost particles using CPU0 if rank == 0: if not os.path.exists(pre_list + "/test_data"): os.mkdir(pre_list + "/test_data") """--------------- tracking for n turns----------------""" for i in range(501): ana.analyzeBunch(b) if rank == 0: f.write( str(i) + " " + str(ana.getEmittanceNormalized(0)) + " " + str(ana.getEmittanceNormalized(1)) + " " + str(ana.getBeta(0)) + " " + str(ana.getBeta(1)) + " " + str(lostbunch.getSize()) + "\n") lattice.trackBunch(b, paramsDict) # record using CPU0 if rank == 0: print("==========================") print("turn: " + str(i)) print("lost: " + str(lostbunch.getSize())) print("remain: " + str(b.getSize())) print("charge: " + str(b.macroSize())) print("intensity: " + str(b.macroSize() * b.getSize() * size)) print( str(ana.getEmittanceNormalized(0)) + " " + str(ana.getEmittanceNormalized(1)))