-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
482af37
commit 6550b21
Showing
8 changed files
with
387 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
%------------------------------------------------------------------------------ | ||
%------------------------------------------------------------------------------ | ||
|
||
%------------------------------------------------------------------------------ | ||
%\subsection{Tracking with Ramping} | ||
%The ESR will not be used to accelerate, however to show what ramping in Bmad might look like we include this section. | ||
|
||
%------------------------------------------------------------------------------ | ||
%\subsection{Adding Siberian Snakes} | ||
%Taylor element overview | ||
|
||
|
||
|
||
%------------------------------------------------------------------------------ | ||
%\subsection{Invariant Spin Field Calculations} | ||
%\sodom $\rightarrow$ \ltt | ||
|
||
\newpage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
90 changes: 90 additions & 0 deletions
90
bmad-doc/tutorial_ring_design/lattices/15_SpinTracking/DepolTao.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from pytao import Tao | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import os | ||
import time | ||
import math | ||
import sys | ||
import csv | ||
|
||
|
||
|
||
def generate_spin_resonant_tunes(NU, Ki, Kf): | ||
# Initialize a dictionary to hold valid K values and their annotations | ||
valid_K_values_with_annotations = {} | ||
|
||
# Estimate a reasonable range for N | ||
N_min = int(Ki - abs(NU)) - 1 | ||
N_max = int(Kf + abs(NU)) + 1 | ||
|
||
for N in range(N_min, N_max): | ||
# Calculate potential K values and check if they meet the criteria | ||
K_values = [ | ||
(NU + N, 2 * math.pi), | ||
(abs(NU - N), -2 * math.pi if N > NU else 2 * math.pi), | ||
(N + NU, 2 * math.pi), | ||
] | ||
|
||
for K, annotation in K_values: | ||
if Ki <= K <= Kf and K > 0 and K not in valid_K_values_with_annotations: | ||
valid_K_values_with_annotations[K] = annotation | ||
|
||
# Sort the dictionary by key (K value) to return a sorted list of tuples | ||
sorted_K_values_and_annotations = sorted(valid_K_values_with_annotations.items()) | ||
|
||
# Return the sorted list of unique K values and their annotations | ||
return sorted_K_values_and_annotations | ||
|
||
def generate_strengths(inf,out,plot_file,particle,SPRINT,lo,hi,J): | ||
tao=Tao(f'-lat {inf} -noplot') | ||
#tao.cmd('set element overlay::* is_on = F') | ||
#tao.cmd('set element * field_master = F') | ||
if SPRINT: | ||
tao.cmd('set ele * spin_tracking_method = sprint') | ||
tao.cmd('set bmad_com spin_tracking_on = T') | ||
#tao.cmd('show -write bmad.twiss lat beginning:end -att l -att ang -att beta_a -att alpha_a -att beta_b -att alpha_b -att phi_b/(2*pi) -att orbit_y -att k1*l -att k2*l -att h1 -att h2 -att orbit_x -att orbit_px -att orbit_py') | ||
data = tao.cmd('show val lat::tune.b[0]/twopi') | ||
Qy =float(data[0]) | ||
Kn = generate_spin_resonant_tunes(Qy, lo, hi) | ||
|
||
strengths = [] | ||
|
||
for i in range(0,len(Kn)): | ||
tao.cmd(f'set element 0 e_tot = {Kn[i][0]} / anomalous_moment_of({particle}) * mass_of({particle})') | ||
s = tao.cmd('python spin_resonance') | ||
d1 = float(s[6][s[6].find('dq_b_sum;REAL;F;')+len('dq_b_sum;REAL;F;'):]) | ||
d2 = float(s[7][s[7].find('dq_b_diff;REAL;F;')+len('dq_b_diff;REAL;F;'):]) | ||
e1 = float(s[8][s[8].find('xi_res_b_sum;REAL;F;')+len('xi_res_b_sum;REAL;F;'):]) | ||
e2 = float(s[9][s[9].find('xi_res_b_diff;REAL;F;')+len('xi_res_b_diff;REAL;F;'):]) | ||
if abs(d1) > abs(d2): | ||
strengths.append(e2*np.sqrt(J)) | ||
else: | ||
strengths.append(e1*np.sqrt(J)) | ||
|
||
lst = zip([Kn[i][0] for i in range(len(Kn))],strengths) | ||
open(out, 'w').close() | ||
with open(out,"w") as f: | ||
writer = csv.writer(f,delimiter='\t') | ||
writer.writerows(lst) | ||
|
||
plt.scatter([k[0] for k in Kn],strengths) | ||
plt.xlabel(r"$G\gamma$") | ||
plt.ylabel("$\epsilon$") | ||
plt.savefig(plot_file, dpi=1200) | ||
|
||
|
||
def main(): | ||
inf = sys.argv[1] | ||
out = sys.argv[2] | ||
plot_file = sys.argv[3] | ||
particle = sys.argv[4] | ||
SPRINT = True if sys.argv[5].upper() == "T" else False | ||
lo = float(sys.argv[6]) | ||
hi = float(sys.argv[7]) | ||
J = float(sys.argv[8]) | ||
generate_strengths(inf,out,plot_file,particle,SPRINT,lo,hi,J) | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main() |
28 changes: 28 additions & 0 deletions
28
bmad-doc/tutorial_ring_design/lattices/15_SpinTracking/solution/long_term_tracking.init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
¶ms | ||
ltt%lat_file = 'spin_lat.bmad' ! Lattice file | ||
ltt%ele_start = '0' ! Where to start in the lattice | ||
ltt%ele_stop = '' ! Where to start in the lattice | ||
ltt%phase_space_output_file = 'tracking.dat' | ||
ltt%averages_output_file = 'ramp.dat' | ||
ltt%averages_output_every_n_turns = 1 | ||
ltt%particle_output_every_n_turns = 1 | ||
|
||
ltt%ramping_on = T | ||
ltt%ramp_update_each_particle = T | ||
ltt%simulation_mode = 'SINGLE' | ||
ltt%tracking_method = 'BMAD' ! | ||
ltt%n_turns = 5000 ! Number of turns to track | ||
ltt%rfcavity_on = T | ||
ltt%split_bends_for_stochastic_rad = F | ||
ltt%random_seed = 0 ! Random number seed. 0 => use system clock. | ||
ltt%add_closed_orbit_to_init_position = T | ||
|
||
bmad_com%spin_tracking_on = T ! See Bmad manual for bmad_com parameters. | ||
bmad_com%radiation_damping_on = F | ||
bmad_com%radiation_fluctuations_on = F | ||
|
||
beam_init%n_particle = 1 | ||
beam_init%spin = 0, 1, 0 ! See Bmad manual for beam_init_struct parameters. | ||
beam_init%center = 0, 0, 1e-5, 0, 2.66, 1.15e-5 | ||
/ | ||
/ |
61 changes: 61 additions & 0 deletions
61
bmad-doc/tutorial_ring_design/lattices/15_SpinTracking/solution/spin_lat.bmad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
parameter[geometry] = Closed | ||
|
||
parameter[e_tot] = 51.82 / anomalous_moment_of(proton) * mass_of(proton) | ||
parameter[particle] = Proton | ||
bmad_com[spin_tracking_on] = T | ||
|
||
beginning[beta_a] = 10.4690053690602 | ||
beginning[alpha_a] = 8.47834323010459E-17 | ||
beginning[eta_x] = 1.59632886512312 | ||
beginning[etap_x] = -4.15786647847316E-16 | ||
beginning[beta_b] = 24.1898493928511 | ||
beginning[alpha_b] = 9.8485584267628E-16 | ||
particle_start[spin_x] = -8.05383665788996E-9 | ||
particle_start[spin_y] = 0.999999999999998 | ||
particle_start[spin_z] = 6.54209117387931E-8 | ||
|
||
|
||
!------------------------------------------------------- | ||
|
||
rampe: ramper = {*[e_tot] : 51.71 / anomalous_moment_of(proton) * mass_of(proton) + (.2/5000 / anomalous_moment_of(proton) * mass_of(proton)) / (2.67024e-6)*time}, var = {time} | ||
|
||
Q1H: Quadrupole, L = 1.33333333333333, K1 = -0.0541431006647352 | ||
DR: Drift, L = 0.666666666666667 | ||
B: SBend, L = 2.66697130844605, G = 0.0196327112309049, E1 = 0.0261799387799149, E2 = 0.0261799387799149 | ||
Q2: Quadrupole, L = 2.66666666666667, K1 = 0.054724356256391 | ||
RF: Rfcavity, L = 0.0, VOLTAGE = 1e6, harmon = 1 | ||
CSNK: Taylor, {S1: cos(18.30*pi/360)|}, {Sx: 0|}, {Sy: 0|}, {Sz: sin(18.30*pi/360)|} | ||
WSNK: Taylor, {S1: cos(10.57*pi/360)|}, {Sx: 0|}, {Sy: 0|}, {Sz: sin(10.57*pi/360)|} | ||
|
||
!------------------------------------------------------- | ||
! Overlays, groups, rampers, and superimpose | ||
|
||
|
||
!------------------------------------------------------- | ||
! Lattice lines | ||
|
||
|
||
RING: line = ( Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, | ||
Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, | ||
DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, | ||
B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, | ||
DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, | ||
Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, | ||
Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, | ||
DR, Q1H, CSNK, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, | ||
Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, | ||
DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, | ||
B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, | ||
DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, | ||
Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, | ||
Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, | ||
DR, Q1H, WSNK, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, | ||
Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, | ||
DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, | ||
B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, | ||
DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, | ||
Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, | ||
Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, DR, Q1H, Q1H, DR, B, DR, Q2, DR, B, | ||
DR, Q1H, RF) | ||
|
||
use, RING |
Oops, something went wrong.