GeneralizedGradients.jl¶
Julia code to calculate and manipulate generalized gradients (GGs): functions
that compactly describe magnetic (and electric) fields. The package is currently
geared toward magnetic fields and supports both straight and curved (sbend)
reference frames.
The notation follows S. Van der Schueren et al., “Magnetic Field Modelling and
Symplectic Integration of Magnetic Fields on Curved Reference Frames for Improved
Synchrotron Design: First Steps” (a copy is in the papers directory of the
repository). Here the gg functions are a(s), b(s), and b_s(s) together
with their s-derivatives.
What it does¶
Starting from a 3D field grid (e.g. from a magnet solver or a measurement), the package can:
Fit the grid to generalized gradients, plane by plane — see Fitting a field grid.
Evaluate the field, vector potential, and its derivatives anywhere from the fitted GGs — see Evaluating the fitted field.
Export to Bmad as either a
grid_fieldor agen_grad_mapelement — see Exporting to Bmad.
The complete docstring reference is in the API Reference (linked in the sidebar).
Quick example¶
using GeneralizedGradients
field = read_field_grid_hdf5("wsnk_fieldmap_reduced.h5") # a FieldGridTable
params = GGFitInputParams()
params.n_planes_add = 1
params.output_file = "gg_fit_result.h5"
results = gg_fit(field, params) # fit GGs plane by plane
gg_fit_show_results(results, field, params) # print a summary
write_gg_fit(results, field, params) # save to HDF5
# Convert the fit to a Bmad gen_grad_map element:
write_bmad_gg_fit("gg_fit_result.h5")