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

plotting twiss parameters #251

Closed zhangli28 closed 4 months ago

zhangli28 commented 4 months ago

Dear Developers,

I am simulating a long beam line with many elements in the lattice. Looking into the tutorials I have seen that twiss parameters (say beta_x,y) is always plotted with initial twiss value tws = twiss(lat, tws0) but I have never seen twiss parameters plot using a tws = twiss(lat, tws_track), where tws_track, _ = track(lat, p_array, navi) Why ?

st-walker commented 4 months ago

No reason, you can do if you like. In principle they should be the same, with linear elements and no/minimal collective effects, they will be the same. It can be a nice way to confirm the tracking works correctly by comparing the two sets of value.

zhangli28 commented 4 months ago

Thanks @st-walker.

I read in some papers that in the regime of strong space-charge effect the particle energy is no longer constant, therefore, in such regimes the twiss parameters are not well defined. Similarly, in dispersive section the electron beam blow out and again the twiss parameters cannot be well defined. PRAB 18, 014201 (2015).

Does this means that if I am simulating a beamline with strong focusing (with quadrupoles) and dispersive sections (like chicane), I cannot get the correct twiss parameter evolution ? But the prime aim of the simulation is to check how twiss parameters evolve during beam transportation.

st-walker commented 4 months ago

Yes, if space charge is contributing strongly to the behaviour of the particles then you will have different Twiss parameters (regardless of whether it is meaningful to define them) compared to the pure linear case with no collective effects.

But the prime aim of the simulation is to check how twiss parameters evolve during beam transportation

Well, try it and see. Maybe you can compare them, maybe you can look at the moments (e.g. variance, mean, etc.) instead. You will just have to try it and find out.

zhangli28 commented 4 months ago

Thanks @st-walker. If I follow you correctly, you mean instead of using: emitx = [tw.emit_x for tw in tws_track] I should do emitx = sqrt( <x**2> <x’**2> - <xx’>) ? And then calculate beta-twiss like: beta_x = <x**2>/emitx

If you don't mind could you let me know how I can get the values of x and x' ?

Is this is correct for x: x = [tw.x for tw in tws_track] ?

sergey-tomin commented 4 months ago

Hi No, this is already done for you when you calculate Twiss parameters from the particle distribution (tws_track as you denote it). See the function get_envelop() from https://github.com/ocelot-collab/ocelot/blob/master/ocelot/cpbd/beam.py. From this point of view, it does not matter if you include any collective effects or not. However, it will not provide the correct Twiss for dispersive sections because coupling between longitudinal and transverse planes. Regarding the paper you mentioned, I need to read it to understand what they meant why Twiss parameters are not well defined in SC dominated regime.

By the way we use tws_track, _ = track(lat, p_array, navi) see Tutorial 2. https://github.com/ocelot-collab/ocelot/blob/master/demos/ipython_tutorials/2_tracking.ipynb

zhangli28 commented 4 months ago

Thanks @sergey-tomin. I checked Tutorial 2 and made comparison of the Twiss-beta evolution both with and without space charge effect. The results are very different for the entire beam line. This means not only dispersive sections like chicane but throughout the beam line the twist-parameters are different.

See the attached comparitive figure.

I simple included the space charge as

# include space-charge effect

p_array = deepcopy(p_array_init)

sc = SpaceCharge()
sc.nmesh_xyz = [63, 63, 63]
sc.step = 1

navi = Navigator(lat_t)

navi.unit_step = 0.1

navi.add_physics_proc(sc, lat_t.sequence[0], lat_t.sequence[-1])

start = time.time()

tws_track2, p_array = track(lat_t, p_array, navi)

print("\n time exec:", time.time() - start, "sec")

How do I interpret the differences in the twiss-beta evolution ? If, in my study, I want to include twiss or emittance evolution what should I do ?

beta_comparison

sergey-tomin commented 4 months ago

I didn't understand the question. They should be different since the SC was switched on in one of the cases.

zhangli28 commented 4 months ago

@sergey-tomin

My question is: If I want to show the evolution of twiss-parameters in my paper, which one I should include, the one with space-charge or without space charge. Please, note that I have done all the simulation including space-charge effects.

st-walker commented 4 months ago

@zhangli28: only you can answer that question. It depends on what you are doing and what you want to say with a figure.

sergey-tomin commented 4 months ago

hi @st-walker is correct. I cannot advise since I do not know what your paper is about. We often only show linear optics if our main interest is in longitudinal dynamics. However, if you are writing about transverse dynamics, both cases may be interesting. Your colleagues can judge how strong the space charge effect is in your particular case. But again, if you have dispersion the Twiss parameters from tracking will be incorrect due to coupling between transverse and longitudinal planes. I would avoid showing it.

zhangli28 commented 4 months ago

Thanks @sergey-tomin and @st-walker

I would like to see how these results look like with other codes. By the way, I would suggest using more examples in the tutorial. Your code is one of the best for end-users. I am thinking of replacing old codes with your codes in my lectures for undergraduate students. At the moment ocelot includes 3D space-charge and 1D CSR effects. It would be great to hear if 3D CSR effects will also be on list.

Best wishes, Zhang