Skip to content

Commit

Permalink
All clean!
Browse files Browse the repository at this point in the history
  • Loading branch information
giadarol committed Nov 10, 2021
1 parent ecec57c commit 9b89881
Show file tree
Hide file tree
Showing 29 changed files with 31 additions and 1,749 deletions.
44 changes: 23 additions & 21 deletions examples/002_beambeam/000_beambeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import xtrack as xt
import xpart as xp

import xslowtrack as xst
import ducktrack as dtk

###################
# Choose context #
Expand Down Expand Up @@ -48,7 +48,7 @@

from xfields.test_support.temp_makepart import generate_particles_object
print('Generate particles b1...')
(particles_b1_pyst, r_probes, _, _, _
(particles_b1_gen, r_probes, _, _, _
) = generate_particles_object(
n_macroparticles_b1,
bunch_intensity_b1,
Expand All @@ -61,13 +61,14 @@
r_max_probes,
z_probes,
theta_probes)
particles_b1 = xp.Particles(_context=context, **particles_b1_pyst.to_dict())
# Move to context
particles_b1 = xp.Particles(_context=context, **particles_b1_gen.to_dict())

particles_b1.x += mean_x_b1
particles_b1.y += mean_y_b1

print('Generate particles b2...')
(particles_b2_pyst, r_probes, _, _, _
(particles_b2_gen, r_probes, _, _, _
) = generate_particles_object(
n_macroparticles_b2,
bunch_intensity_b2,
Expand All @@ -80,7 +81,8 @@
r_max_probes,
z_probes,
theta_probes)
particles_b2 = xp.Particles(_context=context, **particles_b2_pyst.to_dict())
# Move to context
particles_b2 = xp.Particles(_context=context, **particles_b2_gen.to_dict())

particles_b2.x += mean_x_b2
particles_b2.y += mean_y_b2
Expand All @@ -95,7 +97,7 @@
_context=context,
n_particles=bunch_intensity_b2,
q0 = particles_b2.q0,
beta0=particles_b2_pyst.beta0[0],
beta0=particles_b2_gen.beta0[0],
sigma_x=None, # needs to be specified only for weak-strong
sigma_y=None, # needs to be specified only for weak-strong
mean_x=None, # needs to be specified only for weak-strong
Expand All @@ -106,7 +108,7 @@
_context=context,
n_particles=bunch_intensity_b1,
q0 = particles_b1.q0,
beta0=particles_b1_pyst.beta0[0],
beta0=particles_b1_gen.beta0[0],
sigma_x=None, # needs to be specified only for weak-strong
sigma_y=None, # needs to be specified only for weak-strong
mean_x=None, # needs to be specified only for weak-strong
Expand All @@ -123,48 +125,48 @@
print('Track...')
bbeam_b1.track(particles_b1)

#########################
# Compare against xline #
#########################
#############################
# Compare against ducktrack #
#############################

print('Check against xline...')
print('Check against ducktrack...')
p2np = context.nparray_from_context_array
x_probes = p2np(particles_b1.x[:n_probes])
y_probes = p2np(particles_b1.y[:n_probes])
z_probes = p2np(particles_b1.zeta[:n_probes])

bb_b1_pyst= xst.BeamBeam4D(
bb_b1_dtk= dtk.BeamBeam4D(
charge = bunch_intensity_b2,
sigma_x=sigma_x_b2,
sigma_y=sigma_y_b2,
x_bb=mean_x_b2,
y_bb=mean_y_b2,
beta_r=np.float64(particles_b2_pyst.beta0)[0])
beta_r=np.float64(particles_b2_gen.beta0)[0])

p_pyst = xst.TestParticles(p0c=p0c,
p_dtk = dtk.TestParticles(p0c=p0c,
mass=mass,
x=x_probes.copy(),
y=y_probes.copy(),
zeta=z_probes.copy())

bb_b1_pyst.track(p_pyst)
bb_b1_dtk.track(p_dtk)

assert np.allclose(p_pyst.px,
assert np.allclose(p_dtk.px,
p2np(particles_b1.px[:n_probes]),
atol=2e-2*np.max(np.abs(p_pyst.px)))
assert np.allclose(p_pyst.py,
atol=2e-2*np.max(np.abs(p_dtk.px)))
assert np.allclose(p_dtk.py,
p2np(particles_b1.py[:n_probes]),
atol=2e-2*np.max(np.abs(p_pyst.px)))
atol=2e-2*np.max(np.abs(p_dtk.px)))

import matplotlib.pyplot as plt
plt.close('all')
plt.figure()
plt.subplot(211)
plt.plot(r_probes, p_pyst.px, color='red')
plt.plot(r_probes, p_dtk.px, color='red')
plt.plot(r_probes, p2np(particles_b1.px[:n_probes]), color='blue',
linestyle='--')
plt.subplot(212)
plt.plot(r_probes, p_pyst.py, color='red')
plt.plot(r_probes, p_dtk.py, color='red')
plt.plot(r_probes, p2np(particles_b1.py[:n_probes]), color='blue',
linestyle='--')

Expand Down
16 changes: 8 additions & 8 deletions examples/002_beambeam/001_beambeam3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import xfields as xf
import xpart as xp

import xslowtrack as xst
import ducktrack as dtk

context = xo.ContextCpu()

Expand Down Expand Up @@ -74,7 +74,7 @@
d_zeta=0.019
d_delta=3e-4

bb_pyst = xst.elements.BeamBeam6D(
bb_dtk = dtk.elements.BeamBeam6D(
phi=phi, alpha=alpha,
x_bb_co=x_bb_co,
y_bb_co=y_bb_co,
Expand Down Expand Up @@ -104,9 +104,9 @@
d_delta=d_delta
)

bb = xf.BeamBeamBiGaussian3D(old_interface=bb_pyst.to_dict(), _context=context)
bb = xf.BeamBeamBiGaussian3D(old_interface=bb_dtk.to_dict(), _context=context)

pyst_part = xst.TestParticles(
dtk_part = dtk.TestParticles(
p0c=6500e9,
x=-1.23e-3,
px = 50e-3,
Expand All @@ -115,18 +115,18 @@
sigma = 3.,
delta = 2e-4)

part= xp.Particles(_context=context, **pyst_part.to_dict())
part= xp.Particles(_context=context, **dtk_part.to_dict())

bb.track(part)
print('------------------------')

bb_pyst.track(pyst_part)
bb_dtk.track(dtk_part)

for cc in 'x px y py zeta delta'.split():
val_test = getattr(part, cc)[0]
val_ref = getattr(pyst_part, cc)
val_ref = getattr(dtk_part, cc)
print('\n')
print(f'xline: {cc} = {val_ref:.12e}')
print(f'ducktrack: {cc} = {val_ref:.12e}')
print(f'xsuite: {cc} = {val_test:.12e}')
assert np.isclose(val_test, val_ref, rtol=1e-11, atol=5e-12)

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9b89881

Please sign in to comment.