Analysis of the SI BC dipole

Initializations

This section loads necessary python packages, including fieldmaptrack. It also defines a few static parameters that should not change.


In [160]:
import fieldmaptrack
import numpy as np
import matplotlib.pyplot as plt
import math

%matplotlib inline

class Config:
    pass
config = Config()

path = '/home/fac_files/data/sirius/si/magnet_modelling/bc/fieldmaps/'
config.magnet_type = 'dipole'
config.interactive_mode = True

analysis = fieldmaptrack.common_analysis.get_analysis_symbol(config.magnet_type)


def plot_multipole(config, n, title, xfactor, type='normal'):
    if type == 'normal':
        mult = config.multipoles.normal_multipoles
        idx = config.multipoles_normal_field_fitting_monomials.index(n)
    else:
        mult = config.multipoles.skew_multipoles
        idx = config.multipoles_skew_field_fitting_monomials.index(n)
    s  = config.traj.s
    plt.figure(); 
    plt.plot(s, mult[idx,:]); plt.grid(True);
    f = (config.multipoles_r0/1000)**n;
    labely = 'By [T]' if n == 0 else 'dBy/dx [T/m]' if n == 1 else 'd{0:d}By/dx{0:d} [T/m^{0:d}]'.format(n)
    plt.xlabel('s [mm]'); plt.ylabel(labely); plt.title(title);
    ax = plt.gca(); yl = plt.ylim(); ny = ax.twinx(); ny.plot(s, normal[idx,:]*f);
    ny.set_ylabel('By @ r0 [T]');
    plt.ylim(f*yl[0],f*yl[1]);
    plt.xlim(min(s),xfactor*max(s));

Rawfield Analysis

In this section basic analysis on raw fieldmap data is performed. The fielmap is loaded and basic parameters are printed, along with longitudinal and transverse field profiles. These profiles are plotted in the magnet coordinate system (rectangular coordinate system)


In [161]:
# --- parameters ---

config.config_label            = 'bc-model1'
config.fmap_filename           = path + '2015-10-08_Dipolo_Anel_BC_B3_Modelo1_gap_lateral_0mm_peca_0mm_-100_12mm_-2000_2000mm.txt'
config.fmap_extrapolation_flag = False

# --- analysis ---

config = analysis.raw_fieldmap_analysis(config)

# --- plot fields ---

fig, ax = plt.subplots(2,2, sharey=True, figsize=(12,10));

'''By Longitudinal Profile at X = 0 mm'''
x,y = config.fmap.rz, config.fmap.by[config.fmap.ry_zero][config.fmap.rx_zero,:];
ax[0,0].plot(x,y); ax[0,0].grid(True); ax[0,0].set_title('Longitudinal Profile of By');
ax[0,0].set_xlabel('rz [mm]'); ax[0,0].set_ylabel('by [T]');
'''Bx Longitudinal Profile at X = 0 mm'''
x,y = config.fmap.rz, config.fmap.bx[config.fmap.ry_zero][config.fmap.rx_zero,:];
ax[0,1].plot(x,y); ax[0,1].grid(True); ax[0,1].set_title('Longitudinal Profile of Bx');
ax[0,1].set_xlabel('rz [mm]'); ax[0,1].set_ylabel('bx [T]');

'''By Transverse Profile ar Z = 0 mm'''
x,y = config.fmap.rx, config.fmap.by[config.fmap.ry_zero][:,config.fmap.rz_zero];
ax[1,0].plot(x,y); ax[1,0].grid(True); ax[1,0].set_title('Transverse Profile of By');
ax[1,0].set_xlabel('rx [mm]'); ax[1,0].set_ylabel('by [T]');

'''Bx Transverse Profile ar Z = 0 mm'''
x,y = config.fmap.rx, config.fmap.bx[config.fmap.ry_zero][:,config.fmap.rz_zero];
ax[1,1].plot(x,y); ax[1,1].grid(True); ax[1,1].set_title('Transverse Profile of Bx');
ax[1,1].set_xlabel('rx [mm]'); ax[1,1].set_ylabel('bx [T]');


--- fieldmap ---
timestamp:                          2015-10-08_17-08-12
filename:                           2015-10-08_Dipolo_Anel_BC_B3_Modelo1_gap_lateral_0mm_peca_0mm_-100_12mm_-2000_2000mm.txt
magnet_label:                       BC_B3_Anel
magnet_length:                      896.26 mm
main_coil_current:                  -- A
magnetic_gap:                       None mm
control_gap:                        0.0 mm
ry_grid:                            1 point in [0.0,0.0] mm (step of 0.000000 mm)
rx_grid:                            225 points in [-100.0,12.0] mm (step of 0.500000 mm)
rz_grid:                            4001 points in [-2000.0,2000.0] mm (step of 1.000000 mm)
by@(all)(axis):                     (min:-3.22409 max:+0.00007) (min:-3.22409 max:+0.00006) Tesla
bx@(all)(axis):                     (min:-0.00001 max:+0.00004) (min:-0.00000 max:+0.00000) Tesla
bz@(all)(axis):                     (min:-0.00004 max:+0.00003) (min:-0.00000 max:+0.00000) Tesla

Trajectory

Finds Runge-Kutta trajectory from interpolated fieldmap. It also plot the trajectory on the rz-rx plane and the evolution of the deflected angle.


In [162]:
# --- parameters ---

config.beam_energy              = 3.0    # [GeV]
config.traj_load_filename       = None   #           -- used when a traj is to be loaded from file instead of calculated
config.traj_is_reference_traj   = False  #           -- if reference trajectory than 
config.traj_force_midplane_flag = True   #           -- force motion to be on y=0 plane? (through eqs of motion)
config.traj_init_rx             = 0.0    # [mm]      -- initial rx at rz=0 (center of magnet)
config.traj_center_sagitta_flag = False  #           -- search for initial rx so that tyraj. is centered.
config.traj_rk_s_step           = 1.0    # [mm]      -- Runge-Kutta longitudinal s step
config.traj_rk_length           = None   # [mm]      -- Runge-Kutta maximum traj. length
config.traj_rk_nrpts            = None   #           -- Runge-Kutta number of points

# --- RK trajectory calculation ---
config = analysis.trajectory_analysis(config);

# --- rx position and angle
rx = config.traj.rx
rz = config.traj.rz
s  = config.traj.s
angle = np.arctan(config.traj.px/config.traj.pz) * (180/math.pi)

# --- plots ---
fig, ax = plt.subplots(1,2, sharey=False, figsize=(12,4));
ax[0].plot(rz, rx); ax[0].grid(True); ax[0].set_title('Trajectory')
ax[0].set_xlabel('rz [mm]'); ax[0].set_ylabel('rx [mm]');
ax[1].plot(s, angle); ax[1].grid(True); ax[1].set_title('Angle')
ax[1].set_xlabel('s [mm]'); ax[1].set_ylabel('angle [degree]');


--- trajectory (rz > 0) ---
beam_energy:                        3.000 GeV
horizontal_deflection_angle:        -2.1655e+00 deg.
vertical_deflection_angle:          +0.0000e+00 deg.
trajectory_length:                  2001.0 mm
trajectory_nrpts:                   2002
trajectory_s_step:                  1.0 mm
max_abs_bx@trajectory:              +0.000000 Tesla at (s,rx,ry,rz) = (451.0,-9.506789230798825,0.0,450.8807005599615) mm
max_abs_by@trajectory:              -3.224088 Tesla at (s,rx,ry,rz) = (0.0,0.0,0.0,0.0) mm
max_abs_bz@trajectory:              +0.000000 Tesla at (s,rx,ry,rz) = (451.0,-9.506789230798825,0.0,450.8807005599615) mm
rx position of reference point:     +7.574898 mm
initial rx position of trajectory:  +0.000000 mm
sagitta:                            9.433752486057086 mm

Multipoles


In [181]:
# --- parameters ---

config.multipoles_normal_field_fitting_monomials = (0,1,2,3,4)
config.multipoles_skew_field_fitting_monomials = ()
config.multipoles_perpendicular_grid = np.linspace(-10,10,41)
config.multipoles_r0 = 11.7
config.normalization_monomial = 0
config.normalization_is_skew = False
config.normal_multipoles_main_monomials = (0,1)
config.skew_multipoles_main_monomials = ()

# --- multipole calculation ---

config = analysis.multipoles_analysis(config);
normal = config.multipoles.normal_multipoles
skew = config.multipoles.skew_multipoles


--- multipoles on reference trajectory (rz > 0) ---

perpendicular_grid:                 41 points in [-10.000000,+10.000000] mm
max_fitting_error_normal            35.249/32178.770 G/G
max_fitting_error_skew              0.000/0.000 G/G
r0_for_relative_multipoles          11.7 mm
main_monomial                       n = 0, skew:False
                                      MaxAbs_Nn     Integ_Nn     Nn/N0(@r0)   |   MaxAbs_Sn     Integ_Sn     Sn/S0(@r0)  
<multipole_order n>                    [T/m^n]      [T.m/m^n]        []       |    [T/m^n]      [T.m/m^n]        []      
n=00:                                3.2231e+00    -3.7821e-01   +1.0000e+00  |      ---           ---           ---     
n=01:                                1.1199e+01    +3.6338e+00   -1.1241e-01  |      ---           ---           ---     
n=02:                                2.0941e+02    -5.5486e+00   +2.0083e-03  |      ---           ---           ---     
n=03:                                1.5921e+03    -4.1824e+01   +1.7712e-04  |      ---           ---           ---     
n=04:                                8.5336e+06    +7.3563e+04   -3.6448e-03  |      ---           ---           ---     

In [183]:
plot_multipole(config, n=0,  title='Normal Quadrupolar Field', xfactor=0.4, type='normal')
plot_multipole(config, n=1,  title='Normal Quadrupolar Field', xfactor=0.4, type='normal')
plot_multipole(config, n=2,  title='Normal Sextupolar Field', xfactor=0.4, type='normal')
plot_multipole(config, n=4,  title='Normal 2*(4+1)-polar Field', xfactor=0.4, type='normal')
# plot_multipole(config, n=5,  title='Normal 2*(5+1)-polar Field', xfactor=0.4, type='normal')
# plot_multipole(config, n=6,  title='Normal 2*(6+1)-polar Field', xfactor=0.4, type='normal')
# plot_multipole(config, n=7,  title='Normal 2*(7+1)-polar Field', xfactor=0.4, type='normal')
# plot_multipole(config, n=8,  title='Normal 2*(8+1)-polar Field', xfactor=0.4, type='normal')
# plot_multipole(config, n=10, title='Normal 2*(10+1)-polar Field', xfactor=0.4, type='normal')



In [ ]:
title = 'Normal Dipolar Field'; n = 0;
plt.figure(); idx = config.multipoles_normal_field_fitting_monomials.index(n)
plt.plot(s, normal[idx,:]); plt.grid(True); plt.xlim(min(s),0.4*max(s));
plt.xlabel('s [mm]'); plt.ylabel('By [T]'); plt.title(title);

title = 'Normal Quadrupolar Field'; n = 1;
plt.figure(); idx = config.multipoles_normal_field_fitting_monomials.index(n)
plt.plot(s, normal[idx,:]); plt.grid(True); plt.xlim(min(s),0.4*max(s));
plt.xlabel('s [mm]'); plt.ylabel('dBy/dx [T/m]'); plt.title(title);

title = 'Normal Sextupolar Field'; n = 2;
plt.figure(); idx = config.multipoles_normal_field_fitting_monomials.index(n)
plt.plot(s, normal[idx,:]); plt.grid(True); plt.xlim(min(s),0.3*max(s));
plt.xlabel('s [mm]'); plt.ylabel('d2By/dx2 [T/m^2]'); plt.title(title);

title = 'Normal Octupolar Field'; n = 3;
plt.figure(); idx = config.multipoles_normal_field_fitting_monomials.index(n)
plt.plot(s, normal[idx,:]); plt.grid(True); plt.xlim(min(s),0.3*max(s));
plt.xlabel('s [mm]'); plt.ylabel('d3By/dx3 [T/m^3]'); plt.title(title);

title = 'Normal Decapolar Field'; n = 4;
plt.figure(); idx = config.multipoles_normal_field_fitting_monomials.index(n)
plt.plot(s, normal[idx,:]); plt.grid(True); plt.xlim(min(s),0.3*max(s));
plt.xlabel('s [mm]'); plt.ylabel('d4By/dx4 [T/m^4]'); plt.title(title);

title = 'Normal Dodecapolar Field'; n = 5;
plt.figure(); idx = config.multipoles_normal_field_fitting_monomials.index(n)
plt.plot(s, normal[idx,:]); plt.grid(True); plt.xlim(min(s),0.3*max(s));
plt.xlabel('s [mm]'); plt.ylabel('d5By/dx5 [T/m^5]'); plt.title(title);