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

nPoints of twiss output in tracking function #258

Closed SchroederSa closed 2 months ago

SchroederSa commented 2 months ago

Hi,

Is there a way to increase the number of nPoints, i.e. the number of s-evaluations for the tracking twiss output?

I'd like to have tws_track being more granular sampled for nicer plotting: tws_track, p_array = track(triplet.lat, p_array, navi, print_progress=False)

I saw that it works through the envelope calculations, but I couldn't find any handle to increase the stepping output.

In the attached plot, I added an aperture at the s-location of the black dotted line. Given the limited s-sampling of tws_track the first bit of sigma up to the aperture is incorrectly depicted.

Thanks! Sarah

Screenshot 2024-08-29 at 2 40 12 AM
SchroederSa commented 2 months ago

To illustrate what I mean. Here, I added an infinitesimal short drift just in front of the aperture to have an additional value in the envelope extraction:

Screenshot 2024-08-29 at 2 56 19 AM
st-walker commented 2 months ago

If you look at the code track is calculating the twiss at every step given by the navigator. So based on this, I would suggest decreasing the navigator unit step. If this results in too much of a slow down, scale the corresponding steps of all your physics processes, then add an empty proc with a step = 1. I'm not sure I've done this but I think it should work. The idea anyway should be clear: force the navigator to go in smaller steps.

SchroederSa commented 2 months ago

Ok, thanks. So far, I don't have any physics processes included.

st-walker commented 2 months ago

Then add an emptyproc to force the navigator to take small steps and set the unit step of the navigator as small as you like.

SchroederSa commented 2 months ago

Great, thanks for the quick help!

For reference:

navi = Navigator(lat)
navi.activate_apertures()
ep = EmptyProc()
ep.step=0.1
navi.add_physics_proc(ep, lat.sequence[1], triplet.lat.sequence[-2])
navi.unit_step = 0.1
tws_track, p_array = track(.lat, p_array, navi, print_progress=False)

Although I still have the infinitesimal dummy drift just before the aperture, it allows me to have a larger step value and doesn't falsify the result (too much) :).

Screenshot 2024-08-29 at 3 54 39 AM
SchroederSa commented 2 months ago

Thanks!

st-walker commented 2 months ago

In principle step should be an integer (it is dimensionless). The physics process is applied every step*Navigator.unit_step, so Navigator.unit_step defines the increment step forward taken by the ParticleArray, so it is units of metres. I don't know what impact it has in this case, though. I don't know what happens if you pick a float step and particularly if you pick a physics process step <1. Maybe @sergey-tomin can comment on this.