OPAL (Object Oriented Parallel Accelerator Library) 2022.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 "BorisPusher.h"
19#include "Physics/Units.h"
20
21template <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 * Units::ns2s);
32
33 flagNoDeletion = kick_m(bunch, i, t, dt * Units::ns2s, args ...);
34
35 // push for second LF2 half step
36 push_m(bunch->R[i], bunch->P[i], 0.5 * dt * Units::ns2s);
37
38 return flagNoDeletion;
39}
40
41
42template <typename FieldFunction, typename ... Arguments>
44 const double& h) const
45{
46 double const gamma = 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
53template <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}
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Definition: Vector3D.cpp:118
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
constexpr double q_e
The elementary charge in As.
Definition: Physics.h:69
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
constexpr double ns2s
Definition: Units.h:47
constexpr double GeV2eV
Definition: Units.h:68
ParticlePos_t & R
ParticleAttrib< double > M
ParticleAttrib< Vector_t > P
ParticleAttrib< double > Q
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
bool doAdvance_m(PartBunchBase< double, 3 > *bunch, const size_t &i, const double &t, const double dt, Arguments &... args) const
Definition: LF2.hpp:22
bool kick_m(PartBunchBase< double, 3 > *bunch, const size_t &i, const double &t, const double &h, Arguments &... args) const
Definition: LF2.hpp:54
void push_m(Vector_t &R, const Vector_t &P, const double &h) const
Definition: LF2.hpp:43
Vektor< double, 3 > Vector_t
Definition: Vektor.h:6