OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
LF2.hpp
Go to the documentation of this file.
1 //
2 // Class LF2
3 // Second order Leap-Frog time integrator
4 //
5 // Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #include "Physics/Units.h"
19 #include "Steppers/BorisPusher.h"
20 
21 template <typename FieldFunction, typename ... Arguments>
23  const size_t& i,
24  const double& t,
25  const double dt,
26  Arguments& ... args) const
27 {
28  bool flagNoDeletion = true;
29 
30  // push for first LF2 half step
31  push_m(bunch->R[i], bunch->P[i], 0.5 * dt);
32 
33  flagNoDeletion = kick_m(bunch, i, t, dt, args ...);
34 
35  // push for second LF2 half step
36  push_m(bunch->R[i], bunch->P[i], 0.5 * dt);
37 
38  return flagNoDeletion;
39 }
40 
41 
42 template <typename FieldFunction, typename ... Arguments>
44  const double& h) const
45 {
46  double const gamma = std::sqrt(1.0 + dot(P, P));
47  double const c_gamma = Physics::c / gamma;
48  Vector_t const v = P * c_gamma;
49  R += h * v;
50 }
51 
52 
53 template <typename FieldFunction, typename ... Arguments>
55  const double& t, const double& h,
56  Arguments& ... args) const
57 {
58  Vector_t externalE = Vector_t(0.0, 0.0, 0.0);
59  Vector_t externalB = Vector_t(0.0, 0.0, 0.0);
60 
61  bool outOfBound = this->fieldfunc_m(t, i, externalE, externalB, args ...);
62 
63  if ( outOfBound )
64  return false;
65 
66 
67  double const q = bunch->Q[0] / Physics::q_e; // For now all particles have the same charge
68  double const M = bunch->M[0] * Units::GeV2eV; // For now all particles have the same rest energy
69 
70  BorisPusher pusher;
71 
72  pusher.kick(bunch->R[i], bunch->P[i],
73  externalE, externalB,
74  h, M, q);
75 
76  return true;
77 }
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
ParticleAttrib< Vector_t > P
bool doAdvance_m(PartBunchBase< double, 3 > *bunch, const size_t &i, const double &t, const double dt, Arguments &...args) const
Definition: LF2.hpp:22
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6
ParticleAttrib< double > M
bool kick_m(PartBunchBase< double, 3 > *bunch, const size_t &i, const double &t, const double &h, Arguments &...args) const
Definition: LF2.hpp:54
ParticleAttrib< double > Q
constexpr double q_e
The elementary charge in As.
Definition: Physics.h:69
ParticlePos_t & R
constexpr double GeV2eV
Definition: Units.h:68
void kick(const Vector_t &R, Vector_t &P, const Vector_t &Ef, const Vector_t &Bf, const double &dt) const
Definition: BorisPusher.h:65
void push_m(Vector_t &R, const Vector_t &P, const double &h) const
Definition: LF2.hpp:43
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Definition: Vector3D.cpp:118