-
Notifications
You must be signed in to change notification settings - Fork 34
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
Fix RadIntegrals in ringpara #186
base: master
Are you sure you want to change the base?
Conversation
Hello @mashl . |
@TeresiaOlsson: could you share your Diamond-II lattice with wigglers? Ideally, we would need wigglers with more than 1 harmonic (it's a problem at the moment), and with horizontal dependence of the vertical field (Kx ~= 0). It would be helpful also to have the 5 integral contributions from a single wiggler, both from analytical formulae and from Tracy. That's a lot… |
Hello @lfarv |
@lfarv I will check what we have. We have a list of integral contributions for most of our IDs that has been benchmarked between analytic, Elegant and Tracy, but I'm not sure we have an AT lattice with all of them in. I will check that and if not make one, but then it might take a couple of days. |
Dear @lfarv . %Vertical wiggler % Elliptical Polarized Wiggler the results make sense. if the results pass the benchmarks, for the next step, I think the dispersion could be calculated through the ID with a more efficient way than FDM with periodic boundary condition |
@mashl : the pull request is based on your fork, so all modifications you do are taken into account ! I see a problem with the dispersion: you cannot carry the dispersion over a non-linear element as you are doing. The field expansion is valid next to the beam axis, while the dispersion can be tens of centimetres or even meters. |
Hello @lfarv , the modified codes are work well for ILSF lattice. |
Hi @lfarv and @mashl , |
No, that made the situation worse... I am currently trying to use the wiggler_integrals branch, but now my lattice doesn't even work without the wigglers. There seem to have been differences made to the global parameters in atsummary when merging the centralized calculation of the radiation integrals that doesn't work for our lattice. Do you perhaps have a lattice file that works with these changes so I can check how our lattice needs to be modified? |
atsummary in the wiggler_integrals branch doesn't work for the lattices in machine_data either. It gives the error: "Unrecognized function or variable 'E0'. |
Hello @TeresiaOlsson , |
Thank you. It looks like your fork has the same problem in atsummary that doesn't work for our lattice or the ones in machine_data, but at least by looking at your lattice I could hopefully figure out why. My email is [email protected]. I also currently have a new problem in ringpara that didn't exist before. That function doesn't give errors, but I get the wrong momentum compaction which previously was okay. |
@TeresiaOlsson : can you send me your lattice? I'll open a new pull request to correct that bug. |
@lfarv I have attached it. This is the version without wigglers since the other one needs a bit of a clean up for it to be easier to understand for someone outside of Diamond. I'm working on fixing that so it's easier to use for the benchmark. I think there might be a difference in the lattice syntax between @mashl s fork and the common repository that caused the problem. Especially how global variables are used. We would prefer to keep the syntax as it was if possible since we have made that compatible with our MML and is currently starting to test AT2 with MML in the control room. In the meantime, I got a working lattice file from @mashl and will try to temporarily modify our lattice to his syntax and test the radiation integrals with wigglers on his fork. This is the values we had before: ************* Summary for '' ************ Synchrotron Integral 1: 6.58344e-02 [m] Assuming cavities Voltage: 1660.00000 [kV] Injection: |
The bug causing the crash is corrected and will appear in the master branch soon. |
Thank you so much @lfarv . I will pull the change and see if I can get it to work now. |
The bug is now corrected in the |
My lattice seems to work now :) I will continue with putting in the wigglers and see if can solve the problems I had with that from before. It might just be because the input to atwiggler has changed. |
@lfarv , of course, I will update my branch. |
There seems to be a bug with the I1 integral depending on where in the lattice the cavity sits, which caused the wrong value I saw for the momentum compaction in ringpara. Cavity at the end: Synchrotron Integral 1: 6.58525e-02 [m] This is the expected result. Cavity somewhere in the middle: Synchrotron Integral 1: 7.11824e-02 [m] Do you also get this for your lattices? |
@TeresiaOlsson: |
Ah, yes. I had forgotten that AT doesn't have checks for that like pyAT does. Thank you. |
However, there is something that is inconsistent. ringpara does calculation of coupled damping times and for that it seems the cavity has to be on otherwise you get the following warning: Warning: Matrix is singular to working precision.
Warning: failed coupled damping times computation
So at the moment ringpara gives a warning if you have the cavity off and the wrong I1 integral if you have it on and your cavity isn't in the beginning or end of the lattice. For both cases I have the radiation off so it's just the cavity causing the problem. |
I have now managed to put in a single ID in my lattice using @mashl s fork and the results looks as below for I1-I5: Elegant: 6.585240E-02 | 3.308244E-01 | 1.861466E-02 | -1.186174E-01 | 3.814208E-06 analytic: 6.58524E-02 | 3.30820E-01 | 1.86140E-02 | -1.18617E-01 | 3.81421E-06 ringpara: 6.7365389E-2 | 3.308248E-1 | 1.861472E-2 | -1.186031E-01 | 3.82E-06 atsummary: 6.58525E-2 | 3.17270E-01 | 1.72713E-02 | -1.18617e-01 | 3.82460e-06 It looks fairly good for ringpara except I1 which I think has a too large change. The effect of that is that the momentum compaction changes with 2.69884E-06 from 1.17473E-4 to 1.2017e-04, which is much more than I expected. Could perhaps the cause be the same as for why I1 change depending on where the cavity sits in the lattice? I noticed that for the radiation effects of the wiggler to be included I need to use the passmethod "GWigSymplecticRadPass" which means the radiation is turned on for the wiggler even if it's turned of for the rest of the lattice. Should I expect ringpara and atsummary to give the same output for this fork or only after it has been merged? I will continue with putting in some other IDs that are stronger or sit in sections of high dispersion. This was just a fairly weak ID in a low dispersion section. |
@TeresiaOlsson: Thanks for those 1st results. But I insist that to get correct results, you should not include radiation anywhere: the radiation integrals rely on the dispersion function which is wrong if you include radiation. The calculation done in It looks like the numbers you give are for the whole ring, dipole radiation included. Can you get the ID contribution alone, which would make the comparison more accurate? And do you have a reference for what you use for analytical checks ? Thanks you ! |
Dear @lfarv , As you correctly mentioned the radiation effect does not and should not be included in the radiation integrals. The radiation integrals are depend on the magnetic field of the IDs and the optical functions of the lattice. So, the pass method of the wiggler should be GWigSymplecticPass. |
Seems like I might have been doing something wrong the first time because now I also get an effect for Yes, the numbers are for the whole ring. Do you mean I can get only the ID contribution from the code? Or you just want me to calculate the difference between with and without ID? These are the differences I get now with cavity off, radiation off and Elegant: -1.100000E-07 | 1.355490E-02 | 1.343320E-03 | 0.000000E+00 | 1.650000E-10 ringpara: 6.43562E-06 | 1.355524E-02 | 1.343380E-03 | 9.954206E-08 | 8.943734E-12 So it looks like it was the radiation that was the problem. This is a reference I have for the analytic formulas (chapter 5) http://cds.cern.ch/record/399409/files/p807.pdf. I have a more detailed reference that I use myself, but I have to ask my colleague for permission before circulating it because it's his and part of a paper that's not published yet. I however think the only difference is how far the expansion of delta_I5 is done. |
Now I have finished the whole lattice. I1 looks a bit too large to me, but I guess that depends on which precision we expect since it's overall small. Otherwise I only saw problems with I5 in straights with high dispersion or a strong ID so there seems to still be a problem with the dispersion. An example for the K02 for the ID contribution to I1-I5: I have attached the lattice together with a spreadsheet over all results. The spreadsheet has four pages, one with just the ID parameters and three with the results for elegant, AT and the analytic formulas. To run the lattice you need to first run the script create_ID_settings.txt |
@TeresiaOlsson : thanks for the work to provide this large amount of data! We have a lot now to crosscheck our results. I hoped that you could get individual contributions from Elegant, rather that making differences: the is less accurate (for instance on I1, you can get only one significant digit). But anyway with have enough data for benchmarking. I agree with you that a safety check must be added in atlinopt for cavities and radiation on. The errors that you got are surprisingly large, and many people just ignore this… I'll open another branch for that. |
@lfarv I'm not sure if you can get individual contributions from Elegant, but I will investigate. Maybe it at least could be possible to run a smaller part of the lattice and get more digits. Thank you so much. I would definitely had forgotten to turn the cavity off and not be aware that the results were wrong unless you had pointed that out and I knew from another code what to expect. Let me know if you run into problems with running the lattice. It's a bit complicated with all the IDs. It worked for me, but I could easily have made a typo somewhere so it doesn't work for you. There are also 3 three-pole wigglers in the lattice, but those I should have turned off. |
@mashl : I see a few problems with the files created in
2 and 3 can be solved by putting the file in Anyway, to avoid mixing problems, I suggest to leave this as it is for the moment, since it works, and focus on the wrong results for I1 and I5. Did you check the dispersion curve that you get through the wiggler? |
@TeresiaOlsson and @mashl : We have now enough data to validate the results for simple planar wigglers. Then we'll have to check:
I guess that analytical results cannot be used anymore (except probably for vertical wigglers). @TeresiaOlsson, can Elegant handle those cases? I would then try modifying one of your IDs (sorry for DLS users…). |
@lfarv I will ask my colleagues that have more experience with wigglers. There are several different wiggler models in Elegant so they might have tested them and know how reliable they are. |
@lfarv , I have some ideas for solving the gwig.c problems but we get back to them at the appropriate time. |
@mashl : you are absolutely right concerning U0. Since I2 is available, the energy loss/turn could be computed from it, and that would be similar to what is done in |
@lfarv , there were two major bugs! on RadIntegral I tried to solve them. |
@mashl: your scan for step and d is convincing. So it looks like you have now a good dispersion. nstep=25 would make tracking 5 times slower than necessary, so this is again pushing for a dedicated function rather than using the integrator. For the moment, you should avoid modifying all wiggler elements in the ring by replacing at line 83 of
by
But you can also see that the self-induced dispersion is in the tens of microns range (80 um in your case), which is completely negligible compared to the lattice dispersion. I'll prepare a much simpler computation neglecting this self induced dispersion and use only the lattice dispersion. It avoids the problem of tracking the dispersion, so that almost all integrals can be analytically computed. |
Following the outcome of @mashl study of the self-induced dispersion in wigglers, I tried another way of computing the wiggler radiation integrals in #188. Neglecting the self-induced dispersion makes a lot of simplifications. I ran the set of IDs provided by @TeresiaOlsson, and I get:
@TeresiaOlsson and @mashl : can you have a look at this branch? Thanks |
@lfarv , Sorry, I was busy today and now I'm far behind the discussion. |
@mashl: |
@mashl and @lfarv: At Diamond we have been discussing whether if Elegant includes the dispersion correctly or not and our conclusion so far is that it does. That's mostly based on that we got good agreement between the analytic formula and Tracy where Johan Bengtsson did the implementation including the dispersion. He however used some feature of Tracy that as far as I understand doesn't currently exist in AT and is a lot of work to implement. The elegant user manual for the wiggler element says: "The radiation integrals were computed analytically using Mathematica, including the variation of the horizontal beta function and dispersion. For an odd number of poles, half-strength end-poles are assumed in order to match the dispersion of the wiggler. For an even number of poles, half-length end poles are assumed (i.e., we start and end in the middle of a pole), for the same reason." That indicate that it is taken into account, but the manual is very vague on how it's done. So I agree, we aren't completely sure what Elegant is doing and it could be that we are fooling ourselves by trusting it too much. I will try to look at the Elegant source code and see if I manage to find out how it's done so we can feel more confident about the results. |
@lfarv , @TeresiaOlsson , |
@mashl It sounds really good to me if you have time to look into that. I eventually want to be able to do collective effects simulations including wigglers using |
@TeresiaOlsson , I'm not familiar with atfastring but if it uses the Ohmi envelop then this modification could be helpful for you. I used the ohmienvelope function on atx. |
dear all
I think the new RadIntegrals could solve the previous bugs especially in the dispersion issue