Skip to content

Commit

Permalink
First pass at sr z-wake description.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSagan committed May 8, 2024
1 parent 1111521 commit 0bb3abc
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 277 deletions.
4 changes: 2 additions & 2 deletions bmad/code/pointer_to_attribute.f90
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ subroutine pointer_to_attribute (ele, attrib_name, do_allocation, a_ptr, err_fla
if (a_name(1:3) == 'LR(' .or. a_name(1:13) == 'LR_WAKE%MODE(') then
if (.not. associated (ele%wake)) then
if (.not. do_allocation) goto 9100
call init_wake (ele%wake, 0, 0, n)
call init_wake (ele%wake, 0, 0, 0, n)
endif

if (a_name(1:3) == 'LR(') then
Expand Down Expand Up @@ -517,7 +517,7 @@ subroutine pointer_to_attribute (ele, attrib_name, do_allocation, a_ptr, err_fla
'SR_WAKE%SCALE_WITH_LENGTH', 'SR_WAKE%AMP_SCALE', 'SR_WAKE%Z_SCALE')
if (.not. associated(ele%wake)) then
if (.not. do_allocation) goto 9100
call init_wake (ele%wake, 0, 0, 0, .true.)
call init_wake (ele%wake, 0, 0, 0, 0, .true.)
endif
select case (a_name)
case ('LR_SELF_WAKE_ON', 'LR_WAKE%SELF_WAKE_ON')
Expand Down
4 changes: 2 additions & 2 deletions bmad/modules/bmad_routine_interface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1181,11 +1181,11 @@ subroutine init_multipole_cache(ele)
type (ele_struct) ele
end subroutine

subroutine init_wake (wake, n_sr_long, n_sr_trans, n_sr_time, n_lr_mode, always_allocate)
subroutine init_wake (wake, n_sr_long, n_sr_trans, n_sr_z, n_lr_mode, always_allocate)
import
implicit none
type (wake_struct), pointer :: wake
integer n_sr_long, n_sr_trans, n_sr_time, n_lr_mode
integer n_sr_long, n_sr_trans, n_sr_z, n_lr_mode
logical, optional :: always_allocate
end subroutine

Expand Down
8 changes: 4 additions & 4 deletions bmad/modules/bmad_struct.f90
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ module bmad_struct
character(8), parameter :: sr_transverse_position_dep_name(3) = [character(8):: 'none', 'leading', 'trailing']
character(12), parameter :: sr_longitudinal_position_dep_name(5) = &
[character(12):: 'none', 'x_leading', 'y_leading', 'x_trailing', 'y_trailing']
character(8), parameter :: sr_time_plane_name(5) = [character(8):: 'X', 'XY', 'Y', null_name$, 'Z']
character(8), parameter :: sr_z_plane_name(5) = [character(8):: 'X', 'XY', 'Y', null_name$, 'Z']

type wake_sr_mode_struct ! Psudo-mode Short-range wake struct
real(rp) :: amp = 0 ! Amplitude
Expand All @@ -600,8 +600,8 @@ module bmad_struct
! Longitudinal: x_leading$, ..., y_trailing$, none$
end type

type wake_sr_time_struct
type(spline_struct), allocatable :: wake(:) ! Wake vs time.
type wake_sr_z_struct
type(spline_struct), allocatable :: w(:) ! Wake vs time.
type(spline_struct), allocatable :: w1(:), w2(:) ! Running sums used when tracking.
integer :: plane = not_set$ ! x$, y$, xy$, z$.
integer :: position_dependence = not_set$ ! Transverse: leading$, trailing$, none$
Expand All @@ -610,7 +610,7 @@ module bmad_struct

type wake_sr_struct ! Psudo-mode short-Range Wake struct
character(200) :: file = ''
type (wake_sr_time_struct), allocatable :: time(:)
type (wake_sr_z_struct), allocatable :: z(:)
type (wake_sr_mode_struct), allocatable :: long(:)
type (wake_sr_mode_struct), allocatable :: trans(:)
real(rp) :: z_ref_long = 0 ! z reference value for computing the wake amplitude.
Expand Down
32 changes: 22 additions & 10 deletions bmad/modules/equality_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module equality_mod
interface operator (==)
module procedure eq_spline, eq_spin_polar, eq_surface_orientation, eq_ac_kicker_time, eq_ac_kicker_freq
module procedure eq_ac_kicker, eq_interval1_coef, eq_photon_reflect_table, eq_photon_reflect_surface, eq_coord
module procedure eq_coord_array, eq_bpm_phase_coupling, eq_expression_atom, eq_wake_sr_time, eq_wake_sr_mode
module procedure eq_coord_array, eq_bpm_phase_coupling, eq_expression_atom, eq_wake_sr_z, eq_wake_sr_mode
module procedure eq_wake_sr, eq_wake_lr_mode, eq_wake_lr, eq_lat_ele_loc, eq_wake
module procedure eq_taylor_term, eq_taylor, eq_em_taylor_term, eq_em_taylor, eq_cartesian_map_term1
module procedure eq_cartesian_map_term, eq_cartesian_map, eq_cylindrical_map_term1, eq_cylindrical_map_term, eq_cylindrical_map
Expand Down Expand Up @@ -435,28 +435,40 @@ end function eq_expression_atom
!--------------------------------------------------------------------------------
!--------------------------------------------------------------------------------

elemental function eq_wake_sr_time (f1, f2) result (is_eq)
elemental function eq_wake_sr_z (f1, f2) result (is_eq)

implicit none

type(wake_sr_time_struct), intent(in) :: f1, f2
type(wake_sr_z_struct), intent(in) :: f1, f2
logical is_eq

!

is_eq = .true.
!! f_side.equality_test[type, 1, ALLOC]
is_eq = is_eq .and. (allocated(f1%wake) .eqv. allocated(f2%wake))
is_eq = is_eq .and. (allocated(f1%w) .eqv. allocated(f2%w))
if (.not. is_eq) return
if (allocated(f1%wake)) is_eq = all(shape(f1%wake) == shape(f2%wake))
if (allocated(f1%w)) is_eq = all(shape(f1%w) == shape(f2%w))
if (.not. is_eq) return
if (allocated(f1%wake)) is_eq = all(f1%wake == f2%wake)
if (allocated(f1%w)) is_eq = all(f1%w == f2%w)
!! f_side.equality_test[type, 1, ALLOC]
is_eq = is_eq .and. (allocated(f1%w1) .eqv. allocated(f2%w1))
if (.not. is_eq) return
if (allocated(f1%w1)) is_eq = all(shape(f1%w1) == shape(f2%w1))
if (.not. is_eq) return
if (allocated(f1%w1)) is_eq = all(f1%w1 == f2%w1)
!! f_side.equality_test[type, 1, ALLOC]
is_eq = is_eq .and. (allocated(f1%w2) .eqv. allocated(f2%w2))
if (.not. is_eq) return
if (allocated(f1%w2)) is_eq = all(shape(f1%w2) == shape(f2%w2))
if (.not. is_eq) return
if (allocated(f1%w2)) is_eq = all(f1%w2 == f2%w2)
!! f_side.equality_test[integer, 0, NOT]
is_eq = is_eq .and. (f1%plane == f2%plane)
!! f_side.equality_test[integer, 0, NOT]
is_eq = is_eq .and. (f1%position_dependence == f2%position_dependence)

end function eq_wake_sr_time
end function eq_wake_sr_z

!--------------------------------------------------------------------------------
!--------------------------------------------------------------------------------
Expand Down Expand Up @@ -510,11 +522,11 @@ elemental function eq_wake_sr (f1, f2) result (is_eq)
!! f_side.equality_test[character, 0, NOT]
is_eq = is_eq .and. (f1%file == f2%file)
!! f_side.equality_test[type, 1, ALLOC]
is_eq = is_eq .and. (allocated(f1%time) .eqv. allocated(f2%time))
is_eq = is_eq .and. (allocated(f1%z) .eqv. allocated(f2%z))
if (.not. is_eq) return
if (allocated(f1%time)) is_eq = all(shape(f1%time) == shape(f2%time))
if (allocated(f1%z)) is_eq = all(shape(f1%z) == shape(f2%z))
if (.not. is_eq) return
if (allocated(f1%time)) is_eq = all(f1%time == f2%time)
if (allocated(f1%z)) is_eq = all(f1%z == f2%z)
!! f_side.equality_test[type, 1, ALLOC]
is_eq = is_eq .and. (allocated(f1%long) .eqv. allocated(f2%long))
if (.not. is_eq) return
Expand Down
18 changes: 9 additions & 9 deletions bmad/multiparticle/init_wake.f90
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
!+
! Subroutine init_wake (wake, n_sr_long, n_sr_trans, n_sr_time, n_lr_mode, always_allocate)
! Subroutine init_wake (wake, n_sr_long, n_sr_trans, n_sr_z, n_lr_mode, always_allocate)
!
! Subroutine to initialize a wake struct.
! If the wake is allocated, All components are always allocated even when the size is zero.
!
! Input:
! n_sr_long -- Integer: Number of terms: wake%sr%long.
! n_sr_trans -- Integer: Number of terms: wake%sr%trans.
! n_sr_time -- Integer: Number of terms: wake%sr%time.
! n_sr_z -- Integer: Number of terms: wake%sr%z.
! n_lr_mode -- Integer: Number of terms: wake%lr%mode.
! always_allocate -- logical, optional: If present and True then allways allocate wake
! even if n_lr_mode, etc. are all 0. Default is False.
Expand All @@ -16,20 +16,20 @@
! wake -- Wake_struct, pointer: Initialized structure.
!-

subroutine init_wake (wake, n_sr_long, n_sr_trans, n_sr_time, n_lr_mode, always_allocate)
subroutine init_wake (wake, n_sr_long, n_sr_trans, n_sr_z, n_lr_mode, always_allocate)

use bmad_struct

implicit none

type (wake_struct), pointer :: wake
integer n_sr_long, n_sr_trans, n_sr_time, n_lr_mode
integer n_sr_long, n_sr_trans, n_sr_z, n_lr_mode
integer i
logical, optional :: always_allocate

! Deallocate wake if all inputs are zero.

if (n_sr_long == 0 .and. n_sr_trans == 0 .and. n_sr_time == 0 .and. n_lr_mode == 0 .and. .not. logic_option(.false., always_allocate)) then
if (n_sr_long == 0 .and. n_sr_trans == 0 .and. n_sr_z == 0 .and. n_lr_mode == 0 .and. .not. logic_option(.false., always_allocate)) then
if (associated(wake)) deallocate (wake)
return
endif
Expand All @@ -47,9 +47,9 @@ subroutine init_wake (wake, n_sr_long, n_sr_trans, n_sr_time, n_lr_mode, always_
allocate (wake%sr%trans(n_sr_trans))
endif

if (size(wake%sr%time) /= n_sr_time) then
deallocate (wake%sr%time)
allocate (wake%sr%time(n_sr_time))
if (size(wake%sr%z) /= n_sr_z) then
deallocate (wake%sr%z)
allocate (wake%sr%z(n_sr_z))
endif

if (size(wake%lr%mode) /= n_lr_mode) then
Expand All @@ -61,7 +61,7 @@ subroutine init_wake (wake, n_sr_long, n_sr_trans, n_sr_time, n_lr_mode, always_
allocate (wake)
allocate (wake%sr%long(n_sr_long))
allocate (wake%sr%trans(n_sr_trans))
allocate (wake%sr%time(n_sr_time))
allocate (wake%sr%z(n_sr_z))
allocate (wake%lr%mode(n_lr_mode))
endif

Expand Down
6 changes: 3 additions & 3 deletions bmad/multiparticle/transfer_wake.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ subroutine transfer_wake (wake_in, wake_out)
implicit none

type (wake_struct), pointer :: wake_in, wake_out
integer n_sr_long, n_sr_trans, n_sr_time, n_lr_mode, i
integer n_sr_long, n_sr_trans, n_sr_z, n_lr_mode, i

!

if (associated (wake_in)) then
n_sr_long = size(wake_in%sr%long)
n_sr_trans = size(wake_in%sr%trans)
n_sr_time = size(wake_in%sr_time)
n_sr_z = size(wake_in%sr%z)
n_lr_mode = size(wake_in%lr%mode)

call init_wake (wake_out, n_sr_long, n_sr_trans, n_sr_time, n_lr_mode, .true.)
call init_wake (wake_out, n_sr_long, n_sr_trans, n_sr_z, n_lr_mode, .true.)
wake_out = wake_in

else
Expand Down
76 changes: 38 additions & 38 deletions bmad/multiparticle/wake_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ subroutine track1_lr_wake (bunch, ele)

omega = twopi * mode%freq
f_exp = mode%damp
ff0 = ele%wake%lr%amp_scale * abs(particle%charge) * mode%r_over_q

if (mode%polarized) then
c_a = cos(twopi*mode%angle)
Expand All @@ -193,6 +192,7 @@ subroutine track1_lr_wake (bunch, ele)
do k = 1, size(bunch%particle)
particle => bunch%particle(bunch%ix_z(k))
if (particle%state /= alive$) cycle
ff0 = ele%wake%lr%amp_scale * abs(particle%charge) * mode%r_over_q

dt = ele%wake%lr%time_scale * (particle%t - ele%wake%lr%t_ref)
dt_phase = dt
Expand All @@ -219,7 +219,7 @@ subroutine track1_lr_wake (bunch, ele)
w_skew = -ky
endif

particle%vec(6) = particle%vec(6) + (w_norm * kx0 + w_skew * ky0) * cos(twopi * mode%phi) * ff0 * particle%charge
particle%vec(6) = particle%vec(6) + (w_norm * kx0 + w_skew * ky0) * cos(twopi * mode%phi)
endif

! Longitudinal non-self-wake kick
Expand Down Expand Up @@ -270,6 +270,7 @@ subroutine track1_lr_wake (bunch, ele)
mode%b_cos = mode%b_cos + db_cos
mode%a_sin = mode%a_sin + da_sin
mode%a_cos = mode%a_cos + da_cos

enddo ! Wake modes

end subroutine track1_lr_wake
Expand Down Expand Up @@ -481,7 +482,7 @@ end subroutine sr_transverse_wake_particle
!--------------------------------------------------------------------------
!--------------------------------------------------------------------------
!+
! Subroutine sr_time_wake_particle (ele, orbit, ix_particle)
! Subroutine sr_z_wake_particle (ele, orbit, ix_particle)
!
! Subroutine to apply the short-range time wake kick to a particle and then add
! to the existing time wake the contribution from the particle.
Expand All @@ -496,15 +497,17 @@ end subroutine sr_transverse_wake_particle
! orbit -- Coord_struct: Ending particle coords.
!+

subroutine sr_time_wake_particle (ele, orbit, ix_particle)
subroutine sr_z_wake_particle (ele, orbit, ix_particle)

use spline_mod

type (ele_struct), target :: ele
type (wake_sr_time_struct), pointer :: srt
type (wake_sr_z_struct), pointer :: srt
type (coord_struct) orbit

real(rp) x, f0, ff, w_norm, w_skew
real(rp), parameter :: one_sixth = 1.0_rp / 6.0_rp
integer ix_particle, i, j
real(rp) x, f0, ff, f_add, w_norm, w_skew, dz
integer ix_particle, i, j, ix
logical ok

!

Expand All @@ -516,11 +519,12 @@ subroutine sr_time_wake_particle (ele, orbit, ix_particle)

! Loop over wakes

do i = 1, size(ele%wake%sr%time)
srt => ele%wake%sr%time(i)
do i = 1, size(ele%wake%sr%z)
srt => ele%wake%sr%z(i)

!--------------------------------------------
select case (srt%plane == z$) ! Longitudinal
select case (srt%plane)
case (z$) ! Longitudinal
! Kick particle from existing wake.
call spline_evaluate(srt%w1, orbit%vec(5), ok, w_norm)

Expand Down Expand Up @@ -548,7 +552,7 @@ subroutine sr_time_wake_particle (ele, orbit, ix_particle)

! Add to wake

select case (mode%position_dependence)
select case (srt%position_dependence)
case (none$, x_trailing$, y_trailing$)
f_add = f0
case (x_leading$)
Expand Down Expand Up @@ -576,54 +580,50 @@ subroutine sr_time_wake_particle (ele, orbit, ix_particle)
if (srt%plane /= x$) then
if (srt%position_dependence == trailing$) then
orbit%vec(4) = orbit%vec(4) - w_norm * orbit%vec(3)
else leading
else ! leading
orbit%vec(4) = orbit%vec(4) - w_norm
endif
endif

! Add to wake
if (mode%position_dependence == leading$) then
if (srt%position_dependence == leading$) then
endif

end select


And polarizaiton..

if (ix_particle == 1) then
srt%w_sum%x0 = srt%w%x0 + orbit%vec(5)
srt%w_sum%x1 = srt%w%x1 + orbit%vec(5)
srt%w_sum%y0 = srt%w%y0
srt%w_sum%coef = srt%w%coef
srt%w1 = srt%w
srt%w1%x0 = srt%w%x0 + orbit%vec(5)
srt%w1%x1 = srt%w%x1 + orbit%vec(5)

else
do j = 1, size(srt%w_sum)
do j = 1, size(srt%w1)
! First shift existing wake
x = srt%w(j)%x0 + orbit%vec(5)
ok = bracket_index_for_spline(srt%w_sum%x0, x, ix)
ok = bracket_index_for_spline(srt%w1%x0, x, ix)
if (ok) then
srt%w_sum(j)%y0 = spline1(srt%w_sum(ix), x)
srt%w_sum(j)%coef(0) = srt%w_sum(j)%y0
srt%w_sum(j)%coef(1) = spline1(srt%w_sum(j), x, 1)
srt%w_sum(j)%coef(2) = 0.5_rp * spline1(srt%w_sum(j), x, 2)
srt%w_sum(j)%coef(3) = srt%w_sum%coef(3)
srt%w1(j)%y0 = spline1(srt%w1(ix), x)
srt%w1(j)%coef(0) = srt%w1(j)%y0
srt%w1(j)%coef(1) = spline1(srt%w1(j), x, 1)
srt%w1(j)%coef(2) = 0.5_rp * spline1(srt%w1(j), x, 2)
srt%w1(j)%coef(3) = srt%w1(j)%coef(3)
else
srt%w_sum(j)%y0 = 0
srt%w_sum(j)%coef = 0
srt%w1(j)%y0 = 0
srt%w1(j)%coef = 0
endif

! Now add new wake
srt%w_sum(j)%x0 = srt%w%x0 + orbit%vec(5)
srt%w_sum(j)%x1 = srt%w%x1 + orbit%vec(5)
srt%w_sum(j)%y0 = srt%w_sum(j)%y0 + srt%w%y0
srt%w_sum(j)%coef = srt%w_sum(j)%coef + srt%w%coef
srt%w1(j)%x0 = srt%w(j)%x0 + orbit%vec(5)
srt%w1(j)%x1 = srt%w(j)%x1 + orbit%vec(5)
srt%w1(j)%y0 = srt%w1(j)%y0 + srt%w(j)%y0
srt%w1(j)%coef = srt%w1(j)%coef + srt%w(j)%coef
enddo
endif

endif

enddo

end subroutine sr_time_wake_particle
end subroutine sr_z_wake_particle

!--------------------------------------------------------------------------
!--------------------------------------------------------------------------
Expand Down Expand Up @@ -734,7 +734,7 @@ subroutine track1_sr_wake (bunch, ele)
type (ele_struct) ele
type (coord_struct), pointer :: particle
type (coord_struct), pointer :: p(:)
type (wake_sr_time_struct), pointer :: srt
type (wake_sr_z_struct), pointer :: srt

real(rp) sr02
integer i, j, k, i1, i2, n_sr_long, n_sr_trans, k_start, n_live
Expand Down Expand Up @@ -782,7 +782,7 @@ subroutine track1_sr_wake (bunch, ele)
particle => p(bunch%ix_z(j)) ! Particle to kick
call sr_longitudinal_wake_particle (ele, particle)
call sr_transverse_wake_particle (ele, particle)
call sr_time_wake_particle(ele, particle, j)
call sr_z_wake_particle(ele, particle, j)
enddo

end subroutine track1_sr_wake
Expand Down
Loading

0 comments on commit 0bb3abc

Please sign in to comment.