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 #include "mixin/beamoptic.H"
15 #include "mixin/thick.H"
16 
17 #include <AMReX_Extension.H>
18 #include <AMReX_REAL.H>
19 
20 #include <cmath>
21 
22 
23 namespace impactx
24 {
25  struct Drift
26  : public elements::BeamOptic<Drift>,
27  public elements::Thick
28  {
29  static constexpr auto name = "Drift";
31 
37  Drift( amrex::ParticleReal const ds, int const nslice )
38  : Thick(ds, nslice)
39  {
40  }
41 
43  using BeamOptic::operator();
44 
55  PType& AMREX_RESTRICT p,
56  amrex::ParticleReal & AMREX_RESTRICT px,
57  amrex::ParticleReal & AMREX_RESTRICT py,
58  amrex::ParticleReal & AMREX_RESTRICT pt,
59  RefPart const & refpart) const {
60 
61  using namespace amrex::literals; // for _rt and _prt
62 
63  // access AoS data such as positions and cpu/id
64  amrex::ParticleReal const x = p.pos(0);
65  amrex::ParticleReal const y = p.pos(1);
66  amrex::ParticleReal const t = p.pos(2);
67 
68  // initialize output values of momenta
69  amrex::ParticleReal pxout = px;
70  amrex::ParticleReal pyout = py;
71  amrex::ParticleReal ptout = pt;
72 
73  // length of the current slice
74  amrex::ParticleReal const slice_ds = m_ds / nslice();
75 
76  // access reference particle values to find beta*gamma^2
77  amrex::ParticleReal const pt_ref = refpart.pt;
78  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
79 
80  // advance position and momentum (drift)
81  p.pos(0) = x + slice_ds * px;
82  // pxout = px;
83  p.pos(1) = y + slice_ds * py;
84  // pyout = py;
85  p.pos(2) = t + (slice_ds/betgam2) * pt;
86  // ptout = pt;
87 
88  // assign updated momenta
89  px = pxout;
90  py = pyout;
91  pt = ptout;
92 
93  }
94 
100  void operator() (RefPart & AMREX_RESTRICT refpart) const {
101 
102  using namespace amrex::literals; // for _rt and _prt
103 
104  // assign input reference particle values
105  amrex::ParticleReal const x = refpart.x;
106  amrex::ParticleReal const px = refpart.px;
107  amrex::ParticleReal const y = refpart.y;
108  amrex::ParticleReal const py = refpart.py;
109  amrex::ParticleReal const z = refpart.z;
110  amrex::ParticleReal const pz = refpart.pz;
111  amrex::ParticleReal const t = refpart.t;
112  amrex::ParticleReal const pt = refpart.pt;
113  amrex::ParticleReal const s = refpart.s;
114 
115  // length of the current slice
116  amrex::ParticleReal const slice_ds = m_ds / nslice();
117 
118  // assign intermediate parameter
119  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
120 
121  // advance position and momentum (drift)
122  refpart.x = x + step*px;
123  refpart.y = y + step*py;
124  refpart.z = z + step*pz;
125  refpart.t = t - step*pt;
126 
127  // advance integrated path length
128  refpart.s = s + slice_ds;
129 
130  }
131  };
132 
133 } // namespace impactx
134 
135 #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:54
Drift(amrex::ParticleReal const ds, int const nslice)
Definition: Drift.H:37
Definition: ImpactX.cpp:31
Definition: beamoptic.H:131
amrex::ParticleReal pt
energy deviation, normalized by rest energy
Definition: ReferenceParticle.H:39
Definition: Drift.H:25
static constexpr auto name
Definition: Drift.H:29
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
Definition: thick.H:23
Thick(amrex::ParticleReal const ds, int const nslice)
Definition: thick.H:30
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 amrex::ParticleReal ds() const
Definition: thick.H:50
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: thick.H:40
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
amrex::ParticleReal m_ds
Definition: thick.H:56