83 static const T fC = 0.000299792458;
84 static const T ZERO = 0., ONE = 1., TWO = 2., C1_3 = 1. / 3., C1_6 = 1. / 6.;
86 T coef[4] = {0.0, 0.5, 0.5, 1.0};
89 T dAx_dtx[4], dAy_dtx[4], dAx_dty[4], dAy_dty[4];
98 T hCqp =
h * fC * par.
Qp;
101 T
x[4] = {par.
X, par.
Y, par.
Tx, par.
Ty};
108 const LitFieldGrid* Bgrid[4] = {&field1, &field2, &field2, &field3};
131 T txtxtyty1 = ONE + txtx + tyty;
132 T t1 =
sqrt(txtxtyty1);
133 T t2 =
rcp(txtxtyty1);
135 Ax[0] = (txty * Bx + ty * Bz - (ONE + txtx) * By) * t1;
136 Ay[0] = (-txty * By - tx * Bz + (ONE + tyty) * Bx) * t1;
138 dAx_dtx[0] = Ax[0] * tx * t2 + (ty * Bx - TWO * tx * By) * t1;
139 dAx_dty[0] = Ax[0] * ty * t2 + (tx * Bx + Bz) * t1;
140 dAy_dtx[0] = Ay[0] * tx * t2 + (-ty * By - Bz) * t1;
141 dAy_dty[0] = Ay[0] * ty * t2 + (-tx * By + TWO * ty * Bx) * t1;
145 ktx[0] = Ax[0] * hCqp;
146 kty[0] = Ay[0] * hCqp;
151 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
152 x[0] = par.
X + coef[iStep] * kx[iStep - 1];
153 x[1] = par.
Y + coef[iStep] * ky[iStep - 1];
154 x[2] = par.
Tx + coef[iStep] * ktx[iStep - 1];
155 x[3] = par.
Ty + coef[iStep] * kty[iStep - 1];
159 T Bx = Bfield[iStep].
Bx;
160 T By = Bfield[iStep].
By;
161 T Bz = Bfield[iStep].
Bz;
168 T txtxtyty1 = ONE + txtx + tyty;
169 T t1 =
sqrt(txtxtyty1);
170 T t2 =
rcp(txtxtyty1);
172 Ax[iStep] = (txty * Bx + ty * Bz - (ONE + txtx) * By) * t1;
173 Ay[iStep] = (-txty * By - tx * Bz + (ONE + tyty) * Bx) * t1;
175 dAx_dtx[iStep] = Ax[iStep] * tx * t2 + (ty * Bx - TWO * tx * By) * t1;
176 dAx_dty[iStep] = Ax[iStep] * ty * t2 + (tx * Bx + Bz) * t1;
177 dAy_dtx[iStep] = Ay[iStep] * tx * t2 + (-ty * By - Bz) * t1;
178 dAy_dty[iStep] = Ay[iStep] * ty * t2 + (-tx * By + TWO * ty * Bx) * t1;
182 ktx[iStep] = Ax[iStep] * hCqp;
183 kty[iStep] = Ay[iStep] * hCqp;
189 par.
X += kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
190 par.
Y += ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
191 par.
Tx += ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
192 par.
Ty += kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
223 kty[0] = (dAy_dtx[0] *
x[2] + dAy_dty[0] *
x[3]) * hCqp;
225 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
226 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
227 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
229 x[3] = x0[3] + coef[iStep] * kty[iStep - 1];
231 kx[iStep] =
x[2] *
h;
232 ky[iStep] =
x[3] *
h;
234 kty[iStep] = (dAy_dtx[iStep] *
x[2] + dAy_dty[iStep] *
x[3]) * hCqp;
237 F[2] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
238 F[7] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
240 F[17] = x0[3] + kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
253 ktx[0] = (dAx_dtx[0] *
x[2] + dAx_dty[0] *
x[3]) * hCqp;
256 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
257 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
258 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
259 x[2] = x0[2] + coef[iStep] * ktx[iStep - 1];
262 kx[iStep] =
x[2] *
h;
263 ky[iStep] =
x[3] *
h;
264 ktx[iStep] = (dAx_dtx[iStep] *
x[2] + dAx_dty[iStep] *
x[3]) * hCqp;
268 F[3] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
269 F[8] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
270 F[13] = x0[2] + ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
284 ktx[0] = Ax[0] * hC + hCqp * (dAx_dtx[0] *
x[2] + dAx_dty[0] *
x[3]);
285 kty[0] = Ay[0] * hC + hCqp * (dAy_dtx[0] *
x[2] + dAy_dty[0] *
x[3]);
287 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
288 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
289 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
290 x[2] = x0[2] + coef[iStep] * ktx[iStep - 1];
291 x[3] = x0[3] + coef[iStep] * kty[iStep - 1];
293 kx[iStep] =
x[2] *
h;
294 ky[iStep] =
x[3] *
h;
295 ktx[iStep] = Ax[iStep] * hC + hCqp * (dAx_dtx[iStep] *
x[2] + dAx_dty[iStep] *
x[3]);
296 kty[iStep] = Ay[iStep] * hC + hCqp * (dAy_dtx[iStep] *
x[2] + dAy_dty[iStep] *
x[3]);
299 F[4] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
300 F[9] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
301 F[14] = x0[2] + ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
302 F[19] = x0[3] + kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
311 T cIn[15] = {par.
C0, par.
C1, par.
C2, par.
C3, par.
C4, par.
C5, par.
C6, par.
C7,
314 T A = cIn[2] + F[2] * cIn[9] + F[3] * cIn[10] + F[4] * cIn[11];
315 T B = cIn[3] + F[2] * cIn[10] + F[3] * cIn[12] + F[4] * cIn[13];
316 T C = cIn[4] + F[2] * cIn[11] + F[3] * cIn[13] + F[4] * cIn[14];
318 T D = cIn[6] + F[7] * cIn[9] + F[8] * cIn[10] + F[9] * cIn[11];
319 T E = cIn[7] + F[7] * cIn[10] + F[8] * cIn[12] + F[9] * cIn[13];
320 T G = cIn[8] + F[7] * cIn[11] + F[8] * cIn[13] + F[9] * cIn[14];
322 T H = cIn[9] + F[13] * cIn[10] + F[14] * cIn[11];
323 T I = cIn[10] + F[13] * cIn[12] + F[14] * cIn[13];
324 T J = cIn[11] + F[13] * cIn[13] + F[14] * cIn[14];
326 T K = cIn[13] + F[17] * cIn[11] + F[19] * cIn[14];
328 par.
C0 = cIn[0] + F[2] * cIn[2] + F[3] * cIn[3] + F[4] * cIn[4] + A * F[2] + B * F[3] + C * F[4];
329 par.
C1 = cIn[1] + F[2] * cIn[6] + F[3] * cIn[7] + F[4] * cIn[8] + A * F[7] + B * F[8] + C * F[9];
330 par.
C2 = A + B * F[13] + C * F[14];
331 par.
C3 = B + A * F[17] + C * F[19];
334 par.
C5 = cIn[5] + F[7] * cIn[6] + F[8] * cIn[7] + F[9] * cIn[8] + D * F[7] + E * F[8] + G * F[9];
335 par.
C6 = D + E * F[13] + G * F[14];
336 par.
C7 = E + D * F[17] + G * F[19];
339 par.
C9 = H + I * F[13] + J * F[14];
340 par.
C10 = I + H * F[17] + J * F[19];
343 par.
C12 = cIn[12] + F[17] * cIn[10] + F[19] * cIn[13] + (F[17] * cIn[9] + cIn[10] + F[19] * cIn[11]) * F[17]
364 static const T fC = 0.000299792458;
365 static const T ZERO = 0., ONE = 1., TWO = 2., C1_3 = 1. / 3., C1_6 = 1. / 6.;
367 T coef[4] = {0.0, 0.5, 0.5, 1.0};
370 T dAx_dtx[4], dAy_dtx[4], dAx_dty[4], dAy_dty[4];
379 T hCqp =
h * fC * par.
Qp;
382 T
x[4] = {par.
X, par.
Y, par.
Tx, par.
Ty};
396 Bfield[2] = Bfield[1];
412 T txtxtyty1 = ONE + txtx + tyty;
413 T t1 =
sqrt(txtxtyty1);
414 T t2 =
rcp(txtxtyty1);
416 Ax[0] = (txty * Bx + ty * Bz - (ONE + txtx) * By) * t1;
417 Ay[0] = (-txty * By - tx * Bz + (ONE + tyty) * Bx) * t1;
419 dAx_dtx[0] = Ax[0] * tx * t2 + (ty * Bx - TWO * tx * By) * t1;
420 dAx_dty[0] = Ax[0] * ty * t2 + (tx * Bx + Bz) * t1;
421 dAy_dtx[0] = Ay[0] * tx * t2 + (-ty * By - Bz) * t1;
422 dAy_dty[0] = Ay[0] * ty * t2 + (-tx * By + TWO * ty * Bx) * t1;
426 ktx[0] = Ax[0] * hCqp;
427 kty[0] = Ay[0] * hCqp;
432 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
433 x[0] = par.
X + coef[iStep] * kx[iStep - 1];
434 x[1] = par.
Y + coef[iStep] * ky[iStep - 1];
435 x[2] = par.
Tx + coef[iStep] * ktx[iStep - 1];
436 x[3] = par.
Ty + coef[iStep] * kty[iStep - 1];
440 T Bx = Bfield[iStep].
Bx;
441 T By = Bfield[iStep].
By;
442 T Bz = Bfield[iStep].
Bz;
449 T txtxtyty1 = ONE + txtx + tyty;
450 T t1 =
sqrt(txtxtyty1);
451 T t2 =
rcp(txtxtyty1);
453 Ax[iStep] = (txty * Bx + ty * Bz - (ONE + txtx) * By) * t1;
454 Ay[iStep] = (-txty * By - tx * Bz + (ONE + tyty) * Bx) * t1;
456 dAx_dtx[iStep] = Ax[iStep] * tx * t2 + (ty * Bx - TWO * tx * By) * t1;
457 dAx_dty[iStep] = Ax[iStep] * ty * t2 + (tx * Bx + Bz) * t1;
458 dAy_dtx[iStep] = Ay[iStep] * tx * t2 + (-ty * By - Bz) * t1;
459 dAy_dty[iStep] = Ay[iStep] * ty * t2 + (-tx * By + TWO * ty * Bx) * t1;
463 ktx[iStep] = Ax[iStep] * hCqp;
464 kty[iStep] = Ay[iStep] * hCqp;
470 par.
X += kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
471 par.
Y += ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
472 par.
Tx += ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
473 par.
Ty += kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
504 kty[0] = (dAy_dtx[0] *
x[2] + dAy_dty[0] *
x[3]) * hCqp;
506 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
507 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
508 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
510 x[3] = x0[3] + coef[iStep] * kty[iStep - 1];
512 kx[iStep] =
x[2] *
h;
513 ky[iStep] =
x[3] *
h;
515 kty[iStep] = (dAy_dtx[iStep] *
x[2] + dAy_dty[iStep] *
x[3]) * hCqp;
518 F[2] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
519 F[7] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
521 F[17] = x0[3] + kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
534 ktx[0] = (dAx_dtx[0] *
x[2] + dAx_dty[0] *
x[3]) * hCqp;
537 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
538 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
539 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
540 x[2] = x0[2] + coef[iStep] * ktx[iStep - 1];
543 kx[iStep] =
x[2] *
h;
544 ky[iStep] =
x[3] *
h;
545 ktx[iStep] = (dAx_dtx[iStep] *
x[2] + dAx_dty[iStep] *
x[3]) * hCqp;
549 F[3] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
550 F[8] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
551 F[13] = x0[2] + ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
565 ktx[0] = Ax[0] * hC + hCqp * (dAx_dtx[0] *
x[2] + dAx_dty[0] *
x[3]);
566 kty[0] = Ay[0] * hC + hCqp * (dAy_dtx[0] *
x[2] + dAy_dty[0] *
x[3]);
568 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
569 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
570 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
571 x[2] = x0[2] + coef[iStep] * ktx[iStep - 1];
572 x[3] = x0[3] + coef[iStep] * kty[iStep - 1];
574 kx[iStep] =
x[2] *
h;
575 ky[iStep] =
x[3] *
h;
576 ktx[iStep] = Ax[iStep] * hC + hCqp * (dAx_dtx[iStep] *
x[2] + dAx_dty[iStep] *
x[3]);
577 kty[iStep] = Ay[iStep] * hC + hCqp * (dAy_dtx[iStep] *
x[2] + dAy_dty[iStep] *
x[3]);
580 F[4] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
581 F[9] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
582 F[14] = x0[2] + ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
583 F[19] = x0[3] + kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
592 T cIn[15] = {par.
C0, par.
C1, par.
C2, par.
C3, par.
C4, par.
C5, par.
C6, par.
C7,
595 T A = cIn[2] + F[2] * cIn[9] + F[3] * cIn[10] + F[4] * cIn[11];
596 T B = cIn[3] + F[2] * cIn[10] + F[3] * cIn[12] + F[4] * cIn[13];
597 T C = cIn[4] + F[2] * cIn[11] + F[3] * cIn[13] + F[4] * cIn[14];
599 T D = cIn[6] + F[7] * cIn[9] + F[8] * cIn[10] + F[9] * cIn[11];
600 T E = cIn[7] + F[7] * cIn[10] + F[8] * cIn[12] + F[9] * cIn[13];
601 T G = cIn[8] + F[7] * cIn[11] + F[8] * cIn[13] + F[9] * cIn[14];
603 T H = cIn[9] + F[13] * cIn[10] + F[14] * cIn[11];
604 T I = cIn[10] + F[13] * cIn[12] + F[14] * cIn[13];
605 T J = cIn[11] + F[13] * cIn[13] + F[14] * cIn[14];
607 T K = cIn[13] + F[17] * cIn[11] + F[19] * cIn[14];
609 par.
C0 = cIn[0] + F[2] * cIn[2] + F[3] * cIn[3] + F[4] * cIn[4] + A * F[2] + B * F[3] + C * F[4];
610 par.
C1 = cIn[1] + F[2] * cIn[6] + F[3] * cIn[7] + F[4] * cIn[8] + A * F[7] + B * F[8] + C * F[9];
611 par.
C2 = A + B * F[13] + C * F[14];
612 par.
C3 = B + A * F[17] + C * F[19];
615 par.
C5 = cIn[5] + F[7] * cIn[6] + F[8] * cIn[7] + F[9] * cIn[8] + D * F[7] + E * F[8] + G * F[9];
616 par.
C6 = D + E * F[13] + G * F[14];
617 par.
C7 = E + D * F[17] + G * F[19];
620 par.
C9 = H + I * F[13] + J * F[14];
621 par.
C10 = I + H * F[17] + J * F[19];
624 par.
C12 = cIn[12] + F[17] * cIn[10] + F[19] * cIn[13] + (F[17] * cIn[9] + cIn[10] + F[19] * cIn[11]) * F[17]