ImpactX
ChrDrift.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_CHRDRIFT_H
11 #define IMPACTX_CHRDRIFT_H
12 
14 #include "mixin/beamoptic.H"
15 #include "mixin/thick.H"
16 #include "mixin/nofinalize.H"
17 
18 #include <AMReX_Extension.H>
19 #include <AMReX_REAL.H>
20 
21 #include <cmath>
22 
23 
24 namespace impactx
25 {
26  struct ChrDrift
27  : public elements::BeamOptic<ChrDrift>,
28  public elements::Thick,
30  {
31  static constexpr auto name = "ChrDrift";
33 
42  ChrDrift( amrex::ParticleReal const ds, int const nslice )
43  : Thick(ds, nslice)
44  {
45  }
46 
48  using BeamOptic::operator();
49 
60  PType& AMREX_RESTRICT p,
61  amrex::ParticleReal & AMREX_RESTRICT px,
62  amrex::ParticleReal & AMREX_RESTRICT py,
63  amrex::ParticleReal & AMREX_RESTRICT pt,
64  RefPart const & refpart) const {
65 
66  using namespace amrex::literals; // for _rt and _prt
67 
68  // access AoS data such as positions and cpu/id
69  amrex::ParticleReal const x = p.pos(RealAoS::x);
70  amrex::ParticleReal const y = p.pos(RealAoS::y);
71  amrex::ParticleReal const t = p.pos(RealAoS::t);
72 
73  // initialize output values of momenta
74  amrex::ParticleReal pxout = px;
75  amrex::ParticleReal pyout = py;
76  amrex::ParticleReal ptout = pt;
77 
78  // length of the current slice
79  amrex::ParticleReal const slice_ds = m_ds / nslice();
80 
81  // access reference particle values to find beta, gamma
82  amrex::ParticleReal const bet = refpart.beta();
83  amrex::ParticleReal const gam = refpart.gamma();
84 
85  // compute particle momentum deviation delta + 1
86  amrex::ParticleReal delta1;
87  delta1 = sqrt(1_prt - 2_prt*pt/bet + pow(pt,2));
88 
89  // advance transverse position and momentum (drift)
90  p.pos(RealAoS::x) = x + slice_ds * px / delta1;
91  // pxout = px;
92  p.pos(RealAoS::y) = y + slice_ds * py / delta1;
93  // pyout = py;
94 
95  // the corresponding symplectic update to t
96  amrex::ParticleReal term = 2_prt*pow(pt,2)+pow(px,2)+pow(py,2);
97  term = 2_prt - 4_prt*bet*pt + pow(bet,2)*term;
98  term = -2_prt + pow(gam,2)*term;
99  term = (-1_prt+bet*pt)*term;
100  term = term/(2_prt*pow(bet,3)*pow(gam,2));
101  p.pos(RealAoS::t) = t - slice_ds*(1_prt/bet + term/pow(delta1,3));
102  // ptout = pt;
103 
104  // assign updated momenta
105  px = pxout;
106  py = pyout;
107  pt = ptout;
108 
109  }
110 
116  void operator() (RefPart & AMREX_RESTRICT refpart) const {
117 
118  using namespace amrex::literals; // for _rt and _prt
119 
120  // assign input reference particle values
121  amrex::ParticleReal const x = refpart.x;
122  amrex::ParticleReal const px = refpart.px;
123  amrex::ParticleReal const y = refpart.y;
124  amrex::ParticleReal const py = refpart.py;
125  amrex::ParticleReal const z = refpart.z;
126  amrex::ParticleReal const pz = refpart.pz;
127  amrex::ParticleReal const t = refpart.t;
128  amrex::ParticleReal const pt = refpart.pt;
129  amrex::ParticleReal const s = refpart.s;
130 
131  // length of the current slice
132  amrex::ParticleReal const slice_ds = m_ds / nslice();
133 
134  // assign intermediate parameter
135  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
136 
137  // advance position and momentum (drift)
138  refpart.x = x + step*px;
139  refpart.y = y + step*py;
140  refpart.z = z + step*pz;
141  refpart.t = t - step*pt;
142 
143  // advance integrated path length
144  refpart.s = s + slice_ds;
145 
146  }
147  };
148 
149 } // namespace impactx
150 
151 #endif // IMPACTX_CHRDRIFT_H
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Definition: ImpactX.cpp:32
s
Definition: ChrDrift.H:30
ImpactXParticleContainer::ParticleType PType
Definition: ChrDrift.H:32
ChrDrift(amrex::ParticleReal const ds, int const nslice)
Definition: ChrDrift.H:42
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: ChrDrift.H:59
static constexpr auto name
Definition: ChrDrift.H:31
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:42
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:43
@ t
c * time-of-flight [m] (at fixed s)
Definition: ImpactXParticleContainer.H:44
Definition: ReferenceParticle.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition: ReferenceParticle.H:64
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition: ReferenceParticle.H:52
Definition: beamoptic.H:135
Definition: nofinalize.H:22
Definition: thick.H:24
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::ParticleReal m_ds
Definition: thick.H:56
Thick(amrex::ParticleReal const ds, int const nslice)
Definition: thick.H:30