Quad curvature correction in bending magnets#1067
Conversation
|
Some tests are failing because of small deviations introduced by the new tracking. Please ignore that for the moment, I will adapt the tests if the modification proves successful. |
|
A few other points appear when looking into that:
|
|
I ran my scripts again, and I see several issues: I will take a step back and verify that in AT the new integrator give identical results as the old one in the absence of K1. |
|
I confirm a problem with the new sector bend, with the following code all particles are lost which is nit the case in the previous implementation |
|
Very strange: the added term has Note that I will use you script to further check. |
BndSymplectic4Pass seems to be fine at first sight |
|
I see problems with |
Do you? It looked fine for me providing the FringeFields are correctly set (full, or dipole-only in XSuite). |
|
A bug in Note: if K == 0, Now for K != 0, it's up to you ! |
Great thanks! May have to wait until next week (after the restart) before getting back it it though |
f852135 to
a471c14
Compare
|
I confirm that now in the absence of K1, the master and this banch give the same results. Anything I can try? |
|
Other problem, in ExactRectangular bend the case where FringeBend*=1 and QuandBend*=0 now translates to 'linear' instead of 'dipole-only'. |
|
So it is strange now... some things that used to work don't anymore.... are you sure X0ref is correctly handle? Don't you need to change rbendtune() as well? |
corrected
Yes, here is what is happening at the moment: according to the doc: So 1 should indeed translate to "linear". But at the moment, the AT exact methods ignore the value of FringeBend* and always use another method (Forest), even when specifying 0. In the future, this will be method 4, and 1 will be indeed the "linear" method (this is how I tested the agreement with Xsuite). For the time being, don't specify I'm presently working to implement all 4 methods on all the dipole passmethods. |
|
Still I still get strange results: For me the reference particle is np.zeros(6) before rbendtune() it already exists at zero, so why is rbendtune() moving it to some other coordinates? ... maybe I miss someting? In any case not running rbendtune in this case I get perfect agreement using: I would have think that running rbendtune and shifting the xsuite element by the same amount... so something is strange....and clearly the problem lies there |
|
@swhite: you magnet has K1 == 0. So Similarly, if K1 == 0, the Xsuite result should be independent of |
|
@swhite2401: I checked that before iterating, |
I agree, I did not expect this! This is why I am surprised, but maybe I am doing something wrong.... let me check and get back to you... |
|
This new release makes 3 changes:
|
|
A comment on This looks like a problem in transformations. dx works perfectly on straight magnets ! |
atelem.to_file() serializes all element attributes including PolynomA, PolynomB and MaxOrder into atparams. These were then passed twice to Multipole.from_at() — once explicitly and once via **atparams — causing a TypeError. Fix by popping PolynomA, PolynomB and MaxOrder from atparams before the call, so only the values recomputed from KickAngle are used.
|
@lfarv I am having a look back and here is a summary of the present situation: Multipole: all looks good SBEND is ok for any value of FringeQuad*, face angles or K1, dy as long as dx, B0 and A0 are equal to zero RBEND Few questions / remarks come: |
I don't see that: even in that case, I see a strong disagreement as soon as the entrance/exit angles are not half the bending angle |
|
@swhite2401 : after another review, my conclusions on RBEND are different from yours: With faceangles == 0.5*bendingangleEverything works, including
Here is my test dipole: elem = at.Dipole('D', 2.0, 1.0, k=1.0, PassMethod='ExactRectangularBendPass',
EntranceAngle=0.5, ExitAngle=0.5,
FullGap=0.1, FringeInt1=0.65, FringeInt2=0.65,
FringeQuadEntrance=1, FringeQuadExit=1,
NumIntSteps=1000)Here is the translated Xsuite element: With faceangles != 0.5*bendinganglenothing works |
|
Strange let me go case by case in details then. First here is the script I use: nsteps = 10000
energy = 10e9
at_sbend = at.Lattice([at.Dipole('D', 1.0, 1.0, k=0.0, PassMethod='ExactRectangularBendPass',
NumIntSteps=nsteps, EntranceAngle=0.5, ExitAngle=0.5,
PolynomB=[0.0, 0.0], PolynomA=[0.0, 0.0], dx = 0.0)],
energy = energy)
#fquad = 1
at_sbend[0].FringeQuadEntrance = fquad
at_sbend[0].FringeQuadExit = fquad
at_sbend[0].EntranceAngle = 0.0
at_sbend[0].ExitAngle = 0.0
at_sbend[0].K = 0.0
at_sbend[0].dx = 0.0
at_sbend[0].dy = 0.0
at_sbend[0].PolynomB[0] = 0.0
at_sbend[0].PolynomA[0] = 0.0
#at_sbend[0].rbendtune()
xs_sbend = at.line_from_lattice(at_sbend, match_model=True)
xs_sbend[0].rbend_shift += xs_sbend[0]._x0_in - getattr(at_sbend[0], 'X0ref', 0.0)
nax, _, _, diffx = at_xs_track(at_sbend, xs_sbend, axes= [0, 1])
nay, _, _, diffy = at_xs_track(at_sbend, xs_sbend, axes= [2, 3])
plt.subplot(211)
plt.contourf(nax, nax, diffx)
plt.xlabel('x [m]')
plt.ylabel('px')
plt.colorbar()
plt.subplot(212)
plt.contourf(nay, nay, diffy)
plt.xlabel('y [m]')
plt.ylabel('py')
plt.colorbar()
plt.show() |
|
With K1=0 and rbendtune() not called: work for all face angle and model With K1=0 and rbendtune() called:
With K1=1 and rbendtune() not called :
With K1=1 and rbendtune() called :
For me there is still a problem with X0ref the agreement should not depend on whether we call rbendtune or not as long as rbend_shift is set correctly (am I doing something wrong?) The the special case with K1!=0, FringeQuad=1 and face angle !=0.5 never work, so there is a problem there too unrelated to X0ref |
|
@swhite2401: If not, my tests always fail, while you get agreement for your 1st case: K1 == 0 and no So I wonder if the problem is not just a question of transverse positioning : one should always check that the reference particle comes out at 0.0 angle. If not, if k1 == 0, normally there is no reason to call r Remain the problems for K1 != 0. |
|
Now However I found a problem: whatever K1 and face angles, after calling
|
We are progressing! I did write a loop to cancel the output orbit in XSuite but could not reach agreement either.... however, you have made a lot of changes since then. Let me try to run these tests again. |
|
@lfarv, I confirm that even with a numerical loop on the xsuite bend agreement is still not good for K1!=0 and face angles = 0.0 |
|
@lfarv, I may have some news concerning the issue with https://www.sciencedirect.com/science/article/pii/S0168900222007793?ref=cra_js_challenge&fr=RR-1 we are implementing the linearized map and what we observe is rather good agreement up to a certain amplitude which could indicate that the exact map would be needed for large amplitude. I think it would be worth implementing the exact map, this could be done in separate PR, @SebastienJoly when you implemented this transformations, did you by any chance take a look at this exact map? |
|
@swhite2401 : I came to the same conclusion. Implementing the exact map for dx, dy, dz is trivial: it is what is done to apply However from your plots, it looks like for position within 5 cm (which is huge !), the error is within 1.e-7, so it's not so critical. |
|
@lfarv, some more observation with B0 this time. I have tried to simplify the problem as much as possible. In this case I still don't get agreement between the 2 codes, which seems very strange to me because I thought the implementation of the body was solid and well benchmarked....to be followed, I will do the same test with the small angle approximation passmethod just to be sure. |
|
@swhite2401 I did not try implementing the exact map. I chose to implement the linearized map to be able to compare the results with SC/pySC, which also rely on it. |
It is very small, we are talking 1.0e-7 difference on the norm of the phase space coordinates, but since we are going for this one to one agreement, we are going through every possible differences. As @lfarv said this is not a problem for now, it is already quite good. But when on of us as time it should be rather simple to implement the exact map. |





This adds another term to the bending magnets to try and cancel a difference of tracking of combined bending-focusing magnets between AT and Xsuite.
The so-called "K1h" term of the Hamiltonian is included in:
A successful comparison is necessary before accepting this term. @swhite2401 and @kandre2, can you look at that ?