Drift¶
In [1]:
Copied!
# Useful for debugging
%load_ext autoreload
%autoreload 2
# Useful for debugging
%load_ext autoreload
%autoreload 2
In [2]:
Copied!
from astra import Astra
from distgen import Generator
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['figure.figsize'] = (13,8)
%config InlineBackend.figure_format = 'retina'
import os
from astra import Astra
from distgen import Generator
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['figure.figsize'] = (13,8)
%config InlineBackend.figure_format = 'retina'
import os
In [3]:
Copied!
# Input template file
ASTRA_IN = '../templates/drift/astra.in'
DISTGEN_IN = '../templates/drift/distgen.yaml'
# Input template file
ASTRA_IN = '../templates/drift/astra.in'
DISTGEN_IN = '../templates/drift/distgen.yaml'
In [4]:
Copied!
G = Generator(DISTGEN_IN)
G["n_particle"] = 10_000
G.run()
P0 = G.particles
P0
G = Generator(DISTGEN_IN)
G["n_particle"] = 10_000
G.run()
P0 = G.particles
P0
Out[4]:
<ParticleGroup with 10000 particles at 0x10418ddc0>
In [5]:
Copied!
# Make an Astra object
A = Astra(input_file=ASTRA_IN, initial_particles=P0, verbose=True)
# Make an Astra object
A = Astra(input_file=ASTRA_IN, initial_particles=P0, verbose=True)
Configured to run in: /var/folders/2f/l5_mybzs30j4qqvyj98w1_nw0000gn/T/tmp4tffa6s5
In [6]:
Copied!
# Run
A.run()
# Run
A.run()
Initial particles written to /var/folders/2f/l5_mybzs30j4qqvyj98w1_nw0000gn/T/tmp4tffa6s5/astra.particles
--------------------------------------------------------------------------
Astra- A space charge tracking algorithm
Version 4.0 - macOS 64bit - Apple Silicon
DESY, Hamburg 2022
Wed Aug 2 08:50:14
Parameter file is: astra.in
Drift example
Initialize element settings:
--------------------------------------------------------------------------
10001 particles from file astra.particles
Particles taken into account N = 10001
total charge Q = -1.000 nC
horizontal beam position x = 9.1954E-16 mm
vertical beam position y = -6.4483E-16 mm
longitudinal beam position z = 1.3014E-19 m
horizontal beam size sig x = 1.000 mm
vertical beam size sig y = 1.000 mm
longitudinal beam size sig z = 0.1000 mm
average kinetic energy E = 9.502 MeV
energy spread dE = 1.7224E-09 keV
average momentum P = 10.00 MeV/c
transverse beam emittance eps x = 0.000 pi mrad mm
correlated divergence cor x = 0.000 mrad
transverse beam emittance eps y = 0.000 pi mrad mm
correlated divergence cor y = 0.000 mrad
longitudinal beam emittance eps z = 1.7247E-10 pi keV mm
correlated energy spread cor z = 3.9171E-26 keV
emittance ratio eps y/eps x = 0.000
--------------------------------------------------------------------------
Start auto phasing:
--------------------------------------------------------------------------
Start phase scan:
Cavity phasing completed:
Cavity number Energy gain [MeV] at Phase [deg]
--------------------------------------------------------------------------
on axis tracking of the reference particle:
initial position z = 1.8735E-21 m
x = 0.000 mm
y = 0.000 mm
initial momentum p = 10.00 MeV/c
global phase shift phi = 0.000 deg
time step for integration dt = 7.500 ps
--------------------------------------------------------------------------
Online element settings:
--------------------------------------------------------------------------
particle reaches position z = 1.000 m
time of flight is t = 3.340 ns
final momentum p = 10.00 MeV/c
final phase (cavity 1) phi_end = 0.000 deg
--------------------------------------------------------------------------
off axis tracking of the reference particle:
initial position z = 1.8735E-21 m
x = 1.000 mm
y = 1.000 mm
final position x = 1.000 mm
y = 1.000 mm
divergence px/pz = 0.000 mrad
py/pz = 0.000 mrad
--------------------------------------------------------------------------
tracking of 10001 particles:
tracking will stop at z = 1.000 m
space charge forces are INCLUDED
3D FFT algorithm
final checkpoint at z = 1.000 m
total number of iteration steps: 544
**********************************************************************
Particles taken into account N = 10001
total charge Q = -1.000 nC
horizontal beam position x = -1.4417E-04 mm
vertical beam position y = 7.4455E-05 mm
longitudinal beam position z = 1.000 m
horizontal beam size sig x = 2.076 mm
vertical beam size sig y = 2.075 mm
longitudinal beam size sig z = 0.1466 mm
average kinetic energy E = 9.515 MeV
energy spread dE = 311.4 keV
average momentum P = 10.01 MeV/c
transverse beam emittance eps x = 12.38 pi mrad mm
correlated divergence cor x = 1.797 mrad
transverse beam emittance eps y = 12.43 pi mrad mm
correlated divergence cor y = 1.797 mrad
longitudinal beam emittance eps z = 10.93 pi keV mm
correlated energy spread cor z = 302.3 keV
emittance ratio eps y/eps x = 0.9957
Particle Statistics:
Total number of particles on stack = 10001
Electrons (total) = 10001
particles at the cathode = 0
active particles = 10001
passive particles (lost out of bunch) = 0
probe particles = 0
backward traveling particles = 0
particles lost with z<Zmin = 0
particles lost due to cathode field = 0
particles lost on aperture = 0
**********************************************************************
Emittance information saved to file : astra.Xemit.001
Emittance information saved to file : astra.Yemit.001
Emittance information saved to file : astra.Zemit.001
Lost & found saved to file : astra.LandF.001
Ref. part. information saved to file : astra.ref.001
Phase-space distributions logged in : astra.Log.001
Phase scan saved to file : astra.PScan.001
Core emittance data saved to file : astra.Cemit.001
**********************************************************************
finished simulation Wed Aug 2 08:50:19 2023
elapsed time : 5.6 seconds
execution time : 5.5 seconds
system time : 0.0 seconds
Goodbye.
--------------------------------------------------------------------------
loading 1 particle files
[100.0]
{'start_time': 1690991414.116042, 'run_script': '/Users/chrisonian/Code/Astra/bin/Astra astra.in', 'run_time': 5.663373231887817}
Note: The following floating-point exceptions are signalling: IEEE_DIVIDE_BY_ZERO
In [7]:
Copied!
P = A.particles[-1]
P.plot('x', 'px')
P.plot('z', 'pz')
P = A.particles[-1]
P.plot('x', 'px')
P.plot('z', 'pz')
3D¶
In [8]:
Copied!
A2 = A.copy()
A2.input['charge']['lspch'] = True
A2.input['charge']['lspch3d'] = True
A2.input['charge']['l2d_3d'] = False
A2.input['charge']['nxf'] = 32
A2.input['charge']['nyf'] = 32
A2.input['charge']['nzf'] = 32
A2.input['charge']['nx0'] = 4
A2.input['charge']['ny0'] = 4
A2.input['charge']['nz0'] = 4
A2.configure()
A2.run()
A2 = A.copy()
A2.input['charge']['lspch'] = True
A2.input['charge']['lspch3d'] = True
A2.input['charge']['l2d_3d'] = False
A2.input['charge']['nxf'] = 32
A2.input['charge']['nyf'] = 32
A2.input['charge']['nzf'] = 32
A2.input['charge']['nx0'] = 4
A2.input['charge']['ny0'] = 4
A2.input['charge']['nz0'] = 4
A2.configure()
A2.run()
Configured to run in: /var/folders/2f/l5_mybzs30j4qqvyj98w1_nw0000gn/T/tmp65kgsf88
Initial particles written to /var/folders/2f/l5_mybzs30j4qqvyj98w1_nw0000gn/T/tmp65kgsf88/astra.particles
--------------------------------------------------------------------------
Astra- A space charge tracking algorithm
Version 4.0 - macOS 64bit - Apple Silicon
DESY, Hamburg 2022
Wed Aug 2 08:50:20
Parameter file is: astra.in
Drift example
Initialize element settings:
--------------------------------------------------------------------------
10001 particles from file astra.particles
Particles taken into account N = 10001
total charge Q = -1.000 nC
horizontal beam position x = 9.1954E-16 mm
vertical beam position y = -6.4483E-16 mm
longitudinal beam position z = 1.3014E-19 m
horizontal beam size sig x = 1.000 mm
vertical beam size sig y = 1.000 mm
longitudinal beam size sig z = 0.1000 mm
average kinetic energy E = 9.502 MeV
energy spread dE = 1.7224E-09 keV
average momentum P = 10.00 MeV/c
transverse beam emittance eps x = 0.000 pi mrad mm
correlated divergence cor x = 0.000 mrad
transverse beam emittance eps y = 0.000 pi mrad mm
correlated divergence cor y = 0.000 mrad
longitudinal beam emittance eps z = 1.7247E-10 pi keV mm
correlated energy spread cor z = 3.9171E-26 keV
emittance ratio eps y/eps x = 0.000
--------------------------------------------------------------------------
Start auto phasing:
--------------------------------------------------------------------------
Start phase scan:
Cavity phasing completed:
Cavity number Energy gain [MeV] at Phase [deg]
--------------------------------------------------------------------------
on axis tracking of the reference particle:
initial position z = 1.8735E-21 m
x = 0.000 mm
y = 0.000 mm
initial momentum p = 10.00 MeV/c
global phase shift phi = 0.000 deg
time step for integration dt = 7.500 ps
--------------------------------------------------------------------------
Online element settings:
--------------------------------------------------------------------------
particle reaches position z = 1.000 m
time of flight is t = 3.340 ns
final momentum p = 10.00 MeV/c
final phase (cavity 1) phi_end = 0.000 deg
--------------------------------------------------------------------------
off axis tracking of the reference particle:
initial position z = 1.8735E-21 m
x = 1.000 mm
y = 1.000 mm
final position x = 1.000 mm
y = 1.000 mm
divergence px/pz = 0.000 mrad
py/pz = 0.000 mrad
--------------------------------------------------------------------------
tracking of 10001 particles:
tracking will stop at z = 1.000 m
space charge forces are INCLUDED
3D FFT algorithm
final checkpoint at z = 1.000 m
total number of iteration steps: 549
**********************************************************************
Particles taken into account N = 10001
total charge Q = -1.000 nC
horizontal beam position x = 6.0368E-05 mm
vertical beam position y = 7.4282E-05 mm
longitudinal beam position z = 1.000 m
horizontal beam size sig x = 2.068 mm
vertical beam size sig y = 2.067 mm
longitudinal beam size sig z = 0.1463 mm
average kinetic energy E = 9.515 MeV
energy spread dE = 309.8 keV
average momentum P = 10.01 MeV/c
transverse beam emittance eps x = 12.36 pi mrad mm
correlated divergence cor x = 1.788 mrad
transverse beam emittance eps y = 12.41 pi mrad mm
correlated divergence cor y = 1.787 mrad
longitudinal beam emittance eps z = 10.90 pi keV mm
correlated energy spread cor z = 300.7 keV
emittance ratio eps y/eps x = 0.9959
Particle Statistics:
Total number of particles on stack = 10001
Electrons (total) = 10001
particles at the cathode = 0
active particles = 10001
passive particles (lost out of bunch) = 0
probe particles = 0
backward traveling particles = 0
particles lost with z<Zmin = 0
particles lost due to cathode field = 0
particles lost on aperture = 0
**********************************************************************
Emittance information saved to file : astra.Xemit.001
Emittance information saved to file : astra.Yemit.001
Emittance information saved to file : astra.Zemit.001
Lost & found saved to file : astra.LandF.001
Ref. part. information saved to file : astra.ref.001
Phase-space distributions logged in : astra.Log.001
Phase scan saved to file : astra.PScan.001
Core emittance data saved to file : astra.Cemit.001
**********************************************************************
finished simulation Wed Aug 2 08:50:26 2023
elapsed time : 5.5 seconds
execution time : 5.5 seconds
system time : 0.0 seconds
Goodbye.
--------------------------------------------------------------------------
loading 1 particle files
[100.0]
{'start_time': 1690991420.61433, 'run_script': '/Users/chrisonian/Code/Astra/bin/Astra astra.in', 'run_time': 5.618848085403442}
Note: The following floating-point exceptions are signalling: IEEE_DIVIDE_BY_ZERO
In [9]:
Copied!
P2 = A2.particles[-1]
P2.plot('x', 'px')
P2 = A2.particles[-1]
P2.plot('x', 'px')
In [10]:
Copied!
k1 = 'z'
k2 = 'x'
skip = 10
plt.scatter(P[k1][::skip], P[k2][::skip], label='2d', marker='x', alpha=0.5)
plt.scatter(P2[k1][::skip], P2[k2][::skip], label='3d', marker='.', alpha=0.5)
plt.legend()
k1 = 'z'
k2 = 'x'
skip = 10
plt.scatter(P[k1][::skip], P[k2][::skip], label='2d', marker='x', alpha=0.5)
plt.scatter(P2[k1][::skip], P2[k2][::skip], label='3d', marker='.', alpha=0.5)
plt.legend()
Out[10]:
<matplotlib.legend.Legend at 0x156cadb50>
In [11]:
Copied!
k1 = 'x'
k2 = 'px'
skip = 1
plt.scatter(P[k1][::skip], P[k2][::skip], label='2d', marker='x', alpha=0.5)
plt.scatter(P2[k1][::skip], P2[k2][::skip], label='3d', marker='.', alpha=0.5)
plt.legend()
k1 = 'x'
k2 = 'px'
skip = 1
plt.scatter(P[k1][::skip], P[k2][::skip], label='2d', marker='x', alpha=0.5)
plt.scatter(P2[k1][::skip], P2[k2][::skip], label='3d', marker='.', alpha=0.5)
plt.legend()
Out[11]:
<matplotlib.legend.Legend at 0x156c7dd60>