Пример #1
0
    def __init__(self, name="Monitor no name"):
        """
		Constructor. Creates the aperutre element.
		"""
        NodeTEAPOT.__init__(self, name)
        self.setType("monitor teapot")
        self.twiss = BunchTwissAnalysis()
Пример #2
0
    def __init__(self, file, order, nodispersion, emitnorm):
        self.file_out = file
        self.order = order
        self.bunchtwissanalysis = BunchTwissAnalysis()
        if (nodispersion == False):
            self.dispterm = -1
        else:
            self.dispterm = 1

        if (emitnorm == True):
            self.emitnormterm = 1
        else:
            self.emitnormterm = -1
Пример #3
0
	def __init__(self,frequency = 402.5e+6):
		self.bunch_frequency = frequency
		#set H- mass
		#self.bunch.mass(0.9382723 + 2*0.000511)	
		self.bunch = Bunch()
		self.bunch.getSyncParticle().kinEnergy(0.0025)
		self.init_coords = (0.,0.,0.,0.,0.,0.)
		self.bunch.mass(0.939294)
		self.bunch.charge(-1.0)
		self.c = 2.99792458e+8    # speed of light in m/sec
		self.beam_current = 38.0  # beam current in mA , design = 38 mA
		self.rf_wave_lenght = self.c/self.bunch_frequency
		self.si_e_charge = 1.6021773e-19
		#----------------------------------------
		self.twiss_analysis = BunchTwissAnalysis()
Пример #4
0
 def __init__(self, lattice, start_node=None, stop_node=None):
     #---- change in the corrector field
     self.deltaB = 0.001
     #----------------------------------
     self.lattice = lattice
     self.start_node = start_node
     self.stop_node = stop_node
     self.bpm_node_arr = []
     self.transvBPM_arr = []
     self.dch_node_arr = []
     self.dcv_node_arr = []
     #-------------------------
     self.quad_node_arr = []
     self.quad_transvBPM_arr = []
     #-------------------------
     self._updateBPM_Nodes()
     self._updateDC_Nodes(None, DCorrectorH)
     self._updateDC_Nodes(None, DCorrectorV)
     self._updateQuad_Nodes()
     #-------------------------
     self.twiss_analysis = BunchTwissAnalysis()
Пример #5
0
def bunchCentering(bunch):
    """
	Bunch center after generating can have small deviation from the (0,0,0,0,0,0)
	This function will force centering the bunch.
	"""
    twiss_analysis = BunchTwissAnalysis()
    twiss_analysis.analyzeBunch(bunch)
    #-----------------------------------------------
    # let's center the beam
    (x_avg, y_avg) = (twiss_analysis.getAverage(0),
                      twiss_analysis.getAverage(2))
    (xp_avg, yp_avg) = (twiss_analysis.getAverage(1),
                        twiss_analysis.getAverage(3))
    (z_avg, dE_avg) = (twiss_analysis.getAverage(4),
                       twiss_analysis.getAverage(5))
    for part_id in range(bunch.getSize()):
        bunch.x(part_id, bunch.x(part_id) - x_avg)
        bunch.y(part_id, bunch.y(part_id) - y_avg)
        bunch.xp(part_id, bunch.xp(part_id) - xp_avg)
        bunch.yp(part_id, bunch.yp(part_id) - yp_avg)
        bunch.z(part_id, bunch.z(part_id) - z_avg)
        bunch.dE(part_id, bunch.dE(part_id) - dE_avg)
    #-----------------------------------------------
    return (x_avg, y_avg, dE_avg)
Пример #6
0
if frozen:
        tunes.assignTwiss(*[Twiss_at_parentnode_entrance[k] for k in ['betax','alphax','etax','etapx','betay','alphay','etay','etapy']])
        tunes.assignClosedOrbit(*[Twiss_at_parentnode_entrance[k] for k in ['orbitx','orbitpx','orbity','orbitpy']])
        addTeapotDiagnosticsNodeAsChild(Lattice, parentnode, tunes)

#----------------------------------------------------
# Prepare a bunch object to store particle coordinates
#----------------------------------------------------
bunch_tmp = Bunch()
bunch.copyEmptyBunchTo(bunch_tmp)
bunch_tmp.addPartAttr('ParticlePhaseAttributes')

#----------------------------------------------------
# Define twiss analysis and output dictionary
#----------------------------------------------------
bunchtwissanalysis = BunchTwissAnalysis() #Prepare the analysis class that will look at emittances, etc.
get_dpp = lambda b, bta: np.sqrt(bta.getCorrelation(5,5)) / (b.getSyncParticle().gamma()*b.mass()*b.getSyncParticle().beta()**2)
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 = Output_dictionary()
output.addParameter('turn', lambda: turn)
output.addParameter('intensity', lambda: bunchtwissanalysis.getGlobalMacrosize())
output.addParameter('n_mp', lambda: bunchtwissanalysis.getGlobalCount())
output.addParameter('gamma', lambda: bunch.getSyncParticle().gamma())
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))
Пример #7
0
sc_path_length_min = 0.000001
sizeX = 32  #number of grid points in horizontal direction
sizeY = 32  #number of grid points in vertical direction
sizeZ = 16  #number of longitudinal slices

calc2p5d = SpaceChargeForceCalc2p5D(sizeX, sizeY, sizeZ)
scLatticeModifications.setSC2p5DAccNodes(lattice, sc_path_length_min, calc2p5d)

print "SC nodes appied to the lattice"

#--------------------------------Tracking-----------------------------------------

print("tracking")
x_space0 = [(b.x(i), b.px(i)) for i in range(n_particles)]

bunchtwissanalysis = BunchTwissAnalysis()

bunchtwissanalysis.analyzeBunch(b)
Ex = bunchtwissanalysis.getEmittance(0)
Ey = bunchtwissanalysis.getEmittance(1)
x = bunchtwissanalysis.getCorrelation(0, 0)
y = bunchtwissanalysis.getCorrelation(2, 2)

emitX, emitY, xMean, yMean, turn = [Ex], [Ey], [x], [y], [0]
n_turns = 250
for i in range(n_turns):
    lattice.trackBunch(b, trackDict)
    #	if (i+1)%10==0 or i<9:
    bunchtwissanalysis.analyzeBunch(b)
    Ex = bunchtwissanalysis.getEmittance(0)
    Ey = bunchtwissanalysis.getEmittance(1)
Пример #8
0
distGen = WaterBagDist3D(twissX, twissY, twissZ)
distGen = KVDist3D(twissX, twissY, twissZ)
n_parts = 10000
for i in range(n_parts):
    (x, xp, y, yp, z, dE) = distGen.getCoordinates()
    b.addParticle(x, xp, y, yp, z, dE)

b.compress()
syncPart = b.getSyncParticle()
syncPart.kinEnergy(TK)

# copy the initial bunch to another to track through TEAPOT Quad
b1 = Bunch()
b.copyBunchTo(b1)

twiss_analysis = BunchTwissAnalysis()

twiss_analysis.analyzeBunch(b)
print "============before=================="
print "X Twiss =", twiss_analysis.getTwiss(0)
print "Y Twiss =", twiss_analysis.getTwiss(1)
print "Z Twiss =", twiss_analysis.getTwiss(2)
#b.dumpBunch()

G = 30.0  # [T/m]
length = 0.1  # [m]
fieldSource = FieldSource(G)
tracker = RungeKuttaTracker(length)
print "Tracker Entrance plane (a,b,c,d)=", tracker.entrancePlane()
print "Tracker Exit     plane (a,b,c,d)=", tracker.exitPlane()
# the spatial eps is useless because we have quad field = 0 on axis for the syncPart
Пример #9
0
sy = np.sqrt(betay * emitlimy)
spy = np.sqrt(gy * emitlimy)

for i in range(50):
    for j in range(100):
        b.addParticle(10 * sx * float(j) / 100 * cos(float(i) / 50 * pi / 2),
                      0,
                      10 * sx * float(j) / 100 * sin(float(i) / 50 * pi / 2),
                      0, 0, 0.000013229)  #0.000013229

        b.partAttrValue("ParticleIdNumber",
                        b.getSize() - 1, 0,
                        b.getSize() - 1)
"""--------------------------------- end ---------------------------------"""

paramsDict = {}
lostbunch = Bunch()
paramsDict["lostbunch"] = lostbunch
paramsDict["bunch"] = b

b.dumpBunch("./6D_initial_bunch_1p.dat")

ana = BunchTwissAnalysis()

for i in range(5000):
    print("turn: " + str(i))
    print("remaining: " + str(b.getSize()) + "\n")
    lattice.trackBunch(b, paramsDict)

b.dumpBunch("./6D_final_bunch_1p.dat")
Пример #10
0
 def __init__(self, file):
     self.file_out = file
     self.bunchtwissanalysis = BunchTwissAnalysis()
Пример #11
0
 def __init__(self, filename):
     self.file_out = open(filename, "a")
     self.bunchtwissanalysis = BunchTwissAnalysis()
Пример #12
0
 def __init__(self):
     self.bunchtwissanalysis = BunchTwissAnalysis()
     self.xAvg = 0.0
     self.yAvg = 0.0
     self.xpAvg = 0.0
     self.ypAvg = 0.0
Пример #13
0
def TrackingBunch(accLattice, bunch, print_info=False):

    #set up design
    accLattice.trackDesignBunch(bunch)

    #track through the lattice
    paramsDict = {"old_pos": -1., "count": 0, "pos_step": 0.01}
    actionContainer = AccActionsContainer("Bunch Tracking")

    pos_start = 0.

    twiss_analysis = BunchTwissAnalysis()

    results_arr = []

    def action_entrance(paramsDict):
        node = paramsDict["node"]
        bunch = paramsDict["bunch"]
        pos = paramsDict["path_length"]
        if (paramsDict["old_pos"] == pos): return
        if (paramsDict["old_pos"] + paramsDict["pos_step"] > pos): return
        paramsDict["old_pos"] = pos
        paramsDict["count"] += 1
        gamma = bunch.getSyncParticle().gamma()
        beta = bunch.getSyncParticle().beta()
        twiss_analysis.analyzeBunch(bunch)
        x_rms = math.sqrt(
            twiss_analysis.getTwiss(0)[1] *
            twiss_analysis.getTwiss(0)[3]) * 1000.
        y_rms = math.sqrt(
            twiss_analysis.getTwiss(1)[1] *
            twiss_analysis.getTwiss(1)[3]) * 1000.
        z_rms = math.sqrt(
            twiss_analysis.getTwiss(2)[1] *
            twiss_analysis.getTwiss(2)[3]) * 1000.
        z_to_phase_coeff = bunch_gen.getZtoPhaseCoeff(bunch)
        z_rms_deg = z_to_phase_coeff * z_rms / 1000.0
        nParts = bunch.getSizeGlobal()
        (alphaX, betaX, emittX) = (twiss_analysis.getTwiss(0)[0],
                                   twiss_analysis.getTwiss(0)[1],
                                   twiss_analysis.getTwiss(0)[3] * 1.0e+6)
        (alphaY, betaY, emittY) = (twiss_analysis.getTwiss(1)[0],
                                   twiss_analysis.getTwiss(1)[1],
                                   twiss_analysis.getTwiss(1)[3] * 1.0e+6)
        (alphaZ, betaZ, emittZ) = (twiss_analysis.getTwiss(2)[0],
                                   twiss_analysis.getTwiss(2)[1],
                                   twiss_analysis.getTwiss(2)[3] * 1.0e+6)
        norm_emittX = emittX * gamma * beta
        norm_emittY = emittY * gamma * beta
        #---- phi_de_emittZ will be in [pi*deg*MeV]
        phi_de_emittZ = z_to_phase_coeff * emittZ
        eKin = bunch.getSyncParticle().kinEnergy() * 1.0e+3
        s_prt = " %5d  %35s  %4.5f " % (paramsDict["count"], node.getName(),
                                        pos + pos_start)
        s_prt += "  %5.3f  %5.3f   %5.3f " % (x_rms, y_rms, z_rms_deg)
        s_prt += "  %10.6f   %8d " % (eKin, nParts)
        if (print_info): print s_prt
        twiss_arr = [(alphaX, betaX, emittX, norm_emittX),
                     (alphaY, betaY, emittY, norm_emittY),
                     (alphaZ, betaZ, emittZ, phi_de_emittZ)]
        rms_arr = [x_rms, y_rms, z_rms_deg]
        results_arr.append(
            [node.getName(), pos, rms_arr, twiss_arr, eKin, nParts])

    def action_exit(paramsDict):
        action_entrance(paramsDict)

    actionContainer.addAction(action_entrance, AccActionsContainer.ENTRANCE)
    actionContainer.addAction(action_exit, AccActionsContainer.EXIT)

    accLattice.trackBunch(bunch,
                          paramsDict=paramsDict,
                          actionContainer=actionContainer)

    return results_arr