atcollab / at

Accelerator Toolbox
Apache License 2.0
48 stars 31 forks source link

pyat: Optics #4

Closed willrogers closed 4 years ago

willrogers commented 7 years ago

From @willrogers on July 21, 2017 14:23

From @willrogers on October 6, 2016 20:59

Another point is: what’s next ? You brought the engine, but AT is thousands of lines of Matlab code. I was thinking of “atlinopt” and a few convenience routines to extract/modify lattice parameters (atgetcells, atgetfieldvalues, atsetfieldvalues…). Do you already have plans ?

I was going to base the requirements on what I need for a python middle layer type application: twiss parameters, tunes etc.

There is a lot of stuff in AT, but there's no need to make a complete clone, at least to start with, and translating Matlab to Python is relatively straightforward. The code should be more compact in Python as well.

Copied from original issue: willrogers/at#11

Copied from original issue: atcollab/at2devel#5

willrogers commented 7 years ago

From @bnash on October 11, 2016 14:30

Here is a simple function to compute the 6x6 one turn map matrix. From this we can compute generalized Twiss parameters, invariants, etc. May still be a good idea to have uncoupled limits to get simple Twiss params. I checked and got approximate agreement with Matlab on this. The Matlab version uses an epsilon of 6.055454452393343e-006 claiming this is somehow optimal (referencing numerical recipes). I don't really know why. (I'm trying to make the code display with indentation properly, but it doesn't work)

import at
import numpy

def pyATm66(ring):
    eps=1e-10
    epsmat=eps*numpy.identity(6)
    mm=at.atpass(ring, epsmat, 1)/eps
    return numpy.transpose(mm)
willrogers commented 7 years ago

Three backticks before the code and three backticks afterwards.

willrogers commented 7 years ago

(Backtick is top-left on the UK keyboard).

willrogers commented 7 years ago

From @bnash on October 11, 2016 15:3

Thanks, next step is to make a version of the amat function (linear normal form, converts matrix to 3 rotations) https://github.com/willrogers/at/blob/pyat/atmat/atphysics/amat.m in python.

From there, we can also make generalized lattice functions with Forests 'betaoids' and 'etaoids' http://journals.aps.org/pre/abstract/10.1103/PhysRevE.58.2481

https://github.com/willrogers/at/blob/pyat/atmat/pubtools/local_lattice_params/find_betaoids.m

We also need to make utilities for computing things at different places around the ring. Many of the functions in Matlab AT accept a set of indices that compute the quantities at those positions in the lattice.

willrogers commented 7 years ago

From @bnash on October 11, 2016 15:7

amat can also be used to compute eigenemittance following computing second moment matrix (Sigma) from ohmi-envelope https://github.com/willrogers/at/blob/pyat/atmat/atphysics/ohmienvelope.m Though, I think the eigenvalues of J*Sigma also give you the emittances.

willrogers commented 4 years ago

We now have substantial progress on this so I will close the ticket.