Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More wake devel. #1294

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ Steps to reproduce the behavior:
A clear and concise description of what you expected to happen.

**Compiler and Operating system**
Describe compiler and operating system.
Describe compiler with version number and operating system.

**Additional context**
Add any other context about the problem here.

**Attaching Files**

GitHub restricts files that are attached to an issue to have a name with a "supported" suffix. In
particular, files that have a `.bmad` suffix are not allowed. To get around this, zip together all
the files that are to be attached (`.zip` is an allowed suffix).
4 changes: 2 additions & 2 deletions bmad/multiparticle/wake_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ subroutine sr_z_long_wake (ele, bunch, z_ave)

rz_rel = sr%z_scale * (p%vec(5) - z_ave) / srz%dz + n2 + 1
ix1 = floor(rz_rel)
ix2 = ceiling(rz_rel)
ix2 = ix1 + 1
if (ix1 < 1 .or. ix2 > nn) then
n_bad = n_bad + 1
cycle
Expand Down Expand Up @@ -580,7 +580,7 @@ subroutine sr_z_long_wake (ele, bunch, z_ave)

rz_rel = sr%z_scale * (p%vec(5) - z_ave) / srz%dz + n2 + 1
ix1 = floor(rz_rel)
ix2 = ceiling(rz_rel)
ix2 = ix1 + 1

r1 = ix2 - rz_rel
r2 = rz_rel - ix1
Expand Down
2 changes: 1 addition & 1 deletion tao/doc/cover-page.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

\begin{flushright}
\large
Revision: November 8, 2024 \\
Revision: November 15, 2024 \\
\end{flushright}

\vfill
Expand Down
14 changes: 7 additions & 7 deletions util_programs/wake_plot/README
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ make_plot: If False, do not make a plot (used if only a postscript file is wante

postscript_file: If non-blank, Make a postscript file.

Plot_limit:
* For LR plots, the wake is plotted over a time range [0, plot_limit].
* For "sr-z-long" plot the z range is [-plot_limit, +plot_limit] except if plot_limit is zero then the entire
wake table is plotted.
* For SR plots, the wake is plotted over a z range [plot_limit, 0] where plot_limit should be negative in this case.
x_min, x_max: Plot limits for the horizontal axis. Either will default to zero if not set.
* For LR plots, the wake is zero for negative time so best to plot over a time range [0, x_max].
* For "sr-z-long", if both x_min and x_max are not set the plot extent is taken to be the wake extent.
* For SR plots, the wake is zero for positive z so best is to plot over a z range [x_min, 0] where
x_min should be negative.

n_points: Number of data points to use in drawing the wake. Not used with "sr-z-long" where the number
of points is determined by the number points in the wake table that are visible in the plot
Expand All @@ -111,7 +111,7 @@ text_scale: Scale for drawing text. Default is 1.2

plot_size: (width, height) of plot page in pixels (72 pixels = 1 inch).

x_axis_label:
x_axis_label: Label for the x-axis. Default is either "Z" or "Time".

y_axis_label:
y_axis_label: Label for the y-axis. Default is either "Wake" or "Kick".

4 changes: 2 additions & 2 deletions util_programs/wake_plot/example/wake_plot.init
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
ix_wake = 0 ! Index of wake to use. 0 => Ignore this parameter.
xy_leading = 1, 0 ! (x, y) position of leading particle that produces a wake.
xy_trailing = 1, 0 ! (x, y) position of trailing witness particle that samples the bunch.
leading_charge = 1 ! Leading particle charge. Only used when plotting the wake kicks.

plot_type = "wake" ! "wake" or "kick"
make_plot = True ! Open a plotting window.
postscript_file = "" ! If not blank, write wake to a file.
plot_limit = -1e-2 ! Limit of plot range.
x_min = -1e-2 ! Limit of plot range.
x_max = 0
n_points = 1001 ! Number of plot points
draw_knot_points = False ! Draw symbols at SR z-dependent wake knot points?
text_scale = 1.2 ! Scale for drawing text.
Expand Down
112 changes: 60 additions & 52 deletions util_programs/wake_plot/wake_plot.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ program wake_plot
type (bunch_struct), target :: bunch
type (coord_struct), pointer :: p1, p2

real(rp) :: plot_min, plot_max, plot_limit, plot_size(2), text_scale, zero6(6) = 0, vec2(6)
real(rp) xy_leading(2), xy_trailing(2), z
real(rp) :: x_min, x_max, plot_size(2), text_scale, zero6(6) = 0
real(rp) xy_leading(2), xy_trailing(2), vec2(6), z
real(rp), allocatable :: x_axis(:), wx(:), wy(:), wz(:)

integer n, n_points, ix_wake, m_order, i, im, iz, ik, n_loc, ix, nw, n0
integer n, n_points, ix_wake, m_order, i, im, iz, ik, n_loc, ix, nw, n1, n2

logical make_plot, err, err_flag, ok

character(40) wake_ele_name, ans, x_axis_label, y_axis_label, who, plot_type
character(40) wake_ele_name, ans, who, plot_type
character(200) init_file, lat_file, postscript_file

namelist / params / plot_limit, make_plot, plot_size, who, plot_type, &
namelist / params / x_min, x_max, make_plot, plot_size, who, plot_type, &
wake_ele_name, lat_file, n_points, postscript_file, &
text_scale, x_axis_label, y_axis_label, &
xy_leading, xy_trailing, ix_wake, m_order
text_scale, xy_leading, xy_trailing, ix_wake, m_order

! Read input

Expand All @@ -44,6 +43,8 @@ program wake_plot
text_scale = 1.0
ix_wake = 0
m_order = 0
x_min = 0
x_max = 0

open (1, file = init_file, status = 'old')
read (1, nml = params)
Expand Down Expand Up @@ -99,20 +100,22 @@ program wake_plot
stop
endif

if (plot_limit == 0 .or. plot_limit > srz%z0) then
plot_limit= srz%z0
if (x_min < -srz%z0) x_min = -srz%z0
if (x_max > srz%z0) x_max = srz%z0

if (x_min == 0 .and. x_max == 0) then
x_min = -srz%z0
x_max = srz%z0
endif

nw = (size(srz%w) - 1) / 2
n0 = nint(plot_limit / srz%dz)
allocate(wz(2*n0+1), x_axis(2*n0+1))
plot_min = -plot_limit
plot_max = plot_limit

do im = -n0, n0
ix = im + n0 + 1
x_axis(ix) = im * srz%dz
wz(ix) = srz%w(im + nw + 1)
n1 = nint(x_min / srz%dz)
n2 = nint(x_max / srz%dz)
allocate(wz(n1:n2), x_axis(n1:n2))

do im = n1, n2
x_axis(im) = im * srz%dz
wz(im) = srz%w(im + nw + 1)
enddo

if (make_plot) call make_this_plot ('X')
Expand All @@ -128,8 +131,6 @@ program wake_plot
case ('lr')
lr => wake_ele%wake%lr
bmad_com%lr_wakes_on = .true.
plot_max = plot_limit
plot_min = 0

if (size(lr%mode) > 1) then
if (ix_wake == 0) then
Expand All @@ -155,7 +156,7 @@ program wake_plot
call order_particles_in_z(bunch)

do i = 1, n_points
z = plot_min + (plot_max - plot_min) * (i - 1.0_rp) / (n_points - 1.0_rp)
z = x_min + (x_max - x_min) * (i - 1.0_rp) / (n_points - 1.0_rp)
p2%vec = vec2
p2%vec(5) = z
x_axis(i) = z
Expand All @@ -171,33 +172,40 @@ program wake_plot
case ('sr')
sr => wake_ele%wake%sr
bmad_com%sr_wakes_on = .true.
plot_max = 0
plot_min = -abs(plot_limit)

select case (who)
case ('sr-mode')
allocate(sr%z_long%w(0))
case ('sr-long')
allocate(sr%z_long%w(0))
allocate(sr%trans(0))
if (ix_wake /= 0) sr%long = [sr%long(ix_wake)]
case ('sr-trans')
allocate(sr%z_long%w(0))
allocate(sr%long(0))
if (ix_wake /= 0) sr%trans = [sr%trans(ix_wake)]
case ('sr-z-long')
allocate(sr%trans(0))
allocate(sr%long(0))
end select

p2%vec(5) = -1
call order_particles_in_z(bunch)
if (x_min == 0 .and. x_max == 0) then
if (sr%z_long%z0 /= 0) then
x_min = -sr%z_long%z0
x_max = sr%z_long%z0
else
print *, 'X_min nor X_max set! I do not know what to do!'
stop
endif
endif

if (who /= 'sr-z-long') then
srz => sr%z_long
deallocate (srz%w, srz%fw, srz%fbunch, srz%w_out)
allocate (srz%w(0), srz%fw(0), srz%fbunch(0), srz%w_out(0))
endif

if (who /= 'sr-mode' .and. who /= 'sr-trans') then
deallocate (sr%trans)
allocate (sr%trans(0))
endif

if (who /= 'sr_mode' .and. who /= 'sr_long') then
deallocate (sr%long)
allocate (sr%long(0))
endif


do i = 1, n_points
z = plot_min + (plot_max - plot_min) * (i - 1.0_rp) / (n_points - 1.0_rp)
z = x_min + (x_max - x_min) * (i - 1.0_rp) / (n_points - 1.0_rp)
p2%vec = vec2
p2%vec(5) = z
x_axis(i) = z
call order_particles_in_z(bunch)
call track1_sr_wake(bunch, wake_ele)
wx(i) = p2%vec(2)
wy(i) = p2%vec(4)
Expand All @@ -221,7 +229,7 @@ subroutine make_this_plot(plot_window)

real(rp) height
character(*) plot_window
character(16) :: what_str, x_axis_str
character(16) :: y_label, x_axis_str
integer j, k, n, id

!
Expand All @@ -235,9 +243,9 @@ subroutine make_this_plot(plot_window)
endif

select case (plot_type)
case ('wake'); what_str = 'Wake'
case ('kick'); what_str = 'Kick'
case default; what_str = 'Wake'
case ('wake'); y_label = 'Wake'
case ('kick'); y_label = 'Kick'
case default; y_label = 'Wake'
end select

select case (plot_type)
Expand All @@ -257,37 +265,37 @@ subroutine make_this_plot(plot_window)
!

if (who == 'sr-z-long' .and. plot_type == 'wake') then
call qp_calc_and_set_axis ('X', plot_min, plot_max, 4, 8, 'GENERAL')
call qp_calc_and_set_axis ('X', x_min, x_max, 4, 8, 'GENERAL')
call qp_set_box (1, 1, 1, 1)
call qp_calc_and_set_axis ('Y', minval(wz), maxval(wz), 4, 8, 'GENERAL')
call qp_draw_axes (x_axis_str, what_str)
call qp_draw_axes (x_axis_str, trim(y_label) // '_z')

call qp_draw_data (x_axis, wz, .true., 0)

!

else
call qp_calc_and_set_axis ('X', plot_min, plot_max, 4, 8, 'ZERO_AT_END')
call qp_calc_and_set_axis ('X', x_min, x_max, 4, 8, 'GENERAL')

call qp_set_box (1, 3, 1, 3)
call qp_calc_and_set_axis ('Y', minval(wx), maxval(wx), 4, 8, 'GENERAL')
call qp_draw_axes (x_axis_str, what_str)
call qp_draw_axes (x_axis_str, trim(y_label) // '_x')

call qp_draw_data (x_axis, wx, .true., 0)

!

call qp_set_box (1, 2, 1, 3)
call qp_calc_and_set_axis ('Y', minval(wy), maxval(wy), 4, 8, 'GENERAL')
call qp_draw_axes (x_axis_str, what_str)
call qp_draw_axes (x_axis_str, trim(y_label) // '_y')

call qp_draw_data (x_axis, wy, .true., 0)

!

call qp_set_box (1, 1, 1, 3)
call qp_calc_and_set_axis ('Y', minval(wz), maxval(wz), 4, 8, 'GENERAL')
call qp_draw_axes (x_axis_str, what_str)
call qp_draw_axes (x_axis_str, trim(y_label) // '_z')
call qp_draw_data (x_axis, wz, .true., 0)
endif

Expand Down
Loading