Skip to content

Commit

Permalink
Fix: element type instead of name
Browse files Browse the repository at this point in the history
change MADXParser Quad type to Quadrupole to stay consistent with
MADX input
  • Loading branch information
n01r committed Sep 1, 2022
1 parent 1369a80 commit 1260242
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions examples/fodo/fodo.madx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
! TITLE,'FODO.MADX';
BEAM, PARTICLE=ELECTRON,ENERGY=2.0;

D: DRIFT,L=0.25;
QF: QUADRUPOLE,L=0.5,K1=1.0;
QD: QUADRUPOLE,L=0.5,K1=-1.0;
D1: DRIFT,L=0.25;
D2: DRIFT,L=0.50;
QF: QUADRUPOLE,L=1.0,K1=1.0;
QD: QUADRUPOLE,L=1.0,K1=-1.0;

FODO: LINE=(D,QF,D,QD,D);
FODO: LINE=(D1,QF,D2,QD,D1);
USE, SEQUENCE = FODO;
6 changes: 3 additions & 3 deletions src/python/impactx/MADXParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self):

self.__drift_pattern = r"(.*):drift,(.*)=(.*);"

self.__quadrupole = {"name": "", "l": 0.0, "k1": 0.0, "type": "quad"}
self.__quadrupole = {"name": "", "l": 0.0, "k1": 0.0, "type": "quadrupole"}

# don't count name and type --> len - 2
self.__nQuad = 2 * (len(self.__quadrupole) - 2)
Expand Down Expand Up @@ -371,7 +371,7 @@ def __str__(self):
nTypes[0] += 1
elif e["type"] == "sbend":
nTypes[1] += 1
elif e["type"] == "quad":
elif e["type"] == "quadrupole":
nTypes[2] += 1
elif e["type"] == "dipedge":
nTypes[3] += 1
Expand Down Expand Up @@ -428,7 +428,7 @@ def getBeamline(self):
elif e["type"] == "sbend":
print("Sbend L= ", e["l"], " angle = ", e["angle"])
beamline.append(e)
elif e["type"] == "quad":
elif e["type"] == "quadrupole":
print("Quadrupole L= ", e["l"], " k1 = ", e["k1"])
beamline.append(e)
elif e["type"] == "dipedge":
Expand Down
11 changes: 6 additions & 5 deletions src/python/impactx/madx_to_impactx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def lattice(parsed_beamline, nslice=1):
"MARKER": "None",
"DRIFT": "Drift",
"SBEND": "Sbend", # Sector Bending Magnet
"QUAD": "Quad", # Quadrupole
"QUADRUPOLE": "Quad", # Quadrupole
"DIPEDGE": "DipEdge",
"MULTIPOLE": "Multipole",
"NLLENS": "NonlinearLens",
Expand All @@ -41,17 +41,18 @@ def lattice(parsed_beamline, nslice=1):
for d in parsed_beamline:

if d["type"] in [k.casefold() for k in list(madx_to_impactx_dict.keys())]:
if d["name"] == "drift":

if d["type"] == "drift":
impactx_beamline.append(elements.Drift(ds=d["l"], nslice=nslice))
elif d["name"] == "quadrupole":
elif d["type"] == "quadrupole":
impactx_beamline.append(
elements.Quad(ds=d["l"], k=d["k1"], nslice=nslice)
)
elif d["name"] == "sbend":
elif d["type"] == "sbend":
impactx_beamline.append(
elements.Sbend(ds=d["l"], rc=d["l"] / d["angle"], nslice=nslice)
)
elif d["name"] == "dipedge":
elif d["type"] == "dipedge":
impactx_beamline.append(
elements.DipEdge(
psi=d["e1"],
Expand Down

0 comments on commit 1260242

Please sign in to comment.