MethodicalAcceleratorDesign / MAD-X

MAD-X repository
Other
49 stars 39 forks source link

Survey calculations with permanent misalignments show inconsistent results. #1227

Open rdemaria opened 3 months ago

rdemaria commented 3 months ago

This example shows:

mb: sbend,l=1,angle=pi/2;
mq: quadrupole,l=1,k1=0.0;

ss: sequence, l=10;
mq.1:mq, at=1,dx=0,dy=0.0,dpsi=0.0,dphi=0.3,dtheta=0.0;
mb, at=2;
mq.2:mq, at=3,dx=0.0,dy=0.0,dpsi=0.0,dphi=0.3,dtheta=0.0;
endsequence;

beam;
use,sequence=ss;
survey,file=survey.tfs,perm_align_survey=true;
name         l  angle   s        x           y       z   theta         phi psi
ss$start.ENT 0      0   0        0           0       0       0           0   0
ss$start.EXI 0      0   0        0           0       0       0           0   0
mq.1.ENT     1      0 0.5        0           0     0.5       0         0.3   0
mq.1.EXI     1      0 1.5        0     0.29552 1.45534       0         0.3   0
mb.ENT       1 1.5708 1.5        0           0     1.5       0           0   0
mb.EXI       1 1.5708 2.5 -0.63662           0 2.13662 -1.5708           0   0
mq.2.ENT     1      0 2.5 -0.63662           0 2.13662 -1.5708 1.80954e-17 0.3
mq.2.EXI     1      0 3.5 -1.63662 1.80954e-17 2.13662 -1.5708 1.80954e-17 0.3
ss$end.ENT   0      0  10 -8.13662           0 2.13662 -1.5708           0   0
ss$end.EXI   0      0  10 -8.13662           0 2.13662 -1.5708           0   0

That the first dphi correctly gives an elevation angle, while the second dphi, transform in dpsi giving a tilt!

The code in this location is:

          V_AL = V
          W_AL = W
          if(is_permalign() .ne. 0) then
            VE(1) =   node_value('dx ')
            VE(2) =   node_value('dy ')
            VE(3) =   node_value('ds ')
            V_AL = V_AL + matmul(W_AL,VE)
            dphi   = node_value('dphi ')
            dpsi   = node_value('dpsi ')
            dtheta = node_value('dtheta ')

            call sumtrx(dtheta, dphi, dpsi, we_t)
            W_AL = matmul(we_t,W_AL) ! Is this the right way?
          endif
ldeniau commented 3 months ago

I have given it a try with MAD-NG, and from the point of view of MAD-X, the problem doesn't matter because MAD-X never looks "inside" elements, but from the point of view of Survey, I confirm the issue.

local survey, sequence in MAD
local sbend, quadrupole in MAD.element
local pi in MAD.constant

local mb = sbend 'MB' { l=1, angle=pi/2 }
local mq = quadrupole 'MQ' { l=1, k1=0 }
local ss = sequence 'SS' { l=10,
  mq 'mq.1' { at=1, misalign={dphi=0.3} },
  mb 'mb'   { at=2 },
  mq 'mq.2' { at=3, misalign={dphi=0.3} },
}

survey { sequence=ss, misalign=true, save='atenbeex' }
  :remove \row -> row.kind == "drift" :write "survey.tfs"

The slice numbers (column slc) in the survey table below have the following meaning: P = patch, F=fringe, B=body (not selected by atenbeex = at_entry_begin_end_exit)

-1  -3   0     1  -4  -2
 +---+---+-----+---+---+
 | P | F |  B  | F | P |
 +---+---+-----+---+---+
@ name               %02s     "SS"
@ type               %06s     "survey"
@ title              %08s     "no-title"
@ origin             %16s     "MAD 0.9.9 OSX 64"
@ date               %08s     "27/06/24"
@ time               %08s     "14:40:59"
@ refcol             %04s     "name"
@ direction          %le       1
@ observe            %le       0
@ implicit           %b       false
@ misalign           %b       true
* name               kind               s                  l                  angle              tilt               x                  y                  z                  theta              phi                psi                slc
$ %s                 %s                 %le                %le                %le                %le                %le                %le                %le                %le                %le                %le                %le
  "$start"           "marker"            0                  0                  0                  0                  0                  0                  0                  0                  0                  0                 -1
  "$start"           "marker"            0                  0                  0                  0                  0                  0                  0                  0                  0                  0                 -2
  "mq.1"             "quadrupole"        0.5                0                  0                  0                  0                  0                  0.5                0                  0                  0                 -1
  "mq.1"             "quadrupole"        0.5                0                  0                  0                  0                  0                  0.5                0                  0.3                0                 -3
  "mq.1"             "quadrupole"        1.5                1                  0                  0                  0                  0.2955202067       1.455336489        0                  0.3                0                 -4
  "mq.1"             "quadrupole"        1.5                1                  0                  0                  0                  0                  1.5                0                  0                  0                 -2
  "mb"               "sbend"             1.5                0                  0                  0                  0                  0                  1.5                0                  0                  0                 -1
  "mb"               "sbend"             1.5                0                  0                  0                  0                  0                  1.5                0                  0                  0                 -3
  "mb"               "sbend"             2.5                1                  1.570796327        0                 -0.6366197724       0                  2.136619772       -1.570796327        0                  0                 -4
  "mb"               "sbend"             2.5                1                  1.570796327        0                 -0.6366197724       0                  2.136619772       -1.570796327        0                  0                 -2
  "mq.2"             "quadrupole"        2.5                0                  0                  0                 -0.6366197724       0                  2.136619772       -1.570796327        0                  0                 -1
  "mq.2"             "quadrupole"        2.5                0                  0                  0                 -0.6366197724       0                  2.136619772       -1.570796327        0.3                0                 -3
  "mq.2"             "quadrupole"        3.5                1                  0                  0                 -1.591956261        0.2955202067       2.136619772       -1.570796327        0.3                0                 -4
  "mq.2"             "quadrupole"        3.5                1                  0                  0                 -1.636619772        0                  2.136619772       -1.570796327        0                  0                 -2
  "$end"             "marker"            10                 0                  0                  0                 -8.136619772        0                  2.136619772       -1.570796327        0                  0                 -1
  "$end"             "marker"            10                 0                  0                  0                 -8.136619772        0                  2.136619772       -1.570796327        0                  0                 -2