Skip to content

Commit

Permalink
Spin_stroboscope program now takes 6-vector orbit_start, stop.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed Sep 11, 2024
1 parent 0f6a897 commit da8d9ad
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion bmad/doc/beam-init.tex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ \section{Beam_Init_Struct Structure}
initialize a beam. The parameters of this structure, shown with their default values, are:
\begin{example}
type beam_init_struct
character(200) :: position_file = '' ! Initialization file name.
character(200) :: position_file = "" ! Initialization file name.
character distribution_type(3) ! "ELLIPSE", "KV", "GRID", "" (default).
type (ellipse_beam_init_struct) ellipse(3) ! For ellipse beam distribution
type (kv_beam_init_struct) KV ! For KV beam distribution
Expand Down
1 change: 1 addition & 0 deletions bsim/long_term_tracking/doc/long_term_tracking.tex
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@

! Beam initialization
ltt%add_closed_orbit_to_init_position = T
beam_init%position_file = "" ! Set this to use a beam file.
beam_init%use_particle_start = F
beam_init%center = 0, 0, 0, 0, 0, 0
beam_init%n_particle = 10
Expand Down
2 changes: 1 addition & 1 deletion bsim/spin_stroboscope/doc/2www.pl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/perl

`pdflatex spin_stroboscope`;
`cp spin_stroboscope.pdf /home/dcs16/public_html/manuals/`;
`cp spin_stroboscope.pdf /home/dcs16/public_html/bmad/manuals/`;
31 changes: 17 additions & 14 deletions bsim/spin_stroboscope/doc/spin_stroboscope.tex
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
\title{Spin Stroboscope Program}
\author{}
\date{David Sagan \\ June 29, 2023}
\date{David Sagan \\ September 11, 2024}
\begin{document}
Expand Down Expand Up @@ -294,19 +294,22 @@ \section{Superconvergent Calculation}
\Notes:
1) For simple case where spin invariant is independent of phase the superconvergent calculation will produce the
\begin{itemize}
%
\item For simple case where spin invariant is independent of phase the superconvergent calculation will produce the
correct solution after tracking one turn!
2) For Fourier method suseptabal to problems with nonlinearities in the phase space transport since it is assumed
%
\item For Fourier method suseptabal to problems with nonlinearities in the phase space transport since it is assumed
that the phase space advance is constant (check that this statement is true).
3) Superconvergent algorithms: Self-Consistant Stroboscopic Averaging and Scatter Minimization.
4) Merit min algorithim is the real space analogue of the Fourier algorithim.
5) Scatter Minimization can give accurate results with just a few turns of tracking if there are two phase
%
\item Superconvergent algorithms: Self-Consistant Stroboscopic Averaging and Scatter Minimization.
%
\item Merit min algorithim is the real space analogue of the Fourier algorithim.
%
\item Scatter Minimization can give accurate results with just a few turns of tracking if there are two phase
space points that are close together.
%
\end{itemize}
%------------------------------------------------------------------
\Section{Master Input File}
Expand Down Expand Up @@ -360,9 +363,9 @@ \section{Example Master Input File}
ix_lat_branch = 0
dat_file = "spin_stroboscope.dat" ! Output data file.
orbit_start = 0, 0, 0 ! Start x, y, pz
orbit_stop = 0, 0.004, 0 ! Stop
n_points = 1, 10, 1
orbit_start = 0, 0, 0, 0, 0, 0 ! Start orbit x, px, y, py, z, pz
orbit_stop = 0, 0.004, 0 ! Stop orbit
n_points = 1, 0, 10, 0, 0, 1
linear_in_action = T
ix_spin_branch
Expand Down
50 changes: 31 additions & 19 deletions bsim/spin_stroboscope/spin_stroboscope.f90
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ program spin_stroboscope

procedure(track1_custom_def) :: track1_custom

real(rp) orbit_start(3), orbit_stop(3), delta(3), xfer_mat(3,3), closed_orb_invar_spin(3), dtune
real(rp) orbit_start(6), orbit_stop(6), delta(6), xfer_mat(3,3), closed_orb_invar_spin(3), dtune
real(rp) time, unit_mat(3,3), norm_max, norm, tune2, r, axis(3), ave_invar_spin(3), dphase_long, dphase_transverse
real(rp) f(3), p_lim, angle, angle0, angle1, angle2, dangle, j_amp(3), old_relaxed_invar_spin(3), old_scatter_min_invar_spin(3)
real(rp) old_angle, spin_tune, phase(3), d, relaxation_tolerance, g, old_spin_tune, dphase_amp_min, dphase_amp_this
Expand All @@ -90,18 +90,18 @@ program spin_stroboscope
real(rp) scatter_norm_cutoff, spin_tune_tolerance, methods_invar_spin0(3)
real(rp), allocatable :: merit_vec(:)

integer i, j, k, k2, ix, it, ir, j1, j2, jj, n, nn, ibx, iby, ibz, ix_x, ix_y, ix_z, ix_xyz(3), np
integer i, j, k, k2, ix, it, ir, j1, j2, jj, n, nn, ibx, iby, ibz, ix1, ix2, ix3, ix4, ix5, ix6, ix_xyz(6), np
integer i0, i1, i2, n_del, n_turns_min, n_turns_max, n0(3), n1(3), track_state, i_dependent, n_wind
integer i_turn, i_cycle, ix_lat_branch, status, ia, relaxation_weight, scatter_weight, nt_max
integer calc_every, n_points(3), methods_n_turn_invar_spin0
integer calc_every, n_points(6), methods_n_turn_invar_spin0
integer, allocatable :: indx(:)

logical rf_on, first_time, linear_in_action, mode_is_oscillating(3), err, spin_tune_calc, full_average
logical scatter_minimization_calc, self_consistent_calc, is_indep(3), at_end, out_of_range, verbose, debug
logical use_coordinate_for_phase_diff_calc(3)

character(200) bmad_lat, param_file, methods_data_file
character(6) num_str
character(12) num_str

namelist / strob_params / bmad_lat, rf_on, orbit_start, orbit_stop, n_points, n_turns_min, n_turns_max, calc_every, &
relaxation_tolerance, scatter_norm_cutoff, methods_data_file, methods_invar_spin0, scatter_weight, &
Expand Down Expand Up @@ -138,11 +138,18 @@ program spin_stroboscope
scatter_weight = 1
full_average = .true.
use_coordinate_for_phase_diff_calc = .true.
orbit_stop = real_garbage$
n_points = int_garbage$

open (1, file = param_file)
read (1, nml = strob_params)
close (1)

if (any(orbit_stop == real_garbage$) .or. any(n_points == int_garbage$)) then
print *, 'orbit_start, orbit_stop, and n_points are now vectors of length 6 (not 3). Please correct your input file.'
stop
endif

bmad_com%auto_bookkeeper = .false.
bmad_com%spin_tracking_on = .true.

Expand Down Expand Up @@ -209,38 +216,41 @@ program spin_stroboscope
call reallocate_coord (orbit, lat, ix_lat_branch)
call run_timer('START')

open (2, file = 'spin_stroboscope.dat', recl = 300)
write (2, '(a)') '# ix iy iy n_turn Initial position (x, y, pz) Orbit Action (Jx, Jy, Jz) spin_tune p_lim Average Spin (x,y,z) Invariant Spin at Start (x,y,z)'
open (2, file = 'spin_stroboscope.dat', recl = 400)
write (2, '(a)') '# ix ipx iy ipy iz ipz n_turn Initial position Orbit Action (Jx, Jy, Jz) spin_tune p_lim Average Spin (x,y,z) Invariant Spin at Start (x,y,z)'

do ix_x = 1, n_points(1)
do ix_y = 1, n_points(2)
do ix_z = 1, n_points(3)
ix_xyz = [ix_x, ix_y, ix_z]
do ix1 = 1, n_points(1)
do ix2 = 1, n_points(2)
do ix3 = 1, n_points(3)
do ix4 = 1, n_points(4)
do ix5 = 1, n_points(5)
do ix6 = 1, n_points(6)
ix_xyz = [ix1, ix2, ix3, ix4, ix5, ix6]

call init_coord (start_orb, closed_orb(0), branch%ele(0), upstream_end$)

do i = 1, 3
do i = 1, 6
if (linear_in_action .and. i /= 3) then
delta(i) = sqrt(orbit_start(i)**2 + (ix_xyz(i) - 1) * (orbit_stop(i)**2 - orbit_start(i)**2) / max(1, n_points(i) - 1))
else
delta(i) = orbit_start(i) + (ix_xyz(i) - 1) * (orbit_stop(i) - orbit_start(i)) / max(1, n_points(i) - 1)
endif

k = 2*i - 1
if (i == 3) k = 6
start_orb%vec(k) = start_orb%vec(k) + delta(i)
start_orb%vec(i) = start_orb%vec(i) + delta(i)
enddo

orbit(0) = start_orb

mode_is_oscillating(1:3) = (delta /= 0)
do i = 1, 3
mode_is_oscillating(i) = (delta(2*i-1) /= 0 .and. delta(2*i) /= 0)
enddo
if (.not. rf_on) mode_is_oscillating(3) = .false.

call run_timer('READ', time)
if (verbose) then
print *
print '(a)', '!--------------------------------------------------------------'
print '(a, 3i5, 6f12.8)', 'Orbit: ', ix_xyz, orbit(0)%vec - closed_orb(0)%vec
print '(a, 6i5, 6f12.8)', 'Orbit: ', ix_xyz, orbit(0)%vec - closed_orb(0)%vec
print '(a, 3l4)', 'Oscillating Modes: ', mode_is_oscillating
print '(a, f10.1)', 'Time From Start (min):', time/60
endif
Expand Down Expand Up @@ -686,7 +696,7 @@ program spin_stroboscope
!----------------------------
! Write some results

write (num_str, '(3i2.2)') ix_xyz
write (num_str, '(6i2.2)') ix_xyz

call write_spin_track('spin_track.dat' // trim(num_str))

Expand Down Expand Up @@ -715,7 +725,7 @@ program spin_stroboscope
j_amp(i) = (ele0%value(e_tot$)/mass_of(branch%param%particle)) * delta(i)**2 / ele0%b%beta
enddo

write (2, '(3i4, i8, 2x, 3f13.8, 4x, 3es14.6, 5x f11.6, f11.6, 2(5x, 3f11.7))') ix_xyz, i_turn, &
write (2, '(6i4, i8, 2x, 6f13.8, 4x, 3es14.6, 5x f11.6, f11.6, 2(5x, 3f11.7))') ix_xyz, i_turn, &
delta, j_amp, spin_tune, p_lim, ave_invar_spin, s(0)%invar_spin


Expand All @@ -740,7 +750,9 @@ program spin_stroboscope
enddo
endif


enddo
enddo
enddo
enddo
enddo
enddo
Expand Down
2 changes: 1 addition & 1 deletion tao/version/tao_version_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
!-

module tao_version_mod
character(*), parameter :: tao_version_date = "2024/09/04 22:30:30"
character(*), parameter :: tao_version_date = "2024/09/06 22:33:11"
end module

0 comments on commit da8d9ad

Please sign in to comment.