Needs["SynchrotronDesign`"]

Create a simple layout for a 3 Gev synchrotron with 8 dipoles with a 2T field and 6-m long straight sections.

layout = CreateBasicLayout[3000., 2., 8., 6.]

DisplayLayout[layout]

TwissFunctions[layout]

Plot[βH[s], {s, 0, 79.437}, PlotRange -> {0, 10}]

Plot[{αH[s], μH[s], Dispersion[s], DispersionD[s]}, {s, 0, 
        79.437}, PlotRange -> {-1, 11}]

μH[s]

Create a newer layout by adding quads to the original layout

\(strengthF = .3; 
strengthD = \(-.3\); 

    layout = AddQuad[layout, 9, 1.5, 0.5, strengthD]; 

    Do[
	layout = AddQuad[layout, i, 4.0, 0.5, strengthF]; 
	
      \(layout = AddQuad[layout, i, 1.5, 0.5, strengthD]; \), 

      	{i, 8, 2, \(-1\)}]\)layout = AddQuad[layout, 1, 1.0, 0.5, strengthF];

DisplayLayout[layout]

TwissFunctions[layout]

Plot[{βH[s], βV[s]}, {s, 0, 79.437}, 
      PlotRange -> {0, 25}]

Plot[{μH[s], μV[s]}, {s, 0, 79.437}]

Plot[{Dispersion[s], DispersionD[s]}, {s, 0, 79.437}]

Plot[{αH[s], αV[s]}, {s, 0, 79.437}]

Trajectories

\(ParametricPlot3D[{\@βH[s]*Cos[θ], s, 
        \@βH[s]*Sin[θ]}, {s, 0, 79.437}, {θ, 0, 2*π}, 
      
	ViewPoint -> {\(-4\), 2.5, 0.5}, PlotPoints -> {50, 20}, 
      Axes -> False]\)

\(x\_0 = 0.01; 
δ = ArcTan[\(-αH[0]\)]\)ε = ((Subscript[x, 0]^2)/(βH[0]*Cos[δ]^2))

Plot[{(Sqrt[ε*βH[s]]), 
        -(Sqrt[ε*βH[s]]), 
        (Sqrt[ε*βH[s]])*Cos[μH[s] + δ]}, {s, 0, 
        79.437}]

aux1 = 
      Interpolation[
        Table[{s, 
            (Sqrt[ε*βH[Mod[s, 79.4375]]])*
              Cos[⌊(s/79.4375)⌋*μH[79.4375] + 
                  μH[Mod[s, 79.4375]] + δ]}, {s, 0, 200.0}]]

aux2 = 
      Interpolation[
        Table[{s, 
            -(Sqrt[(ε/β)H[Mod[s, 79.4375]]])*
              (Sin[⌊(s/79.4375)⌋*μH[79.4375] + 
                      μH[Mod[s, 79.4375]] + δ] + 
                  αH[Mod[s, 79.4375]]*
                    Cos[⌊(s/79.4375)⌋*μH[79.4375] + 
                        μH[Mod[s, 79.4375]] + δ])}, {s, 0, 
            200.0}]]

ParametricPlot[{aux1[s], aux2[s]}, {s, 0, 200.0}]

\(p = {{x\_0}, {0.}}; 
q = {Flatten[p]}; 

    Do[p = {{1.19865, \(-5.74699\)}, {0.240325, \(-0.317979\)}}.p; 

      	\ \ \ \ \ \(q = Join[q, {Flatten[p]}];\), 
	{i, 100}
	]\)ListPlot[q]

Create FBD layout

layout = 
      CreateFBDLayout[3000., 2., 12, 0.5, 0.5, 0.5, 0.2, -0.2]

DisplayLayout[layout]

TwissFunctions[layout]

Plot[{βH[s], βV[s]}, {s, 0, 61.437}, 
      PlotRange -> {0, 35}]

Plot[{Dispersion[s], DispersionD[s]}, {s, 0, 61.437}]

Plot[{μH[s], μV[s]}, {s, 0, 61.437}]

Plot[{αH[s], αV[s]}, {s, 0, 61.437}]