Skip to content

Commit

Permalink
lower level rf cavity kernels, new structs, const file
Browse files Browse the repository at this point in the history
  • Loading branch information
GavinH2024 committed Jul 25, 2024
1 parent 3ae971d commit 5342c69
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 10 deletions.
8 changes: 0 additions & 8 deletions src/BeamTracking.jl

This file was deleted.

38 changes: 38 additions & 0 deletions src/low_level/apply_energy_kick.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using CUDA, BenchmarkTools
include("structures.jl"); include("sqrt_one.jl");

function apply_energy_kick!(dE, p_in, int)
"""Changes the energy of a particle by dE."""
z, pz, p0c, mc2 = p_in.z, p_in.pz, p_in.p0c, p_in.mc2

beta, E, E_old, pc = int.beta, int.E, int.E_old, int.pc

index = (blockIdx().x - Int32(1)) * blockDim().x + threadIdx().x
stride = blockDim().x * gridDim().x

i = index

while i <= length(z)

@inbounds ( pc[i] = (1 + pz[i]) * p0c[i];
beta[i]= (1+pz[i]) * p0c[i] / sqrt(((1+pz[i])*p0c[i])^2 + mc2[i]^2);
E_old[i] = pc[i] / beta[i]; # E_old

E[i] = E_old[i] + dE;

pz[i] += (1 + pz[i]) * sqrt_one((2*E_old[i]*dE + dE^2)/pc[i]^2);
pc[i] = p0c[i] * (1 + pz[i]);
z[i] /= beta[i];
beta[i] = pc[i] / E[i] ; # beta_new
z[i] *= beta[i]; )

i += stride

end
return nothing
end





3 changes: 3 additions & 0 deletions src/low_level/constants.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# constant values

const c_0 = 2.99792458e8
2 changes: 1 addition & 1 deletion src/low_level/int_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ a quadrupole with zeros to avoid dynamic memory allocation;
change element count as needed."""
global x_ele, px_ele, y_ele, S, C,
beta, beta0, e_tot, evaluation, dz, sqrt_k, sk_l, sx, a11,
a12, a21, c1, c2, c3, b1, rel_p = (CUDA.fill(0.0, elements) for item = 1:21)
a12, a21, c1, c2, c3, rel_p = (fill(0.0, elements) for item = 1:21)

return nothing
end
Expand Down
24 changes: 24 additions & 0 deletions src/low_level/particle_rf_time.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using CUDA, BenchmarkTools
include("structures.jl"); include("constants.jl");


function particle_rf_time(p)
"""Returns rf time of Particle p."""
beta, time = p.beta, p.time

z, pz, p0c, mc2 = p.z, p.pz, p.p0c, p.mc2

index = (blockIdx().x - Int32(1)) * blockDim().x + threadIdx().x
stride = blockDim().x * gridDim().x

i = index

while i <= length(z)

@inbounds ( beta[i] = (1+pz[i]) * p0c[i] / sqrt(((1+pz[i])*p0c[i])^2 + mc2[i]^2);
time[i] = -z[i] / (beta[i] * c_0); )

i += stride
end
return nothing
end
18 changes: 17 additions & 1 deletion src/low_level/structures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ struct int_quad{T}
c1::T
c2::T
c3::T
b1::T
rel_p::T
beta::T
beta0::T
Expand All @@ -116,9 +115,26 @@ struct int_sextupole{T}
dz::T
end

struct rf_time{T}
z::T
pz::T
p0c::T
mc2::Float64
beta::T
time::T
end

struct energy_kick{T}
beta::T
E::T
E_old::T
pc::T
end

"""adapting structs to bitstype"""
Adapt.@adapt_structure particle; Adapt.@adapt_structure drift; Adapt.@adapt_structure offset_and_tilt;
Adapt.@adapt_structure z_correction; Adapt.@adapt_structure quad_calc_input; Adapt.@adapt_structure quad_and_sextupole;
Adapt.@adapt_structure int_drift; Adapt.@adapt_structure int_set; Adapt.@adapt_structure int_unset;
Adapt.@adapt_structure int_z_correction; Adapt.@adapt_structure int_quad; Adapt.@adapt_structure int_sextupole;
Adapt.@adapt_structure rf_time; Adapt.@adapt_structure energy_kick;

0 comments on commit 5342c69

Please sign in to comment.