Skip to content

Commit 6ea69a4

Browse files
committed
Fix fill fraction argument in make_lattice
1 parent 3dddd80 commit 6ea69a4

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

examples/Diagnostics/Tunes/utils.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,33 @@
1313

1414
def make_lattice(
1515
length: float = 5.0,
16-
fill_fraction: float = 0.5,
16+
fill_frac: float = 0.5,
1717
kq: float = 0.65,
1818
start: str = "drift",
19+
sol: float = 0.0,
1920
) -> AccLattice:
21+
"""Create FODO lattice.
22+
23+
Args:
24+
length: Length of lattice [m].
25+
fill_frac: Fraction of lattice occupied by quadrupoles.
26+
27+
"""
2028
if start == "drift":
21-
return make_lattice_drift_start(length=length, fill_fraction=fill_fraction, kq=kq)
29+
return make_lattice_drift_start(length=length, fill_frac=fill_frac, kq=kq)
2230
elif start == "quad":
23-
return make_lattice_quad_start(length=length, fill_fraction=fill_fraction, kq=kq)
31+
return make_lattice_quad_start(length=length, fill_frac=fill_frac, kq=kq)
2432
else:
2533
raise ValueError
2634

2735

2836
def make_lattice_quad_start(
29-
length: float = 5.0, fill_fraction: float = 0.5, kq: float = 0.65
37+
length: float = 5.0, fill_frac: float = 0.5, kq: float = 0.65
3038
) -> AccLattice:
39+
40+
length_quad = length * fill_frac / 2.0
41+
length_drift = length * (1.0 - fill_frac) / 2.0
42+
3143
drift_nodes = [
3244
DriftTEAPOT("drift1"),
3345
DriftTEAPOT("drift2"),
@@ -37,11 +49,14 @@ def make_lattice_quad_start(
3749
QuadTEAPOT("qd"),
3850
QuadTEAPOT("qf2"),
3951
]
40-
for node in [drift_nodes[0], quad_nodes[1], drift_nodes[1]]:
41-
node.setLength(length * fill_fraction * 0.50)
42-
for node in [quad_nodes[0], quad_nodes[2]]:
43-
node.setLength(length * fill_fraction * 0.25)
44-
52+
53+
drift_nodes[0].setLength(length_drift)
54+
drift_nodes[1].setLength(length_drift)
55+
56+
quad_nodes[0].setLength(length_quad * 0.5)
57+
quad_nodes[1].setLength(length_quad)
58+
quad_nodes[2].setLength(length_quad * 0.5)
59+
4560
quad_nodes[0].setParam("kq", +kq)
4661
quad_nodes[1].setParam("kq", -kq)
4762
quad_nodes[2].setParam("kq", +kq)
@@ -65,9 +80,12 @@ def make_lattice_quad_start(
6580

6681

6782
def make_lattice_drift_start(
68-
length: float = 5.0, fill_fraction: float = 0.5, kq: float = 0.65
83+
length: float = 5.0, fill_frac: float = 0.5, kq: float = 0.65
6984
) -> AccLattice:
7085

86+
length_quad = length * fill_frac / 2.0
87+
length_drift = length * (1.0 - fill_frac) / 2.0
88+
7189
drift_nodes = [
7290
DriftTEAPOT("drift1"),
7391
DriftTEAPOT("drift2"),
@@ -77,11 +95,15 @@ def make_lattice_drift_start(
7795
QuadTEAPOT("qf"),
7896
QuadTEAPOT("qd"),
7997
]
80-
for node in [quad_nodes[0], drift_nodes[1], quad_nodes[1]]:
81-
node.setLength(length * fill_fraction * 0.50)
82-
for node in [drift_nodes[0], drift_nodes[2]]:
83-
node.setLength(length * fill_fraction * 0.25)
8498

99+
100+
drift_nodes[0].setLength(length_drift * 0.5)
101+
drift_nodes[1].setLength(length_drift)
102+
drift_nodes[2].setLength(length_drift * 0.5)
103+
104+
quad_nodes[0].setLength(length_quad)
105+
quad_nodes[1].setLength(length_quad)
106+
85107
quad_nodes[0].setParam("kq", +kq)
86108
quad_nodes[1].setParam("kq", -kq)
87109

0 commit comments

Comments
 (0)