Genesis4 Basic Example¶
This will show the basic usage of LUME-Genesis.
import matplotlib.pyplot as plt
import numpy as np
import genesis
from genesis.version4 import Genesis4, Track, Write
%config InlineBackend.figure_format = 'retina'
Setup¶
Instantiate the object on a value init file. This will configure a working directory that stages all input and output files.
G = Genesis4("data/basic4/cu_hxr.in", "data/basic4/hxr.lat", verbose=True)
Here is what the main input ("cu_hxr.in") looks like in Python:
G.input.main
MainInput( namelists=[ Setup( rootname='LCLS2_HXR_9keV', lattice='hxr.lat', beamline='HXR', gamma0=19174.0776, lambda0=1.3789244869952112e-10, delz=0.026, seed=84672, npart=1024, ), Time(slen=1.5e-05, sample=200), Field(dgrid=0.0001, ngrid=101, accumulate=True), ProfileFile( label='beamcurrent', xdata='beam_current.h5/s', ydata='beam_current.h5/current', ), ProfileFile(label='beamgamma', xdata='beam_gamma.h5/s', ydata='beam_gamma.h5/gamma'), Beam( gamma='@beamgamma', delgam=3.97848, current='@beamcurrent', ex=4e-07, ey=4e-07, betax=7.910909406464387, betay=16.881178621346898, alphax=-0.7393217413918415, alphay=1.3870723536888105, ), Track(zstop=10.0), ], filename=pathlib.Path('/home/runner/work/lume-genesis/lume-genesis/docs/examples/genesis4/data/basic4/cu_hxr.in'), )
Inspect the main input by filtering the namelists by their type:
G.input.main.tracks
[Track(zstop=10.0)]
There is also a dictionary mapping you can use to see all types by using their type class directly:
G.input.main.by_namelist[Track]
[Track(zstop=10.0)]
We can use this to modify the z-stop for all track instances:
for track in G.input.main.tracks:
track.zstop = 12
If there is only one instance of a namelist ite, it can be accessed more simply:
G.input.main.track.zstop = 12
You can view the data as a convenient table, too, when looking at a single namelist:
G.input.main.tracks[0].to_table()
Attribute | Value | Type | Description |
---|---|---|---|
type | track | str | |
zstop | 12.0 | float | If `zstop` is shorter than the lattice length the tracking stops at the specified position. |
output_step | 1 | int | Defines the number of integration steps before the particle and field distribution is analyzed for output. |
field_dump_step | 0 | int | Defines the number of integration steps before a field dump is written. Be careful because for time-dependent simulation it can generate many large output files. |
beam_dump_step | 0 | int | Defines the number of integration steps before a particle dump is written. Be careful because for time-dependent simulation it can generate many large output files. |
sort_step | 0 | int | Defines the number of steps of integration before the particle distribution is sorted. Works only for one-4-one simulations. |
s0 | 0.0 | float | Option to override the default time window start from the TIME module. |
slen | 0.0 | float | Option to override the default time window length from the TIME module. |
field_dump_at_undexit | False | bool | Field dumps at the exit of the undulator (one dump for each undulator in the expanded lattice). |
bunchharm | 1 | int | Bunching harmonic output setting. Must be >= 1. |
# Add writing a field file
G.input.main.namelists.append(Write(field="end"))
# Add writing a beam (particle) file
G.input.main.namelists.append(Write(beam="end"))
Let's look at the lattice input format that Genesis will see:
print(G.input.lattice.to_genesis())
QHXH17: quadrupole = {l=0.101, k1=1.78}; QHXH18: quadrupole = {l=0.101, k1=-1.78}; QHXH19: quadrupole = {l=0.101, k1=1.78}; QHXH20: quadrupole = {l=0.101, k1=-1.78}; QHXH21: quadrupole = {l=0.101, k1=1.78}; QHXH22: quadrupole = {l=0.101, k1=-1.78}; QHXH23: quadrupole = {l=0.101, k1=1.78}; QHXH24: quadrupole = {l=0.101, k1=-1.78}; QHXH25: quadrupole = {l=0.101, k1=1.78}; QHXH26: quadrupole = {l=0.101, k1=-1.78}; QHXH27: quadrupole = {l=0.101, k1=1.78}; QHXH28: quadrupole = {l=0.101, k1=-1.78}; QHXH29: quadrupole = {l=0.101, k1=1.78}; QHXH30: quadrupole = {l=0.101, k1=-1.78}; QHXH31: quadrupole = {l=0.101, k1=1.78}; QHXH32: quadrupole = {l=0.101, k1=-1.78}; QHXH33: quadrupole = {l=0.101, k1=1.78}; QHXH34: quadrupole = {l=0.101, k1=-1.78}; QHXH35: quadrupole = {l=0.101, k1=1.78}; QHXH36: quadrupole = {l=0.101, k1=-1.78}; QHXH37: quadrupole = {l=0.101, k1=1.78}; QHXH38: quadrupole = {l=0.101, k1=-1.78}; QHXH39: quadrupole = {l=0.101, k1=1.78}; QHXH40: quadrupole = {l=0.101, k1=-1.78}; QHXH41: quadrupole = {l=0.101, k1=1.78}; QHXH42: quadrupole = {l=0.101, k1=-1.78}; QHXH43: quadrupole = {l=0.101, k1=1.78}; QHXH44: quadrupole = {l=0.101, k1=-1.78}; QHXH45: quadrupole = {l=0.101, k1=1.78}; QHXH46: quadrupole = {l=0.101, k1=-1.78}; QHXH47: quadrupole = {l=0.101, k1=1.78}; QHXH48: quadrupole = {l=0.101, k1=-1.78}; QHXH49: quadrupole = {l=0.101, k1=1.78}; QHXH50: quadrupole = {l=0.101, k1=-1.78}; UMAHXH17: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH18: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH19: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH20: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH21: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH22: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH23: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH25: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH26: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH27: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH28: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH29: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH30: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH31: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH33: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH34: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH35: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH36: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH37: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH38: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH39: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH40: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH41: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH42: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH43: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH44: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH45: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH46: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH47: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH48: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH49: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; UMAHXH50: undulator = {aw=1.7017, lambdau=0.026, nwig=130}; CORR00: corrector = {l=0.001}; CORR01: corrector = {l=0.001}; CORR02: corrector = {l=0.001}; CORR03: corrector = {l=0.001}; CORR04: corrector = {l=0.001}; CORR05: corrector = {l=0.001}; CORR06: corrector = {l=0.001}; CORR07: corrector = {l=0.001}; CORR08: corrector = {l=0.001}; CORR09: corrector = {l=0.001}; CORR10: corrector = {l=0.001}; CORR11: corrector = {l=0.001}; CORR12: corrector = {l=0.001}; CORR13: corrector = {l=0.001}; CORR14: corrector = {l=0.001}; CORR15: corrector = {l=0.001}; CORR16: corrector = {l=0.001}; CORR17: corrector = {l=0.001}; CORR18: corrector = {l=0.001}; CORR19: corrector = {l=0.001}; CORR20: corrector = {l=0.001}; CORR21: corrector = {l=0.001}; CORR22: corrector = {l=0.001}; CORR23: corrector = {l=0.001}; CORR24: corrector = {l=0.001}; CORR25: corrector = {l=0.001}; CORR26: corrector = {l=0.001}; CORR27: corrector = {l=0.001}; CORR28: corrector = {l=0.001}; CORR29: corrector = {l=0.001}; CORR30: corrector = {l=0.001}; CORR31: corrector = {l=0.001}; CORR32: corrector = {l=0.001}; CORR33: corrector = {l=0.001}; D1: drift = {l=0.1335}; D2: drift = {l=0.4615}; D3: drift = {l=0.328}; D4: drift = {l=3.4}; HXRSS: chicane = {l=4.55, lb=0.1}; HXR: LINE = {D1, UMAHXH17, D2, QHXH17, CORR00, D3, D1, UMAHXH18, D2, QHXH18, CORR01, D3, D1, UMAHXH19, D2, QHXH19, CORR02, D3, D1, UMAHXH20, D2, QHXH20, CORR03, D3, D1, UMAHXH21, D2, QHXH21, CORR04, D3, D1, UMAHXH22, D2, QHXH22, CORR05, D3, D1, UMAHXH23, D2, QHXH23, CORR06, D3, D1, HXRSS, D2, QHXH24, CORR07, D3, D1, UMAHXH25, D2, QHXH25, CORR08, D3, D1, UMAHXH26, D2, QHXH26, CORR09, D3, D1, UMAHXH27, D2, QHXH27, CORR10, D3, D1, UMAHXH28, D2, QHXH28, CORR11, D3, D1, UMAHXH29, D2, QHXH29, CORR12, D3, D1, UMAHXH30, D2, QHXH30, CORR13, D3, D1, UMAHXH31, D2, QHXH31, CORR14, D3, D1, D4, D2, QHXH32, CORR15, D3, D1, UMAHXH33, D2, QHXH33, CORR16, D3, D1, UMAHXH34, D2, QHXH34, CORR17, D3, D1, UMAHXH35, D2, QHXH35, CORR18, D3, D1, UMAHXH36, D2, QHXH36, CORR19, D3, D1, UMAHXH37, D2, QHXH37, CORR20, D3, D1, UMAHXH38, D2, QHXH38, CORR21, D3, D1, UMAHXH39, D2, QHXH39, CORR22, D3, D1, UMAHXH40, D2, QHXH40, CORR23, D3, D1, UMAHXH41, D2, QHXH41, CORR24, D3, D1, UMAHXH42, D2, QHXH42, CORR25, D3, D1, UMAHXH43, D2, QHXH43, CORR26, D3, D1, UMAHXH44, D2, QHXH44, CORR27, D3, D1, UMAHXH45, D2, QHXH45, CORR28, D3, D1, UMAHXH46, D2, QHXH46, CORR29, D3, D1, UMAHXH47, D2, QHXH47, CORR30, D3, D1, UMAHXH48, D2, QHXH48, CORR31, D3, D1, UMAHXH49, D2, QHXH49, CORR32, D3, D1, UMAHXH50, D2, QHXH50, CORR33, D3}; LCLS2_HXR_U1: LINE = {D1, UMAHXH17, D2, QHXH17, CORR00, D3, D1, UMAHXH18, D2, QHXH18, CORR01, D3, D1, UMAHXH19, D2, QHXH19, CORR02, D3, D1, UMAHXH20, D2, QHXH20, CORR03, D3, D1, UMAHXH21, D2, QHXH21, CORR04, D3, D1, UMAHXH22, D2, QHXH22, CORR05, D3, D1, UMAHXH23, D2, QHXH23, CORR06, D3}; LCLS2_HXR_U2: LINE = {D1, UMAHXH25, D2, QHXH25, CORR08, D3, D1, UMAHXH26, D2, QHXH26, CORR09, D3, D1, UMAHXH27, D2, QHXH27, CORR10, D3, D1, UMAHXH28, D2, QHXH28, CORR11, D3, D1, UMAHXH29, D2, QHXH29, CORR12, D3, D1, UMAHXH30, D2, QHXH30, CORR13, D3, D1, UMAHXH31, D2, QHXH31, CORR14, D3, D1, D4, D2, QHXH32, CORR15, D3, D1, UMAHXH33, D2, QHXH33, CORR16, D3, D1, UMAHXH34, D2, QHXH34, CORR17, D3, D1, UMAHXH35, D2, QHXH35, CORR18, D3, D1, UMAHXH36, D2, QHXH36, CORR19, D3, D1, UMAHXH37, D2, QHXH37, CORR20, D3, D1, UMAHXH38, D2, QHXH38, CORR21, D3, D1, UMAHXH39, D2, QHXH39, CORR22, D3, D1, UMAHXH40, D2, QHXH40, CORR23, D3, D1, UMAHXH41, D2, QHXH41, CORR24, D3, D1, UMAHXH42, D2, QHXH42, CORR25, D3, D1, UMAHXH43, D2, QHXH43, CORR26, D3, D1, UMAHXH44, D2, QHXH44, CORR27, D3, D1, UMAHXH45, D2, QHXH45, CORR28, D3, D1, UMAHXH46, D2, QHXH46, CORR29, D3, D1, UMAHXH47, D2, QHXH47, CORR30, D3, D1, UMAHXH48, D2, QHXH48, CORR31, D3, D1, UMAHXH49, D2, QHXH49, CORR32, D3, D1, UMAHXH50, D2, QHXH50, CORR33, D3};
Here's what the Python representation would look like:
G.input.lattice
Lattice( elements={ 'QHXH17': Quadrupole(label='QHXH17', L=0.101, k1=1.78), 'QHXH18': Quadrupole(label='QHXH18', L=0.101, k1=-1.78), 'QHXH19': Quadrupole(label='QHXH19', L=0.101, k1=1.78), 'QHXH20': Quadrupole(label='QHXH20', L=0.101, k1=-1.78), 'QHXH21': Quadrupole(label='QHXH21', L=0.101, k1=1.78), 'QHXH22': Quadrupole(label='QHXH22', L=0.101, k1=-1.78), 'QHXH23': Quadrupole(label='QHXH23', L=0.101, k1=1.78), 'QHXH24': Quadrupole(label='QHXH24', L=0.101, k1=-1.78), 'QHXH25': Quadrupole(label='QHXH25', L=0.101, k1=1.78), 'QHXH26': Quadrupole(label='QHXH26', L=0.101, k1=-1.78), 'QHXH27': Quadrupole(label='QHXH27', L=0.101, k1=1.78), 'QHXH28': Quadrupole(label='QHXH28', L=0.101, k1=-1.78), 'QHXH29': Quadrupole(label='QHXH29', L=0.101, k1=1.78), 'QHXH30': Quadrupole(label='QHXH30', L=0.101, k1=-1.78), 'QHXH31': Quadrupole(label='QHXH31', L=0.101, k1=1.78), 'QHXH32': Quadrupole(label='QHXH32', L=0.101, k1=-1.78), 'QHXH33': Quadrupole(label='QHXH33', L=0.101, k1=1.78), 'QHXH34': Quadrupole(label='QHXH34', L=0.101, k1=-1.78), 'QHXH35': Quadrupole(label='QHXH35', L=0.101, k1=1.78), 'QHXH36': Quadrupole(label='QHXH36', L=0.101, k1=-1.78), 'QHXH37': Quadrupole(label='QHXH37', L=0.101, k1=1.78), 'QHXH38': Quadrupole(label='QHXH38', L=0.101, k1=-1.78), 'QHXH39': Quadrupole(label='QHXH39', L=0.101, k1=1.78), 'QHXH40': Quadrupole(label='QHXH40', L=0.101, k1=-1.78), 'QHXH41': Quadrupole(label='QHXH41', L=0.101, k1=1.78), 'QHXH42': Quadrupole(label='QHXH42', L=0.101, k1=-1.78), 'QHXH43': Quadrupole(label='QHXH43', L=0.101, k1=1.78), 'QHXH44': Quadrupole(label='QHXH44', L=0.101, k1=-1.78), 'QHXH45': Quadrupole(label='QHXH45', L=0.101, k1=1.78), 'QHXH46': Quadrupole(label='QHXH46', L=0.101, k1=-1.78), 'QHXH47': Quadrupole(label='QHXH47', L=0.101, k1=1.78), 'QHXH48': Quadrupole(label='QHXH48', L=0.101, k1=-1.78), 'QHXH49': Quadrupole(label='QHXH49', L=0.101, k1=1.78), 'QHXH50': Quadrupole(label='QHXH50', L=0.101, k1=-1.78), 'UMAHXH17': Undulator(label='UMAHXH17', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH18': Undulator(label='UMAHXH18', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH19': Undulator(label='UMAHXH19', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH20': Undulator(label='UMAHXH20', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH21': Undulator(label='UMAHXH21', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH22': Undulator(label='UMAHXH22', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH23': Undulator(label='UMAHXH23', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH25': Undulator(label='UMAHXH25', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH26': Undulator(label='UMAHXH26', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH27': Undulator(label='UMAHXH27', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH28': Undulator(label='UMAHXH28', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH29': Undulator(label='UMAHXH29', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH30': Undulator(label='UMAHXH30', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH31': Undulator(label='UMAHXH31', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH33': Undulator(label='UMAHXH33', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH34': Undulator(label='UMAHXH34', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH35': Undulator(label='UMAHXH35', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH36': Undulator(label='UMAHXH36', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH37': Undulator(label='UMAHXH37', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH38': Undulator(label='UMAHXH38', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH39': Undulator(label='UMAHXH39', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH40': Undulator(label='UMAHXH40', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH41': Undulator(label='UMAHXH41', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH42': Undulator(label='UMAHXH42', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH43': Undulator(label='UMAHXH43', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH44': Undulator(label='UMAHXH44', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH45': Undulator(label='UMAHXH45', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH46': Undulator(label='UMAHXH46', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH47': Undulator(label='UMAHXH47', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH48': Undulator(label='UMAHXH48', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH49': Undulator(label='UMAHXH49', aw=1.7017, lambdau=0.026, nwig=130), 'UMAHXH50': Undulator(label='UMAHXH50', aw=1.7017, lambdau=0.026, nwig=130), 'CORR00': Corrector(label='CORR00', L=0.001), 'CORR01': Corrector(label='CORR01', L=0.001), 'CORR02': Corrector(label='CORR02', L=0.001), 'CORR03': Corrector(label='CORR03', L=0.001), 'CORR04': Corrector(label='CORR04', L=0.001), 'CORR05': Corrector(label='CORR05', L=0.001), 'CORR06': Corrector(label='CORR06', L=0.001), 'CORR07': Corrector(label='CORR07', L=0.001), 'CORR08': Corrector(label='CORR08', L=0.001), 'CORR09': Corrector(label='CORR09', L=0.001), 'CORR10': Corrector(label='CORR10', L=0.001), 'CORR11': Corrector(label='CORR11', L=0.001), 'CORR12': Corrector(label='CORR12', L=0.001), 'CORR13': Corrector(label='CORR13', L=0.001), 'CORR14': Corrector(label='CORR14', L=0.001), 'CORR15': Corrector(label='CORR15', L=0.001), 'CORR16': Corrector(label='CORR16', L=0.001), 'CORR17': Corrector(label='CORR17', L=0.001), 'CORR18': Corrector(label='CORR18', L=0.001), 'CORR19': Corrector(label='CORR19', L=0.001), 'CORR20': Corrector(label='CORR20', L=0.001), 'CORR21': Corrector(label='CORR21', L=0.001), 'CORR22': Corrector(label='CORR22', L=0.001), 'CORR23': Corrector(label='CORR23', L=0.001), 'CORR24': Corrector(label='CORR24', L=0.001), 'CORR25': Corrector(label='CORR25', L=0.001), 'CORR26': Corrector(label='CORR26', L=0.001), 'CORR27': Corrector(label='CORR27', L=0.001), 'CORR28': Corrector(label='CORR28', L=0.001), 'CORR29': Corrector(label='CORR29', L=0.001), 'CORR30': Corrector(label='CORR30', L=0.001), 'CORR31': Corrector(label='CORR31', L=0.001), 'CORR32': Corrector(label='CORR32', L=0.001), 'CORR33': Corrector(label='CORR33', L=0.001), 'D1': Drift(label='D1', L=0.1335), 'D2': Drift(label='D2', L=0.4615), 'D3': Drift(label='D3', L=0.328), 'D4': Drift(label='D4', L=3.4), 'HXRSS': Chicane(label='HXRSS', L=4.55, lb=0.1), 'HXR': Line( label='HXR', elements=[ 'D1', 'UMAHXH17', 'D2', 'QHXH17', 'CORR00', 'D3', 'D1', 'UMAHXH18', 'D2', 'QHXH18', 'CORR01', 'D3', 'D1', 'UMAHXH19', 'D2', 'QHXH19', 'CORR02', 'D3', 'D1', 'UMAHXH20', 'D2', 'QHXH20', 'CORR03', 'D3', 'D1', 'UMAHXH21', 'D2', 'QHXH21', 'CORR04', 'D3', 'D1', 'UMAHXH22', 'D2', 'QHXH22', 'CORR05', 'D3', 'D1', 'UMAHXH23', 'D2', 'QHXH23', 'CORR06', 'D3', 'D1', 'HXRSS', 'D2', 'QHXH24', 'CORR07', 'D3', 'D1', 'UMAHXH25', 'D2', 'QHXH25', 'CORR08', 'D3', 'D1', 'UMAHXH26', 'D2', 'QHXH26', 'CORR09', 'D3', 'D1', 'UMAHXH27', 'D2', 'QHXH27', 'CORR10', 'D3', 'D1', 'UMAHXH28', 'D2', 'QHXH28', 'CORR11', 'D3', 'D1', 'UMAHXH29', 'D2', 'QHXH29', 'CORR12', 'D3', 'D1', 'UMAHXH30', 'D2', 'QHXH30', 'CORR13', 'D3', 'D1', 'UMAHXH31', 'D2', 'QHXH31', 'CORR14', 'D3', 'D1', 'D4', 'D2', 'QHXH32', 'CORR15', 'D3', 'D1', 'UMAHXH33', 'D2', 'QHXH33', 'CORR16', 'D3', 'D1', 'UMAHXH34', 'D2', 'QHXH34', 'CORR17', 'D3', 'D1', 'UMAHXH35', 'D2', 'QHXH35', 'CORR18', 'D3', 'D1', 'UMAHXH36', 'D2', 'QHXH36', 'CORR19', 'D3', 'D1', 'UMAHXH37', 'D2', 'QHXH37', 'CORR20', 'D3', 'D1', 'UMAHXH38', 'D2', 'QHXH38', 'CORR21', 'D3', 'D1', 'UMAHXH39', 'D2', 'QHXH39', 'CORR22', 'D3', 'D1', 'UMAHXH40', 'D2', 'QHXH40', 'CORR23', 'D3', 'D1', 'UMAHXH41', 'D2', 'QHXH41', 'CORR24', 'D3', 'D1', 'UMAHXH42', 'D2', 'QHXH42', 'CORR25', 'D3', 'D1', 'UMAHXH43', 'D2', 'QHXH43', 'CORR26', 'D3', 'D1', 'UMAHXH44', 'D2', 'QHXH44', 'CORR27', 'D3', 'D1', 'UMAHXH45', 'D2', 'QHXH45', 'CORR28', 'D3', 'D1', 'UMAHXH46', 'D2', 'QHXH46', 'CORR29', 'D3', 'D1', 'UMAHXH47', 'D2', 'QHXH47', 'CORR30', 'D3', 'D1', 'UMAHXH48', 'D2', 'QHXH48', 'CORR31', 'D3', 'D1', 'UMAHXH49', 'D2', 'QHXH49', 'CORR32', 'D3', 'D1', 'UMAHXH50', 'D2', 'QHXH50', 'CORR33', 'D3', ], ), 'LCLS2_HXR_U1': Line( label='LCLS2_HXR_U1', elements=[ 'D1', 'UMAHXH17', 'D2', 'QHXH17', 'CORR00', 'D3', 'D1', 'UMAHXH18', 'D2', 'QHXH18', 'CORR01', 'D3', 'D1', 'UMAHXH19', 'D2', 'QHXH19', 'CORR02', 'D3', 'D1', 'UMAHXH20', 'D2', 'QHXH20', 'CORR03', 'D3', 'D1', 'UMAHXH21', 'D2', 'QHXH21', 'CORR04', 'D3', 'D1', 'UMAHXH22', 'D2', 'QHXH22', 'CORR05', 'D3', 'D1', 'UMAHXH23', 'D2', 'QHXH23', 'CORR06', 'D3', ], ), 'LCLS2_HXR_U2': Line( label='LCLS2_HXR_U2', elements=[ 'D1', 'UMAHXH25', 'D2', 'QHXH25', 'CORR08', 'D3', 'D1', 'UMAHXH26', 'D2', 'QHXH26', 'CORR09', 'D3', 'D1', 'UMAHXH27', 'D2', 'QHXH27', 'CORR10', 'D3', 'D1', 'UMAHXH28', 'D2', 'QHXH28', 'CORR11', 'D3', 'D1', 'UMAHXH29', 'D2', 'QHXH29', 'CORR12', 'D3', 'D1', 'UMAHXH30', 'D2', 'QHXH30', 'CORR13', 'D3', 'D1', 'UMAHXH31', 'D2', 'QHXH31', 'CORR14', 'D3', 'D1', 'D4', 'D2', 'QHXH32', 'CORR15', 'D3', 'D1', 'UMAHXH33', 'D2', 'QHXH33', 'CORR16', 'D3', 'D1', 'UMAHXH34', 'D2', 'QHXH34', 'CORR17', 'D3', 'D1', 'UMAHXH35', 'D2', 'QHXH35', 'CORR18', 'D3', 'D1', 'UMAHXH36', 'D2', 'QHXH36', 'CORR19', 'D3', 'D1', 'UMAHXH37', 'D2', 'QHXH37', 'CORR20', 'D3', 'D1', 'UMAHXH38', 'D2', 'QHXH38', 'CORR21', 'D3', 'D1', 'UMAHXH39', 'D2', 'QHXH39', 'CORR22', 'D3', 'D1', 'UMAHXH40', 'D2', 'QHXH40', 'CORR23', 'D3', 'D1', 'UMAHXH41', 'D2', 'QHXH41', 'CORR24', 'D3', 'D1', 'UMAHXH42', 'D2', 'QHXH42', 'CORR25', 'D3', 'D1', 'UMAHXH43', 'D2', 'QHXH43', 'CORR26', 'D3', 'D1', 'UMAHXH44', 'D2', 'QHXH44', 'CORR27', 'D3', 'D1', 'UMAHXH45', 'D2', 'QHXH45', 'CORR28', 'D3', 'D1', 'UMAHXH46', 'D2', 'QHXH46', 'CORR29', 'D3', 'D1', 'UMAHXH47', 'D2', 'QHXH47', 'CORR30', 'D3', 'D1', 'UMAHXH48', 'D2', 'QHXH48', 'CORR31', 'D3', 'D1', 'UMAHXH49', 'D2', 'QHXH49', 'CORR32', 'D3', 'D1', 'UMAHXH50', 'D2', 'QHXH50', 'CORR33', 'D3', ], ), }, filename=pathlib.Path('/home/runner/work/lume-genesis/lume-genesis/docs/examples/genesis4/data/basic4/hxr.lat'), )
Here's what a fully-detailed table representation looks like:
G.input.lattice.to_table()
Attribute | Value | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
QHXH17 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH18 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH19 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH20 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH21 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH22 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH23 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH24 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH25 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH26 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH27 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH28 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH29 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH30 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH31 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH32 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH33 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH34 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH35 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH36 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH37 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH38 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH39 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH40 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH41 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH42 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH43 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH44 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH45 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH46 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH47 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH48 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH49 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
QHXH50 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH17 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH18 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH19 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH20 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH21 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH22 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH23 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH25 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH26 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH27 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH28 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH29 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH30 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH31 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH33 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH34 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH35 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH36 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH37 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH38 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH39 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH40 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH41 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH42 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH43 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH44 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH45 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH46 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH47 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH48 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH49 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UMAHXH50 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR00 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR01 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR02 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR03 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR04 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR05 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR06 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR07 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR08 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR09 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR10 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR11 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR12 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR13 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR14 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR15 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR16 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR17 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR18 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR19 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR20 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR21 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR22 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR23 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR24 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR25 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR26 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR27 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR28 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR29 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR30 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR31 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR32 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
CORR33 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
D1 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
D2 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
D3 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
D4 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
HXRSS |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
HXR |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
LCLS2_HXR_U1 |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
LCLS2_HXR_U2 |
|
You can turn off/on descriptions in tables and configure other aspects of LUME-Genesis rendering of objects for Jupyter:
genesis.global_display_options.include_description = False
G.input.main.writes[0].to_table()
Attribute | Value | Type |
---|---|---|
type | write | str |
field | end | str |
beam | str | |
stride | 1 | int |
View it as a markdown table for easy pasting into GitHub and other platforms:
print(G.input.main.profile_files[0].to_string("markdown"))
| Attribute | Value | Type | | :--------: | :---------------------: | :--: | | type | profile_file | str | | label | beamcurrent | str | | xdata | beam_current.h5/s | str | | ydata | beam_current.h5/current | str | | isTime | False | bool | | reverse | False | bool | | autoassign | False | bool |
Run¶
Run with MPI. Here, setting G.nproc = 0
will automatically select the maximum number of CPUs.
G.nproc = 0
output = G.run()
Configured to run in: /tmp/tmpb6sf9bwv Setting use_mpi = True because nproc = 2 Running Genesis4 in /tmp/tmpb6sf9bwv /home/runner/miniconda3/envs/lume-genesis-dev/bin/mpirun -n 2 /home/runner/miniconda3/envs/lume-genesis-dev/bin/genesis4 -l hxr.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:09:52 2024 MPI-Comm Size: 2 nodes Opened input file genesis4.in Parsing lattice file hxr.lat ... Setting up time window of 15.0027 microns with 544 sample points... Generating input radiation field for HARM = 1 ...
Adding profile with label: beamcurrent Adding profile with label: beamgamma Generating input particle distribution... Running Core Simulation... Time-dependent run with 544 slices for a time window of 15.0027 microns Initial analysis of electron beam and radiation field... Calculation: 0% done
Calculation: 10% done
Calculation: 20% done
Calculation: 30% done
Calculation: 40% done
Calculation: 50% done
Calculation: 60% done
Calculation: 70% done
Calculation: 80% done
Calculation: 90% done
Calculation: 100% done
Calculation: 110% done
Calculation terminated due to requested stop. Writing output file... Core Simulation done. End of Track Writing field distribution to file: end.fld.h5 ...
Writing particle distribution to file: end.par.h5 ... Program is terminating... Ending Time: Thu Aug 29 16:11:34 2024 Total Wall Clock Time: 102.527 seconds -------------------------------------
Success - execution took 102.65s.
if output.run.error:
print(G.output.run.error_reason)
else:
print("No error")
No error
Output¶
The main output is an HDF5. The Genesis4 object loads all array data into convenient Pydantic models:
G.output.beam, G.output.field
(OutputBeam( extra={}, globals=OutputBeamGlobal( extra={}, energy=array([], dtype=float64), energyspread=array([], dtype=float64), xposition=array([], dtype=float64), yposition=array([], dtype=float64), xsize=array([], dtype=float64), ysize=array([], dtype=float64), ), bunching=array(shape=(390, 544), dtype=float64), bunchingphase=array(shape=(390, 544), dtype=float64), energy=array(shape=(390, 544), dtype=float64), energyspread=array(shape=(390, 544), dtype=float64), xsize=array(shape=(390, 544), dtype=float64), ysize=array(shape=(390, 544), dtype=float64), lsc_field=array(shape=(390, 544), dtype=float64), ssc_field=array(shape=(390, 544), dtype=float64), efield=array(shape=(390, 544), dtype=float64), wakefield=array(shape=(390, 544), dtype=float64), emin=array(shape=(390, 544), dtype=float64), emax=array(shape=(390, 544), dtype=float64), pxmin=array(shape=(390, 544), dtype=float64), pxmax=array(shape=(390, 544), dtype=float64), pymin=array(shape=(390, 544), dtype=float64), pymax=array(shape=(390, 544), dtype=float64), pxposition=array(shape=(390, 544), dtype=float64), pyposition=array(shape=(390, 544), dtype=float64), xmin=array(shape=(390, 544), dtype=float64), xmax=array(shape=(390, 544), dtype=float64), ymin=array(shape=(390, 544), dtype=float64), ymax=array(shape=(390, 544), dtype=float64), xposition=array(shape=(390, 544), dtype=float64), yposition=array(shape=(390, 544), dtype=float64), alphax=array(shape=(1, 544), dtype=float64), alphay=array(shape=(1, 544), dtype=float64), betax=array(shape=(1, 544), dtype=float64), betay=array(shape=(1, 544), dtype=float64), current=array(shape=(390, 544), dtype=float64), emitx=array(shape=(1, 544), dtype=float64), emity=array(shape=(1, 544), dtype=float64), ), OutputField( extra={}, globals=OutputFieldGlobal( extra={}, energy=array([], dtype=float64), intensity_farfield=array([], dtype=float64), intensity_nearfield=array([], dtype=float64), xdivergence=array([], dtype=float64), ydivergence=array([], dtype=float64), xpointing=array([], dtype=float64), ypointing=array([], dtype=float64), xposition=array([], dtype=float64), yposition=array([], dtype=float64), xsize=array([], dtype=float64), ysize=array([], dtype=float64), ), dgrid=2e-06, intensity_farfield=array(shape=(390, 544), dtype=float64), intensity_nearfield=array(shape=(390, 544), dtype=float64), ngrid=101, phase_farfield=array(shape=(390, 544), dtype=float64), phase_nearfield=array(shape=(390, 544), dtype=float64), power=array(shape=(390, 544), dtype=float64), xdivergence=array(shape=(390, 544), dtype=float64), ydivergence=array(shape=(390, 544), dtype=float64), xpointing=array(shape=(390, 544), dtype=float64), ypointing=array(shape=(390, 544), dtype=float64), xposition=array(shape=(390, 544), dtype=float64), yposition=array(shape=(390, 544), dtype=float64), xsize=array(shape=(390, 544), dtype=float64), ysize=array(shape=(390, 544), dtype=float64), energy=array(shape=(390,), dtype=float64), ))
G.output.beam.stat.alphax.shape
(390,)
plt.plot(G.output.beam.stat.sigma_x)
plt.yscale("log")
Each of these parameters has a string alias that you can use to refer to the data. These string parameters can be used in G.plot()
and similar methods.
Here are the first 10 of those keys:
list(G.output.keys())[:10]
['beam_globals_energy', 'beam_globals_energyspread', 'beam_globals_xposition', 'beam_globals_yposition', 'beam_globals_xsize', 'beam_globals_ysize', 'beam_bunching', 'beam_bunchingphase', 'beam_energy', 'beam_energyspread']
print("Took", G.output.run.run_time, "sec")
Took 102.65288374 sec
To inspect these aliases, check this dictionary:
print(G.output.alias["alphax"])
beam.alphax
G.output["alphax"] is G.output.beam.alphax
True
The above indicates that the alias "alphax"
corresponds to the attribute beam.alphax
. So, you could access the data either as G.output["alphax"]
or G.output.beam.alphax
.
Though the former may be shorter, you can take advantage of tab completion when working with the Python classes directly. Try typing G.output.beam.
and then hit tab with the cursor after the final .
. You should see a list of other output beam data.
There are many outputs. .output_info()
gives a convenient table describing what was read in.
genesis.global_display_options.include_description = True
G.output.info()
Key | Units | Shape | Description |
---|---|---|---|
alphax | rad | (1, 544) | Twiss alpha horizontal. Evaluated only at the beginning. [rad] |
alphay | rad | (1, 544) | Twiss alpha vertical. Evaluated only at the beginning. [rad] |
aw | (4332,) | The dimensionless rms undulator parameter. For planar undulator this value is smaller by a factor $1 / \sqrt{2}$ than its K-value, while for helical undulator rms and peak values are identical. | |
ax | m | (4332,) | Offset of the undulator module in $x$ in meter. |
ay | m | (4332,) | Offset of the undulator module in $y$ in meter. |
beam_alphax | rad | (1, 544) | Twiss alpha horizontal. Evaluated only at the beginning. [rad] |
beam_alphay | rad | (1, 544) | Twiss alpha vertical. Evaluated only at the beginning. [rad] |
beam_betax | m | (1, 544) | Twiss beta horizontal. Evaluated only at the beginning. [m] |
beam_betay | m | (1, 544) | Twiss beta vertical. Evaluated only at the beginning. [m] |
beam_bunching | (390, 544) | Evaluated at each integration step. [unitless] | |
beam_bunchingphase | rad | (390, 544) | Evaluated at each integration step. [rad] |
beam_current | A | (390, 544) | Beam current. Evaluated only at the beginning. [A] |
beam_efield | eV/m | (390, 544) | Efield, internally eloss+longESC [eV/m] |
beam_emax | eV | (390, 544) | Particle energy maximum. Genesis4 mc^2 units are automatically converted to eV in LUME-Genesis. |
beam_emin | eV | (390, 544) | Particle energy minimum. Genesis4 mc^2 units are automatically converted to eV in LUME-Genesis. |
beam_emitx | m | (1, 544) | Beam horizontal emittance. Evaluated only at the beginning. [m] |
beam_emity | m | (1, 544) | Beam vertical emittance. Evaluated only at the beginning. [m] |
beam_energy | eV | (390, 544) | Evaluated at each integration step. Genesis4 mc^2 units are automatically converted to eV in LUME-Genesis. |
beam_energyspread | eV | (390, 544) | Evaluated at each integration step. Genesis4 mc^2 units are automatically converted to eV in LUME-Genesis. |
beam_globals_energy | (0,) | ||
beam_globals_energyspread | (0,) | ||
beam_globals_xposition | (0,) | ||
beam_globals_xsize | (0,) | ||
beam_globals_yposition | (0,) | ||
beam_globals_ysize | (0,) | ||
beam_lsc_field | eV/m | (390, 544) | Longitudinal space charge [eV/m] |
beam_pxmax | rad | (390, 544) | Particle horizontal maximum momentum [rad] |
beam_pxmin | rad | (390, 544) | Particle horizontal minimum momentum [rad] |
beam_pxposition | rad | (390, 544) | Particle horizontal position in momentum space [rad] |
beam_pymax | rad | (390, 544) | Particle vertical maximum momentum [rad] |
beam_pymin | rad | (390, 544) | Particle vertical minimum momentum [rad] |
beam_pyposition | rad | (390, 544) | Particle vertical position in momentum space [rad] |
beam_sigma_energy | eV | (390,) | |
beam_sigma_x | m | (390,) | |
beam_sigma_y | m | (390,) | |
beam_ssc_field | eV/m | (390, 544) | Short-range space charge [eV/m] |
beam_stat_alphax | rad | (390,) | |
beam_stat_alphay | rad | (390,) | |
beam_stat_betax | m | (390,) | |
beam_stat_betay | m | (390,) | |
beam_stat_bunching | (390,) | ||
beam_stat_bunchingphase | rad | (390,) | |
beam_stat_current | A | (390,) | |
beam_stat_efield | eV/m | (390,) | |
beam_stat_emitx | m | (390,) | |
beam_stat_emity | m | (390,) | |
beam_stat_energy | eV | (390,) | |
beam_stat_energyspread | eV | (390,) | |
beam_stat_lsc_field | eV/m | (390,) | |
beam_stat_pxmax | rad | (390,) | |
beam_stat_pxmin | rad | (390,) | |
beam_stat_pxposition | rad | (390,) | |
beam_stat_pymax | rad | (390,) | |
beam_stat_pymin | rad | (390,) | |
beam_stat_pyposition | rad | (390,) | |
beam_stat_sigma_energy | eV | (390,) | |
beam_stat_sigma_x | m | (390,) | |
beam_stat_sigma_y | m | (390,) | |
beam_stat_ssc_field | eV/m | (390,) | |
beam_stat_wakefield | eV/m | (390,) | |
beam_stat_xmax | m | (390,) | |
beam_stat_xmin | m | (390,) | |
beam_stat_xposition | m | (390,) | |
beam_stat_ymax | m | (390,) | |
beam_stat_ymin | m | (390,) | |
beam_stat_yposition | m | (390,) | |
beam_wakefield | eV/m | (390, 544) | Wakefield, internally the energy loss. [eV/m] |
beam_xmax | m | (390, 544) | Particle horizontal maximum position [m] |
beam_xmin | m | (390, 544) | Particle horizontal minimum position [m] |
beam_xposition | m | (390, 544) | Partical horizontal position [m] |
beam_xsize | m | (390, 544) | Beam horizontal sigma. [m] |
beam_ymax | m | (390, 544) | Particle vertical maximum position [m] |
beam_ymin | m | (390, 544) | Particle vertical minimum position [m] |
beam_yposition | m | (390, 544) | Partical vertical position [m] |
beam_ysize | m | (390, 544) | Beam horizontal sigma. [m] |
betax | m | (1, 544) | Twiss beta horizontal. Evaluated only at the beginning. [m] |
betay | m | (1, 544) | Twiss beta vertical. Evaluated only at the beginning. [m] |
bunching | (390, 544) | Evaluated at each integration step. [unitless] | |
bunchingphase | rad | (390, 544) | Evaluated at each integration step. [rad] |
chic_angle | degree | (4332,) | |
chic_lb | m | (4332,) | Length of an individual dipole in meter. |
chic_ld | m | (4332,) | Drift between the outer and inner dipoles, projected onto the undulator axis. The actual path length is longer by the factor $1/\cos\theta$, where $\theta$ is the bending angle of an individual dipole. |
chic_lt | m | (4332,) | |
current | A | (390, 544) | Beam current. Evaluated only at the beginning. [A] |
cx | rad | (4332,) | Kick angle in $x$ in units of $\gamma \beta_x$. |
cy | rad | (4332,) | Kick angle in $y$ in units of $\gamma \beta_y$. |
dz | m | (4332,) | Step length |
efield | eV/m | (390, 544) | Efield, internally eloss+longESC [eV/m] |
emax | eV | (390, 544) | Particle energy maximum. Genesis4 mc^2 units are automatically converted to eV in LUME-Genesis. |
emin | eV | (390, 544) | Particle energy minimum. Genesis4 mc^2 units are automatically converted to eV in LUME-Genesis. |
emitx | m | (1, 544) | Beam horizontal emittance. Evaluated only at the beginning. [m] |
emity | m | (1, 544) | Beam vertical emittance. Evaluated only at the beginning. [m] |
field1_energy | J | (390,) | Calculated by LUME-Genesis using slen from /Global. |
field1_globals_energy | (0,) | ||
field1_globals_intensity_farfield | (0,) | Field intensity in the far field [arb units] | |
field1_globals_intensity_nearfield | (0,) | Field intensity in the near field [arb units] | |
field1_globals_xdivergence | (0,) | Horizontal divergence [rad] | |
field1_globals_xpointing | (0,) | Horizontal pointing. [rad] | |
field1_globals_xposition | (0,) | Horizontal position. [m] | |
field1_globals_xsize | (0,) | Horizontal sigma. [m] | |
field1_globals_ydivergence | (0,) | Vertical divergence [rad] | |
field1_globals_ypointing | (0,) | Vertical pointing. [rad] | |
field1_globals_yposition | (0,) | Vertical position. [m] | |
field1_globals_ysize | (0,) | Vertical sigma. [m] | |
field1_intensity_farfield | W/rad^2 | (390, 544) | Field intensity in the far field [arb units] |
field1_intensity_nearfield | W/m^2 | (390, 544) | Field intensity in the near field [arb units] |
field1_peak_power | W | (390,) | Peak power [W]. |
field1_phase_farfield | rad | (390, 544) | Far field phase [rad] |
field1_phase_nearfield | rad | (390, 544) | Near field phase [rad] |
field1_power | W | (390, 544) | Power [W] |
field1_stat_energy | (390,) | ||
field1_stat_intensity_farfield | (390,) | ||
field1_stat_intensity_nearfield | (390,) | ||
field1_stat_phase_farfield | (390,) | ||
field1_stat_phase_nearfield | (390,) | ||
field1_stat_power | (390,) | ||
field1_stat_xdivergence | (390,) | ||
field1_stat_xpointing | (390,) | ||
field1_stat_xposition | (390,) | ||
field1_stat_xsize | (390,) | ||
field1_stat_ydivergence | (390,) | ||
field1_stat_ypointing | (390,) | ||
field1_stat_yposition | (390,) | ||
field1_stat_ysize | (390,) | ||
field1_xdivergence | rad | (390, 544) | Horizontal divergence [rad] |
field1_xpointing | rad | (390, 544) | Horizontal pointing. [rad] |
field1_xposition | m | (390, 544) | Horizontal position. [m] |
field1_xsize | m | (390, 544) | Horizontal sigma. [m] |
field1_ydivergence | rad | (390, 544) | Vertical divergence [rad] |
field1_ypointing | rad | (390, 544) | Vertical pointing. [rad] |
field1_yposition | m | (390, 544) | Vertical position. [m] |
field1_ysize | m | (390, 544) | Vertical sigma. [m] |
field_energy | J | (390,) | Calculated by LUME-Genesis using slen from /Global. |
field_globals_energy | (0,) | ||
field_globals_intensity_farfield | (0,) | Field intensity in the far field [arb units] | |
field_globals_intensity_nearfield | (0,) | Field intensity in the near field [arb units] | |
field_globals_xdivergence | (0,) | Horizontal divergence [rad] | |
field_globals_xpointing | (0,) | Horizontal pointing. [rad] | |
field_globals_xposition | (0,) | Horizontal position. [m] | |
field_globals_xsize | (0,) | Horizontal sigma. [m] | |
field_globals_ydivergence | (0,) | Vertical divergence [rad] | |
field_globals_ypointing | (0,) | Vertical pointing. [rad] | |
field_globals_yposition | (0,) | Vertical position. [m] | |
field_globals_ysize | (0,) | Vertical sigma. [m] | |
field_intensity_farfield | W/rad^2 | (390, 544) | Field intensity in the far field [arb units] |
field_intensity_nearfield | W/m^2 | (390, 544) | Field intensity in the near field [arb units] |
field_peak_power | W | (390,) | Peak power [W]. |
field_phase_farfield | rad | (390, 544) | Far field phase [rad] |
field_phase_nearfield | rad | (390, 544) | Near field phase [rad] |
field_power | W | (390, 544) | Power [W] |
field_stat_energy | (390,) | ||
field_stat_intensity_farfield | (390,) | ||
field_stat_intensity_nearfield | (390,) | ||
field_stat_phase_farfield | (390,) | ||
field_stat_phase_nearfield | (390,) | ||
field_stat_power | (390,) | ||
field_stat_xdivergence | (390,) | ||
field_stat_xpointing | (390,) | ||
field_stat_xposition | (390,) | ||
field_stat_xsize | (390,) | ||
field_stat_ydivergence | (390,) | ||
field_stat_ypointing | (390,) | ||
field_stat_yposition | (390,) | ||
field_stat_ysize | (390,) | ||
field_xdivergence | rad | (390, 544) | Horizontal divergence [rad] |
field_xpointing | rad | (390, 544) | Horizontal pointing. [rad] |
field_xposition | m | (390, 544) | Horizontal position. [m] |
field_xsize | m | (390, 544) | Horizontal sigma. [m] |
field_ydivergence | rad | (390, 544) | Vertical divergence [rad] |
field_ypointing | rad | (390, 544) | Vertical pointing. [rad] |
field_yposition | m | (390, 544) | Vertical position. [m] |
field_ysize | m | (390, 544) | Vertical sigma. [m] |
frequency | (544,) | Frequency [eV] | |
globals_frequency | (544,) | Frequency [eV] | |
globals_s | (544,) | Longitudinal position [m] | |
gradx | 1/m | (4332,) | Relative transverse gradient of undulator field in $x$ $\equiv (1/a_w) \partial a_w/\partial x$. |
grady | 1/m | (4332,) | Relative transverse gradient of undulator field in $y$ $\equiv (1/a_w) \partial a_w/\partial y$. |
ku | 1/m | (4332,) | |
kx | (4332,) | Roll-off parameter of the quadratic term of the undulator field in x. It is normalized with respect to $k_u^2$. | |
ky | (4332,) | Roll-off parameter of the quadratic term of the undulator field in y. | |
lattice_aw | (4332,) | The dimensionless rms undulator parameter. For planar undulator this value is smaller by a factor $1 / \sqrt{2}$ than its K-value, while for helical undulator rms and peak values are identical. | |
lattice_ax | m | (4332,) | Offset of the undulator module in $x$ in meter. |
lattice_ay | m | (4332,) | Offset of the undulator module in $y$ in meter. |
lattice_chic_angle | degree | (4332,) | |
lattice_chic_lb | m | (4332,) | Length of an individual dipole in meter. |
lattice_chic_ld | m | (4332,) | Drift between the outer and inner dipoles, projected onto the undulator axis. The actual path length is longer by the factor $1/\cos\theta$, where $\theta$ is the bending angle of an individual dipole. |
lattice_chic_lt | m | (4332,) | |
lattice_cx | rad | (4332,) | Kick angle in $x$ in units of $\gamma \beta_x$. |
lattice_cy | rad | (4332,) | Kick angle in $y$ in units of $\gamma \beta_y$. |
lattice_dz | m | (4332,) | Step length |
lattice_gradx | 1/m | (4332,) | Relative transverse gradient of undulator field in $x$ $\equiv (1/a_w) \partial a_w/\partial x$. |
lattice_grady | 1/m | (4332,) | Relative transverse gradient of undulator field in $y$ $\equiv (1/a_w) \partial a_w/\partial y$. |
lattice_ku | 1/m | (4332,) | |
lattice_kx | (4332,) | Roll-off parameter of the quadratic term of the undulator field in x. It is normalized with respect to $k_u^2$. | |
lattice_ky | (4332,) | Roll-off parameter of the quadratic term of the undulator field in y. | |
lattice_phaseshift | rad | (4332,) | Phase shift in radians. |
lattice_qf | 1/m^2 | (4332,) | Quadrupole focusing strength in $1/m^2$ |
lattice_qx | m | (4332,) | Quadrupole offset in $x$ in meters. |
lattice_qy | m | (4332,) | Quadrupole offset in $y$ in meters. |
lattice_slippage | (4332,) | Lattice slippage. | |
lattice_z | m | (4332,) | Step Z position in m. The same length and describes the lattice quantities from the position ``.z[i]`` to ``.z[i]+.dz[i]`` of the i-th integration step. |
lattice_zplot | m | (390,) | For plotting the beam or field parameters along the undulator. |
lsc_field | eV/m | (390, 544) | Longitudinal space charge [eV/m] |
meta_beamdumps_intstep | (0,) | ||
meta_fielddumps_intstep | (0,) | ||
peak_power | W | (390,) | Peak power [W]. |
phase_farfield | rad | (390, 544) | Far field phase [rad] |
phase_nearfield | rad | (390, 544) | Near field phase [rad] |
phaseshift | rad | (4332,) | Phase shift in radians. |
power | W | (390, 544) | Power [W] |
pxmax | rad | (390, 544) | Particle horizontal maximum momentum [rad] |
pxmin | rad | (390, 544) | Particle horizontal minimum momentum [rad] |
pxposition | rad | (390, 544) | Particle horizontal position in momentum space [rad] |
pymax | rad | (390, 544) | Particle vertical maximum momentum [rad] |
pymin | rad | (390, 544) | Particle vertical minimum momentum [rad] |
pyposition | rad | (390, 544) | Particle vertical position in momentum space [rad] |
qf | 1/m^2 | (4332,) | Quadrupole focusing strength in $1/m^2$ |
qx | m | (4332,) | Quadrupole offset in $x$ in meters. |
qy | m | (4332,) | Quadrupole offset in $y$ in meters. |
s | (544,) | Longitudinal position [m] | |
slippage | (4332,) | Lattice slippage. | |
ssc_field | eV/m | (390, 544) | Short-range space charge [eV/m] |
wakefield | eV/m | (390, 544) | Wakefield, internally the energy loss. [eV/m] |
xmax | m | (390, 544) | Particle horizontal maximum position [m] |
xmin | m | (390, 544) | Particle horizontal minimum position [m] |
ymax | m | (390, 544) | Particle vertical maximum position [m] |
ymin | m | (390, 544) | Particle vertical minimum position [m] |
z | m | (4332,) | Step Z position in m. The same length and describes the lattice quantities from the position ``.z[i]`` to ``.z[i]+.dz[i]`` of the i-th integration step. |
zplot | m | (390,) | For plotting the beam or field parameters along the undulator. |
Fields¶
Field files can be very large and are made readily available for lazy loading.
Loaded fields are present in .field
attribute of the output:
list(G.output.field3d)
[]
For convenience, fields and particles may be automatically loaded after a run by using run(load_fields=True, load_particles=True)
instead.
Otherwise, these can be manually loaded individually or all at once:
G.output.load_fields()
['end']
list(G.output.field3d)
['end']
This field data has two parts: basic parameters param
, and the raw 3D complex array dfl
:
G.output.field3d["end"].param
FieldFileParams( gridpoints=101, gridsize=2e-06, wavelength=1.3789244869952112e-10, slicecount=544, slicespacing=2.7578489739904225e-08, )
G.output.field3d["end"].dfl.shape
(101, 101, 544)
.field
is a convenience property that points to this
G.output.field3d["end"].param
FieldFileParams( gridpoints=101, gridsize=2e-06, wavelength=1.3789244869952112e-10, slicecount=544, slicespacing=2.7578489739904225e-08, )
Visualize Field¶
# Sum over y and compute the absolute square
dfl = G.output.field3d["end"].dfl
param = G.output.field3d["end"].param
dat2 = np.abs(np.sum(dfl, axis=1)) ** 2
plt.imshow(dat2)
<matplotlib.image.AxesImage at 0x7f0690a2aae0>
def plot_slice(i=0):
dat = np.angle(dfl[:, :, i])
dx = param.gridsize * 1e6
plt.xlabel("x (µm)")
plt.xlabel("y (µm)")
plt.title(f"Phase for slize {i}")
plt.imshow(dat.T, origin="lower", extent=[-dx, dx, -dx, dx])
plot_slice(i=100)
Particles¶
Particle files can be read in as openPMD-beamphysics ParticleGroup
objects.
These are loaded only on-demand by default (run(load_particles=False)
). They may also be loaded all at once, with load_particles()
.
list(G.output.particle_files)
['end']
G.output.load_particles()
['end']
After loading particles, use the .particles
attribute to access their data:
G.output.particles
{'end': <ParticleGroup with 557056 particles at 0x7f068ccf23f0>}
P = G.output.particles["end"]
P.plot("z", "energy")
Change to z coordinates to see the current. Note that the head of the bunch is now on the left.
P.drift_to_z()
P.plot("t", "energy")
Check some statistics
P["norm_emit_x"], P["norm_emit_y"], P["mean_gamma"]
(np.float64(4.000048858978795e-07), np.float64(4.0000677465417614e-07), np.float64(19174.078131770453))
Bunching¶
wavelength = G.input.main.setup.lambda0
bunching_key = f"bunching_{wavelength}"
P.drift_to_t()
P.slice_plot(bunching_key, n_slice=1000)
# Genesis4 data
final_bunching = G.output.beam.bunching[-1, :]
current = G.output.beam.current[-1, :]
s = G.output.globals.s
# ParticleGroup data
ss = P.slice_statistics(bunching_key, n_slice=len(s))
ss.keys()
x = ss["mean_z"]
y = ss[bunching_key]
Compare
fig, ax = plt.subplots()
ax.plot(x * 1e6, y, label="ParticleGroup")
ax.plot(s * 1e6, final_bunching, "--", label="Genesis4 output")
ax.set_xlabel("s (µm)")
ax.set_ylabel("bunching")
plt.legend()
<matplotlib.legend.Legend at 0x7f0677103860>
This is the average bunching from the ParticleGroup:
P.bunching(wavelength)
np.complex128(-5.1640693087131355e-05+5.012701108053942e-05j)
That agrees with the appropriate averaging of Genesis4's bunching calc:
G.stat("bunching")[-1]
np.float64(7.196859337842972e-05)
G.plot("bunching")
Check the total charge in pC:
P["charge"] / 1e-12 # pC
np.float64(50.1584225612439)
Units¶
Each item in the output class should have corresponding units.
G.output.units("beam_betax")
pmd_unit('m', 1, (1, 0, 0, 0, 0, 0, 0))
Plotting¶
Convenient plotting of the data in .output
is provided by .plot
. The default is to plot the power. Depending on the key these statistics are averaged or integrated over the slices. Some keys like power
are converted to peak_power
, while field_energy
is the integral over field_power
.
print(G.output.alias["power"])
field.power
G.plot()
Left and right axes can be set this way:
G.plot("field_energy", yscale="log", y2=["beam_xsize", "beam_ysize"], ylim2=(0, 100e-6))
By default, these plots average over slices. In the case of beam sizes, simply averaging these does not take into account the effect of misaligned slices. To plot this, LUME-Genesis provides additional beam_sigma_x
, beam_sima_y
, beam_sigma_energy
keys that properly project these quantities. The difference is noticable in the energy spread calculation:
G.plot(["beam_sigma_energy", "beam_energyspread"], ylim=(0, 100))
The field slice statistics are power-weighted averages:
G.plot(["field_xsize", "field_ysize"])
plt.imshow(G.output.field.power, aspect="auto");
Archiving¶
G.archive("archived.h5")
Grestored = Genesis4.from_archive("archived.h5")
Grestored.output.plot()
Check that the restored object is the same¶
The Genesis4 object as well as the input, output, and all namelists support equality checks:
Grestored == G
True
Grestored.input == G.input
True
Grestored.output == G.output
True
Manual loading of Genesis4 data¶
Sometimes it is necessary to run Genesis4 manually, and load the output into LUME-Genesis for further analysis.
First, let's create some input to run in a local directory temp/
:
import os
os.makedirs("temp/", exist_ok=True)
G.write_input("temp/")
Now run on the command line:
!cd temp; ./run | tee log.txt
--------------------------------------------- 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:11:42 2024 MPI-Comm Size: 2 nodes Opened input file genesis4.in Parsing lattice file hxr.lat ... Setting up time window of 15.0027 microns with 544 sample points... Generating input radiation field for HARM = 1 ...
Adding profile with label: beamcurrent Adding profile with label: beamgamma Generating input particle distribution...
Running Core Simulation... Time-dependent run with 544 slices for a time window of 15.0027 microns Initial analysis of electron beam and radiation field...
Calculation: 0% done
Calculation: 10% done
Calculation: 20% done
Calculation: 30% done
Calculation: 40% done
Calculation: 50% done
Calculation: 60% done
Calculation: 70% done
Calculation: 80% done
Calculation: 90% done
Calculation: 100% done
Calculation: 110% done
Calculation terminated due to requested stop. Writing output file...
Core Simulation done. End of Track Writing field distribution to file: end.fld.h5 ...
Writing particle distribution to file: end.par.h5 ...
Program is terminating... Ending Time: Thu Aug 29 16:13:25 2024 Total Wall Clock Time: 102.814 seconds -------------------------------------
Using the use_temp_dir=False
and workdir
options, the input and output data can be loaded into a new Genesis4 object:
G2 = Genesis4("genesis4.in", use_temp_dir=False, workdir="temp/", verbose=True)
G2.configure()
output = G2.load_output()
Configured to run in: temp/
output.plot()
Cleanup¶
import shutil
shutil.rmtree("temp")
os.remove("archived.h5")