Astra Generator¶
Particle generation
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 AstraGenerator
import os
from astra import AstraGenerator
import os
Point to template input file:
In [3]:
Copied!
GENERATOR_IN = 'templates/dcgun/generator.in'
GENERATOR_IN = 'templates/dcgun/generator.in'
Make generator object:
In [4]:
Copied!
G = AstraGenerator(input_file=GENERATOR_IN)
G.input
G = AstraGenerator(input_file=GENERATOR_IN)
G.input
Out[4]:
{'fname': 'generator.part', 'add': False, 'n_add': 0, 'ipart': 2000, 'species': 'electrons', 'probe': True, 'noise_reduc': True, 'cathode': True, 'q_total': 0.1, 'ref_zpos': 0, 'ref_clock': 0, 'ref_ekin': 1e-06, 'high_res': True, 'dist_x': 'r', 'sig_x': 0.25, 'c_sig_x': 5, 'dist_px': 'g', 'sig_px': 357.7, 'c_sig_px': 5, 'cor_px': 0, 'dist_y': 'r', 'sig_y': 0.25, 'c_sig_y': 5, 'dist_py': 'g', 'sig_py': 357.7, 'cor_py': 0, 'dist_z': 'g', 'sig_clock': 0.00849257, 'c_sig_clock': 3, 'dist_pz': 'g', 'sig_ekin': 0.0005, 'c_sig_ekin': 5}
Look at its input:
In [5]:
Copied!
G.input
G.input
Out[5]:
{'fname': 'generator.part', 'add': False, 'n_add': 0, 'ipart': 2000, 'species': 'electrons', 'probe': True, 'noise_reduc': True, 'cathode': True, 'q_total': 0.1, 'ref_zpos': 0, 'ref_clock': 0, 'ref_ekin': 1e-06, 'high_res': True, 'dist_x': 'r', 'sig_x': 0.25, 'c_sig_x': 5, 'dist_px': 'g', 'sig_px': 357.7, 'c_sig_px': 5, 'cor_px': 0, 'dist_y': 'r', 'sig_y': 0.25, 'c_sig_y': 5, 'dist_py': 'g', 'sig_py': 357.7, 'cor_py': 0, 'dist_z': 'g', 'sig_clock': 0.00849257, 'c_sig_clock': 3, 'dist_pz': 'g', 'sig_ekin': 0.0005, 'c_sig_ekin': 5}
Change some input:
In [6]:
Copied!
G.input['ipart']= 999
G.input['ipart']= 999
Run:
In [7]:
Copied!
G.verbose=True
G.run()
G.verbose=True
G.run()
-------------------------------------------------------------------------- generator Version 1.0 - macOS 64bit - Intel DESY, Hamburg 2002 Wed Aug 2 08:48:37 Working File is: generator.in Initializing 999 electrons including 6 probe particles at standard positions Particles start from a cathode Particles are quasi randomly distributed WARNING: Values could not be reached: Energy spread too high. 23 times standard correction procedure Final check: Particles taken into account N = 999 total charge Q = -0.1000 nC horizontal beam position x = -7.8510E-07 mm vertical beam position y = 6.2144E-06 mm longitudinal beam position z = 0.000 m horizontal beam size sig x = 0.2500 mm vertical beam size sig y = 0.2500 mm longitudinal beam size sig z = 0.000 mm total emission time t = 5.0872E-02 ns rms emission time sig t = 8.4198E-03 ns average kinetic energy E = 1.0189E-06 MeV energy spread dE = 4.2521E-04 keV average momentum P = 1.0205E-03 MeV/c transverse beam emittance eps x = 0.1736 pi mrad mm correlated divergence cor x = 4.4093E-02 mrad transverse beam emittance eps y = 0.1750 pi mrad mm correlated divergence cor y = 1.9513E-03 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 = 0.9922 phase-space distribution saved to file: generator.part Generator ended with 1 warning(s)
Output is parsed as a ParticleGroup
:
In [8]:
Copied!
P = G.output['particles']
P = G.output['particles']
In [9]:
Copied!
P.plot('x', 'y', figsize=(6,6))
P.plot('x', 'y', figsize=(6,6))
In [10]:
Copied!
P.plot('t', 'pz', figsize=(6,6))
P.plot('t', 'pz', figsize=(6,6))
The input can be archived:
In [11]:
Copied!
afile = G.archive()
afile = G.archive()
Archiving to file astra_generator_3edf607ef3e76f2846cd471aed6be637.h5
In [12]:
Copied!
G2 = AstraGenerator.from_archive(afile)
G2 = AstraGenerator.from_archive(afile)
Check that the fingerprint is the same:
In [13]:
Copied!
G2.fingerprint() == G.fingerprint()
G2.fingerprint() == G.fingerprint()
Out[13]:
True