-
Notifications
You must be signed in to change notification settings - Fork 0
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
4adef0a
commit 8d94213
Showing
2 changed files
with
39 additions
and
21 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 |
---|---|---|
@@ -1,33 +1,42 @@ | ||
using CUDA, BenchmarkTools, Adapt | ||
include("structures.jl") | ||
|
||
function offset_particle_set!(x_offset, y_offset, tilt, p_lab) | ||
Adapt.@adapt_structure GPU_Particle; Adapt.@adapt_structure Intermediate_Offset; | ||
|
||
function offset_particle_set!(x_offset, y_offset, tilt, p_lab, int) | ||
"""Transform from lab to element coords. | ||
See Bmad manual (2022-11-06) sections 5.6.1, 15.3.1 and 24.2 | ||
**NOTE**: transverse only as of now. | ||
""" | ||
|
||
(x, px, y, py, z, pz) = p_lab.r | ||
|
||
s = sin(tilt) | ||
c = cos(tilt) | ||
x_ele_int = p_lab.r[1] - x_offset | ||
y_ele_int = p_lab.r[3] - y_offset | ||
x_ele = x_ele_int*c + y_ele_int*s | ||
y_ele = -x_ele_int*s + y_ele_int*c | ||
|
||
p_lab.r[1], p_lab.r[3] = x_ele, y_ele | ||
x_ele_int, y_ele_int, x_ele, y_ele, px_ele, py_ele = int.x_ele_int, | ||
int.y_ele_int, int.x_ele, int.y_ele, int.px_ele, int.py_ele | ||
x, px, y, py = p_lab.x, p_lab.px, p_lab.y, p_lab.py | ||
|
||
index = (blockIdx().x - Float32(1)) * blockDim().x + threadIdx().x | ||
stride = gridDim().x * blockDim().x | ||
|
||
px_ele = p_lab.r[2]*c + p_lab.r[4]*s | ||
py_ele = -p_lab.r[2]*s + p_lab.r[4]*c | ||
while i <= length(x) | ||
|
||
@inbounds (s[i] = sin(tilt[i]); | ||
c[i] = cos(tilt[i]); | ||
x_ele_int[i] = x[i] - x_offset[i]; | ||
y_ele_int[i] = y[i] - y_offset[i]; | ||
x_ele[i] = x_ele_int[i]*c[i]+ y_ele_int[i]*s[i]; | ||
y_ele[i] = -x_ele_int[i]*s[i] + y_ele_int[i]*c[i]; | ||
px_ele[i] = px[i]*c[i] + py[i]*s[i]; | ||
py_ele[i] = -px[i]*s[i] + py[i]*c[i];) | ||
|
||
p_ele = p_lab | ||
p_ele.r = (x_ele, px_ele, y_ele, py_ele, z, pz) | ||
i += stride | ||
end | ||
|
||
return p_ele | ||
GPU_particles = GPU_Particle(x_ele, px_ele, y_ele, py_ele, z, pz, s, p0c, mc2) | ||
|
||
return | ||
end | ||
|
||
|
||
"""Test Value""" | ||
p_lab = Particle(1.0, 1.0, 1.0, [1.0, 0.5, 1.0, 0.2, 1.0, 0.5]) | ||
offset_particle_set!(0.01, 0.01, 0.01, p_lab) | ||
x_offset = CUDA.fill(0.01, 50000); y_offset = CUDA.fill(0.01, 50000); tilt = CUDA.fill(0.01, 50000); | ||
|
||
p_lab = GPU_Particle(x, px, y, py, z, pz, s, p0c, mc2) |
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