MethodicalAcceleratorDesign / MAD-NG

MAD Next-Generation official repository
GNU General Public License v3.0
32 stars 11 forks source link

Change l_pz calculation to make drift more stable #360

Closed jgray-19 closed 1 year ago

jgray-19 commented 1 year ago

I found this version of drift to be more stable for T, specifically the _pz*(l/m->beta+p.pt) + (m->T-1)*l/m->beta; calculation

rdemaria commented 1 year ago

The following is not longer correct to me

p.t -= _pz(l/m->beta+p.pt) + (m->T-1)l/m->beta;

You need:

p.t -= _pz(l/m->beta+lp.pt) + (m->T-1)*l/m->beta;

ldeniau commented 1 year ago

Absolutely! I just made a commit that restores l_pz. The "instability" is not a true instability but a case of "bits cancellation" due to the change of sign in the assignment and the swap of (T-1) to take advantage of C++ op= operators. Thus this will vary from run to run depending on the numerical values involved.