266 const double& mass) {
267 std::vector<double> t, E, t2, E2;
268 std::vector<std::pair<double, double> > F;
275 if (F.size() == 0)
return 0.0;
277 int N1 =
static_cast<int>(std::floor(F.size() / 4.)) + 1;
278 int N2 = F.size() - 2 * N1 + 1;
279 int N3 = 2 * N1 +
static_cast<int>(std::floor((
numCells_m - 1) * N2 *
mode_m)) - 1;
280 int N4 =
static_cast<int>(std::round(N2 *
mode_m));
281 double Dz = F[N1 + N2].first - F[N1].first;
287 for (
int i = 1; i < N1; ++ i) {
288 E[i] = E0 + (F[i].first + F[i - 1].first) / 2. *
scale_m / mass;
291 for (
int i = N1; i < N3 - N1 + 1; ++ i) {
292 int I = (i - N1) % N2 + N1;
293 double Z = (F[I].first + F[I - 1].first) / 2. + std::floor((i - N1) / N2) * Dz;
297 for (
int i = N3 - N1 + 1; i < N3; ++ i) {
298 int I = i - N3 - 1 + 2 * N1 + N2;
299 double Z = (F[I].first + F[I - 1].first) / 2. + ((
numCells_m - 1) *
mode_m - 1) * Dz;
300 E[i] = E0 + Z *
scale_m / mass;
304 for (
int iter = 0; iter < 10; ++ iter) {
307 for (
int i = 1; i < N1; ++ i) {
308 t[i] = t[i - 1] +
getdT(i, i, E, F, mass);
309 t2[i] = t2[i - 1] +
getdT(i, i, E2, F, mass);
313 for (
int i = N1; i < N3 - N1 + 1; ++ i) {
314 int I = (i - N1) % N2 + N1;
315 int J = (i - N1 + N4) % N2 + N1;
316 t[i] = t[i - 1] +
getdT(i, I, E, F, mass);
317 t2[i] = t2[i - 1] +
getdT(i, I, E2, F, mass);
321 for (
int i = N3 - N1 + 1; i < N3; ++ i) {
322 int I = i - N3 - 1 + 2 * N1 + N2;
323 t[i] = t[i - 1] +
getdT(i, I, E, F, mass);
324 t2[i] = t2[i - 1] +
getdT(i, I, E2, F, mass);
329 if (std::abs(B) > 0.0000001) {
330 tmp_phi = std::atan(A / B);
334 if (q * (A * std::sin(tmp_phi) + B * std::cos(tmp_phi)) < 0) {
338 if (std::abs(phi - tmp_phi) <
frequency_m * (t[N3 - 1] - t[0]) / N3) {
339 for (
int i = 1; i < N1; ++ i) {
342 for (
int i = N1; i < N3 - N1 + 1; ++ i) {
343 int I = (i - N1) % N2 + N1;
344 int J = (i - N1 + N4) % N2 + N1;
345 E[i] = E[i - 1] + q *
scaleCore_m * (
getdE(i, I, t, phi + phaseC1, F) +
getdE(i, J, t, phi + phaseC2, F));
347 for (
int i = N3 - N1 + 1; i < N3; ++ i) {
348 int I = i - N3 - 1 + 2 * N1 + N2;
349 E[i] = E[i - 1] + q *
scale_m *
getdE(i, I, t, phi + phaseE, F);
352 const int prevPrecision =
Ippl::Info->precision(8);
353 INFOMSG(
level2 <<
"estimated phase= " << tmp_phi <<
" rad = "
355 <<
"Ekin= " << E[N3 - 1] <<
" MeV" << std::setprecision(prevPrecision) <<
"\n" <<
endl);
361 for (
int i = 1; i < N1; ++ i) {
363 E2[i] = E2[i - 1] + q *
scale_m *
getdE(i, i, t, phi + dphi, F);
364 t[i] = t[i - 1] +
getdT(i, i, E, F, mass);
365 t2[i] = t2[i - 1] +
getdT(i, i, E2, F, mass);
367 E2[i] = E2[i - 1] + q *
scale_m *
getdE(i, i, t2, phi + dphi, F);
369 for (
int i = N1; i < N3 - N1 + 1; ++ i) {
370 int I = (i - N1) % N2 + N1;
371 int J = (i - N1 + N4) % N2 + N1;
372 E[i] = E[i - 1] + q *
scaleCore_m * (
getdE(i, I, t, phi + phaseC1, F) +
getdE(i, J, t, phi + phaseC2, F));
373 E2[i] = E2[i - 1] + q *
scaleCore_m * (
getdE(i, I, t, phi + phaseC1 + dphi, F) +
getdE(i, J, t, phi + phaseC2 + dphi, F));
374 t[i] = t[i - 1] +
getdT(i, I, E, F, mass);
375 t2[i] = t2[i - 1] +
getdT(i, I, E2, F, mass);
376 E[i] = E[i - 1] + q *
scaleCore_m * (
getdE(i, I, t, phi + phaseC1, F) +
getdE(i, J, t, phi + phaseC2, F));
377 E2[i] = E2[i - 1] + q *
scaleCore_m * (
getdE(i, I, t2, phi + phaseC1 + dphi, F) +
getdE(i, J, t2, phi + phaseC2 + dphi, F));
379 for (
int i = N3 - N1 + 1; i < N3; ++ i) {
380 int I = i - N3 - 1 + 2 * N1 + N2;
381 E[i] = E[i - 1] + q *
scale_m *
getdE(i, I, t, phi + phaseE, F);
382 E2[i] = E2[i - 1] + q *
scale_m *
getdE(i, I, t, phi + phaseE + dphi, F);
383 t[i] = t[i - 1] +
getdT(i, I, E, F, mass);
384 t2[i] = t2[i - 1] +
getdT(i, I, E2, F, mass);
385 E[i] = E[i - 1] + q *
scale_m *
getdE(i, I, t, phi + phaseE, F);
386 E2[i] = E2[i - 1] + q *
scale_m *
getdE(i, I, t2, phi + phaseE + dphi, F);
392 const int prevPrecision =
Ippl::Info->precision(8);
393 INFOMSG(
level2 <<
"estimated phase= " << tmp_phi <<
" rad = "
395 <<
"Ekin= " << E[N3 - 1] <<
" MeV" << std::setprecision(prevPrecision) <<
"\n" <<
endl);