TWS: Traveling Wave Structure¶
TWS are defined by special fieldmaps
In [1]:
Copied!
# Useful for debugging
%load_ext autoreload
%autoreload 2
# Useful for debugging
%load_ext autoreload
%autoreload 2
In [2]:
Copied!
%pylab --no-import-all inline
%config InlineBackend.figure_format = 'retina'
%pylab --no-import-all inline
%config InlineBackend.figure_format = 'retina'
%pylab is deprecated, use %matplotlib inline and import the required libraries. Populating the interactive namespace from numpy and matplotlib
In [3]:
Copied!
from astra import Astra, AstraGenerator
from astra.fieldmaps import expand_tws_fmap
import os
from astra import Astra, AstraGenerator
from astra.fieldmaps import expand_tws_fmap
import os
In [4]:
Copied!
# Input template file
ASTRA_IN = '../templates/tws/astra.in'
GENERATOR_IN = '../templates/tws/generator.in'
# Input template file
ASTRA_IN = '../templates/tws/astra.in'
GENERATOR_IN = '../templates/tws/generator.in'
In [5]:
Copied!
G = AstraGenerator(GENERATOR_IN)
G.run()
P0 = G.output['particles']
G = AstraGenerator(GENERATOR_IN)
G.run()
P0 = G.output['particles']
In [6]:
Copied!
# Make an Astra object
A = Astra(input_file=ASTRA_IN, initial_particles = P0, verbose=True)
# Turn off space charge for this example
A.input['charge']['lspch'] = False
# This has a TWS cavity
A.input['cavity']
# Make an Astra object
A = Astra(input_file=ASTRA_IN, initial_particles = P0, verbose=True)
# Turn off space charge for this example
A.input['charge']['lspch'] = False
# This has a TWS cavity
A.input['cavity']
Configured to run in: /var/folders/2f/l5_mybzs30j4qqvyj98w1_nw0000gn/T/tmp1xvos8w4
Out[6]:
{'lefield': True, 'file_efield(1)': '/Users/chrisonian/Code/GitHub/lume-astra/docs/examples/templates/tws/sonde_ideal_SF_100.dat', 'nue(1)': 2.99855, 'maxe(1)': 80, 'phi(1)': 0, 'c_pos(1)': 0, 'c_smooth(1)': 0, 'file_efield(2)': '/Users/chrisonian/Code/GitHub/lume-astra/docs/examples/templates/tws/tws.dat', 'nue(2)': 2.99855, 'maxe(2)': 14, 'phi(2)': 0, 'c_pos(2)': 1.528, 'c_smooth(2)': 0, 'c_numb(2)': 135}
In [7]:
Copied!
# This is the fieldmap
A.load_fieldmaps()
fmap = A.fieldmap['tws.dat']
# Attributes
fmap['attrs']
# This is the fieldmap
A.load_fieldmaps()
fmap = A.fieldmap['tws.dat']
# Attributes
fmap['attrs']
Loading fieldmap file /Users/chrisonian/Code/GitHub/lume-astra/docs/examples/templates/tws/sonde_ideal_SF_100.dat Loading fieldmap file /Users/chrisonian/Code/GitHub/lume-astra/docs/examples/templates/tws/tws.dat Loading fieldmap file /Users/chrisonian/Code/GitHub/lume-astra/docs/examples/templates/tws/B3CV_23cm_sstilt.dat
Out[7]:
{'type': 'astra_tws', 'z1': 0.0463882, 'z2': 0.146368, 'n': 1, 'm': 3}
In [8]:
Copied!
# Actual data
fmap['data'].shape
# Actual data
fmap['data'].shape
Out[8]:
(101, 2)
In [9]:
Copied!
# This expands the data for 6 cells
zfull, Ezfull = expand_tws_fmap(fmap, 6)
plt.plot(zfull, Ezfull)
# This expands the data for 6 cells
zfull, Ezfull = expand_tws_fmap(fmap, 6)
plt.plot(zfull, Ezfull)
Out[9]:
[<matplotlib.lines.Line2D at 0x12e7dfac0>]
In [10]:
Copied!
# Run
A.run()
# Run
A.run()
Initial particles written to /var/folders/2f/l5_mybzs30j4qqvyj98w1_nw0000gn/T/tmp1xvos8w4/astra.particles 3 fieldmaps written to /var/folders/2f/l5_mybzs30j4qqvyj98w1_nw0000gn/T/tmp1xvos8w4 -------------------------------------------------------------------------- Astra- A space charge tracking algorithm Version 4.0 - macOS 64bit - Apple Silicon DESY, Hamburg 2022 Wed Aug 2 08:48:56 Parameter file is: astra.in TEST - LINAC - LIL Initialize element settings: neglecting space charge forces -------------------------------------------------------------------------- Cavity: Reading cavity field data from: sonde_ideal_SF_100.dat Cavity Frequency f = 2.999 GHz maximum gradient 80.00 MV/m at 5.4000E-02 m estimated average gradient 27.46 MV/m nominal phase 0.000 deg Reading cavity field data from: tws.dat Cavity Frequency f = 2.999 GHz beta = 1 traveling wave structure TW Cell Length 3.3327E-02 m Number of Cells 135 Phase Advance/Cell 120.0 deg TW Section starts at 1.528 m TW Section ends at 6.120 m Max E-field 14.00 MV/m at 1.675 m nominal phase 0.000 deg -------------------------------------------------------------------------- Solenoid: Reading solenoid field data from: B3CV_23cm_sstilt.dat maximum |Bz| field 0.2500 T at 0.2040 m integral Bz squared 8.0805E-03 T^2m -------------------------------------------------------------------------- 1000 particles from file astra.particles Cathode located at: z = 0.000 m Particles taken into account N = 1000 total charge Q = -1.000 nC horizontal beam position x = 1.0140E-04 mm vertical beam position y = 7.4847E-05 mm longitudinal beam position z = 0.000 m horizontal beam size sig x = 0.5185 mm vertical beam size sig y = 0.5156 mm longitudinal beam size sig z = 0.000 mm total emission time t = 1.2621E-02 ns rms emission time sig t = 1.9926E-03 ns average kinetic energy E = 9.9997E-04 MeV energy spread dE = 3.8783E-03 keV average momentum P = 3.1984E-02 MeV/c transverse beam emittance eps x = 18.69 pi mrad mm correlated divergence cor x = -3.2908E-02 mrad transverse beam emittance eps y = 18.61 pi mrad mm correlated divergence cor y = 2.3856E-02 mrad longitudinal beam emittance eps z = 0.000 pi keV mm correlated energy spread cor z = 0.000 keV emittance ratio eps y/eps x = 1.004 WARNING: Bz is not zero at the cathode, estimated emittance contribution: eps x = 2.8776E-02 pi mrad mm eps y = 2.8458E-02 pi mrad mm -------------------------------------------------------------------------- Start auto phasing: Scan cavity number : 1 6 unstable trajectories out of 50 Scan cavity number : 2 0 unstable trajectories out of 50 Cavity phasing completed: Cavity number Energy gain [MeV] at Phase [deg] 1 5.380 46.221 2 46.34 306.08 -------------------------------------------------------------------------- on axis tracking of the reference particle: initial position z = 0.000 m x = 1.0140E-04 mm y = 7.4847E-05 mm initial momentum p = 1.6038E-02 MeV/c global phase shift phi = 0.000 deg time step for integration dt = 1.000 ps -------------------------------------------------------------------------- Online element settings: -------------------------------------------------------------------------- particle reaches position z = 6.200 m time of flight is t = 20.73 ns final momentum p = 52.23 MeV/c final phase (cavity 1) phi_end = 101.2 deg -------------------------------------------------------------------------- off axis tracking of the reference particle: initial position z = 0.000 m x = 0.5186 mm y = 0.5157 mm final position x = 1.831 mm y = -2.459 mm divergence px/pz = 0.3674 mrad py/pz = -0.4938 mrad -------------------------------------------------------------------------- tracking of 1000 particles: tracking will stop at z = 6.200 m final checkpoint at z = 6.200 m total number of iteration steps: 22023 ********************************************************************** Particles taken into account N = 1000 total charge Q = -1.000 nC horizontal beam position x = 6.3567E-04 mm vertical beam position y = -8.9888E-04 mm longitudinal beam position z = 6.200 m horizontal beam size sig x = 2.534 mm vertical beam size sig y = 2.533 mm longitudinal beam size sig z = 0.5271 mm average kinetic energy E = 51.69 MeV energy spread dE = 40.76 keV average momentum P = 52.20 MeV/c transverse beam emittance eps x = 18.69 pi mrad mm correlated divergence cor x = 0.5528 mrad transverse beam emittance eps y = 18.72 pi mrad mm correlated divergence cor y = 0.5524 mrad longitudinal beam emittance eps z = 21.00 pi keV mm correlated energy spread cor z = 8.603 keV emittance ratio eps y/eps x = 0.9983 Particle Statistics: Total number of particles on stack = 1000 Electrons (total) = 1000 particles at the cathode = 0 active particles = 1000 passive particles (lost out of bunch) = 0 probe particles = 6 backward traveling particles = 0 particles lost with z<Zmin = 0 particles lost due to cathode field = 0 particles lost on aperture = 0 Tracking ended with 1 warning(s) ********************************************************************** 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 Phase-space distributions logged in : astra.Log.001 ********************************************************************** finished simulation Wed Aug 2 08:49:03 2023 elapsed time : 7.0 seconds execution time : 7.0 seconds system time : 0.1 seconds Goodbye. -------------------------------------------------------------------------- loading 32 particle files [20.0, 41.0, 61.0, 82.0, 102.0, 120.0, 123.0, 143.0, 164.0, 184.0, 205.0, 225.0, 246.0, 266.0, 286.0, 307.0, 327.0, 348.0, 368.0, 389.0, 409.0, 430.0, 450.0, 471.0, 491.0, 511.0, 532.0, 552.0, 573.0, 593.0, 614.0, 620.0] {'start_time': 1690991336.888692, 'run_script': '/Users/chrisonian/Code/Astra/bin/Astra astra.in', 'run_time': 7.116514205932617}
In [11]:
Copied!
A.plot(y=['sigma_x', 'sigma_y'], y2='mean_kinetic_energy', xlim=(0,8), figsize=(16,9))
A.plot(y=['sigma_x', 'sigma_y'], y2='mean_kinetic_energy', xlim=(0,8), figsize=(16,9))
In [12]:
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')