From 1260242743a9c95c53c9704dc96b252bc64fdf74 Mon Sep 17 00:00:00 2001 From: Marco Garten Date: Wed, 31 Aug 2022 18:36:18 -0700 Subject: [PATCH] Fix: element type instead of name change MADXParser Quad type to Quadrupole to stay consistent with MADX input --- examples/fodo/fodo.madx | 9 +++++---- src/python/impactx/MADXParser.py | 6 +++--- src/python/impactx/madx_to_impactx.py | 11 ++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/fodo/fodo.madx b/examples/fodo/fodo.madx index bdb706b98..4b51d4a7b 100644 --- a/examples/fodo/fodo.madx +++ b/examples/fodo/fodo.madx @@ -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; diff --git a/src/python/impactx/MADXParser.py b/src/python/impactx/MADXParser.py index d0992451a..4095b6333 100644 --- a/src/python/impactx/MADXParser.py +++ b/src/python/impactx/MADXParser.py @@ -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) @@ -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 @@ -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": diff --git a/src/python/impactx/madx_to_impactx.py b/src/python/impactx/madx_to_impactx.py index 61669ae27..c5013a28c 100644 --- a/src/python/impactx/madx_to_impactx.py +++ b/src/python/impactx/madx_to_impactx.py @@ -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", @@ -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"],