Example 2¶
This is adapted from https://github.com/svenreiche/Genesis-1.3-Version4/tree/master/examples/Example2-Dumps
The internal data of genesis is represented by wavefronts for the fields and the 6D particle distribution for electrons. They contain more information than the output of the main output file.
Genesis supports to export the information to external files, also called dumps.
This example will show the three methods to utilize dumps.
import matplotlib.animation as animation
import matplotlib.pyplot as plt
import numpy as np
from genesis.version4 import Genesis4
%config InlineBackend.figure_format = 'retina' # Nicer plots
Markers¶
Markers in the lattice file can trigger the output of either field or particle distribution. To enable outputting the
lattice file from Example1.lat
is modified with these lines (replacing the previous definition of the FODO cell of example 1):
M: MARKER = {dumpfield = 1};
FODO: LINE={UND,D1,QF,D2,UND,D1,QD,D2,M};
Markers are zero length element and do not add to the total length of the lattice. In this case the Marker is added to the end of the FODO cell.
With 6 cells in the full lattice there will be 6 field dumps. They are prefixed with the rootname
(as in the setup
namelist) and have the extension
.fld.h5
. To differentiate the different outputs the name has also the integration step number in between the rootname
and the extension. For example, integration step 184 would have the filename Example2.184.fld.h5
.
Dumps Outside of Tracking¶
The namelist write
in the main input file can write the field or particle distribution at any point outside of the tracking.
In this example, the input file has the write
namelist:
&write
field = dump
&end
This will write the field distribution with the name dump.fld.h5
. The extension is included automatically, so you do not specify it in the namelist.
Since Genesis has executed the tracking before, the field distribution represents the state at the end of the tracked beamline. In our case this is the end of the undulator.
Periodic Output While Tracking¶
The last method for dumping data is to define in the track
namelist the number of integration steps after which a dump is issued.
For this example, we modify it to output after every second integration step:
&track
beam_dump_step = 2
&end
In total about 600 files will be generated with this method, with the filename suffixes including the integration step number.
Note that generating dumps at each step can cause to a large number of files. In particular for time-dependent runs, the size per dump can be large (on the order of gigabytes) and generating hundreds of them may fill up your disk faster than you expect.
Running the example¶
Running Example2.in
causes the additional output when ever a dump file is generated. Also for a better illustraiton of the output, the
energy spread of the beam has been reduced to
delgam=0.100000
for a better display of the FEL process.
G = Genesis4("data/example2-dumps/Example2.in")
G.verbose = True
output = G.run()
Configured to run in: /tmp/tmprpnwxypj Running Genesis4 in /tmp/tmprpnwxypj /home/runner/miniconda3/envs/lume-genesis-dev/bin/genesis4 -l Example2.lat genesis4.in --------------------------------------------- GENESIS - Version 4.6.6 has started... Compile info: Compiled by conda at 2024-06-10 16:25:29 [UTC] from Git Commit ID: 07004e4cb437003b4b6cf024122db18caee13722 Starting Time: Thu Aug 29 16:08:48 2024 MPI-Comm Size: 1 node Opened input file genesis4.in Parsing lattice file Example2.lat ... Matching for periodic solution between z = 0 and z = 9.5 : betax (m) : 8.53711 alphax : -0.703306 phix (deg): 45.818 betay (m) : 17.3899 alphay : 1.40348 phiy (deg): 45.818 Generating input radiation field for HARM = 1 ... Generating input particle distribution... Running Core Simulation... Steady-state run Initial analysis of electron beam and radiation field... Calculation: 0% done Writing particle distribution to file: Example2.0.par.h5 ... Writing particle distribution to file: Example2.2.par.h5 ... Writing particle distribution to file: Example2.4.par.h5 ... Writing particle distribution to file: Example2.6.par.h5 ... Writing particle distribution to file: Example2.8.par.h5 ... Writing particle distribution to file: Example2.10.par.h5 ... Writing particle distribution to file: Example2.12.par.h5 ... Writing particle distribution to file: Example2.14.par.h5 ... Writing particle distribution to file: Example2.16.par.h5 ... Writing particle distribution to file: Example2.18.par.h5 ... Writing particle distribution to file: Example2.20.par.h5 ...
Writing particle distribution to file: Example2.22.par.h5 ... Writing particle distribution to file: Example2.24.par.h5 ... Writing particle distribution to file: Example2.26.par.h5 ... Writing particle distribution to file: Example2.28.par.h5 ... Writing particle distribution to file: Example2.30.par.h5 ... Writing particle distribution to file: Example2.32.par.h5 ... Writing particle distribution to file: Example2.34.par.h5 ... Writing particle distribution to file: Example2.36.par.h5 ... Writing particle distribution to file: Example2.38.par.h5 ... Writing particle distribution to file: Example2.40.par.h5 ... Writing particle distribution to file: Example2.42.par.h5 ... Writing particle distribution to file: Example2.44.par.h5 ... Writing particle distribution to file: Example2.46.par.h5 ... Writing particle distribution to file: Example2.48.par.h5 ... Writing particle distribution to file: Example2.50.par.h5 ...
Writing particle distribution to file: Example2.52.par.h5 ... Writing particle distribution to file: Example2.54.par.h5 ... Writing particle distribution to file: Example2.56.par.h5 ... Writing particle distribution to file: Example2.58.par.h5 ... Writing particle distribution to file: Example2.60.par.h5 ... Writing particle distribution to file: Example2.62.par.h5 ... Writing particle distribution to file: Example2.64.par.h5 ... Writing particle distribution to file: Example2.66.par.h5 ... Writing particle distribution to file: Example2.68.par.h5 ... Writing particle distribution to file: Example2.70.par.h5 ... Writing particle distribution to file: Example2.72.par.h5 ... Writing particle distribution to file: Example2.74.par.h5 ... Writing particle distribution to file: Example2.76.par.h5 ... Writing particle distribution to file: Example2.78.par.h5 ... Writing particle distribution to file: Example2.80.par.h5 ...
Writing particle distribution to file: Example2.82.par.h5 ... Writing particle distribution to file: Example2.84.par.h5 ... Writing particle distribution to file: Example2.86.par.h5 ... Writing particle distribution to file: Example2.88.par.h5 ... Writing particle distribution to file: Example2.90.par.h5 ... Writing particle distribution to file: Example2.92.par.h5 ... Writing particle distribution to file: Example2.94.par.h5 ... Writing particle distribution to file: Example2.96.par.h5 ... Writing particle distribution to file: Example2.98.par.h5 ... Writing particle distribution to file: Example2.100.par.h5 ... Writing particle distribution to file: Example2.102.par.h5 ... Writing particle distribution to file: Example2.104.par.h5 ... Writing particle distribution to file: Example2.106.par.h5 ... Writing particle distribution to file: Example2.108.par.h5 ... Calculation: 10% done Writing particle distribution to file: Example2.110.par.h5 ...
Writing particle distribution to file: Example2.112.par.h5 ... Writing particle distribution to file: Example2.114.par.h5 ... Writing particle distribution to file: Example2.116.par.h5 ... Writing particle distribution to file: Example2.118.par.h5 ... Writing particle distribution to file: Example2.120.par.h5 ... Writing particle distribution to file: Example2.122.par.h5 ... Writing particle distribution to file: Example2.124.par.h5 ... Writing particle distribution to file: Example2.126.par.h5 ... Writing particle distribution to file: Example2.128.par.h5 ... Writing particle distribution to file: Example2.130.par.h5 ... Writing particle distribution to file: Example2.132.par.h5 ... Writing particle distribution to file: Example2.134.par.h5 ... Writing particle distribution to file: Example2.136.par.h5 ... Writing particle distribution to file: Example2.138.par.h5 ... Writing particle distribution to file: Example2.140.par.h5 ...
Writing particle distribution to file: Example2.142.par.h5 ... Writing particle distribution to file: Example2.144.par.h5 ... Writing particle distribution to file: Example2.146.par.h5 ... Writing particle distribution to file: Example2.148.par.h5 ... Writing particle distribution to file: Example2.150.par.h5 ... Writing particle distribution to file: Example2.152.par.h5 ... Writing particle distribution to file: Example2.154.par.h5 ... Writing particle distribution to file: Example2.156.par.h5 ... Writing particle distribution to file: Example2.158.par.h5 ... Writing particle distribution to file: Example2.160.par.h5 ... Writing particle distribution to file: Example2.162.par.h5 ... Writing particle distribution to file: Example2.164.par.h5 ... Writing particle distribution to file: Example2.166.par.h5 ... Writing particle distribution to file: Example2.168.par.h5 ... Writing particle distribution to file: Example2.170.par.h5 ...
Writing particle distribution to file: Example2.172.par.h5 ... Writing particle distribution to file: Example2.174.par.h5 ... Writing particle distribution to file: Example2.176.par.h5 ... Writing particle distribution to file: Example2.178.par.h5 ... Writing particle distribution to file: Example2.180.par.h5 ... Writing particle distribution to file: Example2.182.par.h5 ... Writing field distribution to file: Example2.184.fld.h5 ... Writing particle distribution to file: Example2.184.par.h5 ... Writing particle distribution to file: Example2.186.par.h5 ... Writing particle distribution to file: Example2.188.par.h5 ... Writing particle distribution to file: Example2.190.par.h5 ... Writing particle distribution to file: Example2.192.par.h5 ... Writing particle distribution to file: Example2.194.par.h5 ... Writing particle distribution to file: Example2.196.par.h5 ... Writing particle distribution to file: Example2.198.par.h5 ... Writing particle distribution to file: Example2.200.par.h5 ...
Writing particle distribution to file: Example2.202.par.h5 ... Writing particle distribution to file: Example2.204.par.h5 ... Writing particle distribution to file: Example2.206.par.h5 ... Writing particle distribution to file: Example2.208.par.h5 ... Writing particle distribution to file: Example2.210.par.h5 ... Writing particle distribution to file: Example2.212.par.h5 ... Writing particle distribution to file: Example2.214.par.h5 ... Writing particle distribution to file: Example2.216.par.h5 ... Writing particle distribution to file: Example2.218.par.h5 ... Calculation: 20% done Writing particle distribution to file: Example2.220.par.h5 ... Writing particle distribution to file: Example2.222.par.h5 ... Writing particle distribution to file: Example2.224.par.h5 ... Writing particle distribution to file: Example2.226.par.h5 ... Writing particle distribution to file: Example2.228.par.h5 ... Writing particle distribution to file: Example2.230.par.h5 ...
Writing particle distribution to file: Example2.232.par.h5 ... Writing particle distribution to file: Example2.234.par.h5 ... Writing particle distribution to file: Example2.236.par.h5 ... Writing particle distribution to file: Example2.238.par.h5 ... Writing particle distribution to file: Example2.240.par.h5 ... Writing particle distribution to file: Example2.242.par.h5 ... Writing particle distribution to file: Example2.244.par.h5 ... Writing particle distribution to file: Example2.246.par.h5 ... Writing particle distribution to file: Example2.248.par.h5 ... Writing particle distribution to file: Example2.250.par.h5 ... Writing particle distribution to file: Example2.252.par.h5 ... Writing particle distribution to file: Example2.254.par.h5 ... Writing particle distribution to file: Example2.256.par.h5 ... Writing particle distribution to file: Example2.258.par.h5 ... Writing particle distribution to file: Example2.260.par.h5 ...
Writing particle distribution to file: Example2.262.par.h5 ... Writing particle distribution to file: Example2.264.par.h5 ... Writing particle distribution to file: Example2.266.par.h5 ... Writing particle distribution to file: Example2.268.par.h5 ... Writing particle distribution to file: Example2.270.par.h5 ... Writing particle distribution to file: Example2.272.par.h5 ... Writing particle distribution to file: Example2.274.par.h5 ... Writing particle distribution to file: Example2.276.par.h5 ... Writing particle distribution to file: Example2.278.par.h5 ... Writing particle distribution to file: Example2.280.par.h5 ... Writing particle distribution to file: Example2.282.par.h5 ... Writing particle distribution to file: Example2.284.par.h5 ... Writing particle distribution to file: Example2.286.par.h5 ... Writing particle distribution to file: Example2.288.par.h5 ... Writing particle distribution to file: Example2.290.par.h5 ...
Writing particle distribution to file: Example2.292.par.h5 ... Writing particle distribution to file: Example2.294.par.h5 ... Writing particle distribution to file: Example2.296.par.h5 ... Writing particle distribution to file: Example2.298.par.h5 ... Writing particle distribution to file: Example2.300.par.h5 ... Writing particle distribution to file: Example2.302.par.h5 ... Writing particle distribution to file: Example2.304.par.h5 ... Writing particle distribution to file: Example2.306.par.h5 ... Writing particle distribution to file: Example2.308.par.h5 ... Writing particle distribution to file: Example2.310.par.h5 ... Writing particle distribution to file: Example2.312.par.h5 ... Writing particle distribution to file: Example2.314.par.h5 ... Writing particle distribution to file: Example2.316.par.h5 ... Writing particle distribution to file: Example2.318.par.h5 ... Writing particle distribution to file: Example2.320.par.h5 ...
Writing particle distribution to file: Example2.322.par.h5 ... Writing particle distribution to file: Example2.324.par.h5 ... Writing particle distribution to file: Example2.326.par.h5 ... Writing particle distribution to file: Example2.328.par.h5 ... Calculation: 30% done Writing particle distribution to file: Example2.330.par.h5 ... Writing particle distribution to file: Example2.332.par.h5 ... Writing particle distribution to file: Example2.334.par.h5 ... Writing particle distribution to file: Example2.336.par.h5 ... Writing particle distribution to file: Example2.338.par.h5 ... Writing particle distribution to file: Example2.340.par.h5 ... Writing particle distribution to file: Example2.342.par.h5 ... Writing particle distribution to file: Example2.344.par.h5 ... Writing particle distribution to file: Example2.346.par.h5 ... Writing particle distribution to file: Example2.348.par.h5 ... Writing particle distribution to file: Example2.350.par.h5 ...
Writing particle distribution to file: Example2.352.par.h5 ... Writing particle distribution to file: Example2.354.par.h5 ... Writing particle distribution to file: Example2.356.par.h5 ... Writing particle distribution to file: Example2.358.par.h5 ... Writing particle distribution to file: Example2.360.par.h5 ... Writing particle distribution to file: Example2.362.par.h5 ... Writing particle distribution to file: Example2.364.par.h5 ... Writing particle distribution to file: Example2.366.par.h5 ... Writing field distribution to file: Example2.368.fld.h5 ... Writing particle distribution to file: Example2.368.par.h5 ... Writing particle distribution to file: Example2.370.par.h5 ... Writing particle distribution to file: Example2.372.par.h5 ... Writing particle distribution to file: Example2.374.par.h5 ... Writing particle distribution to file: Example2.376.par.h5 ... Writing particle distribution to file: Example2.378.par.h5 ... Writing particle distribution to file: Example2.380.par.h5 ...
Writing particle distribution to file: Example2.382.par.h5 ... Writing particle distribution to file: Example2.384.par.h5 ... Writing particle distribution to file: Example2.386.par.h5 ... Writing particle distribution to file: Example2.388.par.h5 ... Writing particle distribution to file: Example2.390.par.h5 ... Writing particle distribution to file: Example2.392.par.h5 ... Writing particle distribution to file: Example2.394.par.h5 ... Writing particle distribution to file: Example2.396.par.h5 ... Writing particle distribution to file: Example2.398.par.h5 ... Writing particle distribution to file: Example2.400.par.h5 ... Writing particle distribution to file: Example2.402.par.h5 ... Writing particle distribution to file: Example2.404.par.h5 ... Writing particle distribution to file: Example2.406.par.h5 ... Writing particle distribution to file: Example2.408.par.h5 ... Writing particle distribution to file: Example2.410.par.h5 ...
Writing particle distribution to file: Example2.412.par.h5 ... Writing particle distribution to file: Example2.414.par.h5 ... Writing particle distribution to file: Example2.416.par.h5 ... Writing particle distribution to file: Example2.418.par.h5 ... Writing particle distribution to file: Example2.420.par.h5 ... Writing particle distribution to file: Example2.422.par.h5 ... Writing particle distribution to file: Example2.424.par.h5 ... Writing particle distribution to file: Example2.426.par.h5 ... Writing particle distribution to file: Example2.428.par.h5 ... Writing particle distribution to file: Example2.430.par.h5 ... Writing particle distribution to file: Example2.432.par.h5 ... Writing particle distribution to file: Example2.434.par.h5 ... Writing particle distribution to file: Example2.436.par.h5 ... Writing particle distribution to file: Example2.438.par.h5 ... Calculation: 40% done Writing particle distribution to file: Example2.440.par.h5 ...
Writing particle distribution to file: Example2.442.par.h5 ... Writing particle distribution to file: Example2.444.par.h5 ... Writing particle distribution to file: Example2.446.par.h5 ... Writing particle distribution to file: Example2.448.par.h5 ... Writing particle distribution to file: Example2.450.par.h5 ... Writing particle distribution to file: Example2.452.par.h5 ... Writing particle distribution to file: Example2.454.par.h5 ... Writing particle distribution to file: Example2.456.par.h5 ... Writing particle distribution to file: Example2.458.par.h5 ... Writing particle distribution to file: Example2.460.par.h5 ... Writing particle distribution to file: Example2.462.par.h5 ... Writing particle distribution to file: Example2.464.par.h5 ... Writing particle distribution to file: Example2.466.par.h5 ... Writing particle distribution to file: Example2.468.par.h5 ... Writing particle distribution to file: Example2.470.par.h5 ...
Writing particle distribution to file: Example2.472.par.h5 ... Writing particle distribution to file: Example2.474.par.h5 ... Writing particle distribution to file: Example2.476.par.h5 ... Writing particle distribution to file: Example2.478.par.h5 ... Writing particle distribution to file: Example2.480.par.h5 ... Writing particle distribution to file: Example2.482.par.h5 ... Writing particle distribution to file: Example2.484.par.h5 ... Writing particle distribution to file: Example2.486.par.h5 ... Writing particle distribution to file: Example2.488.par.h5 ... Writing particle distribution to file: Example2.490.par.h5 ... Writing particle distribution to file: Example2.492.par.h5 ... Writing particle distribution to file: Example2.494.par.h5 ... Writing particle distribution to file: Example2.496.par.h5 ... Writing particle distribution to file: Example2.498.par.h5 ... Writing particle distribution to file: Example2.500.par.h5 ...
Writing particle distribution to file: Example2.502.par.h5 ... Writing particle distribution to file: Example2.504.par.h5 ... Writing particle distribution to file: Example2.506.par.h5 ... Writing particle distribution to file: Example2.508.par.h5 ... Writing particle distribution to file: Example2.510.par.h5 ... Writing particle distribution to file: Example2.512.par.h5 ... Writing particle distribution to file: Example2.514.par.h5 ... Writing particle distribution to file: Example2.516.par.h5 ... Writing particle distribution to file: Example2.518.par.h5 ... Writing particle distribution to file: Example2.520.par.h5 ... Writing particle distribution to file: Example2.522.par.h5 ... Writing particle distribution to file: Example2.524.par.h5 ... Writing particle distribution to file: Example2.526.par.h5 ... Writing particle distribution to file: Example2.528.par.h5 ... Writing particle distribution to file: Example2.530.par.h5 ...
Writing particle distribution to file: Example2.532.par.h5 ... Writing particle distribution to file: Example2.534.par.h5 ... Writing particle distribution to file: Example2.536.par.h5 ... Writing particle distribution to file: Example2.538.par.h5 ... Writing particle distribution to file: Example2.540.par.h5 ... Writing particle distribution to file: Example2.542.par.h5 ... Writing particle distribution to file: Example2.544.par.h5 ... Writing particle distribution to file: Example2.546.par.h5 ... Writing particle distribution to file: Example2.548.par.h5 ... Calculation: 50% done Writing particle distribution to file: Example2.550.par.h5 ... Writing field distribution to file: Example2.552.fld.h5 ... Writing particle distribution to file: Example2.552.par.h5 ... Writing particle distribution to file: Example2.554.par.h5 ... Writing particle distribution to file: Example2.556.par.h5 ... Writing particle distribution to file: Example2.558.par.h5 ... Writing particle distribution to file: Example2.560.par.h5 ...
Writing particle distribution to file: Example2.562.par.h5 ... Writing particle distribution to file: Example2.564.par.h5 ... Writing particle distribution to file: Example2.566.par.h5 ... Writing particle distribution to file: Example2.568.par.h5 ... Writing particle distribution to file: Example2.570.par.h5 ... Writing particle distribution to file: Example2.572.par.h5 ... Writing particle distribution to file: Example2.574.par.h5 ... Writing particle distribution to file: Example2.576.par.h5 ... Writing particle distribution to file: Example2.578.par.h5 ... Writing particle distribution to file: Example2.580.par.h5 ... Writing particle distribution to file: Example2.582.par.h5 ... Writing particle distribution to file: Example2.584.par.h5 ... Writing particle distribution to file: Example2.586.par.h5 ... Writing particle distribution to file: Example2.588.par.h5 ... Writing particle distribution to file: Example2.590.par.h5 ...
Writing particle distribution to file: Example2.592.par.h5 ... Writing particle distribution to file: Example2.594.par.h5 ... Writing particle distribution to file: Example2.596.par.h5 ... Writing particle distribution to file: Example2.598.par.h5 ... Writing particle distribution to file: Example2.600.par.h5 ... Writing particle distribution to file: Example2.602.par.h5 ... Writing particle distribution to file: Example2.604.par.h5 ... Writing particle distribution to file: Example2.606.par.h5 ... Writing particle distribution to file: Example2.608.par.h5 ... Writing particle distribution to file: Example2.610.par.h5 ... Writing particle distribution to file: Example2.612.par.h5 ... Writing particle distribution to file: Example2.614.par.h5 ... Writing particle distribution to file: Example2.616.par.h5 ... Writing particle distribution to file: Example2.618.par.h5 ... Writing particle distribution to file: Example2.620.par.h5 ...
Writing particle distribution to file: Example2.622.par.h5 ... Writing particle distribution to file: Example2.624.par.h5 ... Writing particle distribution to file: Example2.626.par.h5 ... Writing particle distribution to file: Example2.628.par.h5 ... Writing particle distribution to file: Example2.630.par.h5 ... Writing particle distribution to file: Example2.632.par.h5 ... Writing particle distribution to file: Example2.634.par.h5 ... Writing particle distribution to file: Example2.636.par.h5 ... Writing particle distribution to file: Example2.638.par.h5 ... Writing particle distribution to file: Example2.640.par.h5 ... Writing particle distribution to file: Example2.642.par.h5 ... Writing particle distribution to file: Example2.644.par.h5 ... Writing particle distribution to file: Example2.646.par.h5 ... Writing particle distribution to file: Example2.648.par.h5 ... Writing particle distribution to file: Example2.650.par.h5 ...
Writing particle distribution to file: Example2.652.par.h5 ... Writing particle distribution to file: Example2.654.par.h5 ... Writing particle distribution to file: Example2.656.par.h5 ... Writing particle distribution to file: Example2.658.par.h5 ... Calculation: 60% done Writing particle distribution to file: Example2.660.par.h5 ... Writing particle distribution to file: Example2.662.par.h5 ... Writing particle distribution to file: Example2.664.par.h5 ... Writing particle distribution to file: Example2.666.par.h5 ... Writing particle distribution to file: Example2.668.par.h5 ... Writing particle distribution to file: Example2.670.par.h5 ... Writing particle distribution to file: Example2.672.par.h5 ... Writing particle distribution to file: Example2.674.par.h5 ... Writing particle distribution to file: Example2.676.par.h5 ... Writing particle distribution to file: Example2.678.par.h5 ... Writing particle distribution to file: Example2.680.par.h5 ...
Writing particle distribution to file: Example2.682.par.h5 ... Writing particle distribution to file: Example2.684.par.h5 ... Writing particle distribution to file: Example2.686.par.h5 ... Writing particle distribution to file: Example2.688.par.h5 ... Writing particle distribution to file: Example2.690.par.h5 ... Writing particle distribution to file: Example2.692.par.h5 ... Writing particle distribution to file: Example2.694.par.h5 ... Writing particle distribution to file: Example2.696.par.h5 ... Writing particle distribution to file: Example2.698.par.h5 ... Writing particle distribution to file: Example2.700.par.h5 ... Writing particle distribution to file: Example2.702.par.h5 ... Writing particle distribution to file: Example2.704.par.h5 ... Writing particle distribution to file: Example2.706.par.h5 ... Writing particle distribution to file: Example2.708.par.h5 ... Writing particle distribution to file: Example2.710.par.h5 ...
Writing particle distribution to file: Example2.712.par.h5 ... Writing particle distribution to file: Example2.714.par.h5 ... Writing particle distribution to file: Example2.716.par.h5 ... Writing particle distribution to file: Example2.718.par.h5 ... Writing particle distribution to file: Example2.720.par.h5 ... Writing particle distribution to file: Example2.722.par.h5 ... Writing particle distribution to file: Example2.724.par.h5 ... Writing particle distribution to file: Example2.726.par.h5 ... Writing particle distribution to file: Example2.728.par.h5 ... Writing particle distribution to file: Example2.730.par.h5 ... Writing particle distribution to file: Example2.732.par.h5 ... Writing particle distribution to file: Example2.734.par.h5 ... Writing field distribution to file: Example2.736.fld.h5 ... Writing particle distribution to file: Example2.736.par.h5 ... Writing particle distribution to file: Example2.738.par.h5 ... Writing particle distribution to file: Example2.740.par.h5 ...
Writing particle distribution to file: Example2.742.par.h5 ... Writing particle distribution to file: Example2.744.par.h5 ... Writing particle distribution to file: Example2.746.par.h5 ... Writing particle distribution to file: Example2.748.par.h5 ... Writing particle distribution to file: Example2.750.par.h5 ... Writing particle distribution to file: Example2.752.par.h5 ... Writing particle distribution to file: Example2.754.par.h5 ... Writing particle distribution to file: Example2.756.par.h5 ... Writing particle distribution to file: Example2.758.par.h5 ... Writing particle distribution to file: Example2.760.par.h5 ... Writing particle distribution to file: Example2.762.par.h5 ... Writing particle distribution to file: Example2.764.par.h5 ... Writing particle distribution to file: Example2.766.par.h5 ... Writing particle distribution to file: Example2.768.par.h5 ... Calculation: 70% done Writing particle distribution to file: Example2.770.par.h5 ...
Writing particle distribution to file: Example2.772.par.h5 ... Writing particle distribution to file: Example2.774.par.h5 ... Writing particle distribution to file: Example2.776.par.h5 ... Writing particle distribution to file: Example2.778.par.h5 ... Writing particle distribution to file: Example2.780.par.h5 ... Writing particle distribution to file: Example2.782.par.h5 ... Writing particle distribution to file: Example2.784.par.h5 ... Writing particle distribution to file: Example2.786.par.h5 ... Writing particle distribution to file: Example2.788.par.h5 ... Writing particle distribution to file: Example2.790.par.h5 ... Writing particle distribution to file: Example2.792.par.h5 ... Writing particle distribution to file: Example2.794.par.h5 ... Writing particle distribution to file: Example2.796.par.h5 ... Writing particle distribution to file: Example2.798.par.h5 ... Writing particle distribution to file: Example2.800.par.h5 ...
Writing particle distribution to file: Example2.802.par.h5 ... Writing particle distribution to file: Example2.804.par.h5 ... Writing particle distribution to file: Example2.806.par.h5 ... Writing particle distribution to file: Example2.808.par.h5 ... Writing particle distribution to file: Example2.810.par.h5 ... Writing particle distribution to file: Example2.812.par.h5 ... Writing particle distribution to file: Example2.814.par.h5 ... Writing particle distribution to file: Example2.816.par.h5 ... Writing particle distribution to file: Example2.818.par.h5 ... Writing particle distribution to file: Example2.820.par.h5 ... Writing particle distribution to file: Example2.822.par.h5 ... Writing particle distribution to file: Example2.824.par.h5 ... Writing particle distribution to file: Example2.826.par.h5 ... Writing particle distribution to file: Example2.828.par.h5 ... Writing particle distribution to file: Example2.830.par.h5 ...
Writing particle distribution to file: Example2.832.par.h5 ... Writing particle distribution to file: Example2.834.par.h5 ... Writing particle distribution to file: Example2.836.par.h5 ... Writing particle distribution to file: Example2.838.par.h5 ... Writing particle distribution to file: Example2.840.par.h5 ... Writing particle distribution to file: Example2.842.par.h5 ... Writing particle distribution to file: Example2.844.par.h5 ... Writing particle distribution to file: Example2.846.par.h5 ... Writing particle distribution to file: Example2.848.par.h5 ... Writing particle distribution to file: Example2.850.par.h5 ... Writing particle distribution to file: Example2.852.par.h5 ... Writing particle distribution to file: Example2.854.par.h5 ... Writing particle distribution to file: Example2.856.par.h5 ... Writing particle distribution to file: Example2.858.par.h5 ...
Writing particle distribution to file: Example2.860.par.h5 ... Writing particle distribution to file: Example2.862.par.h5 ... Writing particle distribution to file: Example2.864.par.h5 ... Writing particle distribution to file: Example2.866.par.h5 ... Writing particle distribution to file: Example2.868.par.h5 ... Writing particle distribution to file: Example2.870.par.h5 ... Writing particle distribution to file: Example2.872.par.h5 ... Writing particle distribution to file: Example2.874.par.h5 ... Writing particle distribution to file: Example2.876.par.h5 ... Writing particle distribution to file: Example2.878.par.h5 ... Calculation: 80% done Writing particle distribution to file: Example2.880.par.h5 ... Writing particle distribution to file: Example2.882.par.h5 ... Writing particle distribution to file: Example2.884.par.h5 ... Writing particle distribution to file: Example2.886.par.h5 ...
Writing particle distribution to file: Example2.888.par.h5 ... Writing particle distribution to file: Example2.890.par.h5 ... Writing particle distribution to file: Example2.892.par.h5 ... Writing particle distribution to file: Example2.894.par.h5 ... Writing particle distribution to file: Example2.896.par.h5 ... Writing particle distribution to file: Example2.898.par.h5 ... Writing particle distribution to file: Example2.900.par.h5 ... Writing particle distribution to file: Example2.902.par.h5 ... Writing particle distribution to file: Example2.904.par.h5 ... Writing particle distribution to file: Example2.906.par.h5 ... Writing particle distribution to file: Example2.908.par.h5 ... Writing particle distribution to file: Example2.910.par.h5 ... Writing particle distribution to file: Example2.912.par.h5 ... Writing particle distribution to file: Example2.914.par.h5 ...
Writing particle distribution to file: Example2.916.par.h5 ... Writing particle distribution to file: Example2.918.par.h5 ... Writing field distribution to file: Example2.920.fld.h5 ... Writing particle distribution to file: Example2.920.par.h5 ... Writing particle distribution to file: Example2.922.par.h5 ... Writing particle distribution to file: Example2.924.par.h5 ... Writing particle distribution to file: Example2.926.par.h5 ... Writing particle distribution to file: Example2.928.par.h5 ... Writing particle distribution to file: Example2.930.par.h5 ... Writing particle distribution to file: Example2.932.par.h5 ... Writing particle distribution to file: Example2.934.par.h5 ... Writing particle distribution to file: Example2.936.par.h5 ... Writing particle distribution to file: Example2.938.par.h5 ... Writing particle distribution to file: Example2.940.par.h5 ...
Writing particle distribution to file: Example2.942.par.h5 ... Writing particle distribution to file: Example2.944.par.h5 ... Writing particle distribution to file: Example2.946.par.h5 ... Writing particle distribution to file: Example2.948.par.h5 ... Writing particle distribution to file: Example2.950.par.h5 ... Writing particle distribution to file: Example2.952.par.h5 ... Writing particle distribution to file: Example2.954.par.h5 ... Writing particle distribution to file: Example2.956.par.h5 ... Writing particle distribution to file: Example2.958.par.h5 ... Writing particle distribution to file: Example2.960.par.h5 ... Writing particle distribution to file: Example2.962.par.h5 ... Writing particle distribution to file: Example2.964.par.h5 ... Writing particle distribution to file: Example2.966.par.h5 ... Writing particle distribution to file: Example2.968.par.h5 ...
Writing particle distribution to file: Example2.970.par.h5 ... Writing particle distribution to file: Example2.972.par.h5 ... Writing particle distribution to file: Example2.974.par.h5 ... Writing particle distribution to file: Example2.976.par.h5 ... Writing particle distribution to file: Example2.978.par.h5 ... Writing particle distribution to file: Example2.980.par.h5 ... Writing particle distribution to file: Example2.982.par.h5 ... Writing particle distribution to file: Example2.984.par.h5 ... Writing particle distribution to file: Example2.986.par.h5 ... Writing particle distribution to file: Example2.988.par.h5 ... Calculation: 90% done Writing particle distribution to file: Example2.990.par.h5 ... Writing particle distribution to file: Example2.992.par.h5 ... Writing particle distribution to file: Example2.994.par.h5 ... Writing particle distribution to file: Example2.996.par.h5 ...
Writing particle distribution to file: Example2.998.par.h5 ... Writing particle distribution to file: Example2.1000.par.h5 ... Writing particle distribution to file: Example2.1002.par.h5 ... Writing particle distribution to file: Example2.1004.par.h5 ... Writing particle distribution to file: Example2.1006.par.h5 ... Writing particle distribution to file: Example2.1008.par.h5 ... Writing particle distribution to file: Example2.1010.par.h5 ... Writing particle distribution to file: Example2.1012.par.h5 ... Writing particle distribution to file: Example2.1014.par.h5 ... Writing particle distribution to file: Example2.1016.par.h5 ... Writing particle distribution to file: Example2.1018.par.h5 ... Writing particle distribution to file: Example2.1020.par.h5 ... Writing particle distribution to file: Example2.1022.par.h5 ... Writing particle distribution to file: Example2.1024.par.h5 ...
Writing particle distribution to file: Example2.1026.par.h5 ... Writing particle distribution to file: Example2.1028.par.h5 ... Writing particle distribution to file: Example2.1030.par.h5 ... Writing particle distribution to file: Example2.1032.par.h5 ... Writing particle distribution to file: Example2.1034.par.h5 ... Writing particle distribution to file: Example2.1036.par.h5 ... Writing particle distribution to file: Example2.1038.par.h5 ... Writing particle distribution to file: Example2.1040.par.h5 ... Writing particle distribution to file: Example2.1042.par.h5 ... Writing particle distribution to file: Example2.1044.par.h5 ... Writing particle distribution to file: Example2.1046.par.h5 ... Writing particle distribution to file: Example2.1048.par.h5 ... Writing particle distribution to file: Example2.1050.par.h5 ... Writing particle distribution to file: Example2.1052.par.h5 ...
Writing particle distribution to file: Example2.1054.par.h5 ... Writing particle distribution to file: Example2.1056.par.h5 ... Writing particle distribution to file: Example2.1058.par.h5 ... Writing particle distribution to file: Example2.1060.par.h5 ... Writing particle distribution to file: Example2.1062.par.h5 ... Writing particle distribution to file: Example2.1064.par.h5 ... Writing particle distribution to file: Example2.1066.par.h5 ... Writing particle distribution to file: Example2.1068.par.h5 ... Writing particle distribution to file: Example2.1070.par.h5 ... Writing particle distribution to file: Example2.1072.par.h5 ... Writing particle distribution to file: Example2.1074.par.h5 ... Writing particle distribution to file: Example2.1076.par.h5 ... Writing particle distribution to file: Example2.1078.par.h5 ... Writing particle distribution to file: Example2.1080.par.h5 ...
Writing particle distribution to file: Example2.1082.par.h5 ... Writing particle distribution to file: Example2.1084.par.h5 ... Writing particle distribution to file: Example2.1086.par.h5 ... Writing particle distribution to file: Example2.1088.par.h5 ... Writing particle distribution to file: Example2.1090.par.h5 ... Writing particle distribution to file: Example2.1092.par.h5 ... Writing particle distribution to file: Example2.1094.par.h5 ... Writing particle distribution to file: Example2.1096.par.h5 ... Writing particle distribution to file: Example2.1098.par.h5 ... Calculation: 100% done Writing particle distribution to file: Example2.1100.par.h5 ... Writing particle distribution to file: Example2.1102.par.h5 ... Writing field distribution to file: Example2.1104.fld.h5 ... Writing particle distribution to file: Example2.1104.par.h5 ... Writing output file... Core Simulation done. End of Track Writing field distribution to file: dump.fld.h5 ... Program is terminating... Ending Time: Thu Aug 29 16:08:56 2024 Total Wall Clock Time: 7.83784 seconds ------------------------------------- Success - execution took 7.88s.
G.plot(["beam_xsize", "beam_ysize", "field_xsize", "field_ysize"], figsize=(8, 8))
print("Loaded fields:", output.load_fields())
print("Total loaded particles files=", len(output.load_particles()))
Loaded fields: ['dump', 184, 368, 552, 736, 920, 1104]
Total loaded particles files= 553
Wavefront¶
Wavefront distribution after the first 4 FODO cells. Note that the output seems noisy, which comes from the limited number of macro particles in the simulation and the reduced diffraction in the Angstrom wavelength regime.
def get_slice(field, slc: int) -> np.ndarray:
return field.dfl[:, :, slc]
def get_wavefront(field, slice=0):
# inten = np.reshape(fre * fre + fim * fim, (ng, ng))
inten = np.abs(get_slice(field, slice) ** 2)
return inten, field.param.gridsize * (field.param.gridpoints - 1) * 0.5 * 1e3
# plot wavefront
istep = 184
_, axs = plt.subplots(2, 2, figsize=(8, 8))
color = "yellow"
for i1 in range(2):
for i2 in range(2):
i = (i2 * 2 + i1 + 1) * istep
inten, dg = get_wavefront(output.field3d[i], slice=0)
axs[i2, i1].imshow(inten, extent=(-dg, dg, -dg, dg))
txt = r"$z$ = %3.1f m" % (9.5 * (i2 * 2 + i1 + 1))
axs[i2, i1].text(-0.15, 0.15, txt, color=color)
axs[1, 0].set_xlabel(r"$x$ (mm)")
axs[1, 1].set_xlabel(r"$x$ (mm)")
axs[0, 0].set_ylabel(r"$y$ (mm)")
axs[1, 0].set_ylabel(r"$y$ (mm)")
plt.show()
Longitudinal Phasespace Distribution¶
This is snapshot of the longitudinal phase space of the electron beam towards the end of the undulator beamline. The x-axis coordinate is the ponderomotive phase, which is given by the longidutinal position multiplied with the wavenumber of the resonant wavelength. In this case, it corresponds to a slice thickness of 1 Angstrom.
def get_phase_space(particles, lambda0):
theta = np.mod(particles.z / lambda0, 1) * 2 * np.pi
return theta, particles.energy
# get range for phase space plots
emin = np.min(output.beam.emin)
emax = np.max(output.beam.emax)
xmin = np.min(output.beam.xmin)
xmax = np.max(output.beam.xmax)
# plot final phase space
theta, energy = get_phase_space(
output.particles[700], lambda0=G.input.main.setup.lambda0
)
plt.scatter(theta, energy / 1e9, s=0.2)
plt.xlabel(r"$\theta$ (rad)")
plt.ylabel(r"$E$ (GeV)")
plt.ylim(xmin, xmax)
plt.ylim(emin / 1e9, emax / 1e9)
plt.show()
Animate phase space¶
Animation 1¶
With the dump of the electron phase space after every second integration step, the python script generates two animation. One for the longitudinal phase space, similar to the plot above. The other is the distribution in the horizontal plane.
Here the formation of the micro bunching can be seen with its initial modulation in energy to roughly a quarter rotation in phase space. A significant part of electrons are not modulated. These corresponds for electrons with large betatron amplitude, which cannot stay in resonance with the radiation field.
from IPython.display import Video
fig = plt.figure()
ax = plt.axes(xlim=(0, 2 * np.pi), ylim=(emin / 1e9, emax / 1e9))
ax.set_xlabel(r"$\theta$ (rad)")
ax.set_ylabel(r"$E$ (GeV)")
scat = ax.scatter([], [], s=0.2)
def init():
scat.set_offsets(np.empty((0, 2)))
return (scat,)
def animate(i):
theta, energy = get_phase_space(
output.particles[2 * i], lambda0=G.input.main.setup.lambda0
)
scat.set_offsets(np.hstack((theta[:, np.newaxis], energy[:, np.newaxis] / 1e9)))
return (scat,)
# We could also get individual frames by doing the following:
# animate(1)
anim = animation.FuncAnimation(
fig,
animate,
init_func=init,
blit=False,
interval=20,
frames=500,
)
anim.save("Animation1.mp4")
# Hide our plot and then show the final animation:
plt.close()
Video("Animation1.mp4")
Animation 2¶
The breathing in the transverse size comes from the focusing of the FODO lattice. Note that electrons with large amplitude have the tendency to fall backwards quickly. They cannot stay in resonance and thus do not get modulated in energy.
The small jerks in the animation corresponds to the phase shifter, since in the drift there is a phase velocity mismatch between field and beam. To correct that a phase shifter adjust the phase. In Genesis this is done automatically via autophase
.
fig = plt.figure()
ax = plt.axes(xlim=(0, 2 * np.pi), ylim=(xmin * 1e6, xmax * 1e6))
ax.set_xlabel(r"$\theta$ (rad)")
ax.set_ylabel(r"$x$ ($\mu$m)")
scat = ax.scatter([], [])
def animate2(i):
particles = output.particles[2 * i]
theta, _ = get_phase_space(particles, lambda0=G.input.main.setup.lambda0)
scat.set_offsets(
np.hstack((theta[:, np.newaxis], particles.x[:, np.newaxis] * 1e6))
)
return (scat,)
# We could also get individual frames by doing the following:
# animate2(1)
anim = animation.FuncAnimation(
fig,
animate2,
init_func=init,
blit=False,
interval=20,
frames=500,
)
anim.save("Animation2.mp4")
# Hide our plot and then show the final animation:
plt.close()
Video("Animation2.mp4")