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
86 stars 58 forks source link

Some plotting functions #226

Closed dmargarone closed 7 months ago

dmargarone commented 7 months ago

Dear Developers,

I am an 2nd year bachelor student and trying my best to understand the functioning of the code.

Although I am really enjoying using OCELOT, I am having some confusion on how to make plots of some of the parameters evolution of the electron beam when it is passing through a chicane.

For example: (1) I want to make plot of electron beam spot size evolution throughout the propagation from the chicane. (2) I want to make plot of electron beam emittance evolution throughout the propagation from the chicane. (3) I want to plot trajectory of electron beam with maximum, minimum and mean energy throughout the propagation from the chicane. (4) I want to plot of chirp evolution throughout the propagation from the chicane.

Any help and suggestion on how to make above plots will be high appreciable.

Thank you.

Daniele

dmargarone commented 7 months ago

Dear All,

any suggestions or help to my question will be very useful for my mid-term bachelor thesis ...

Thank you.

st-walker commented 7 months ago

Add SaveBeam processes to the Navigator to a marker (so you have to/should pad your lattice with markers) at the end of each element. This writes the ParticleArray to file.

from  ocelot.cpbd.physics_proc import SaveBeam
sb = SaveBeam("marker0,s=0.3m.npz") # For example, say (but you do this many times with different names)
navi.add_physics_proc(sb)

Then you run your simulation, and lots of files will be written. one file = one particle array (at a given point in the lattice) Then you do all the analysis offline. Load each particle array, do the analysis on each array in a loop, extract e.g. beam size, make a plot.

dmargarone commented 7 months ago

Thank you @st-walker , the process looks longer but not difficult. It will really help me.

One more question, the beta_x and beta_y of the electron beam can be plotted while running the simulation using the following command:

tws_track, _ = track(lat, p_array, navi) plot_opt_func(lat, tws_track, fig_name=1, legend=False)

does there is any such method also for emittance (or other parameters) evolution ?

Thank you.

st-walker commented 7 months ago

If it's not included in the output (tws_track), then you will need to use the SaveBeam approach in combination with get_envelope (projected parameters_ or get_slice_properties (slice parameters).

Just look into tws_track and see what is there.

dmargarone commented 7 months ago

Thanks a lot @st-walker , you are so good in explaining.

st-walker commented 7 months ago

I just noticed in this snippet:

navi.add_physics_proc(sb)

this is wrong, you of course need to put the correct start and stop poitns as well. tehse should be the same, and tehy shoudl eb a marker.