ocelot-collab / ocelot

OCELOT is a multiphysics simulation toolkit designed for studying FEL and storage ring-based light sources.
GNU General Public License v3.0
84 stars 58 forks source link

Help to understand "plot_opt_func" #232

Closed laxmisubramanyam closed 4 months ago

laxmisubramanyam commented 5 months ago

Hi,

I made some more progress in understanding how different functions work, however, I got confused at one point when I was making use of plot_opt_func.

I made one very small test case, and tried to make three figures (with plot_opt_func) at different stages of the simulation. But I could not completely understand what these plots means. Please, could you provide some help to understand what the three figures display in the test code below:


from copy import deepcopy

# import from Ocelot main modules and functions
from ocelot import *

# import from Ocelot graphical modules
from ocelot.gui import *
from ocelot.gui.accelerator import *

import time

# Generate an electron beam - ParticleArray

tws0 = Twiss()
tws0.beta_x = 10
tws0.beta_y = 10
tws0.alpha_x = 0
tws0.alpha_y = 0
tws0.E = 100e-3

p_array_initial = generate_parray(sigma_tau=0.5e-3,
                               sigma_px=5.0e-4, energy=tws0.E, sigma_p=1.0e-3,
                               nparticles=20000, charge=700.0e-12)

Twiss_initial = get_envelope(p_array_initial)

#############################
### create a chicane lattice
#############################

d =Drift(0.1)

Lmag = 0.1      # length of magnets

angle0 = 10.75 *np.pi/180

b1 = SBend(l=Lmag, angle=angle0, e2=angle0, eid='B1')
b2 = SBend(l=Lmag, angle=-angle0, e1=-angle0, eid='B2')
b3 = SBend(l=Lmag, angle=-angle0, e2=-angle0, eid='B3')
b4 = SBend(l=Lmag, angle=angle0, e1=angle0, eid='B4')

m1 = Marker(eid="START")
m2 = Marker(eid="SCREEN")

chicane = (b1, d, b2, d, d, b3, d, b4)

cell = (m1, d, chicane, d, m2)

lat = MagneticLattice(cell, method={"global": SecondTM})

########################################
# First plot
########################################

tws = twiss(lat, Twiss_initial)

plot_opt_func(lat, tws, fig_name= 'first plot', legend=False)

# Now, track the beam through the lattice *

p_array = deepcopy(p_array_initial)

sc1 = SpaceCharge()
sc1.nmesh_xyz = [63, 63, 63]
sc1.step = 0.01

navi = Navigator(lat)

navi.add_physics_proc(sc1, lat.sequence[0], lat.sequence[-1])

tws_track, _ = track(lat, p_array, navi)

########################################
# Second plot
########################################

plot_opt_func(lat, tws_track, fig_name= 'second plot', legend=False)

########################################
# Third plot
########################################

Twiss_final = get_envelope(p_array)
tws_fin = twiss(lat, Twiss_final)

plot_opt_func(lat, tws_fin, fig_name= 'third plot', legend=False)

plt.show()

Could you please let me know what is the difference between: tws, tws_track and tws_fin in the above code.

Thanks a lot. Laxmi

laxmisubramanyam commented 5 months ago

Hi,

my main aim is to plot the evolution of beta_x and beta_y etc. of the electron beam as it propagates through the chicane and including the space-charge effect.

Thank you.

laxmisubramanyam commented 4 months ago

Hi,

it would be great if any help is provided to properly use space-charge effect in beam transportation. In the above test simulation do you think plot_opt_func(lat, tws, fig_name= 'first plot', legend=False) is without space-charge and plot_opt_func(lat, tws_track, fig_name= 'second plot', legend=False) is with space-charge effect ?

sergey-tomin commented 4 months ago

Hi, I did not run you script but what I see it following:

First plot - you just tracked the Twiss parameters through the lattice, so you plotted the linear optics of your beamline.

Second plot - You tracked the beam with space charge, and on each step, the get_envelop() function was called to calculate the Twiss parameters. So it is "Twiss parameters" with SC and second order effect. However, please note that in dispersive sections e.g. bunch compressor, twiss parameters are calculated not correctly due to dispersion if the beam non zero energy spread.

Third plot - does not make sense

Cheers, Sergey

laxmisubramanyam commented 4 months ago

Hi @sergey-tomin

Thanks for making things pretty clear. Maybe now I understand why the longitudinal dispersion (Dx) show a nice plot on the top of beta_x and beta_y evolution with plot_opt_func(lat, tws) . But Dx is always zero when I was trying to see the beta_x and beta_y evolution including the space-charge effect plot_opt_func(lat, tws_track).

Thanks a lot.

Best regards, Laxmi

sergey-tomin commented 4 months ago

yes exactly get_envelop calculates moments of beam distribution and Dx/Dy will be always zero. And Dx is actually transverse dispersion.