def parseLatticeString(text, facility): spaceChargeOn = facility.getSpaceChargeOn() multipart = facility.getMultipart() twiss = facility.getTwiss() beamdata = facility.getBeamdata() nbrOfSplits = facility.getNbrOfSplits() lattice = Lattice('ParsedLattice', beamdata, twiss, multipart) for line in iter(text.splitlines()): words = line.split() typeOfElem = words[0] name = words[1] l = float(words[words.index("L:") + 1]) #what comes after "L:" if typeOfElem == "cavity": cavityOscillations = float(words[words.index("Oscillations:") + 1]) cavityAmplitudeA = float(words[words.index("AmplitudeA:") + 1]) cavityAmplitudeB = float(words[words.index("AmplitudeB:") + 1]) cavityE_0 = float(words[words.index("E_0:") + 1]) cavitySigma = float(words[words.index("sigma:") + 1]) cavityP = float(words[words.index("p:") + 1]) cavityEzofs = [cavityOscillations, cavityAmplitudeA, cavityAmplitudeB, cavityE_0, cavitySigma, cavityP] elem = Cavity(name, l, cavityEzofs, beamdata, nbrOfSplits) lattice.appendElement(elem) continue if typeOfElem == "dipole": rho = float(words[words.index("rho:") + 1]) #what comes after "rho:" #k_x = what comes after "K_x: " #k_y = what comes after "K_y: " # not needed for construction beta = beamdata[0] nparam = float(words[words.index("nparam:") + 1]) #what comes after "nparam:" alpha = float(words[words.index("Alpha:") + 1]) #what comes after "Alpha:" #elem = Dipole(name, rho, alpha, nparam, spaceChargeOn, multipart, twiss, beamdata, nbrOfSplits) lattice.createDipole(name, rho, alpha, nparam) continue elif typeOfElem != "drift" and typeOfElem != "cavity": k = float(words[words.index("K:") + 1]) #what comes after "K:" if typeOfElem == "liealgelem": hamToUse = words[words.index("HamUsed:") + 1] #what comes after "HamUsed:" and before next whitespace order = int(words[words.index("Order:") + 1]) #what comes after "Order:" #elem = LieAlgElement(name, hamToUse, k, l, order, spaceChargeOn, multipart, twiss, beamdata, nbrOfSplits) lattice.createSextupole(name, k, l, order) continue if typeOfElem == "quad": #elem = Quad(name, k, l, spaceChargeOn, multipart, twiss, beamdata, nbrOfSplits) lattice.createQuadrupole(name, k, l) continue if typeOfElem == "drift": #elem = Drift(name, l, spaceChargeOn, multipart, twiss, beamdata, nbrOfSplits) lattice.createDrift(name, l) continue return lattice
## the lattice will be a FODSO cell (Focusing Quad, Drift, Defocusing Quad, Sextupole, Drift) compLattice = Lattice('compLattice', beamdata, twissfromold, multipartfromold) cavityName = "cavity" cavityLength = 2.0 cavityOscillations = 2 cavityAmplitudeA = 0 cavityAmplitudeB = 30 # 30 MeV / m cavityE_0 = cavityAmplitudeB cavitySigma = 1 cavityP = 3 cavityEzofs = [cavityOscillations, cavityAmplitudeA, cavityAmplitudeB, cavityE_0, cavitySigma, cavityP] cavity = Cavity(cavityName, cavityLength, cavityEzofs, beamdata, nbrOfSplits) # Changes beta in beamdata! E = cavity.getNewE() # Updates the energy compLattice.appendElement(cavity) print compLattice.printLattice() fQName = "fQ" fQuadLength = 0.4 fQuadStrength = -0.8 # this is k fQ = Quad(fQName, fQuadStrength, fQuadLength, spaceChargeOnInComp, multipartfromold, twissfromold, beamdata, nbrOfSplits) #compLattice.appendElement(fQ) driftName = "drift" driftLength = 1.0 compDrift = Drift(driftName, driftLength, spaceChargeOnInComp, multipartfromold, twissfromold, beamdata, nbrOfSplits) #compLattice.appendElement(compDrift) dQName = "dQ" dQuadLength = 0.4