18 #ifndef LITEXTRAPOLATION_H_
19 #define LITEXTRAPOLATION_H_
45 T t3 = par.
C2 + dz * par.
C9;
48 T t19 = par.
C7 + dz * par.
C12;
49 par.
C0 += dz * par.
C2 + t3 * dz;
50 par.
C1 += dz * par.
C6 + t8 * dz;
53 par.
C4 += dz * par.
C11;
54 par.
C5 += dz * par.
C7 + t19 * dz;
57 par.
C8 += dz * par.
C13;
78 static const T fC = 0.000299792458;
79 static const T
ZERO = 0.,
ONE = 1., TWO = 2., C1_3 = 1. / 3.,
82 T coef[4] = {0.0, 0.5, 0.5, 1.0};
85 T dAx_dtx[4], dAy_dtx[4], dAx_dty[4], dAy_dty[4];
94 T hCqp =
h * fC * par.
Qp;
97 T
x[4] = {par.
X, par.
Y, par.
Tx, par.
Ty};
104 const LitFieldGrid* Bgrid[4] = {&field1, &field2, &field2, &field3};
127 T txtxtyty1 =
ONE + txtx + tyty;
128 T t1 =
sqrt(txtxtyty1);
129 T t2 =
rcp(txtxtyty1);
131 Ax[0] = (txty * Bx + ty * Bz - (
ONE + txtx) * By) * t1;
132 Ay[0] = (-txty * By - tx * Bz + (
ONE + tyty) * Bx) * t1;
134 dAx_dtx[0] = Ax[0] * tx * t2 + (ty * Bx - TWO * tx * By) * t1;
135 dAx_dty[0] = Ax[0] * ty * t2 + (tx * Bx + Bz) * t1;
136 dAy_dtx[0] = Ay[0] * tx * t2 + (-ty * By - Bz) * t1;
137 dAy_dty[0] = Ay[0] * ty * t2 + (-tx * By + TWO * ty * Bx) * t1;
141 ktx[0] = Ax[0] * hCqp;
142 kty[0] = Ay[0] * hCqp;
147 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
148 x[0] = par.
X + coef[iStep] * kx[iStep - 1];
149 x[1] = par.
Y + coef[iStep] * ky[iStep - 1];
150 x[2] = par.
Tx + coef[iStep] * ktx[iStep - 1];
151 x[3] = par.
Ty + coef[iStep] * kty[iStep - 1];
155 T Bx = Bfield[iStep].
Bx;
156 T By = Bfield[iStep].
By;
157 T Bz = Bfield[iStep].
Bz;
164 T txtxtyty1 =
ONE + txtx + tyty;
165 T t1 =
sqrt(txtxtyty1);
166 T t2 =
rcp(txtxtyty1);
168 Ax[iStep] = (txty * Bx + ty * Bz - (
ONE + txtx) * By) * t1;
169 Ay[iStep] = (-txty * By - tx * Bz + (
ONE + tyty) * Bx) * t1;
171 dAx_dtx[iStep] = Ax[iStep] * tx * t2 + (ty * Bx - TWO * tx * By) * t1;
172 dAx_dty[iStep] = Ax[iStep] * ty * t2 + (tx * Bx + Bz) * t1;
173 dAy_dtx[iStep] = Ay[iStep] * tx * t2 + (-ty * By - Bz) * t1;
174 dAy_dty[iStep] = Ay[iStep] * ty * t2 + (-tx * By + TWO * ty * Bx) * t1;
178 ktx[iStep] = Ax[iStep] * hCqp;
179 kty[iStep] = Ay[iStep] * hCqp;
185 par.
X += kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
186 par.
Y += ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
187 par.
Tx += ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
188 par.
Ty += kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
219 kty[0] = (dAy_dtx[0] *
x[2] + dAy_dty[0] *
x[3]) * hCqp;
221 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
222 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
223 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
225 x[3] = x0[3] + coef[iStep] * kty[iStep - 1];
227 kx[iStep] =
x[2] *
h;
228 ky[iStep] =
x[3] *
h;
230 kty[iStep] = (dAy_dtx[iStep] *
x[2] + dAy_dty[iStep] *
x[3]) * hCqp;
233 F[2] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
234 F[7] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
237 x0[3] + kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
250 ktx[0] = (dAx_dtx[0] *
x[2] + dAx_dty[0] *
x[3]) * hCqp;
253 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
254 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
255 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
256 x[2] = x0[2] + coef[iStep] * ktx[iStep - 1];
259 kx[iStep] =
x[2] *
h;
260 ky[iStep] =
x[3] *
h;
261 ktx[iStep] = (dAx_dtx[iStep] *
x[2] + dAx_dty[iStep] *
x[3]) * hCqp;
265 F[3] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3
267 F[8] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3
269 F[13] = x0[2] + ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3
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
296 + hCqp * (dAx_dtx[iStep] *
x[2] + dAx_dty[iStep] *
x[3]);
297 kty[iStep] = Ay[iStep] * hC
298 + hCqp * (dAy_dtx[iStep] *
x[2] + dAy_dty[iStep] *
x[3]);
301 F[4] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
302 F[9] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
304 x0[2] + ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
306 x0[3] + kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
331 T A = cIn[2] + F[2] * cIn[9] + F[3] * cIn[10] + F[4] * cIn[11];
332 T B = cIn[3] + F[2] * cIn[10] + F[3] * cIn[12] + F[4] * cIn[13];
333 T C = cIn[4] + F[2] * cIn[11] + F[3] * cIn[13] + F[4] * cIn[14];
335 T D = cIn[6] + F[7] * cIn[9] + F[8] * cIn[10] + F[9] * cIn[11];
336 T E = cIn[7] + F[7] * cIn[10] + F[8] * cIn[12] + F[9] * cIn[13];
337 T G = cIn[8] + F[7] * cIn[11] + F[8] * cIn[13] + F[9] * cIn[14];
339 T H = cIn[9] + F[13] * cIn[10] + F[14] * cIn[11];
340 T I = cIn[10] + F[13] * cIn[12] + F[14] * cIn[13];
341 T J = cIn[11] + F[13] * cIn[13] + F[14] * cIn[14];
343 T K = cIn[13] + F[17] * cIn[11] + F[19] * cIn[14];
345 par.
C0 = cIn[0] + F[2] * cIn[2] + F[3] * cIn[3] + F[4] * cIn[4]
346 + A * F[2] + B * F[3] + C * F[4];
347 par.
C1 = cIn[1] + F[2] * cIn[6] + F[3] * cIn[7] + F[4] * cIn[8]
348 + A * F[7] + B * F[8] + C * F[9];
349 par.
C2 = A + B * F[13] + C * F[14];
350 par.
C3 = B + A * F[17] + C * F[19];
353 par.
C5 = cIn[5] + F[7] * cIn[6] + F[8] * cIn[7] + F[9] * cIn[8]
354 + D * F[7] + E * F[8] + G * F[9];
355 par.
C6 = D + E * F[13] + G * F[14];
356 par.
C7 = E + D * F[17] + G * F[19];
359 par.
C9 = H + I * F[13] + J * F[14];
360 par.
C10 = I + H * F[17] + J * F[19];
363 par.
C12 = cIn[12] + F[17] * cIn[10] + F[19] * cIn[13]
364 + (F[17] * cIn[9] + cIn[10] + F[19] * cIn[11]) * F[17]
387 static const T fC = 0.000299792458;
388 static const T
ZERO = 0.,
ONE = 1., TWO = 2., C1_3 = 1. / 3.,
391 T coef[4] = {0.0, 0.5, 0.5, 1.0};
394 T dAx_dtx[4], dAy_dtx[4], dAx_dty[4], dAy_dty[4];
403 T hCqp =
h * fC * par.
Qp;
406 T
x[4] = {par.
X, par.
Y, par.
Tx, par.
Ty};
420 Bfield[2] = Bfield[1];
436 T txtxtyty1 =
ONE + txtx + tyty;
437 T t1 =
sqrt(txtxtyty1);
438 T t2 =
rcp(txtxtyty1);
440 Ax[0] = (txty * Bx + ty * Bz - (
ONE + txtx) * By) * t1;
441 Ay[0] = (-txty * By - tx * Bz + (
ONE + tyty) * Bx) * t1;
443 dAx_dtx[0] = Ax[0] * tx * t2 + (ty * Bx - TWO * tx * By) * t1;
444 dAx_dty[0] = Ax[0] * ty * t2 + (tx * Bx + Bz) * t1;
445 dAy_dtx[0] = Ay[0] * tx * t2 + (-ty * By - Bz) * t1;
446 dAy_dty[0] = Ay[0] * ty * t2 + (-tx * By + TWO * ty * Bx) * t1;
450 ktx[0] = Ax[0] * hCqp;
451 kty[0] = Ay[0] * hCqp;
456 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
457 x[0] = par.
X + coef[iStep] * kx[iStep - 1];
458 x[1] = par.
Y + coef[iStep] * ky[iStep - 1];
459 x[2] = par.
Tx + coef[iStep] * ktx[iStep - 1];
460 x[3] = par.
Ty + coef[iStep] * kty[iStep - 1];
464 T Bx = Bfield[iStep].
Bx;
465 T By = Bfield[iStep].
By;
466 T Bz = Bfield[iStep].
Bz;
473 T txtxtyty1 =
ONE + txtx + tyty;
474 T t1 =
sqrt(txtxtyty1);
475 T t2 =
rcp(txtxtyty1);
477 Ax[iStep] = (txty * Bx + ty * Bz - (
ONE + txtx) * By) * t1;
478 Ay[iStep] = (-txty * By - tx * Bz + (
ONE + tyty) * Bx) * t1;
480 dAx_dtx[iStep] = Ax[iStep] * tx * t2 + (ty * Bx - TWO * tx * By) * t1;
481 dAx_dty[iStep] = Ax[iStep] * ty * t2 + (tx * Bx + Bz) * t1;
482 dAy_dtx[iStep] = Ay[iStep] * tx * t2 + (-ty * By - Bz) * t1;
483 dAy_dty[iStep] = Ay[iStep] * ty * t2 + (-tx * By + TWO * ty * Bx) * t1;
487 ktx[iStep] = Ax[iStep] * hCqp;
488 kty[iStep] = Ay[iStep] * hCqp;
494 par.
X += kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
495 par.
Y += ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
496 par.
Tx += ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
497 par.
Ty += kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
528 kty[0] = (dAy_dtx[0] *
x[2] + dAy_dty[0] *
x[3]) * hCqp;
530 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
531 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
532 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
534 x[3] = x0[3] + coef[iStep] * kty[iStep - 1];
536 kx[iStep] =
x[2] *
h;
537 ky[iStep] =
x[3] *
h;
539 kty[iStep] = (dAy_dtx[iStep] *
x[2] + dAy_dty[iStep] *
x[3]) * hCqp;
542 F[2] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
543 F[7] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
546 x0[3] + kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
559 ktx[0] = (dAx_dtx[0] *
x[2] + dAx_dty[0] *
x[3]) * hCqp;
562 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
563 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
564 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
565 x[2] = x0[2] + coef[iStep] * ktx[iStep - 1];
568 kx[iStep] =
x[2] *
h;
569 ky[iStep] =
x[3] *
h;
570 ktx[iStep] = (dAx_dtx[iStep] *
x[2] + dAx_dty[iStep] *
x[3]) * hCqp;
574 F[3] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3
576 F[8] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3
578 F[13] = x0[2] + ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3
593 ktx[0] = Ax[0] * hC + hCqp * (dAx_dtx[0] *
x[2] + dAx_dty[0] *
x[3]);
594 kty[0] = Ay[0] * hC + hCqp * (dAy_dtx[0] *
x[2] + dAy_dty[0] *
x[3]);
596 for (
unsigned int iStep = 1; iStep < 4; iStep++) {
597 x[0] = x0[0] + coef[iStep] * kx[iStep - 1];
598 x[1] = x0[1] + coef[iStep] * ky[iStep - 1];
599 x[2] = x0[2] + coef[iStep] * ktx[iStep - 1];
600 x[3] = x0[3] + coef[iStep] * kty[iStep - 1];
602 kx[iStep] =
x[2] *
h;
603 ky[iStep] =
x[3] *
h;
604 ktx[iStep] = Ax[iStep] * hC
605 + hCqp * (dAx_dtx[iStep] *
x[2] + dAx_dty[iStep] *
x[3]);
606 kty[iStep] = Ay[iStep] * hC
607 + hCqp * (dAy_dtx[iStep] *
x[2] + dAy_dty[iStep] *
x[3]);
610 F[4] = x0[0] + kx[0] * C1_6 + kx[1] * C1_3 + kx[2] * C1_3 + kx[3] * C1_6;
611 F[9] = x0[1] + ky[0] * C1_6 + ky[1] * C1_3 + ky[2] * C1_3 + ky[3] * C1_6;
613 x0[2] + ktx[0] * C1_6 + ktx[1] * C1_3 + ktx[2] * C1_3 + ktx[3] * C1_6;
615 x0[3] + kty[0] * C1_6 + kty[1] * C1_3 + kty[2] * C1_3 + kty[3] * C1_6;
640 T A = cIn[2] + F[2] * cIn[9] + F[3] * cIn[10] + F[4] * cIn[11];
641 T B = cIn[3] + F[2] * cIn[10] + F[3] * cIn[12] + F[4] * cIn[13];
642 T C = cIn[4] + F[2] * cIn[11] + F[3] * cIn[13] + F[4] * cIn[14];
644 T D = cIn[6] + F[7] * cIn[9] + F[8] * cIn[10] + F[9] * cIn[11];
645 T E = cIn[7] + F[7] * cIn[10] + F[8] * cIn[12] + F[9] * cIn[13];
646 T G = cIn[8] + F[7] * cIn[11] + F[8] * cIn[13] + F[9] * cIn[14];
648 T H = cIn[9] + F[13] * cIn[10] + F[14] * cIn[11];
649 T I = cIn[10] + F[13] * cIn[12] + F[14] * cIn[13];
650 T J = cIn[11] + F[13] * cIn[13] + F[14] * cIn[14];
652 T K = cIn[13] + F[17] * cIn[11] + F[19] * cIn[14];
654 par.
C0 = cIn[0] + F[2] * cIn[2] + F[3] * cIn[3] + F[4] * cIn[4]
655 + A * F[2] + B * F[3] + C * F[4];
656 par.
C1 = cIn[1] + F[2] * cIn[6] + F[3] * cIn[7] + F[4] * cIn[8]
657 + A * F[7] + B * F[8] + C * F[9];
658 par.
C2 = A + B * F[13] + C * F[14];
659 par.
C3 = B + A * F[17] + C * F[19];
662 par.
C5 = cIn[5] + F[7] * cIn[6] + F[8] * cIn[7] + F[9] * cIn[8]
663 + D * F[7] + E * F[8] + G * F[9];
664 par.
C6 = D + E * F[13] + G * F[14];
665 par.
C7 = E + D * F[17] + G * F[19];
668 par.
C9 = H + I * F[13] + J * F[14];
669 par.
C10 = I + H * F[17] + J * F[19];
672 par.
C12 = cIn[12] + F[17] * cIn[10] + F[19] * cIn[13]
673 + (F[17] * cIn[9] + cIn[10] + F[19] * cIn[11]) * F[17]
697 static const T C1_2 = 0.5;