OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
BorisPusher.h
Go to the documentation of this file.
1 //
2 // Class BorisPusher
3 // Boris-Buneman 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 #ifndef CLASSIC_PartPusher_H
19 #define CLASSIC_PartPusher_H
20 
21 #include "Algorithms/Vektor.h"
22 #include "Algorithms/PartData.h"
23 #include "Physics/Physics.h"
24 
25 /*
26 
27 
28  */
29 
30 class BorisPusher {
31 
32 public:
33  BorisPusher(const PartData &ref);
34  BorisPusher();
35  void initialise(const PartData *ref);
36 
37  void kick(const Vector_t &R, Vector_t &P,
38  const Vector_t &Ef, const Vector_t &Bf,
39  const double &dt) const;
40 
41  void kick(const Vector_t &R, Vector_t &P,
42  const Vector_t &Ef, const Vector_t &Bf,
43  const double &dt, const double &mass,
44  const double &charge) const;
45 
46  void push(Vector_t &R, const Vector_t &P, const double &dt) const;
47 
48 private:
50 };
51 
53  itsReference(&ref)
54 { }
55 
57  itsReference(NULL)
58 { }
59 
61 {
62  itsReference = ref;
63 }
64 
65 inline void BorisPusher::kick(const Vector_t &R, Vector_t &P,
66  const Vector_t &Ef, const Vector_t &Bf,
67  const double &dt) const
68 {
69  kick(R, P, Ef, Bf, dt, itsReference->getM(), itsReference->getQ());
70 }
71 
72 
73 inline void BorisPusher::kick(const Vector_t &/*R*/, Vector_t &P,
74  const Vector_t &Ef, const Vector_t &Bf,
75  const double &dt, const double &mass,
76  const double &charge) const
77 {
78  // Implementation follows chapter 4-4, p. 61 - 63 from
79  // Birdsall, C. K. and Langdon, A. B. (1985). Plasma physics
80  // via computer simulation.
81  //
82  // Up to finite precision effects, the new implementation is equivalent to the
83  // old one, but uses less floating point operations.
84  //
85  // Relativistic variant implemented below is described in
86  // chapter 15-4, p. 356 - 357.
87  // However, since other units are used here, small
88  // modifications are required. The relativistic variant can be derived
89  // from the nonrelativistic one by replacing
90  // mass
91  // by
92  // gamma * rest mass
93  // and transforming the units.
94  //
95  // Parameters:
96  // R = x / (c * dt): Scaled position x, not used in here
97  // P = v / c * gamma: Scaled velocity v
98  // Ef: Electric field
99  // Bf: Magnetic field
100  // dt: Timestep
101  // mass = rest energy = rest mass * c * c
102  // charge
103 
104  // Half step E
105  P += 0.5 * dt * charge * Physics::c / mass * Ef;
106 
107  // Full step B
108 
109  /*
110  LF
111  double const gamma = sqrt(1.0 + dot(P, P));
112  Vector_t const t = dt * charge * c * c / (gamma * mass) * Bf;
113  P += cross(P, t);
114  */
115 
116  double const gamma = sqrt(1.0 + dot(P, P));
117  Vector_t const t = 0.5 * dt * charge * Physics::c * Physics::c / (gamma * mass) * Bf;
118  Vector_t const w = P + cross(P, t);
119  Vector_t const s = 2.0 / (1.0 + dot(t, t)) * t;
120  P += cross(w, s);
121 
122  /* a poor Leap-Frog
123  P += 1.0 * dt * charge * c * c / (gamma * mass) * cross(P,Bf);
124  */
125 
126  // Half step E
127  P += 0.5 * dt * charge * Physics::c / mass * Ef;
128 }
129 
130 
131 inline void BorisPusher::push(Vector_t &R, const Vector_t &P, const double &/* dt */) const {
138  R += 0.5 * P / sqrt(1.0 + dot(P, P));
139 }
140 
141 #endif
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
Vector3D cross(const Vector3D &lhs, const Vector3D &rhs)
Vector cross product.
Definition: Vector3D.cpp:111
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Definition: Vector3D.cpp:118
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:51
Particle reference data.
Definition: PartData.h:35
double getQ() const
The constant charge per particle.
Definition: PartData.h:104
double getM() const
The constant mass per particle.
Definition: PartData.h:109
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
const PartData * itsReference
Definition: BorisPusher.h:49
void initialise(const PartData *ref)
Definition: BorisPusher.h:60
void push(Vector_t &R, const Vector_t &P, const double &dt) const
Definition: BorisPusher.h:131