ImpactX
Drift.H
Go to the documentation of this file.
1 /* Copyright 2022-2023 The Regents of the University of California, through Lawrence
2  * Berkeley National Laboratory (subject to receipt of any required
3  * approvals from the U.S. Dept. of Energy). All rights reserved.
4  *
5  * This file is part of ImpactX.
6  *
7  * Authors: Chad Mitchell, Axel Huebl
8  * License: BSD-3-Clause-LBNL
9  */
10 #ifndef IMPACTX_DRIFT_H
11 #define IMPACTX_DRIFT_H
12 
14 
15 #include <AMReX_Extension.H>
16 #include <AMReX_REAL.H>
17 
18 #include <cmath>
19 
20 
21 namespace impactx
22 {
23  struct Drift
24  {
25  static constexpr auto name = "Drift";
27 
33  Drift( amrex::ParticleReal const ds, int const nslice )
34  : m_ds(ds), m_nslice(nslice)
35  {
36  }
37 
48  PType& AMREX_RESTRICT p,
49  amrex::ParticleReal & AMREX_RESTRICT px,
50  amrex::ParticleReal & AMREX_RESTRICT py,
51  amrex::ParticleReal & AMREX_RESTRICT pt,
52  RefPart const & refpart) const {
53 
54  using namespace amrex::literals; // for _rt and _prt
55 
56  // access AoS data such as positions and cpu/id
57  amrex::ParticleReal const x = p.pos(0);
58  amrex::ParticleReal const y = p.pos(1);
59  amrex::ParticleReal const t = p.pos(2);
60 
61  // initialize output values of momenta
62  amrex::ParticleReal pxout = px;
63  amrex::ParticleReal pyout = py;
64  amrex::ParticleReal ptout = pt;
65 
66  // length of the current slice
67  amrex::ParticleReal const slice_ds = m_ds / nslice();
68 
69  // access reference particle values to find beta*gamma^2
70  amrex::ParticleReal const pt_ref = refpart.pt;
71  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
72 
73  // advance position and momentum (drift)
74  p.pos(0) = x + slice_ds * px;
75  // pxout = px;
76  p.pos(1) = y + slice_ds * py;
77  // pyout = py;
78  p.pos(2) = t + (slice_ds/betgam2) * pt;
79  // ptout = pt;
80 
81  // assign updated momenta
82  px = pxout;
83  py = pyout;
84  pt = ptout;
85 
86  }
87 
93  void operator() (RefPart & AMREX_RESTRICT refpart) const {
94 
95  using namespace amrex::literals; // for _rt and _prt
96 
97  // assign input reference particle values
98  amrex::ParticleReal const x = refpart.x;
99  amrex::ParticleReal const px = refpart.px;
100  amrex::ParticleReal const y = refpart.y;
101  amrex::ParticleReal const py = refpart.py;
102  amrex::ParticleReal const z = refpart.z;
103  amrex::ParticleReal const pz = refpart.pz;
104  amrex::ParticleReal const t = refpart.t;
105  amrex::ParticleReal const pt = refpart.pt;
106  amrex::ParticleReal const s = refpart.s;
107 
108  // length of the current slice
109  amrex::ParticleReal const slice_ds = m_ds / nslice();
110 
111  // assign intermediate parameter
112  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
113 
114  // advance position and momentum (drift)
115  refpart.x = x + step*px;
116  refpart.y = y + step*py;
117  refpart.z = z + step*pz;
118  refpart.t = t - step*pt;
119 
120  // advance integrated path length
121  refpart.s = s + slice_ds;
122 
123  }
124 
130  int nslice () const
131  {
132  return m_nslice;
133  }
134 
140  amrex::ParticleReal ds () const
141  {
142  return m_ds;
143  }
144 
145  private:
146  amrex::ParticleReal m_ds;
147  int m_nslice;
148  };
149 
150 } // namespace impactx
151 
152 #endif // IMPACTX_DRIFT_H
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(PType &AMREX_RESTRICT p, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py, amrex::ParticleReal &AMREX_RESTRICT pt, RefPart const &refpart) const
Definition: Drift.H:47
Drift(amrex::ParticleReal const ds, int const nslice)
Definition: Drift.H:33
Definition: ImpactX.cpp:31
amrex::ParticleReal m_ds
Definition: Drift.H:146
amrex::ParticleReal pt
energy deviation, normalized by rest energy
Definition: ReferenceParticle.H:39
Definition: Drift.H:23
static constexpr auto name
Definition: Drift.H:25
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: Drift.H:140
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
int m_nslice
segment length in m
Definition: Drift.H:147
Definition: ReferenceParticle.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
s
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: Drift.H:130