Esempio n. 1
0
def test_unique_names():
    drift_1 = ap.Drift("Drift", length=1)
    drift_2 = ap.Drift("Drift", length=2)

    with pytest.raises(ap.AmbiguousNameError):
        ap.Lattice("Lattice", [drift_1, drift_2])

    cell_1 = ap.Lattice("cell", [])
    cell_2 = ap.Lattice("cell", [])

    with pytest.raises(ap.AmbiguousNameError):
        ap.Lattice("Lattice", [cell_1, cell_2])
Esempio n. 2
0
def test_length_changed():
    drift = ap.Drift("Drift", length=1)
    cell_1 = ap.Lattice("Cell1", [drift, drift])
    cell_2 = ap.Lattice("Cell2", [cell_1, cell_1])
    cell_3 = ap.Lattice("Cell3", [cell_2, cell_2])
    initial_length = cell_3.length
    for i in range(2, 10):
        drift.length += 1
        print("TEST:", drift.length, cell_3.length)
        assert i * initial_length == cell_3.length
Esempio n. 3
0
def test_quadrupole():
    d1 = ap.Drift("D1", length=5)
    d2 = ap.Drift("D2", length=0.2)
    q = ap.Quadrupole("Q1", length=0.2, k1=1.5)
    s = ap.Sextupole("S1", length=0.4, k2=1000)
    # s = ap.Drift("S1", length=0.4)
    lattice = ap.Lattice("Lattice", [d2, q, d2, s, d1])

    distribution = ap.distribution(5,
                                   x_dist="uniform",
                                   x_width=0.0002,
                                   delta_dist="uniform",
                                   delta_width=0.2)
    tracking = Tracking(lattice)
    s, trajectory = tracking.track(distribution)
    _, ax = plt.subplots(figsize=(20, 5))
    ax.plot(s, trajectory[:, 0])
    plt.ylim(-0.0002, 0.0002)
    draw_lattice(lattice, draw_sub_lattices=False)
    plt.savefig("/tmp/test_quadrupole.pdf")
Esempio n. 4
0
"""
Twiss parameter of a FODO lattice
=================================

This example shows how to calulate and plot the Twiss parameter of a FOOD lattice.
"""

#%% Create a fodo based ring
import numpy as np
import apace as ap

D1 = ap.Drift("D1", length=0.55)
d1 = ap.Drift("D1", length=0.55)
b1 = ap.Dipole("B1", length=1.5, angle=0.392701, e1=0.1963505, e2=0.1963505)
q1 = ap.Quadrupole("Q1", length=0.2, k1=1.2)
q2 = ap.Quadrupole("Q2", length=0.4, k1=-1.2)
fodo_cell = ap.Lattice("FODO_CELL", [q1, d1, b1, d1, q2, d1, b1, d1, q1])
fodo_ring = ap.Lattice("FODO_RING", [fodo_cell] * 8)

#%%
# Output some info on the FODO lattice

print(
    f"Overview of {fodo_ring.name}",
    f"Num of elements: {len(fodo_ring.arrangement)}",
    f"Lattice Length : {fodo_ring.length}",
    f"Cell Length    : {fodo_cell.length}",
    sep="\n",
)

#%%
Esempio n. 5
0
"""
Necktie Plot
============

Plot the lattice stability in dependence of the quadrupole strengths.
"""

#%%
# Create a new FODO lattice
import apace as ap

D1 = ap.Drift("D1", length=0.55)
d1 = ap.Drift("D1", length=0.55)
b1 = ap.Drift("B1", length=1.5)
b1 = ap.Dipole("B1", length=1.5, angle=0.392701, e1=0.1963505, e2=0.1963505)
q1 = ap.Quadrupole("Q1", length=0.2, k1=1.2)
q2 = ap.Quadrupole("Q2", length=0.4, k1=-1.2)
fodo_cell = ap.Lattice("FODO_CELL", [q1, d1, b1, d1, q2, d1, b1, d1, q1])
fodo_ring = ap.Lattice("FODO_RING", [fodo_cell] * 8)

#%%
# Scan the quadrupole strength and record lattice stability
import numpy as np

n_steps = 100
k1_start = 0
k1_end = 2

q1_values = np.linspace(k1_start, k1_end, n_steps)
q2_values = np.linspace(k1_start, -k1_end, n_steps)
stable = np.empty((n_steps, n_steps), dtype=bool)