def __init__(self, phaseLength, nMacrosMin, nBins,\ useX, useY,\ bunch, impeDict,\ qX, alphaX, betaX, qY, alphaY, betaY,\ name = "betfreq. dep. TImpedance node"): """ Constructor. Creates the BetFreqDep_TImpedance-teapot element. """ DriftTEAPOT.__init__(self, name) self.timpedance = TImpedance(phaseLength, nMacrosMin, nBins,\ useX, useY) self.setType("betafreq. dep. timpedance node") self.setLength(0.0) self.phaseLength = phaseLength self.nBins = nBins self.useX = useX self.useY = useY self.localDict = impeDict self.bet_tuple = self.localDict["betas"] self.bet_range = (len(self.bet_tuple) - 1) self.freq_tuple = self.localDict["freqs"] self.freq_range = (len(self.freq_tuple) - 1) self.c = consts.speed_of_light BetaRel = bunch.getSyncParticle().beta() Freq0 = (BetaRel * self.c) / self.phaseLength self.assignLatFuncs(qX, alphaX, betaX, qY, alphaY, betaY) self.calcImpedance(BetaRel, Freq0, self.qX, self.qY)
def __init__(self, phaseLength, nMacrosMin, nBins,\ bunch, impeDict,\ name = "freq. dep. LImpedance node"): """ Constructor. Creates the FreqDep_LImpedance-teapot element. """ DriftTEAPOT.__init__(self, name) self.limpedance = LImpedance(phaseLength, nMacrosMin, nBins) self.setType("freq. dep. limpedance node") self.setLength(0.0) self.phaseLength = phaseLength self.nBins = nBins self.localDict = impeDict self.freq_tuple = self.localDict["freqs"] self.freq_range = (len(self.freq_tuple) - 1) self.z_tuple = self.localDict["z_imp"] self.c = consts.speed_of_light BetaRel = bunch.getSyncParticle().beta() Freq0 = (BetaRel * self.c) / self.phaseLength Z = [] for n in range(self.nBins / 2 - 1): freq_mode = Freq0 * (n + 1) z_mode = interp(freq_mode, self.freq_range,\ self.freq_tuple, self.z_tuple) Z.append(z_mode) self.limpedance.assignImpedance(Z)
def __init__(self, length, ma, density_fac, shape, a, b, c, d, angle, pos = 0, name = "collimator no name"): """ Constructor. Creates the Collimator TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.collimator = Collimator(length,ma,density_fac,shape,a,b,c,d,angle,pos) self.setType("collimator teapot") self.setLength(length)
def __init__(self, length, name = "base_rfnode"): """ Constructor. Creates Base RF Cavity TEAPOT element. It will never be called. """ DriftTEAPOT.__init__(self, name) self.setType("base rf node") self.setLength(0.0)
def __init__(self, bunch, xbump, xpbump, ybump, ypbump, name = "bump"): """ Constructor. Creates the Bumpe TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.simplebump = simpleBump(bunch, xbump, xpbump, ybump, ypbump); self.setType("Bump") self.setLength(0.0)
def __init__(self, phaseLength, nMacrosMin, nBins,\ name = "LImpedance node"): """ Constructor. Creates LImpedance element. """ DriftTEAPOT.__init__(self, name) self.limpedance = LImpedance(phaseLength, nMacrosMin, nBins) self.setType("limpedance node") self.setLength(0.0)
def __init__(self, k,\ name = "Quad Kicker"): """ Constructor. Creates QuadKicker element. """ DriftTEAPOT.__init__(self, name) self.setType("quadrupole kicker node") self.setLength(0.0) self.k = k
def __init__(self, disp,\ name = "BendYF Displacement"): """ Constructor. Creates BendDisplacementYF element. """ DriftTEAPOT.__init__(self, name) self.setType("yf bend displacement node") self.setLength(0.0) self.disp = disp
def __init__(self, angle,\ name = "XY Rotation"): """ Constructor. Creates StraightRotationXY element. """ DriftTEAPOT.__init__(self, name) self.setType("xy rotation node") self.setLength(0.0) self.angle = angle
def __init__(self, drho,\ name = "BendF Field"): """ Constructor. Creates BendFieldF element. """ DriftTEAPOT.__init__(self, name) self.setType("bendf field node") self.setLength(0.0) self.drho = drho
def __init__(self, ds,\ name = "Longitudinal Displacement"): """ Constructor. Creates LongDisplacement element. """ DriftTEAPOT.__init__(self, name) self.setType("longitudinal displacement node") self.setLength(0.0) self.ds = ds
def __init__(self, a, b, pos = 0, c = 0, d = 0, name = "aperture"): DriftTEAPOT.__init__(self,name) self.shape = 3 self.a = a self.b = b self.c = c self.d = d self.pos = pos self.Aperture = Aperture(self.shape, self.a, self.b, self.c, self.d, self.pos)
def __init__(self, name = "BPMSignal no name"): """ Constructor. Creates the StatLats TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.bpm = BPMSignal() self.setType("BPMSignal") self.lattlength = 0.0 self.setLength(0.0) self.position = 0.0
def __init__(self, name = "tuneanalysis no name"): """ Constructor. Creates the StatLats TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.bunchtune = BunchTuneAnalysis() self.setType("tune calculator teapot") self.lattlength = 0.0 self.setLength(0.0) self.position = 0.0
def __init__(self, theta, disp,\ name = "BendLI Displacement"): """ Constructor. Creates BendDisplacementLI element. """ DriftTEAPOT.__init__(self, name) self.setType("li bend displacement node") self.setLength(0.0) self.theta = theta self.disp = disp
def __init__(self, bx, by, ax, ay, ex, epx, l, zi, zf, ds, niters, resid, xrefi, yrefi, eulerai, eulerbi, eulergi, b, filename): """ Constructor. Creates the FieldTracker TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.fieldtracker = FieldTracker(order, bx, by, ax, ay, ex, epx, l, zi, zf, ds, niters, resid, xrefi, yrefi, eulerai, eulerbi, eulergi, apflag, b) self.setType("fieldtracker teapot") self.setLength(l)
def __init__(self, dxp, dyp,\ name = "Dipole Kicker"): """ Constructor. Creates DipoleKicker element. """ DriftTEAPOT.__init__(self, name) self.setType("dipole kicker node") self.setLength(0.0) self.dxp = dxp self.dyp = dyp
def __init__(self, xmin, xmax, ymin, ymax, thick, name = "foil no name"): """ Constructor. Creates the Foil TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.foil = Foil(xmin, xmax, ymin, ymax, thick) self.setType("foil teapot") self.setLength(0.0) # The user choice of scattering routine. Defualt (0) is full scatter self.scatterChoice = 0
def __init__(self, angle, lengthelt,\ name = "YSF Rotation"): """ Constructor. Creates StraightRotationYSF element. """ DriftTEAPOT.__init__(self, name) self.setType("ysf rotation node") self.setLength(0.0) self.angle = angle self.lengthelt = lengthelt
def __init__(self, filename , name = "statlats no name"): """ Constructor. Creates the StatLats TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.statlats = StatLats(filename) self.setType("statlats teapot") self.setLength(0.0) self.position = 0.0 self.lattlength = 0.0 self.file_out = open(filename,"w")
def __init__(self, filename, order, nodispersion = True, emitnorm = False, name = "moments no name"): """ Constructor. Creates the StatLats TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.moments = Moments(filename, order, nodispersion, emitnorm) self.setType("moments teapot") self.setLength(0.0) self.position = 0.0 self.lattlength = 0.0 self.file_out = open(filename,"w")
def __init__(self, k, phaselength, phase,\ name = "Quad Kicker Osc"): """ Constructor. Creates QuadKickerOsc element. """ DriftTEAPOT.__init__(self, name) self.setType("oscillating quadrupole kicker node") self.setLength(0.0) self.k = k self.phaselength = phaselength self.phase = phase
def __init__(self, phaseLength, nMacrosMin, nBins,\ useX, useY,\ name = "TImpedance node"): """ Constructor. Creates TImpedance element. """ DriftTEAPOT.__init__(self, name) self.timpedance = TImpedance(phaseLength, nMacrosMin, nBins,\ useX, useY) self.setType("timpedance node") self.setLength(0.0) self.nBins = nBins
def __init__(self, file, name = "statlats no name"): """ Constructor. Creates the StatLats TEAPOT element. """ DriftTEAPOT.__init__(self,name) self.statlats = StatLatsSetMember(file) self.setType("statlats teapot") self.setLength(0.0) self.position = 0.0 self.lattlength = 0.0 self.active = True self.file = file
def __init__(self, file, order, nodispersion = True, emitnorm = False, name = "moments no name"): """ Constructor. Creates the Moments TEAPOT element. """ DriftTEAPOT.__init__(self,str(name)) self.file = file self.moments = MomentsSetMember(self.file, order, nodispersion, emitnorm) self.setType("moments teapot") self.setLength(0.0) self.position = 0.0 self.lattlength = 0.0 self.active = True
def __init__(self, angle, rhoi, theta, lengthelt, et, rotype,\ name = "RotationF General"): """ Constructor. Creates RotationF element. """ DriftTEAPOT.__init__(self, name) self.setType("generalf rotation node") self.setLength(0.0) self.angle = angle self.rhoi = rhoi self.theta = theta self.lengthelt = lengthelt self.et = et self.rotype = rotype
def __init__(self, dx, dxp, dy, dyp, dz, dE,\ name = "Coordinate Displacement"): """ Constructor. Creates CoordDisplacement element. """ DriftTEAPOT.__init__(self, name) self.setType("coordinate displacement node") self.setLength(0.0) self.dx = dx self.dxp = dxp self.dy = dy self.dyp = dyp self.dz = dz self.dE = dE
def addTeapotDiagnosticsNode(lattice, position, diagnostics_node): """ It will put one Teapot diagnostics node in the lattice """ length_tollerance = 0.0001 lattice.initialize() position_start = position position_stop = position + diagnostics_node.getLength() diagnostics_node.setPosition(position) diagnostics_node.setLatticeLength(lattice.getLength()) (node_start_ind, node_stop_ind, z, ind) = (-1, -1, 0., 0) for node in lattice.getNodes(): if (position_start >= z and position_start <= z + node.getLength()): node_start_ind = ind if (position_stop >= z and position_stop <= z + node.getLength()): node_stop_ind = ind ind += 1 z += node.getLength() #-------now we check that between start and end we have only non-modified drift elements #-------if the space charge was added first - that is a problem. The collimation should be added first. for node in lattice.getNodes()[node_start_ind:node_stop_ind + 1]: #print "debug node=",node.getName()," type=",node.getType()," L=",node.getLength() if (not isinstance(node, DriftTEAPOT)): print "Non-drift node=", node.getName(), " type=", node.getType( ), " L=", node.getLength() orbitFinalize( "We have non-drift element at the place of the diagnostics! Stop!" ) # make array of nodes from diagnostics in the center and possible two drifts if their length is more than length_tollerance [m] nodes_new_arr = [ diagnostics_node, ] drift_node_start = lattice.getNodes()[node_start_ind] drift_node_stop = lattice.getNodes()[node_stop_ind] #------now we will create two drift nodes: before the diagnostics and after #------if the length of one of these additional drifts less than length_tollerance [m] we skip this drift if (position_start > lattice.getNodePositionsDict()[drift_node_start][0] + length_tollerance): drift_node_start_new = DriftTEAPOT(drift_node_start.getName()) drift_node_start_new.setLength( position_start - lattice.getNodePositionsDict()[drift_node_start][0]) nodes_new_arr.insert(0, drift_node_start_new) if (position_stop < lattice.getNodePositionsDict()[drift_node_stop][1] - length_tollerance): drift_node_stop_new = DriftTEAPOT(drift_node_stop.getName()) drift_node_stop_new.setLength( lattice.getNodePositionsDict()[drift_node_stop][1] - position_stop) nodes_new_arr.append(drift_node_stop_new) #------ now we will modify the lattice by replacing the found part with the new nodes lattice.getNodes()[node_start_ind:node_stop_ind + 1] = nodes_new_arr # initialize the lattice lattice.initialize()
def __init__(self, nparts, bunch, lostbunch, foilparams, xDistFunc, yDistFunc, lDistFun, nmaxmacroparticles=-1, name="injection"): """ Constructor. Creates the Injection TEAPOT element. """ DriftTEAPOT.__init__(self, name) self.injectparts = InjectParts(nparts, bunch, lostbunch, foilparams, xDistFunc, yDistFunc, lDistFun, nmaxmacroparticles) self.setType("Injection") self.setLength(0.0)
def __init__(self, file, order, nodispersion=True, emitnorm=False, name="moments no name"): """ Constructor. Creates the Moments TEAPOT element. """ DriftTEAPOT.__init__(self, str(name)) self.file = file self.moments = MomentsSetMember(self.file, order, nodispersion, emitnorm) self.setType("moments teapot") self.setLength(0.0) self.position = 0.0 self.lattlength = 0.0 self.active = True
def addTeapotApertureNode(lattice, position, Aperture_node): """ It will put one Teapot Aperture node in the lattice """ length_tolerance = 0.0001 lattice.initialize() if(position > lattice.getLength() ): position = lattice.getLength(); print "User-specified aperture position is larger than lattice length. Resetting it to lattice length." Aperture_node.setPosition(position); position_start = position position_stop = position + Aperture_node.getLength() (node_start_ind,node_stop_ind,z,ind) = (-1,-1, 0., 0) for node in lattice.getNodes(): if(position_start >= z and position_start <= z + node.getLength()): node_start_ind = ind if(position_stop >= z and position_stop <= z + node.getLength()): node_stop_ind = ind ind += 1 z += node.getLength() #-------now we check that between start and end we have only non-modified drift elements #-------if the space charge was added first - that is a problem. The collimation should be added first. for node in lattice.getNodes()[node_start_ind:node_stop_ind+1]: #print "debug node=",node.getName()," type=",node.getType()," L=",node.getLength() if(not isinstance(node,DriftTEAPOT)): if(isinstance(node,LinacDrift)): print "You are trying to work with linac lattice! This method is working only with TEAPOT lattice!" print "Node=",node.getName()," type=",node.getType()," L=",node.getLength() orbitFinalize("addTeapotCollimatorNode function is used on Linac lattice! Stop!") print "Non-drift node=",node.getName()," type=",node.getType()," L=",node.getLength() orbitFinalize("We have non-drift element at the place of the Aperture node! Stop!") #if(node.getNumberOfChildren() != 4): #print "Node=",node.getName()," type=",node.getType()," L=",node.getLength()," N children nodes=",node.getNumberOfChildren() #orbitFinalize("Drift element was modified with additional functionality (SC or something else)! Add collimation first! Stop!") # make array of nodes from Aperture node in the center and possible two drifts if their length is more than length_tollerance [m] nodes_new_arr = [Aperture_node,] drift_node_start = lattice.getNodes()[node_start_ind] drift_node_stop = lattice.getNodes()[node_stop_ind] #------now we will create two drift nodes: before the Aperture node and after #------if the length of one of these additional drifts less than length_tollerance [m] we skip this drift if(position_start > lattice.getNodePositionsDict()[drift_node_start][0] + length_tolerance): drift_node_start_new = DriftTEAPOT(drift_node_start.getName()) drift_node_start_new.setLength(position_start - lattice.getNodePositionsDict()[drift_node_start][0]) nodes_new_arr.insert(0,drift_node_start_new) if(position_stop < lattice.getNodePositionsDict()[drift_node_stop][1] - length_tolerance): drift_node_stop_new = DriftTEAPOT(drift_node_stop.getName()) drift_node_stop_new.setLength(lattice.getNodePositionsDict()[drift_node_stop][1] - position_stop) nodes_new_arr.append(drift_node_stop_new) #------ now we will modify the lattice by replacing the found part with the new nodes lattice.getNodes()[node_start_ind:node_stop_ind+1] = nodes_new_arr # initialize the lattice lattice.initialize()
def __init__(self, length, ma, density_fac, shape, a, b, c, d, angle, pos=0., name="collimator no name"): """ Constructor. Creates the Collimator TEAPOT element. """ DriftTEAPOT.__init__(self, name) self.collimator = Collimator(length, ma, density_fac, shape, a, b, c, d, angle, pos) self.setType("collimator teapot") self.setLength(length)
def addLongitudinalSpaceChargeNode(lattice, position, sc1D_node): """ This will put one longitudinal space charge node into the lattice """ length_tolerance = 0.0001 lattice.initialize() position_start = position position_stop = position + sc1D_node.getLength() (node_start_ind,node_stop_ind,z,ind) = (-1,-1, 0., 0) for node in lattice.getNodes(): if(position_start >= z and position_start <= z + node.getLength()): node_start_ind = ind if(position_stop >= z and position_stop <= z + node.getLength()): node_stop_ind = ind ind += 1 z += node.getLength() #-------now we check that between start and end we have only non-modified drift elements #-------if the space charge was added first - that is a problem. The collimation should be added first. for node in lattice.getNodes()[node_start_ind:node_stop_ind+1]: #print "debug node=",node.getName()," type=",node.getType()," L=",node.getLength() if(not isinstance(node,DriftTEAPOT)): print "Non-drift node=",node.getName()," type=",node.getType()," L=",node.getLength() orbitFinalize("We have non-drift element at the place of the longitudinal space charge node! Stop!") #if(node.getNumberOfChildren() != 4): #print "Node=",node.getName()," type=",node.getType()," L=",node.getLength()," N children nodes=",node.getNumberOfChildren() #orbitFinalize("Drift element was modified with additional functionality (SC or something else)! Add collimation first! Stop!") # make array of nodes from long sc node in the center and possible two drifts if their length is more than length_tollerance [m] nodes_new_arr = [sc1D_node,] drift_node_start = lattice.getNodes()[node_start_ind] drift_node_stop = lattice.getNodes()[node_stop_ind] #------now we will create two drift nodes: before the long sc node and after #------if the length of one of these additional drifts less than length_tollerance [m] we skip this drift if(position_start > lattice.getNodePositionsDict()[drift_node_start][0] + length_tolerance): drift_node_start_new = DriftTEAPOT(drift_node_start.getName()) drift_node_start_new.setLength(position_start - lattice.getNodePositionsDict()[drift_node_start][0]) nodes_new_arr.insert(0,drift_node_start_new) if(position_stop < lattice.getNodePositionsDict()[drift_node_stop][1] - length_tolerance): drift_node_stop_new = DriftTEAPOT(drift_node_stop.getName()) drift_node_stop_new.setLength(lattice.getNodePositionsDict()[drift_node_stop][1] - position_stop) nodes_new_arr.append(drift_node_stop_new) #------ now we will modify the lattice by replacing the found part with the new nodes lattice.getNodes()[node_start_ind:node_stop_ind+1] = nodes_new_arr # initialize the lattice lattice.initialize()
def addTeapotCollimatorNode(lattice, position, collimator_node): """ It will put one Teapot collimation node in the lattice """ length_tolerance = 0.0001 lattice.initialize() if(position > lattice.getLength() ): position = lattice.getLength(); print "User-specified aperture position is larger than lattice length. Resetting it to lattice length." collimator_node.setPosition(position); position_start = position position_stop = position + collimator_node.getLength() (node_start_ind,node_stop_ind,z,ind) = (-1,-1, 0., 0) for node in lattice.getNodes(): if(position_start >= z and position_start <= z + node.getLength()): node_start_ind = ind if(position_stop >= z and position_stop <= z + node.getLength()): node_stop_ind = ind ind += 1 z += node.getLength() #-------now we check that between start and end we have only non-modified drift elements #-------if the space charge was added first - that is a problem. The collimation should be added first. for node in lattice.getNodes()[node_start_ind:node_stop_ind+1]: #print "debug node=",node.getName()," type=",node.getType()," L=",node.getLength() if(not isinstance(node,DriftTEAPOT)): print "Non-drift node=",node.getName()," type=",node.getType()," L=",node.getLength() orbitFinalize("We have non-drift element at the place of the collimator! Stop!") #if(node.getNumberOfChildren() != 4): #print "Node=",node.getName()," type=",node.getType()," L=",node.getLength()," N children nodes=",node.getNumberOfChildren() #orbitFinalize("Drift element was modified with additional functionality (SC or something else)! Add collimation first! Stop!") # make array of nodes from collimator in the center and possible two drifts if their length is more than length_tolerance [m] nodes_new_arr = [collimator_node,] drift_node_start = lattice.getNodes()[node_start_ind] drift_node_stop = lattice.getNodes()[node_stop_ind] #------now we will create two drift nodes: before the collimator and after #------if the length of one of these additional drifts less than length_tollerance [m] we skip this drift if(position_start > lattice.getNodePositionsDict()[drift_node_start][0] + length_tolerance): drift_node_start_new = DriftTEAPOT(drift_node_start.getName()) drift_node_start_new.setLength(position_start - lattice.getNodePositionsDict()[drift_node_start][0]) nodes_new_arr.insert(0,drift_node_start_new) if(position_stop < lattice.getNodePositionsDict()[drift_node_stop][1] - length_tolerance): drift_node_stop_new = DriftTEAPOT(drift_node_stop.getName()) drift_node_stop_new.setLength(lattice.getNodePositionsDict()[drift_node_stop][1] - position_stop) nodes_new_arr.append(drift_node_stop_new) #------ now we will modify the lattice by replacing the found part with the new nodes lattice.getNodes()[node_start_ind:node_stop_ind+1] = nodes_new_arr # initialize the lattice lattice.initialize()
def addTeapotDiagnosticsNode(lattice, position, diagnostics_node): """ It will put one Teapot diagnostics node in the lattice """ length_tollerance = 0.0001 lattice.initialize() position_start = position position_stop = position + diagnostics_node.getLength() diagnostics_node.setPosition(position) diagnostics_node.setLatticeLength(lattice.getLength()) (node_start_ind,node_stop_ind,z,ind) = (-1,-1, 0., 0) for node in lattice.getNodes(): if(position_start >= z and position_start <= z + node.getLength()): node_start_ind = ind if(position_stop >= z and position_stop <= z + node.getLength()): node_stop_ind = ind ind += 1 z += node.getLength() #-------now we check that between start and end we have only non-modified drift elements #-------if the space charge was added first - that is a problem. The collimation should be added first. for node in lattice.getNodes()[node_start_ind:node_stop_ind+1]: #print "debug node=",node.getName()," type=",node.getType()," L=",node.getLength() if(not isinstance(node,DriftTEAPOT)): print "Non-drift node=",node.getName()," type=",node.getType()," L=",node.getLength() orbitFinalize("We have non-drift element at the place of the diagnostics! Stop!") # make array of nodes from diagnostics in the center and possible two drifts if their length is more than length_tollerance [m] nodes_new_arr = [diagnostics_node,] drift_node_start = lattice.getNodes()[node_start_ind] drift_node_stop = lattice.getNodes()[node_stop_ind] #------now we will create two drift nodes: before the diagnostics and after #------if the length of one of these additional drifts less than length_tollerance [m] we skip this drift if(position_start > lattice.getNodePositionsDict()[drift_node_start][0] + length_tollerance): drift_node_start_new = DriftTEAPOT(drift_node_start.getName()) drift_node_start_new.setLength(position_start - lattice.getNodePositionsDict()[drift_node_start][0]) nodes_new_arr.insert(0,drift_node_start_new) if(position_stop < lattice.getNodePositionsDict()[drift_node_stop][1] - length_tollerance): drift_node_stop_new = DriftTEAPOT(drift_node_stop.getName()) drift_node_stop_new.setLength(lattice.getNodePositionsDict()[drift_node_stop][1] - position_stop) nodes_new_arr.append(drift_node_stop_new) #------ now we will modify the lattice by replacing the found part with the new nodes lattice.getNodes()[node_start_ind:node_stop_ind+1] = nodes_new_arr # initialize the lattice lattice.initialize()
#---PRINT Function for Matrix def printM(m): print "----matrix--- size=",m.size() for i in xrange(m.size()[0]): for j in xrange(m.size()[1]): print ("(%1d,%1d)=% 6.5e "%(i,j,m.get(i,j))), print "" b = Bunch() Ekin = 1.0 # in GeV b.getSyncParticle().kinEnergy(Ekin) #define TEAPOT drift node0 = DriftTEAPOT("drift") node0.setLength(1.0) #define TEAPOT quad node1 = QuadTEAPOT("quad") node1.setLength(1.0) node1.addParam("kq",0.5) matrixGenerator = MatrixGenerator() #========matrix for drift ===== m = Matrix(6,6) matrixGenerator.initBunch(b) node0.trackBunch(b) matrixGenerator.calculateMatrix(b,m) print "drift matrix L=",node0.getLength()
def __init__(self, bunch, xbump, xpbump, ybump, ypbump, waveform=None, name="bump"): """Constructor. Creates the Bump TEAPOT element.""" DriftTEAPOT.__init__(self, name) self.simplebump = simpleBump(bunch, xbump, xpbump, ybump, ypbump, waveform); self.setType("Bump") self.setLength(0.0)
def addErrorNode(lattice, position, Error_Node): """ This will put one error node into the lattice """ length_tolerance = 0.0001 lattice.initialize() position_start = position position_stop = position + Error_Node.getLength() (node_start_ind, node_stop_ind, z, ind) = (-1, -1, 0.0, 0) for node in lattice.getNodes(): if (position_start >= z and position_start <= z + node.getLength()): node_start_ind = ind if (position_stop >= z and position_stop <= z + node.getLength()): node_stop_ind = ind ind += 1 z += node.getLength() """ Check that between start and end there are only non-modified drift elements. If space charge was added first - that is a problem. The collimation should be added first. """ for node in lattice.getNodes()[node_start_ind:node_stop_ind + 1]: """ print "debug node = ", node.getName(), " type = ", node.getType(),\ " L = ", node.getLength() """ if (not isinstance(node, DriftTEAPOT)): print "Non-drift node = ", node.getName(), " type = ",\ node.getType(), " L = ", node.getLength() orbitFinalize("We have non-drift element at the place of \ the error node! Stop!") """ if(node.getNumberOfChildren() != 4): print "Node = ", node.getName()," type = ", node.getType(),\ " L = ", node.getLength(), " N child nodes = ",\ node.getNumberOfChildren() orbitFinalize("Drift element was modified with additional \ functionality (SC or something else)! Add collimation first! \ Stop!") """ """ Make array of nodes with error node in the center and two possible drifts, if their length is more than length_tollerance [m] """ nodes_new_arr = [ Error_Node, ] drift_node_start = lattice.getNodes()[node_start_ind] drift_node_stop = lattice.getNodes()[node_stop_ind] """ Now create two drift nodes: before and after the error node. If the length of either of these additional drifts is less than length_tollerance [m], skip this drift. """ if(position_start > lattice.getNodePositionsDict()[drift_node_start][0] +\ length_tolerance): drift_node_start_new = DriftTEAPOT(drift_node_start.getName()) drift_node_start_new.setLength(position_start -\ lattice.getNodePositionsDict()[drift_node_start][0]) nodes_new_arr.insert(0, drift_node_start_new) if(position_stop < lattice.getNodePositionsDict()[drift_node_stop][1] -\ length_tolerance): drift_node_stop_new = DriftTEAPOT(drift_node_stop.getName()) drift_node_stop_new.setLength(lattice.getNodePositionsDict()[drift_node_stop][1] -\ position_stop) nodes_new_arr.append(drift_node_stop_new) """ Now modify the lattice by replacing the old part with the new nodes """ lattice.getNodes()[node_start_ind:node_stop_ind + 1] = nodes_new_arr """ Initialize the lattice """ lattice.initialize()