This repository provides a Python tool to extract 2D multipole components (dipole, quadrupole, sextupole, octupole, …) from a transverse electric field map containing Ex(x,y) and Ey(x,y).
It computes complex multipole coefficients (C_n) using a circular Fourier method and generates:
- 2D maps of Ex, Ey, and |E| for total and each multipole order
- 1D cuts along x (y≈0) and y (x≈0) with total + multipole components
- a run report (
*_OPT.txt) including (C_n), (|C_n|), phase, normalized amplitude, and field-quality radii (0.2%, 0.5%, 1%)
This tool treats your transverse 2D electric field map as approximately source-free in the region of interest (no space charge inside the aperture), so the electrostatic potential satisfies Laplace’s equation:
In a 2D Laplace region, the field can be represented by an analytic complex function. Define the complex coordinate and complex field:
In a charge-free region,
The coefficients
-
$n=1$ : dipole (uniform field) -
$n=2$ : quadrupole (linear gradient) -
$n=3$ : sextupole (quadratic nonlinearity) -
$n=4$ : octupole (cubic nonlinearity) - etc.
Write
Then the $n$th-order contribution is
So the amplitude of each order scales with radius as:
This is why higher-order errors grow quickly as you move away from the center.
Because
the real field components are obtained by:
For each multipole order:
If
The tool also reports a normalized amplitude at a reference radius
which has units of V/m and represents the characteristic magnitude of the $n$th multipole contribution at that radius. A simple nonlinearity estimate at
The coefficients are computed by sampling the field on a circle of radius
Form the complex field on that circle:
Using the orthogonality of
With
If multiple radii are provided, the tool computes
The total field magnitude is:
Let
For each radius bin (thin annulus), the tool computes the peak relative deviation:
The 0.2%, 0.5%, and 1% radii are the smallest radii where:
These radii are drawn as dashed circles on the total _OPT.txt report.
A .dat (or .txt / .csv) file with a header and 4 columns:
X Y Ex Ey
Create an environment and install dependencies:
pip install -r requirements.txt├─ README.md ├─ requirements.txt ├─ .gitignore ├─ data/ │ ├─ field.dat # example input (NOT required to commit) │ └─ .gitkeep ├─ outputs/ │ └─ .gitkeep # outputs are generated at runtime └─ src/ └─ *.py # your script
electrode_geometry.yaml
Main configuration file defining electrode geometry parameters.
electrode_geometry_example.yaml
Example YAML configuration template.
genXXXX_evalYYYYYY_best.yaml
Optimized geometry files produced during CMA‑ES runs.
electrodes_field.py
Main FEM solver that:
- Builds electrode geometry
- Generates FEM mesh
- Solves electrostatic potential
- Computes electric field (Ex, Ey)
Outputs:
- phi_map.png
- emag_density.png
- mesh_wireframe.png
- simulation_output.txt
electrodes_fast_v1.py
A faster FEM implementation optimized for repeated evaluations during optimization.
field_analysis.py
Computes multipole expansion coefficients from field data.
electrodes_field_analysis.py
Runs the field solver and performs multipole analysis automatically.
Outputs a table:
n name Re(Cn) Im(Cn) |Cn| phase(rad) |Cn|*r_ref^(n-1)
Also calculates:
- Sum of higher‑order multipoles (n > 2)
- Radius where field deviation reaches 0.005
cma_es_optimize_serial.py
Runs CMA‑ES optimization in serial mode.
cma_es_optimize_ll.py
Advanced CMA‑ES optimization implementation.
electrodes_interp.cma.py
Interpolation utilities used during optimization.
- Edit geometry
electrode_geometry.yaml
- Run field solver
python electrodes_field.py electrode_geometry.yaml
- Run field analysis
python electrodes_field_analysis.py electrode_geometry.yaml
- Run optimization
python cma_es_optimize_serial.py
or
python cma_es_optimize_ll.py
or
electrodes_interp.cma.py # multiple points interpolation
This toolkit provides a workflow for:
- Electrode geometry generation
- Electrostatic FEM simulation
- Multipole field analysis
- Automatic electrode optimization