Note
Go to the end to download the full example code.
Electrode Creation
Before creating any electrodes, we need to familiarize ourselves with a few concepts. First- whenever you initialize a system, you need to pick nr, nz, axial_size and radial_size. nr is the grid resolution in the r-dimension, and nz is the same for the z-dimension. Axial_size is the total length of the domain in meters in the z-dimension, and radial_size is the same for the r-dimension.
This means the grid resolution in the z-dimension is axial_size/nz, and in the r-dimension is radial_size/nr. You should, if using nonstandard values for these, ensure you’re aware of these so you can properly convert from grid units to meters.
You can initialize a two-cylinder lens with -5000V and 0V respectively as follows:

13 import numpy as np
14 from picht import ElectronOptics, ElectrodeConfig
15 import matplotlib.pyplot as plt
16
17 system = ElectronOptics(nr=100, nz=600, axial_size=0.6, radial_size = 0.1)
18
19 electrode = ElectrodeConfig(
20 start=30,
21 width=100,
22 ap_start=30,
23 ap_width=40,
24 outer_diameter = 50,
25 voltage=-5000
26 )
27
28 system.add_electrode(electrode)
29 electrode1 = ElectrodeConfig(
30 start=160,
31 width=100,
32 ap_start=30,
33 ap_width=40,
34 outer_diameter = 50,
35 voltage=0
36 )
37
38 system.add_electrode(electrode1)
39
40 potential = system.solve_fields()
41
42 trajectories = system.simulate_beam(
43 energy_eV= 1000,
44 start_z=0,
45 r_range=(0.04, 0.06),
46 angle_range=(0, 0),
47 num_particles=10,
48 simulation_time=2e-8
49 )
50
51 figure = system.visualize_system(
52 trajectories=trajectories,
53 display_options=[True, False, False, False]) #only switches on the lens visualization, keeps the e-field, b-field and animations off in the start, so the generated thumbnails look cleaner
54
55 plt.show()
Total running time of the script: (0 minutes 5.215 seconds)