23 scaleCore_m(right.scaleCore_m),
24 scaleCoreError_m(right.scaleCoreError_m),
25 phaseCore1_m(right.phaseCore1_m),
26 phaseCore2_m(right.phaseCore2_m),
27 phaseExit_m(right.phaseExit_m),
28 startCoreField_m(right.startCoreField_m),
29 startExitField_m(right.startExitField_m),
30 mappedStartExitField_m(right.mappedStartExitField_m),
31 periodLength_m(right.periodLength_m),
32 numCells_m(right.numCells_m),
33 cellLength_m(right.cellLength_m),
34 mode_m(right.mode_m) {}
83 const double omega_t = freq * t;
85 const double cosEntry = std::cos(omega_t +
phase_m + phaseError);
86 const double sinEntry = std::sin(omega_t +
phase_m + phaseError);
88 const double cosCore1 = std::cos(omega_t +
phaseCore1_m + phaseError);
89 const double sinCore1 = std::sin(omega_t +
phaseCore1_m + phaseError);
91 const double cosCore2 = std::cos(omega_t +
phaseCore2_m + phaseError);
92 const double sinCore2 = std::sin(omega_t +
phaseCore2_m + phaseError);
94 const double cosExit = std::cos(omega_t +
phaseExit_m + phaseError);
95 const double sinExit = std::sin(omega_t +
phaseExit_m + phaseError);
98 if (dynamicFieldmap ==
nullptr) {
100 "TravelingWave::apply",
101 "TravelingWave particle application currently requires an Astra1DDynamic field "
105 dynamicFieldmap->applyTravelingWave(
106 pc, scaleEntry * cosEntry, -scaleEntry * sinEntry, scaleCore * cosCore1,
107 -scaleCore * sinCore1, scaleCore * cosCore2, -scaleCore * sinCore2,
108 scaleEntry * cosExit, -scaleEntry * sinExit, startField, startCoreField, startExitField,
109 mappedStartExit, periodLength, cellLength, fieldLength);
312 const double& E0,
const double& t0,
const double& q,
const double& mass) {
313 std::vector<double> t, E, t2, E2;
314 std::vector<std::pair<double, double> > F;
321 if (F.size() == 0)
return 0.0;
323 int N1 =
static_cast<int>(std::floor(F.size() / 4.)) + 1;
324 int N2 = F.size() - 2 * N1 + 1;
325 int N3 = 2 * N1 +
static_cast<int>(std::floor((
numCells_m - 1) * N2 *
mode_m)) - 1;
326 int N4 =
static_cast<int>(std::round(N2 *
mode_m));
327 double Dz = F[N1 + N2].first - F[N1].first;
333 for (
int i = 1; i < N1; ++i) {
334 E[i] = E0 + (F[i].first + F[i - 1].first) / 2. *
scale_m / mass;
337 for (
int i = N1; i < N3 - N1 + 1; ++i) {
338 int I = (i - N1) % N2 + N1;
339 double Z = (F[I].first + F[I - 1].first) / 2. + std::floor((i - N1) / N2) * Dz;
343 for (
int i = N3 - N1 + 1; i < N3; ++i) {
344 int I = i - N3 - 1 + 2 * N1 + N2;
345 double Z = (F[I].first + F[I - 1].first) / 2. + ((
numCells_m - 1) *
mode_m - 1) * Dz;
346 E[i] = E0 + Z *
scale_m / mass;
350 for (
int iter = 0; iter < 10; ++iter) {
353 for (
int i = 1; i < N1; ++i) {
354 t[i] = t[i - 1] +
getdT(i, i, E, F, mass);
355 t2[i] = t2[i - 1] +
getdT(i, i, E2, F, mass);
359 for (
int i = N1; i < N3 - N1 + 1; ++i) {
360 int I = (i - N1) % N2 + N1;
361 int J = (i - N1 + N4) % N2 + N1;
362 t[i] = t[i - 1] +
getdT(i, I, E, F, mass);
363 t2[i] = t2[i - 1] +
getdT(i, I, E2, F, mass);
365 * (
getdA(i, I, t, phaseC1, F) +
getdA(i, J, t, phaseC2, F));
367 * (
getdB(i, I, t, phaseC1, F) +
getdB(i, J, t, phaseC2, F));
369 for (
int i = N3 - N1 + 1; i < N3; ++i) {
370 int I = i - N3 - 1 + 2 * N1 + N2;
371 t[i] = t[i - 1] +
getdT(i, I, E, F, mass);
372 t2[i] = t2[i - 1] +
getdT(i, I, E2, F, mass);
377 if (std::abs(B) > 0.0000001) {
378 tmp_phi = std::atan(A / B);
382 if (q * (A * std::sin(tmp_phi) + B * std::cos(tmp_phi)) < 0) {
386 if (std::abs(phi - tmp_phi) <
frequency_m * (t[N3 - 1] - t[0]) / N3) {
387 for (
int i = 1; i < N1; ++i) {
390 for (
int i = N1; i < N3 - N1 + 1; ++i) {
391 int I = (i - N1) % N2 + N1;
392 int J = (i - N1 + N4) % N2 + N1;
395 * (
getdE(i, I, t, phi + phaseC1, F)
396 +
getdE(i, J, t, phi + phaseC2, F));
398 for (
int i = N3 - N1 + 1; i < N3; ++i) {
399 int I = i - N3 - 1 + 2 * N1 + N2;
400 E[i] = E[i - 1] + q *
scale_m *
getdE(i, I, t, phi + phaseE, F);
403 const int prevPrecision = ippl::Info->precision(8);
404 Inform m(
"TravelingWave::getAutoPhaseEstimate");
405 m << level2 <<
"estimated phase= " << tmp_phi <<
" rad = " << tmp_phi *
Units::rad2deg
407 <<
"Ekin= " << E[N3 - 1] <<
" MeV" << std::setprecision(prevPrecision) <<
"\n"
413 for (
int i = 1; i < N1; ++i) {
417 t[i] = t[i - 1] +
getdT(i, i, E, F, mass);
418 t2[i] = t2[i - 1] +
getdT(i, i, E2, F, mass);
420 E2[i] = E2[i - 1] + q *
scale_m *
getdE(i, i, t2, phi + dphi, F);
422 for (
int i = N1; i < N3 - N1 + 1; ++i) {
423 int I = (i - N1) % N2 + N1;
424 int J = (i - N1 + N4) % N2 + N1;
427 * (
getdE(i, I, t, phi + phaseC1, F)
428 +
getdE(i, J, t, phi + phaseC2, F));
431 * (
getdE(i, I, t, phi + phaseC1 + dphi, F)
432 +
getdE(i, J, t, phi + phaseC2 + dphi,
434 t[i] = t[i - 1] +
getdT(i, I, E, F, mass);
435 t2[i] = t2[i - 1] +
getdT(i, I, E2, F, mass);
438 * (
getdE(i, I, t, phi + phaseC1, F)
439 +
getdE(i, J, t, phi + phaseC2, F));
442 * (
getdE(i, I, t2, phi + phaseC1 + dphi, F)
443 +
getdE(i, J, t2, phi + phaseC2 + dphi, F));
445 for (
int i = N3 - N1 + 1; i < N3; ++i) {
446 int I = i - N3 - 1 + 2 * N1 + N2;
447 E[i] = E[i - 1] + q *
scale_m *
getdE(i, I, t, phi + phaseE, F);
450 *
getdE(i, I, t, phi + phaseE + dphi, F);
451 t[i] = t[i - 1] +
getdT(i, I, E, F, mass);
452 t2[i] = t2[i - 1] +
getdT(i, I, E2, F, mass);
453 E[i] = E[i - 1] + q *
scale_m *
getdE(i, I, t, phi + phaseE, F);
454 E2[i] = E2[i - 1] + q *
scale_m *
getdE(i, I, t2, phi + phaseE + dphi, F);
459 const int prevPrecision = ippl::Info->precision(8);
460 Inform m(
"TravelingWave::getAutoPhaseEstimate");
461 m << level2 <<
"estimated phase= " << tmp_phi <<
" rad = " << tmp_phi *
Units::rad2deg
463 <<
"Ekin= " << E[N3 - 1] <<
" MeV" << std::setprecision(prevPrecision) <<
"\n"