|
29 | 29 | #include "pos.h" |
30 | 30 | #include "auxiliary.h" |
31 | 31 | #include "tpsa.h" |
| 32 | +#include "linalg.h" |
32 | 33 | #include <cmath> |
33 | 34 |
|
34 | 35 | // constants for 4th-order symplectic integrator |
@@ -121,6 +122,21 @@ Status::type kicktablethinkick(Pos<T>& pos, const Kicktable* kicktable, |
121 | 122 | return status; |
122 | 123 | } |
123 | 124 |
|
| 125 | +template <typename T> |
| 126 | +void matthinkick(Pos<T> &pos, const Matrix &m) { |
| 127 | + |
| 128 | + T rx = pos.rx, px = pos.px; |
| 129 | + T ry = pos.ry, py = pos.py; |
| 130 | + T de = pos.de, dl = pos.dl; |
| 131 | + |
| 132 | + pos.rx = m[0][0]*rx+m[0][1]*px+m[0][2]*ry+m[0][3]*py+m[0][4]*de+m[0][5]*dl; |
| 133 | + pos.px = m[1][0]*rx+m[1][1]*px+m[1][2]*ry+m[1][3]*py+m[1][4]*de+m[1][5]*dl; |
| 134 | + pos.ry = m[2][0]*rx+m[2][1]*px+m[2][2]*ry+m[2][3]*py+m[2][4]*de+m[2][5]*dl; |
| 135 | + pos.py = m[3][0]*rx+m[3][1]*px+m[3][2]*ry+m[3][3]*py+m[3][4]*de+m[3][5]*dl; |
| 136 | + pos.de = m[4][0]*rx+m[4][1]*px+m[4][2]*ry+m[4][3]*py+m[4][4]*de+m[4][5]*dl; |
| 137 | + pos.dl = m[5][0]*rx+m[5][1]*px+m[5][2]*ry+m[5][3]*py+m[5][4]*de+m[5][5]*dl; |
| 138 | +} |
| 139 | + |
124 | 140 | template <typename T> |
125 | 141 | void strthinkick(Pos<T>& pos, const double& length, |
126 | 142 | const std::vector<double>& polynom_a, |
@@ -230,7 +246,6 @@ void local_2_global(Pos<T> &pos, const Element &elem) { |
230 | 246 | translate_pos(pos, elem.t_out); |
231 | 247 | } |
232 | 248 |
|
233 | | - |
234 | 249 | template <typename T> |
235 | 250 | Status::type pm_identity_pass(Pos<T> &pos, const Element &elem, |
236 | 251 | const Accelerator& accelerator) { |
@@ -259,9 +274,9 @@ Status::type pm_str_mpole_symplectic4_pass(Pos<T> &pos, const Element &elem, |
259 | 274 | const std::vector<double> &polynom_a = elem.polynom_a; |
260 | 275 | const std::vector<double> &polynom_b = elem.polynom_b; |
261 | 276 | for(unsigned int i=0; i<elem.nr_steps; ++i) { |
262 | | - drift(pos, l1); |
| 277 | + drift<T>(pos, l1); |
263 | 278 | strthinkick<T>(pos, k1, polynom_a, polynom_b, accelerator); |
264 | | - drift(pos, l2); |
| 279 | + drift<T>(pos, l2); |
265 | 280 | strthinkick<T>(pos, k2, polynom_a, polynom_b, accelerator); |
266 | 281 | drift<T>(pos, l2); |
267 | 282 | strthinkick<T>(pos, k1, polynom_a, polynom_b, accelerator); |
@@ -301,7 +316,6 @@ Status::type pm_bnd_mpole_symplectic4_pass(Pos<T> &pos, const Element &elem, |
301 | 316 | return Status::success; |
302 | 317 | } |
303 | 318 |
|
304 | | - |
305 | 319 | template <typename T> |
306 | 320 | Status::type pm_corrector_pass(Pos<T> &pos, const Element &elem, |
307 | 321 | const Accelerator& accelerator) { |
@@ -333,7 +347,6 @@ Status::type pm_corrector_pass(Pos<T> &pos, const Element &elem, |
333 | 347 | return Status::success; |
334 | 348 | } |
335 | 349 |
|
336 | | - |
337 | 350 | template <typename T> |
338 | 351 | Status::type pm_cavity_pass(Pos<T> &pos, const Element &elem, |
339 | 352 | const Accelerator& accelerator) { |
@@ -410,6 +423,37 @@ Status::type pm_kicktable_pass(Pos<T> &pos, const Element &elem, |
410 | 423 | return status; |
411 | 424 | } |
412 | 425 |
|
| 426 | +template <typename T> |
| 427 | +Status::type pm_matrix_pass(Pos<T> &pos, const Element &elem, |
| 428 | + const Accelerator& accelerator) { |
| 429 | + |
| 430 | + global_2_local(pos, elem); |
| 431 | + if (elem.length > 0) { |
| 432 | + double sl = elem.length / float(elem.nr_steps); |
| 433 | + double l1 = sl * DRIFT1; |
| 434 | + double l2 = sl * DRIFT2; |
| 435 | + double k1 = KICK1 / float(elem.nr_steps); |
| 436 | + double k2 = KICK2 / float(elem.nr_steps); |
| 437 | + Matrix mat1 = elem.matrix66; |
| 438 | + Matrix mat2 = elem.matrix66; |
| 439 | + multiply_transf_matrix66(mat1, k1); |
| 440 | + multiply_transf_matrix66(mat2, k2); |
| 441 | + for(unsigned int i=0; i<elem.nr_steps; ++i) { |
| 442 | + drift<T>(pos, l1); |
| 443 | + matthinkick<T>(pos, mat1); |
| 444 | + drift<T>(pos, l2); |
| 445 | + matthinkick<T>(pos, mat2); |
| 446 | + drift<T>(pos, l2); |
| 447 | + matthinkick<T>(pos, mat1); |
| 448 | + drift<T>(pos, l1); |
| 449 | + } |
| 450 | + } else { |
| 451 | + matthinkick<T>(pos, elem.matrix66); |
| 452 | + } |
| 453 | + local_2_global(pos, elem); |
| 454 | + return Status::success; |
| 455 | +} |
| 456 | + |
413 | 457 | #undef DRIFT1 |
414 | 458 | #undef DRIFT2 |
415 | 459 | #undef KICK1 |
|
0 commit comments