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