Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twiss with coupled latice #40

Closed
iagapov opened this issue Oct 2, 2015 · 5 comments
Closed

twiss with coupled latice #40

iagapov opened this issue Oct 2, 2015 · 5 comments
Assignees

Comments

@iagapov
Copy link
Owner

iagapov commented Oct 2, 2015

with coupling twiss does not work with error

ocelot/cpbd/optics.py:170: RuntimeWarning: divide by zero encountered in double_scalars
d_mux = arctan(M[0, 1]/(M[0, 0]_m.beta_x - M[0, 1]_m.alpha_x))

this should be changed to some other warning/error indicating that in coupled case decoupled twiss is not correct

test case:

D0 = Drift (l = 5., id = "D0")
D1 = Drift (l = 1., id = "D1")
D2 = Drift (l = 2.0, id = "D2")

Q1 = Quadrupole (l = 0.1, k1 = -0.6, id = "Q1")
Q2 = Quadrupole (l = 0.1, k1 = 0.01, id = "Q2", tilt = pi/4)

sec = (D0, Q1, D1, Q2, D2)

beam = Beam()
beam.E = 6.0
beam.sigma_E = 0.002
beam.emit_xn = 0.4e-6
beam.emit_yn = 0.4e-6
beam.gamma_rel = beam.E / (0.511e-3)
beam.emit_x = beam.emit_xn / beam.gamma_rel
beam.emit_y = beam.emit_yn / beam.gamma_rel
beam.beta_x = 10.0
beam.beta_y = 3.0
beam.alpha_x = 2.0
beam.alpha_y = -2.0

lat = MagneticLattice(sec)
tw0 = Twiss(beam)
tws=twiss(lat, tw0, nPoints = 1000)

@sergey-tomin
Copy link
Collaborator

this is warning and it works on my laptop. anyway here must be checking to avoid divided by zero.
figure_1

@iagapov
Copy link
Owner Author

iagapov commented Oct 2, 2015

divide by zero is not a 'warning'. The code works incorrectly, so this needs to be fixed.

@sergey-tomin
Copy link
Collaborator

divided by zero is error which crushs the code. Here is not this case see below

print M[2, 3]/M[2, 2]_m.beta_y - M[2, 3]_m.alpha_y, arctan(M[2, 3]/(M[2, 2]_m.beta_y - M[2, 3]_m.alpha_y))

5.45502412182 0.00111206462467
6.07237322199 0.00123637344116
/home/sergey/Dropbox/DESY/repository/ocelot/cpbd/optics.py:170: RuntimeWarning: divide by zero encountered in double_scalars
d_mux = arctan(M[0, 1]/(M[0, 0]_m.beta_x - M[0, 1]_m.alpha_x))
6.69011365804 0.00136045838756
7.30828567367 0.00148433007011

@iagapov
Copy link
Owner Author

iagapov commented Oct 2, 2015

stranhe. Why does devide by zero not cause code to crash. Anyway it has nothing to do with coupliong

@sergey-tomin
Copy link
Collaborator

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants