def __init__(self, name = "no name"): #debug = sys.flags.debug #debug = True #print('debug is on?: ',debug) #if (debug): #logging.basicConfig(level=logging.DEBUG) # logging.basicConfig(level=logging.INFO) #else: # logging.basicConfig(level=logging.WARNING) TEAPOT_Lattice.__init__(self, name)
def load_lattice(file_name, lattice_name, new_parser=False): lattice = TEAPOT_Lattice("lattice") if new_parser: print "Generate Lattice using MADX (new) parser from .SEQ file" lattice.readMADX(file_name, lattice_name) else: print "Generate Lattice using MAD parser from .LAT file" lattice.readMAD(file_name, lattice_name) lattice.setUseRealCharge(useCharge=1) return lattice
def readLattice(file_name, lattice_name): lattice = TEAPOT_Lattice("lattice") print "Generate Lattice using MADX (new) parser from .SEQ file" lattice.readMADX(file_name, lattice_name) lattice.setUseRealCharge(1) # change to + 1 for proton return lattice
from bunch import Bunch from orbit.teapot import TEAPOT_Lattice from spacecharge import SpaceChargeCalc2p5D from spacecharge import Boundary2D from orbit.utils.orbit_mpi_utils import bunch_pyorbit_to_orbit, bunch_orbit_to_pyorbit from orbit.space_charge.sc2p5d import scAccNodes, scLatticeModifications print "Start." #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("sc_lattice") 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
def __init__(self, name = "no name"): TEAPOT_Lattice.__init__(self, name)
from orbit.teapot import teapot from orbit.teapot import TEAPOT_Lattice from orbit.teapot_base import MatrixGenerator from orbit.lattice import AccLattice, AccNode, AccActionsContainer from bunch import Bunch from orbit_utils import Matrix print "Start." b = Bunch() syncPart = b.getSyncParticle() energy = 1.0 #energy in GeV syncPart.kinEnergy(energy) lattice = TEAPOT_Lattice("test_lattice") elem1 = teapot.DriftTEAPOT("drift1") elem2 = teapot.QuadTEAPOT("quad") elem3 = teapot.DriftTEAPOT("drift1") #lattice.addNode(elem1) lattice.addNode(elem2) #lattice.addNode(elem3) #----------------------------- # Set TEAPOT nodes parameters #----------------------------- elem1.setLength(1.0) elem2.setLength(1.0) elem3.setLength(1.0)
def __init__(self, name="no name"): TEAPOT_Lattice.__init__(self, name)
#------------------------------ b = Bunch() print "Read Bunch." b.readBunch("pyorbit_bunch_input.dat") b.mass(0.93827231) b.macroSize(1.0) energy = 1.0 #Gev b.getSyncParticle().kinEnergy(energy) #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("no_sc_lattice") lattice.readMAD("./LATTICES/Q_0p125.LAT", "FODO") # set the number of sections in quads to the same as for ORBIT_MPI for acc_elem in lattice.getNodes(): if (acc_elem.getType() == "quad teapot"): acc_elem.setnParts(5) print "lattice length=", lattice.getLength() # dump initial bunch for ORBIT_MPI input bunch_pyorbit_to_orbit(lattice.getLength(), b, "orbit_mpi_bunch_input.dat") #=====track bunch ============ ACC_TURNS = 1 print("Tracking.")
Qx, Qy = 18.84, 18.73 #Qx,Qy = 18.88,18.8 #---------------------------------------------Bunch init--------------------------------------------- print "Start." b = Bunch() energy = 1 syncPart = b.getSyncParticle() syncPart.kinEnergy(energy) #---------------------------------------------Make a Teapot COLD Lattice --------------- print "Generate ideal cold Lattice." lattice = TEAPOT_Lattice("lattice") lattice.readMADX("sis100cold.seq", "sis100ring") lattice.setUseRealCharge(useCharge=1) [ node.setnParts(10) for node in lattice.getNodes() if node.getType() in ["drift teapot", "quad teapot"] ] # match cold lattice bc = betaCorrection(lattice, b) bc.matchTunes(qx0=Qx, qy0=Qy, quadsDict=qDict, A=0.01) #---------------------------------------------Make a Teapot WARM Lattice-------------- print "Generate Lattice with warm quads." latt = TEAPOT_Lattice("lattice")
def __init__(self, name = "no name"): TEAPOT_Lattice.__init__(self,name) self.__latticeDict = {} self.__TDNodeDict = {} self.__turns = 1
#------------------------------ b = Bunch() print "Read Bunch." b.readBunch("pyorbit_bunch_input.dat") b.mass(0.93827231) b.macroSize(1.0) energy = 1.0 #Gev b.getSyncParticle().kinEnergy(energy) #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("no_sc_lattice") lattice.readMAD("./LATTICES/Test.LAT","TEST") setDict = {} paramsDict = {} """ ##################################################################### positioni = 2.8 positionf = 3.2 paramsDict["errtype"] = "StraightError" paramsDict["subtype"] = "TransDisp" paramsDict["sample"] = "Fixed" paramsDict["dx"] = 0.1 paramsDict["dy"] = 0.1
#------------------------------ b = Bunch() print "Read Bunch." b.readBunch("pyorbit_bunch_input.dat") b.mass(0.93827231) b.macroSize(1.0) energy = 1.0 #Gev b.getSyncParticle().kinEnergy(energy) #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("no_sc_lattice") lattice.readMAD("./LATTICES/Q_0p125.LAT","FODO") # set the number of sections in quads to the same as for ORBIT_MPI for acc_elem in lattice.getNodes(): if(acc_elem.getType() == "quad teapot"): acc_elem.setnParts(5) print "lattice length=",lattice.getLength() # dump initial bunch for ORBIT_MPI input bunch_pyorbit_to_orbit(lattice.getLength(), b, "orbit_mpi_bunch_input.dat") #=====track bunch ============ ACC_TURNS = 1 print("Tracking.")
print "Start." #---------------------------------------------Bunch init--------------------------------------------- b = Bunch() b.mass(0.93827231) b.macroSize(1.0) energy = 1.0 #Gev b.getSyncParticle().kinEnergy(energy) #---------------------------------------------Bunch init--------------------------------------------- print "Generate Lattice." #---------------------------------------------Make a Teapot Lattice---------------------------------- lattice = TEAPOT_Lattice("lattice") lattice.readMAD("sis18.lat","SIS18") #---------------------------------------------Make a Teapot Lattice---------------------------------- print "INTRODUCE MISALIGNEMENT IN THE QUADRUPOLES" #---------------------------------------------ORBIT ERRORS------------------------------------------- # WE INTRODUCE MISALIGNEMENT IN THE QUADRUPOLES; dx, dy = HOR AND VER DISPLACEMENT OF QUADRUPOLES setDict = {} paramsDict = {} positioni = 0.0 positionf = lattice.getLength() paramsDict["errtype"] = "StraightError" paramsDict["subtype"] = "TransDisp" paramsDict["sample"] = "Uniform" paramsDict["maximum"] = 0.5 paramsDict["minimum"] = 0.0
INTENSITY = 1.0e+14 nMaxMacroParticles = 100000 macro_size = INTENSITY / nMaxMacroParticles b.macroSize(macro_size) energy = 1.0 #Gev b.getSyncParticle().kinEnergy(energy) #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("sc_lattice") lattice.readMAD("./LATTICES/Q_0p125.LAT", "FODO") #lattice.readMAD("./LATTICES/TEST_SC_LATTICE.LAT","FODO") print "lattice length=", lattice.getLength() """ #if user want to generagte the bunch by himself r_bunch = 0.05 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())
rc('axes', linewidth=2) rc('lines', linewidth=3) rc('legend', fontsize=18) rc('figure', figsize=(9, 8)) #------------------------------------------------------ # Read MADX twiss file, match and plot envelopes #------------------------------------------------------- bunch = Bunch() #energy = 11.4e-3 # beta must be on def. of disperion energy = 0.001 bunch.getSyncParticle().kinEnergy(energy) lattice = TEAPOT_Lattice("no_sc_lattice") lattice.readMAD("fodo.lat", "CELLA") # lattice start at injection point lattice.setUseRealCharge(useCharge=1) matrix_lattice = TEAPOT_MATRIX_Lattice(lattice, bunch) (muX, arrPosAlphaX, arrPosBetaX0) = matrix_lattice.getRingTwissDataX() #(muY, arrPosAlphaY, arrPosBetaY0) = matrix_lattice.getRingTwissDataY() #---------------------------------------------FIELD ERRORS------------------------------------------- setDict = {} paramsDict = {} positioni = 0.0 positionf = lattice.getLength() paramsDict["errtype"] = "FieldError" paramsDict["subtype"] = "QuadField"
from bunch import Bunch from orbit.teapot import TEAPOT_Lattice from spacecharge import SpaceChargeCalc2p5D from spacecharge import Boundary2D from orbit.utils.orbit_mpi_utils import bunch_pyorbit_to_orbit, bunch_orbit_to_pyorbit from orbit.space_charge.sc2p5d import scAccNodes, scLatticeModifications print "Start." #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("sc_lattice") 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
print "Read Bunch." NPIC = 500 A = 1 Z = 1 energy = 11.4e-3*A # Gev intensity = 1.4e10 emittance_x = 50e-6 emittance_y = 50e-6 bunch.mass(0.93827231) bunch.getSyncParticle().kinEnergy(energy) #=====set up bunch stuff============ print "Generate Lattice." lattice = TEAPOT_Lattice("no_sc_lattice") case = "inj" #case = "mid" if case == "inj": lattice.readMAD("sis18_inj.lat","SIS18") # lattice start at injection point if case == "mid": lattice.readMAD("sis18_inj.lat","SIS18_MID") # lattice start at injection point plus half circumference # get the lattice function for the kick and bpms, jet only horizontal find = closed_orbit_bumps() xc0 = 70e-3 xcs0 = 7.0e-3 # or 7.0e-3
bunch = Bunch() print "Read Bunch." A = 1 Z = 1 energy = 11.4e-3*A # Gev intensity = 1.4e10 emittance_x = 50e-6 emittance_y = 50e-6 bunch.mass(0.93827231) bunch.getSyncParticle().kinEnergy(energy) #=====set up bunch stuff============ print "Generate Lattice." lattice = TEAPOT_Lattice("no_sc_lattice") lattice.readMAD("lattice/sis18_inj.lat","SIS18_MID") # lattice start at injection point plus half circumference # get the lattice function for the kick and bpms, jet only horizontal find = close_orbit_bumps() xc0 = 70e-3 xcs0 = 7.0e-3 # set variable, list [[node.name], [variable, start value], ...] kicker1 = [["S11MB1"], ["kx",-0.00111]] kicker2 = [["S12MB2"], ["kx",0.00]]
INTENSITY = 1.0e+14 nMaxMacroParticles = 100000 macro_size = INTENSITY / nMaxMacroParticles b.macroSize(macro_size) energy = 1.0 #Gev b.getSyncParticle().kinEnergy(energy) #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("sc_lattice") lattice.readMAD("./LATTICES/Q_0p125.LAT","FODO") #lattice.readMAD("./LATTICES/TEST_SC_LATTICE.LAT","FODO") print "lattice length=",lattice.getLength() """ #if user want to generagte the bunch by himself r_bunch = 0.05 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())
print "Start." #---------------------------------------------Bunch init--------------------------------------------- b = Bunch() total_macroSize = 1e+11 b.macroSize(total_macroSize) energy = 50 * 10**(-6) syncPart = b.getSyncParticle() syncPart.kinEnergy(energy) EE = syncPart.kinEnergy() print(EE) #---------------------------------------------Bunch init--------------------------------------------- print "Generate Lattice." #---------------------------------------------Make a Teapot Lattice---------------------------------- lattice = TEAPOT_Lattice("lattice") #lattice.readMADX("fodo_thin.seq","fodo") #lattice.readMADX("FODO_x6.seq","fodo") lattice.readMADX("cryring.madx", "cryring") #lattice.readMADX("sis100_full_thin_fix.seq","sis100ring") lattice.setUseRealCharge(useCharge=1) #----------------------------------------------- LL = lattice.getLength() print("check the quads") #L = 0 #for node in lattice.getNodes(): # if node.getType() == "quad teapot": # print("parameters. kq {} length {}".format(node.getParam("kq"),node.getLength())) # print(L+node.getLength()/2) # L+=node.getLength()
rc('font', size=16) rc('axes', linewidth=2) rc('lines', linewidth=3) rc('legend', fontsize=18) rc('figure', figsize=(9, 8)) #------------------------------------------------------ # Read MADX twiss file, match and plot envelopes #------------------------------------------------------- bunch = Bunch() energy = 11.4e-3 # beta must be on def. of disperion bunch.getSyncParticle().kinEnergy(energy) lattice = TEAPOT_Lattice("no_sc_lattice") lattice.readMAD("fodo.lat", "CELLA") # lattice start at injection point lattice.setUseRealCharge(useCharge=1) beamline = Optics().readtwiss_teapot(lattice, bunch) beamline.print_line() emitx = 12.5e-6 # emittance_x emity = 12.5e-6 # emittance_y sigma_p = 1.0e-3 # rms momentum spread Ksc = 1.e-6 * 5 # space charge perveance circum = 216.0 # 1080.0 # circumference Ncells = 12.0 # number of cells solve = EnvelopeSolver(beamline)
def fodo(k1, k2): """Create FODO lattice. k1 and k2 are the focusing strengths of the focusing (1st) and defocusing (2nd) quads, respectively. """ # Instantiate elements lattice = TEAPOT_Lattice() drift1 = teapot.DriftTEAPOT('drift1') drift2 = teapot.DriftTEAPOT('drift2') drift_half1 = teapot.DriftTEAPOT('drift_half1') drift_half2 = teapot.DriftTEAPOT('drift_half2') qf = teapot.QuadTEAPOT('qf') qd = teapot.QuadTEAPOT('qd') qf_half1 = teapot.QuadTEAPOT('qf_half1') qf_half2 = teapot.QuadTEAPOT('qf_half2') qd_half1 = teapot.QuadTEAPOT('qd_half1') qd_half2 = teapot.QuadTEAPOT('qd_half2') # Set lengths half_nodes = (drift_half1, drift_half2, qf_half1, qf_half2, qd_half1, qd_half2) full_nodes = (drift1, drift2, qf, qd) for node in half_nodes: node.setLength(L * fill_fac / 4) for node in full_nodes: node.setLength(L * fill_fac / 2) # Set quad focusing strengths for node in (qf, qf_half1, qf_half2): node.addParam('kq', +k1) for node in (qd, qd_half1, qd_half2): node.addParam('kq', -k2) # Create lattice if start == 'drift': lattice.addNode(drift_half1) lattice.addNode(qf) lattice.addNode(drift2) lattice.addNode(qd) lattice.addNode(drift_half2) elif start == 'quad': lattice.addNode(qf_half1) lattice.addNode(drift1) lattice.addNode(qd) lattice.addNode(drift2) lattice.addNode(qf_half2) # Other if reverse: lattice.reverseOrder() lattice.set_fringe(fringe) lattice.initialize() for node in lattice.getNodes(): name = node.getName() if 'qf' in name: node.setTiltAngle(+angle) elif 'qd' in name: node.setTiltAngle(-angle) return lattice
print "Read Bunch." NPIC = 1000 A = 1 Z = 1 energy = 11.4e-3 # Gev emittance_x = 50e-6 emittance_y = 50e-6 bunch.mass(0.93827231) bunch.getSyncParticle().kinEnergy(energy) print "Generate Lattice." lattice = TEAPOT_Lattice("no_sc_lattice") lattice.readMAD("./lattice/sis18_inj.lat","SIS18_MID") offset = 0.#70e-3 #============Set BPMs into lattice=============== length = round(lattice.getLength()/12,4) for i in range(12): name = TeapotBPMSignalNode("BPM") addTeapotDiagnosticsNode(lattice, i*length, name) #============Set BPMs into lattice=============== matrix_lattice = TEAPOT_MATRIX_Lattice(lattice,bunch) (muX, arrPosAlphaX, arrPosBetaX) = matrix_lattice.getRingTwissDataX() (muY, arrPosAlphaY, arrPosBetaY) = matrix_lattice.getRingTwissDataY() (arrDispX,arrDispPrimeX) = matrix_lattice.getRingDispersionDataX()
print "Start." #---------------------------------------------Bunch init--------------------------------------------- b = Bunch() total_macroSize = 4e+10 b.macroSize(total_macroSize) energy = 2 syncPart = b.getSyncParticle() syncPart.kinEnergy(energy) EE = syncPart.kinEnergy() print(EE) #---------------------------------------------Bunch init--------------------------------------------- print "Generate Lattice." #---------------------------------------------Make a Teapot Lattice---------------------------------- lattice = TEAPOT_Lattice("lattice") lattice.readMADX("fodo_thin.seq", "fodo") lattice.setUseRealCharge(useCharge=1) #----------------------------------------------- matrix_lattice = TEAPOT_MATRIX_Lattice(lattice, b) (muX0, arrPosAlphaX0, arrPosBetaX0) = matrix_lattice.getRingTwissDataX() (muY0, arrPosAlphaY0, arrPosBetaY0) = matrix_lattice.getRingTwissDataY() beamline0 = Optics().readtwiss_teapot(lattice, b) solve = EnvelopeSolver(beamline0) twiss0 = solve.match_twiss_matrix(12.5e-6, 12.5e-6, 0.0, 0.0) #----------------------------------------------- #---------------------------------------------Make a Teapot Lattice----------------------------------
#------------------------------ b = Bunch() print "Read Bunch." b.readBunch("pyorbit_bunch_input.dat") b.mass(0.93827231) b.macroSize(1.0) energy = 1.0 #Gev b.getSyncParticle().kinEnergy(energy) #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("no_sc_lattice") lattice.readMAD("./LATTICES/Test.LAT", "TEST") setDict = {} paramsDict = {} """ ##################################################################### positioni = 2.8 positionf = 3.2 paramsDict["errtype"] = "StraightError" paramsDict["subtype"] = "TransDisp" paramsDict["sample"] = "Fixed" paramsDict["dx"] = 0.1 paramsDict["dy"] = 0.1
INTENSITY = 1.0e+14 nMaxMacroParticles = 10000 macro_size = INTENSITY / nMaxMacroParticles b.macroSize(macro_size) energy = 1.0 #Gev b.getSyncParticle().kinEnergy(energy) #------------------------------ #Make a Teapot Lattice #------------------------------ print "Generate Lattice." lattice = TEAPOT_Lattice("rcs_lattice") lattice.readMAD( "./lattice_data/rcslat_6450.6420_woQMBMfringe_woMKC_wLeakFld.foiltofoil.lat", "RING") print "lattice length=", lattice.getLength() quads = lattice.getNodesOfClass(QuadTEAPOT) rfs = lattice.getNodesOfClass(RingRFTEAPOT) bends = lattice.getNodesOfClass(BendTEAPOT) print "debug N quads =", len(quads) print "debug N RFs =", len(rfs) print "debug N bends =", len(bends) #---- this is a printing of the quads' parameters #---- User can change these parameters if he/she wants to
lostbunch = Bunch() trackDict = {} trackDict["lostbunch"] = lostbunch trackDict["bunch"] = b lostbunch.addPartAttr("LostParticleAttributes") energy = 1 syncPart = b.getSyncParticle() syncPart.kinEnergy(energy) EE = syncPart.kinEnergy() print(EE) #---------------------------------------------Make a Teapot Lattice---------------------------------- print "Generate Lattice." lattice = TEAPOT_Lattice("lattice") #lattice.readMADX("fodo_thin.seq","fodo") lattice.readMADX("FODO_x6.seq", "fodo") #lattice.readMADX("cryring.madx","cryring") #lattice.readMADX("sis100_full_thin_fix.seq","sis100ring") lattice.setUseRealCharge(useCharge=1) #---------------------------------------------SPLIT LONG ELEMENTS-------------------------------------- for node in lattice.getNodes(): if node.getLength() > 1.0: node.setnParts(int(node.getLength() // 1 + 1)) #------------------------------------------------------------------------------------------------------ matrix_lattice = TEAPOT_MATRIX_Lattice(lattice, b)
energy = 1 syncPart=b.getSyncParticle() syncPart.kinEnergy(energy) #---------------------------------------------Make a Teapot Lattice---------------------------------- ''' print "Generate Lattice." lattice = TEAPOT_Lattice("lattice") lattice.readMAD("/home/laptop/Documents/Scripts/FODO_thick.lat","fodo") lattice.setUseRealCharge(useCharge = 1) ''' #---------------------------------------------Make a Teapot Lattice---------------------------------- print "Generate Lattice." latt = TEAPOT_Lattice("lattice") #latt.readMADX("/home/laptop/Documents/Scripts/FODO_thick.seq","fodo") latt.readMADX("cryring.madx","cryring") latt.setUseRealCharge(useCharge = 1) #---------------------------------------------SPLIT LONG ELEMENTS-------------------------------------- d =latt.getNodePositionsDict() for node in latt.getNodes(): L =node.getLength() val = d[node] print node.getName(),val,L, val[0]/2+val[-1]/2, val[0]+L/2 node.setnParts(10) #for key,val in sorted(d.items(),reverse=False,key=lambda x: x[1][0]):