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
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)) output.addParameter('gamma', lambda: bunch.getSyncParticle().gamma())
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]: Jx = n_factor**2 * curr_emitx / 2