Closed
Conversation
…them together in the right way.
… a different field map.
…tively. Also, the subscript of ks and kn used to run from 1 to multipole_order+1, now from 0 to multipole_order. Additionally, spline_param_schema makes sure the parameters are always ordered in the correct way to be imported by SplineBoris.
…nue with radiation first.
…ls. Quantum does not work yet.
…entation of the Boris integrator.
Contributor
|
I had a quick look and some comments. |
# Conflicts: # xtrack/beam_elements/elements.py
…at takes care of unit conversion in the FieldFitter.
…t. So gitignore updated.
…oved the sls_2.0 directory and moved everything to sls. All related tests continue to pass.
Member
|
Superseded by #758 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Added the SplineBoris and SplineBorisSequence to the elements.
SplineBoris (
xtrack/beam_elements/elements.py)The SplineBoris is based on a magnetic field description from bpmeth. We describe the field components (Bx, By, Bs) and the derivatives of Bx and By w.r.t. x as fourth order polynomials. These coefficients are ultimately passed to a field-evaluation function that is constructed using bpmeth. SplineBoris accepts the coefficients of these polynomials, as well as the start and end s-coordinate of the element and the number of steps to track particles through the magnetic field. The tracking algorithm is the Boris integrator (see
xtrack/beam_elements/elements_src/splineboris.handxtrack/beam_elements/elements_src/track_splineboris.h), which is written in C, but adopted from the existing Python implementation from BorisSpatialIntegrator. The magnetic field evaluation function is generated fromxtrack/beam_elements/elements_src/_generate_bpmeth_to_C.py. The resulting file isxtrack/beam_elements/elements_src/_spline_B_field_eval.h.SplineBorisSequence (
xtrack/beam_elements/elements.py)The SplineBorisSequence element allows for defining a sequence of SplineBoris elements to describe more complicated field structures. It requires a pandas dataframe of aforementioned polynomial coefficients indexed by their start and end s-coordinates. The SplineBorisSequence constructs a line consisting of individual SplineBoris elements, which can used as a usual line.
FieldFitter (see
xtrack/_temp/field_fitter.py)The required pandas dataframe can be generated using the FieldFitter class, which requires a path to a file of raw data which can either be a csv file or pandas dataframe and is set to df_raw_data. At each$s$ -point in the data, it fits $B_x(x)$ and $B_y(x)$ as a polynomial of deg+1. It then computes successive derivatives of these polynomials and evaluates them at $x=x_0$ , the $x$ -coordinate of the longitudinal axis. The values of these derivatives are stored in df_on_axis_raw.
After df_on_axis_raw is filled, the fitter checks the order-of-magnitude of the derivatives w.r.t. the main field. This tolerance can be set with field_tol, which is$10^-3$ by default. More specifically, it checks if:
Here,$n$ is the order of the derivative and $i \in (x,\ y)$ . If the above is true, it is assumed that the particular combination of $B_i$ and derivative order $n$ has negligible effect on the dynamics and will not be fitted. This serves as a noise-filter.
Then, the FieldFitter finds extrema in the remaining fields/derivatives and defines these extrema as region boundaries. Then, it cuts the regions between the extrema in regions of min_region_size points. The aim of this method is to provide good accuracy around the extrema, as well as in between them.
To each of these regions, a polynomial of degree 4 is fitted. The resulting polynomial coefficients are stored in df_fit_pars, indexed by their magnetic field, derivative, s_start, s_end, idx_start and idx_end. This df_fit_pars can be read directly by SplineBorisSequence to build a sequence of individual SplineBoris elements with the correct set of parameters.
Parameter Ordering
An important point of note: The field evaluation function (_spline_B_field_eval.h) requires the parameters to be ordered as: The coefficients of the Bs polynomial, the coefficients of Bx and subsequent derivatives, the coefficients of By and subsequent derivatives. This parameter ordering is defined inside SplineBoris under the ParamFormat class, which contains several methods to check parameter ordering, as well as the definition of the polynomial used to describe the field. The FieldFitter etc. derive their parameter ordering and naming convention from ParamFormat.
Tests:
test_splineboris_homogeneous_analytic: Tests the SplineBoris for a homogeneous magnetic field at various angles against an analytical solution.test_splineboris_homogeneous_rbend: Tests the SplineBoris for a similar field as in the test above, but against the RBend in Xsuite.test_uniform_solenoid: Tests the SplineBoris for a uniform solenoid against the UniformSolenoid in Xsuite.test_splineboris_solenoid_vs_variable_solenoid: Tests the SplineBoris(Sequence) against the VariableSolenoid in Xsuite.test_splineboris_undulator_vs_boris_spatial: Tests the SplineBoris(Sequence) against the BorisSpatialIntegrator in Xsuite on the same field map.test_splineboris_rotated_undulator_vs_boris_spatial: Rotates the field map from the previous test by 90 degrees and checks that the fit-parameters are also rotated by 90 degrees (that is,test_splineboris_radiation: Tests mean and quantum radiation in a homogeneous magnetic field against an analytical solution.test_splineboris_variable_solenoid_radiation: Similar totest_splineboris_solenoid_vs_variable_solenoid, but tests radiation.test_splineboris_spin_uniform_solenoid: Tests the SplineBoris spin tracking against the UniformSolenoid in Xsuite.test_splineboris_spin_quadrupole: Tests the SplineBoris spin tracking in an ideal quadrupole against the Quadrupole in Xsuite.Examples:
000a_sls_no_undulators: Reference to later examples, twissing the SLS000b_sls_no_undulators_closed_spin: Reference to later examples, SLS with spin tracking001_fieldfitter_basic_usage: Simple example applying the FieldFitter and plotting the results002_homogeneous_rbend: Similar to the RBend test, demonstrates the SplineBoris against the RBend for several "roll" angles003a_undulator_open_spin_tracking: Open spin-tracking through the undulator003b_undulator_open_spin_tracking_radiation: Open spin and radiation tracking through the undulator004a_sls_with_undulators: Inserts the undulators in the SLS and performs a closed orbit Twiss004b_sls_with_undulators_closed_spin: Same as 004a but with spin004c_sls_with_undulators_closed_spin_radiation: Same as 004a but with spin and radiation004d_sls_offset_undulators: Same as 004a, but with the undulators offset004e_sls_offset_undulators_closed_spin: Same as 004d, but with spin tracking005_solenoid: Similar to thetest_splineboris_solenoid_vs_variable_solenoidtest, but with a few plots to show the tracksCloses # .
Checklist
Mandatory:
Optional: