felix-andreas / apace

Another Particle Accelerator Code
https://apace.readthedocs.io
GNU General Public License v3.0
7 stars 1 forks source link

Improve the workflow with the `Twiss` object #71

Open felix-andreas opened 4 years ago

felix-andreas commented 4 years ago

Currently an instance of the Twiss class is linked a given Lattice object. If the Lattice object changes so will the Twiss object.

This can be counter-intuitive if one wants to save some reference values before optimizing a given lattice and can lead to mistakes:

twiss = ap.Twiss(lattice)
ref_beta_x = twiss.beta_x

# do the opitmization
beta_x = twiss.beta_x

Now ref_beta_x is bound to the same underlying numpy.ndarray as beta_x. This might be error prone.

One solution to that would be to always allocate a new numpy.ndarray when calculating th twiss parameter instead of reusing the old one. Test how large the overhead would be!