bunch_orbit_to_pyorbit(paramsDict["length"], kin_Energy,
                           Particle_distribution_file,
                           bunch)  #read in N_mp particles.
    print 'total number of particles in main bunch: ', bunch.getSizeGlobal()
    for i in range(bunch.getSize()):
        bunch.partAttrValue(
            "macrosize", i, 0,
            macrosize)  #main bunch has finite macrosize for space charge
    Lattice.trackBunch(bunch, paramsDict)
    bunchtwissanalysis.analyzeBunch(bunch)  # analyze twiss and emittance
    output.update()
    bunch.dumpBunch("Output/mainbunch_" + str(index_files) + ".dat")
    lostbunch.dumpBunch("Output/lostbunch_" + str(index_files) + ".dat")
    output.save_to_matfile(output_file)
    readScriptPTC("ptc/update-twiss.ptc")
    updateParamsPTC(Lattice, bunch)

bunch.dumpBunch("Output/mainbunch_after_injection.dat")
lostbunch.dumpBunch("Output/lostbunch_after_injection.dat")

#----------------------------------------------------
# Doing some turns after injection
#----------------------------------------------------

for turn in range(turn, turns_max):
    print 'turn number: ', turn
    Lattice.trackBunch(bunch, paramsDict)
    bunchtwissanalysis.analyzeBunch(bunch)  # analyze twiss and emittance
    output.update()
    if turn in turns_print:
        bunch.dumpBunch("Output/mainbunch_%s" % (str(turn).zfill(6)))
示例#2
0
kin_Energy = b.getSyncParticle().kinEnergy()
print kin_Energy, b.charge(), b.mass()

total_macroSize = 1.0e+10

bunch_orbit_to_pyorbit(Lattice.getLength(), kin_Energy, "bunch.dat", b)

nParticlesGlobal = b.getSizeGlobal()
b.macroSize(total_macroSize / nParticlesGlobal)
print nParticlesGlobal, b.macroSize()
"""
Acc_File = "ACCWAVE_40kV_280kV_350ms.DAT"
readAccelTablePTC(Acc_File)
"""

updateParamsPTC(Lattice, b)

synchronousSetPTC(-1)
"""
synchronousAfterPTC(-1)
"""

Turns = 100
for i in range(Turns):
    print i
    trackBunchThroughLatticePTC(Lattice, b, PhaseLength)
"""
trackBunchInRangePTC(Lattice, b, PhaseLength, 0, 500)

trackBunchInRangePTC(Lattice, b, PhaseLength, 501, 932)
# Track
#-----------------------------------------------------------------------
print '\n\t\tStart tracking on MPI process: ', rank
start_time = time.time()
last_time = time.time()

print '\n\t\tstart time = ', start_time

for turn in range(sts['turn']+1, sts['turns_max']):
	if not rank:	last_time = time.time()

	Lattice.trackBunch(bunch, paramsDict)
	bunchtwissanalysis.analyzeBunch(bunch)  # analyze twiss and emittance
	moments = BunchGather(bunch, turn, p)	# Calculate bunch moments and kurtosis
	if s['Update_Twiss']: 
		readScriptPTC_noSTDOUT("PTC/update-twiss.ptc") # this is needed to correclty update the twiss functions in all lattice nodes in updateParamsPTC
		updateParamsPTC(Lattice,bunch) 			# to update bunch energy and twiss functions

	if turn in sts['turns_update']:	sts['turn'] = turn

	output.update()

	if turn in sts['turns_print']:
		saveBunchAsMatfile(bunch, "input/mainbunch")
		saveBunchAsMatfile(bunch, "bunch_output/mainbunch_%s"%(str(turn).zfill(6)))
		saveBunchAsMatfile(lostbunch, "lost/lostbunch_%s"%(str(turn).zfill(6)))
		output.save_to_matfile(output_file)
		if not rank:
			with open(status_file, 'w') as fid:
				pickle.dump(sts, fid)
示例#4
0
print "Read Bunch."
runName = "PTC Test"

setBunchParamsPTC(b)
kin_Energy = b.getSyncParticle().kinEnergy()
print kin_Energy, b.charge(), b.mass()

total_macroSize=1.0e+10

bunch_orbit_to_pyorbit(Lattice.getLength(), kin_Energy, "bunch_ini.dat", b)

nParticlesGlobal = b.getSizeGlobal()
b.macroSize(total_macroSize/nParticlesGlobal)
print nParticlesGlobal, b.macroSize()

updateParamsPTC(Lattice, b)

synchronousSetPTC(-1)

"""
synchronousAfterPTC(-1)
"""

Turns = 1
for i in range(Turns):
    print i
    trackBunchThroughLatticePTC(Lattice, b, PhaseLength)

"""
trackBunchInRangePTC(Lattice, b, PhaseLength, 0, 500)