if(node_pos_start > pos_start and node_pos_stop < pos_stop):
		print "node=",node.getName()," type=",node.getType(),"  pos=",node_pos_start," L=",node.getLength()


#------------------------------
#Main Bunch init
#------------------------------
b = Bunch()
print "Read Bunch."
runName = "Benchmark_Collimator"

b.mass(0.93827231)
b.macroSize(1.0e+1)
energy = 1.0 #Gev
# get initial bunch from ORBIT_MPI input
bunch_orbit_to_pyorbit(teapot_latt.getLength(), energy, "Bm_KV_Uniform_10000",b)
#b.readBunch("parts_in.dat")

b.getSyncParticle().kinEnergy(energy)

#=====track bunch through Collimator Node============
paramsDict = {}
lostbunch = Bunch()
paramsDict["lostbunch"]=lostbunch
paramsDict["bunch"]= b

#collimator.trackBunch(b,paramsDict)
collimator.track(paramsDict)

# dump ORBIT_MPI bunch to compare results
bunch_pyorbit_to_orbit(teapot_latt.getLength(), b, "mainbunch.dat")
Esempio n. 2
0
p['harmonic_number'] = Lattice.nHarm 
p['phi_s']           = 0
p['gamma']           = bunch.getSyncParticle().gamma()
p['beta']            = bunch.getSyncParticle().beta()
p['energy']          = 1e9 * bunch.mass() * bunch.getSyncParticle().gamma()
p['bunch_length'] = p['blength_rms']/speed_of_light/bunch.getSyncParticle().beta()*4
kin_Energy = bunch.getSyncParticle().kinEnergy()
print 'Energy of particle = ', p['energy']
print 'Kinetic Energy of particle = ', kin_Energy

if horizontal:
        Particle_distribution_file = generate_initial_5mm_distributionH(s['InitialParticleTransversePosition'], p, Lattice, output_file='input/ParticleDistribution.in', summary_file='input/ParticleDistribution_summary.txt')
else:
        Particle_distribution_file = generate_initial_5mm_distributionV(s['InitialParticleTransversePosition'], p, Lattice, output_file='input/ParticleDistribution.in', summary_file='input/ParticleDistribution_summary.txt')

bunch_orbit_to_pyorbit(paramsDict["length"], kin_Energy, Particle_distribution_file, bunch, p['n_macroparticles'] + 1) #read in only first N_mp particles.
bunch.addPartAttr("macrosize")
map(lambda i: bunch.partAttrValue("macrosize", i, 0, p['macrosize']), range(bunch.getSize()))
ParticleIdNumber().addParticleIdNumbers(bunch) # Give them unique number IDs
bunch.dumpBunch("input/mainbunch_start.dat")
saveBunchAsMatfile(bunch, "output/mainbunch_-000001")

lostbunch = Bunch()
bunch.copyEmptyBunchTo(lostbunch)
lostbunch.addPartAttr('ParticlePhaseAttributes')
lostbunch.addPartAttr("LostParticleAttributes")
paramsDict["lostbunch"]=lostbunch
paramsDict["bunch"]= bunch

#----------------------------------------------------
# Add space charge nodes - FROZEN
    output.import_from_matfile(output_file)

#----------------------------------------------------
# Injecting turn by turn
#----------------------------------------------------
print '\n\n now start injecting...'

for index_files in range(index_files, index_files_max + 1):
    # n_rows = 0
    Particle_distribution_file = 'Input/Distribution_at_injection_full/OrbitL' + str(
        index_files) + '.dat'  # final distribution with the correct angle
    N_mp = file_len(Particle_distribution_file)
    print 'Injection file: ', Particle_distribution_file, '-- number of particles: ', N_mp
    kin_Energy = bunch.getSyncParticle().kinEnergy()
    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)
Esempio n. 4
0
#------------------------------
# Bunch initialization
#------------------------------

b = Bunch()
print "Read Bunch."
runName = "Benchmark_Collimator"

total_macroSize=1.0e+16
b.mass(consts.mass_proton)

ERef = 1.0 # Gev
print "Reference energy is 1.0 (GeV). \nPlease input desired energy:"
energy = float(raw_input())
print "energy is:", energy
bunch_orbit_to_pyorbit(lattice.getLength(), energy, "Bm_KV_Uniform_10000",b)
b.getSyncParticle().kinEnergy(energy)
nParticlesGlobal = b.getSizeGlobal()
b.macroSize(total_macroSize/nParticlesGlobal)

ERef = 1.0
GammaRef = 1.0 + ERef / b.mass()
BetaRef = math.sqrt(1.0 - 1.0 / (GammaRef * GammaRef))
FreqRef = (consts.speed_of_light * BetaRef) / lattice_length
print "BetaRef =", BetaRef
print "FreqRef =", FreqRef

Gamma = 1.0 + b.getSyncParticle().kinEnergy(energy) / b.mass()
Beta = math.sqrt(1.0 - 1.0 / (Gamma * Gamma))
Freq = (consts.speed_of_light * Beta) / lattice_length
print "Beta =", Beta
Esempio n. 5
0
lattice.readMAD("../LATTICES/Q_0p125.LAT", "FODO")

print "lattice length=", lattice.getLength()

#------------------------------
#Bunch init
#------------------------------
b = Bunch()
print "Read Bunch."
runName = "KV_Ellipse_5e12_1"
energy = 1.0  #Gev
b.mass(0.93827231)
b.macroSize(5.0e+7)

# get initial bunch from ORBIT_MPI input
bunch_orbit_to_pyorbit(lattice.getLength(), energy,
                       "../DISTRIBUTIONS/Bm_KV_Ellipse", b)

#make 2.5D space charge calculator
sizeX = 128
sizeY = 128
sizeZ = 32
xy_ratio = 10.0
calc2p5d = SpaceChargeCalc2p5D(sizeX, sizeY, sizeZ, xy_ratio)

# boundary
nBoundaryPoints = 128
N_FreeSpaceModes = 32
boundary_radius = 0.11
boundary = Boundary2D(nBoundaryPoints, N_FreeSpaceModes, "Circle",
                      2 * boundary_radius)
Esempio n. 6
0
#------------------------------
# Bunch initialization
#------------------------------

b = Bunch()
print "Read Bunch."
runName = "Benchmark_Collimator"

total_macroSize = 1.0e+10
b.mass(consts.mass_proton)

ERef = 1.0  #Gev
print "Reference energy is 1.0 (GeV). \nPlease input desired energy:"
energy = float(raw_input())
print "energy is:", energy
bunch_orbit_to_pyorbit(lattice.getLength(), energy, "Bm_KV_Uniform_10000", b)
b.getSyncParticle().kinEnergy(energy)
nParticlesGlobal = b.getSizeGlobal()
b.macroSize(total_macroSize / nParticlesGlobal)

ERef = 1.0
GammaRef = 1.0 + ERef / b.mass()
BetaRef = math.sqrt(1.0 - 1.0 / (GammaRef * GammaRef))
FreqRef = (consts.speed_of_light * BetaRef) / lattice_length
print "BetaRef =", BetaRef
print "FreqRef =", FreqRef

Gamma = 1.0 + b.getSyncParticle().kinEnergy(energy) / b.mass()
Beta = math.sqrt(1.0 - 1.0 / (Gamma * Gamma))
Freq = (consts.speed_of_light * Beta) / lattice_length
print "Beta =", Beta
Esempio n. 7
0
r_bunch = 0.05
l_bunch = lattice.getLength()
x_offset = 0.00
y_offset = 0.00
count = 0
while(count < nMaxMacroParticles):
	x = r_bunch*2.0*(0.5-random.random())
	y = r_bunch*2.0*(0.5-random.random())
	z = l_bunch*2.0*(0.5-random.random())
	if(x**2+y**2 < r_bunch**2):
		b.addParticle(x+x_offset,0.,y+y_offset,0.,z,0.)
		count += 1
"""

# read ORBIT bunch
bunch_orbit_to_pyorbit(lattice.getLength(), energy,
                       "./bunch_distribution/Bm_KV_Uniform", b)
print "debug bunch is ready."

#make 2.5D space charge calculator
sizeX = 256
sizeY = sizeX
sizeZ = 1
xy_ratio = 1.0
calc2p5d = SpaceChargeCalc2p5D(sizeX, sizeY, sizeZ, xy_ratio)

# boundary
nBoundaryPoints = 32
N_FreeSpaceModes = 10
boundary_radius = 0.11
boundary = Boundary2D(nBoundaryPoints, N_FreeSpaceModes, "Circle",
                      2.0 * boundary_radius)
Esempio n. 8
0
# print all nodes around the specified position
for node in teapot_latt.getNodes():
    print "node=", node.getName(), " type=", node.getType(
    ), " L=", node.getLength()

#------------------------------
#Main Bunch init
#------------------------------

b = Bunch()
print "Read Bunch."
runName = "Benchmark_Diagnostics"
b.mass(0.93827231)
b.macroSize(1.0e+1)
energy = 1.0  #Gev
bunch_orbit_to_pyorbit(teapot_latt.getLength(), energy, "Bm_KV_Uniform_1000",
                       b)
b.getSyncParticle().kinEnergy(energy)
paramsDict = {}
lostbunch = Bunch()
paramsDict["lostbunch"] = lostbunch
paramsDict["bunch"] = b
lostbunch.addPartAttr("LostParticleAttributes")

#=====track bunch ============

print "Tracking..."
for turn in range(1):
    teapot_latt.trackBunch(b, paramsDict)
b.dumpBunch("bunch_final.dat")
lostbunch.dumpBunch("lostbunch_final.dat")
Esempio n. 9
0
"""
for node in Lattice.getNodes():
    print node.getType(), node.getLength(), node.getParam("node_index"), node.getParam("betax"), node.getParam("betay"), node.getParam("alphax"), node.getParam("alphay"), node.getParam("etax"), node.getParam("etapx")
"""

b = Bunch()
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.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)
"""
Esempio n. 10
0
rank = orbit_mpi.MPI_Comm_rank(comm)
size = orbit_mpi.MPI_Comm_size(comm)

b = Bunch()

#
ORBIT_file_name = "Bm_Parts_1_0"
ORBIT_NEW_file_name = "new_orbit_file.dat"
pyORBIT_DUMP_file_name = "pyorbit_bunch_dump_test.dat"

kineticEnergy = 1.0
ringLength = 248.0

time_start = time.clock()

bunch_orbit_to_pyorbit(ringLength, kineticEnergy, ORBIT_file_name, b)
print "rank=", rank, " n_parts=", b.getSize()
bunch_pyorbit_to_orbit(ringLength, b, ORBIT_NEW_file_name)
time_exec = time.clock() - time_start
if (rank == 0): print "time[sec]=", time_exec

b.dumpBunch(pyORBIT_DUMP_file_name)

x_sum = 0.
xp_sum = 0.
y_sum = 0.
yp_sum = 0.
phi_sum = 0.
dE_sum = 0.

for i in range(b.getSize()):
Esempio n. 11
0
l_bunch = lattice.getLength()
x_offset = 0.04
y_offset = 0.00
count = 0
while(count < nMaxMacroParticles):
	x = r_bunch*2.0*(0.5-random.random())
	y = r_bunch*2.0*(0.5-random.random())
	z = l_bunch*2.0*(0.5-random.random())
	if(x**2+y**2 < r_bunch**2):
		b.addParticle(x+x_offset,0.,y+y_offset,0.,z,0.)
		count += 1
"""

# read ORBIT bunch
#bunch_orbit_to_pyorbit(lattice.getLength(),energy, "./DISTRIBUTIONS/Bm_KV_offset_40mm_Uniform",b)
bunch_orbit_to_pyorbit(lattice.getLength(),energy, "./DISTRIBUTIONS/Bm_KV_Uniform",b)
#bunch_orbit_to_pyorbit(lattice.getLength(),energy, "./DISTRIBUTIONS/Bm_50mm_Uniform",b)
#bunch_orbit_to_pyorbit(lattice.getLength(),energy, "./DISTRIBUTIONS/Bm_50mm_offset_40mm_Uniform",b)
bunch_pyorbit_to_orbit(lattice.getLength(), b, "pyorbit_initial.dat")
#make 2.5D space charge calculator
sizeX = 256
sizeY = sizeX
sizeZ = 1
xy_ratio = 1.0
calc2p5d = SpaceChargeCalc2p5D(sizeX,sizeY,sizeZ,xy_ratio)

# boundary 
nBoundaryPoints = 32
N_FreeSpaceModes = 10
boundary_radius = 0.11
boundary = Boundary2D(nBoundaryPoints,N_FreeSpaceModes,"Circle",2.0*boundary_radius)
Esempio n. 12
0
"""
for node in Lattice.getNodes():
    print node.getType(), node.getLength(), node.getParam("node_index"), node.getParam("betax"), node.getParam("betay"), node.getParam("alphax"), node.getParam("alphay"), node.getParam("etax"), node.getParam("etapx")
"""

b = Bunch()
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):
Esempio n. 13
0
l_bunch = lattice.getLength()
x_offset = 0.04
y_offset = 0.00
count = 0
while(count < nMaxMacroParticles):
	x = r_bunch*2.0*(0.5-random.random())
	y = r_bunch*2.0*(0.5-random.random())
	z = l_bunch*2.0*(0.5-random.random())
	if(x**2+y**2 < r_bunch**2):
		b.addParticle(x+x_offset,0.,y+y_offset,0.,z,0.)
		count += 1
"""

# read ORBIT bunch
#bunch_orbit_to_pyorbit(lattice.getLength(),energy, "./DISTRIBUTIONS/Bm_KV_offset_40mm_Uniform",b)
bunch_orbit_to_pyorbit(lattice.getLength(), energy,
                       "./DISTRIBUTIONS/Bm_KV_Uniform", b)
#bunch_orbit_to_pyorbit(lattice.getLength(),energy, "./DISTRIBUTIONS/Bm_50mm_Uniform",b)
#bunch_orbit_to_pyorbit(lattice.getLength(),energy, "./DISTRIBUTIONS/Bm_50mm_offset_40mm_Uniform",b)
bunch_pyorbit_to_orbit(lattice.getLength(), b, "pyorbit_initial.dat")
#make 2.5D space charge calculator
sizeX = 256
sizeY = sizeX
sizeZ = 1
xy_ratio = 1.0
calc2p5d = SpaceChargeCalc2p5D(sizeX, sizeY, sizeZ, xy_ratio)

# boundary
nBoundaryPoints = 32
N_FreeSpaceModes = 10
boundary_radius = 0.11
boundary = Boundary2D(nBoundaryPoints, N_FreeSpaceModes, "Circle",
rank = orbit_mpi.MPI_Comm_rank(comm)
size = orbit_mpi.MPI_Comm_size(comm)	

b = Bunch()

#
ORBIT_file_name = "Bm_Parts_1_0"
ORBIT_NEW_file_name = "new_orbit_file.dat"
pyORBIT_DUMP_file_name = "pyorbit_bunch_dump_test.dat"

kineticEnergy = 1.0
ringLength = 248.0

time_start = time.clock()

bunch_orbit_to_pyorbit(ringLength, kineticEnergy, ORBIT_file_name,b)
print "rank=",rank," n_parts=",b.getSize()
bunch_pyorbit_to_orbit(ringLength, b, ORBIT_NEW_file_name)
time_exec = time.clock() - time_start
if(rank == 0): print "time[sec]=",time_exec

b.dumpBunch(pyORBIT_DUMP_file_name)

x_sum = 0.
xp_sum = 0.
y_sum = 0.
yp_sum = 0.
phi_sum = 0.
dE_sum = 0.	

for i in range(b.getSize()):
Esempio n. 15
0
lattice.readMAD("../LATTICES/Q_0p125.LAT","FODO")

print "lattice length=",lattice.getLength()

#------------------------------
#Bunch init
#------------------------------
b = Bunch()
print "Read Bunch."
runName = "KV_Ellipse_5e12_1"
energy = 1.0 #Gev
b.mass(0.93827231)
b.macroSize(5.0e+7)

# get initial bunch from ORBIT_MPI input
bunch_orbit_to_pyorbit(lattice.getLength(), energy, "../DISTRIBUTIONS/Bm_KV_Ellipse",b)

#make 2.5D space charge calculator
sizeX = 128
sizeY = 128
sizeZ = 32
xy_ratio = 10.0
calc2p5d = SpaceChargeCalc2p5D(sizeX,sizeY,sizeZ,xy_ratio)

# boundary 
nBoundaryPoints = 128
N_FreeSpaceModes = 32
boundary_radius = 0.11
boundary = Boundary2D(nBoundaryPoints,N_FreeSpaceModes,"Circle",2*boundary_radius)

#=====track bunch through SC Node============