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/alignment.H"
15 #include "mixin/beamoptic.H"
16 #include "mixin/thick.H"
17 #include "mixin/nofinalize.H"
18 
19 #include <AMReX_Extension.H>
20 #include <AMReX_REAL.H>
21 
22 #include <cmath>
23 
24 
25 namespace impactx
26 {
27  struct ChrDrift
28  : public elements::BeamOptic<ChrDrift>,
29  public elements::Thick,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "ChrDrift";
35 
48  amrex::ParticleReal ds,
49  amrex::ParticleReal dx = 0,
50  amrex::ParticleReal dy = 0,
51  amrex::ParticleReal rotation_degree = 0,
52  int nslice = 1
53  )
54  : Thick(ds, nslice),
55  Alignment(dx, dy, rotation_degree)
56  {
57  }
58 
60  using BeamOptic::operator();
61 
75  amrex::ParticleReal & AMREX_RESTRICT x,
76  amrex::ParticleReal & AMREX_RESTRICT y,
77  amrex::ParticleReal & AMREX_RESTRICT t,
78  amrex::ParticleReal & AMREX_RESTRICT px,
79  amrex::ParticleReal & AMREX_RESTRICT py,
80  amrex::ParticleReal & AMREX_RESTRICT pt,
81  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
82  RefPart const & refpart
83  ) const
84  {
85  using namespace amrex::literals; // for _rt and _prt
86 
87  // shift due to alignment errors of the element
88  shift_in(x, y, px, py);
89 
90  // access position data
91  amrex::ParticleReal const xout = x;
92  amrex::ParticleReal const yout = y;
93  amrex::ParticleReal const tout = t;
94 
95  // initialize output values of momenta
96  amrex::ParticleReal const pxout = px;
97  amrex::ParticleReal const pyout = py;
98  amrex::ParticleReal const ptout = pt;
99 
100  // length of the current slice
101  amrex::ParticleReal const slice_ds = m_ds / nslice();
102 
103  // access reference particle values to find beta, gamma
104  amrex::ParticleReal const bet = refpart.beta();
105  amrex::ParticleReal const gam = refpart.gamma();
106 
107  // compute particle momentum deviation delta + 1
108  amrex::ParticleReal delta1;
109  delta1 = sqrt(1_prt - 2_prt*pt/bet + pow(pt,2));
110 
111  // advance transverse position and momentum (drift)
112  x = xout + slice_ds * px / delta1;
113  // pxout = px;
114  y = yout + slice_ds * py / delta1;
115  // pyout = py;
116 
117  // the corresponding symplectic update to t
118  amrex::ParticleReal term = 2_prt*pow(pt,2)+pow(px,2)+pow(py,2);
119  term = 2_prt - 4_prt*bet*pt + pow(bet,2)*term;
120  term = -2_prt + pow(gam,2)*term;
121  term = (-1_prt+bet*pt)*term;
122  term = term/(2_prt*pow(bet,3)*pow(gam,2));
123  t = tout - slice_ds * (1_prt / bet + term / pow(delta1, 3));
124  // ptout = pt;
125 
126  // assign updated momenta
127  px = pxout;
128  py = pyout;
129  pt = ptout;
130 
131  // undo shift due to alignment errors of the element
132  shift_out(x, y, px, py);
133  }
134 
140  void operator() (RefPart & AMREX_RESTRICT refpart) const
141  {
142  using namespace amrex::literals; // for _rt and _prt
143 
144  // assign input reference particle values
145  amrex::ParticleReal const x = refpart.x;
146  amrex::ParticleReal const px = refpart.px;
147  amrex::ParticleReal const y = refpart.y;
148  amrex::ParticleReal const py = refpart.py;
149  amrex::ParticleReal const z = refpart.z;
150  amrex::ParticleReal const pz = refpart.pz;
151  amrex::ParticleReal const t = refpart.t;
152  amrex::ParticleReal const pt = refpart.pt;
153  amrex::ParticleReal const s = refpart.s;
154 
155  // length of the current slice
156  amrex::ParticleReal const slice_ds = m_ds / nslice();
157 
158  // assign intermediate parameter
159  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
160 
161  // advance position and momentum (drift)
162  refpart.x = x + step*px;
163  refpart.y = y + step*py;
164  refpart.z = z + step*pz;
165  refpart.t = t - step*pt;
166 
167  // advance integrated path length
168  refpart.s = s + slice_ds;
169  }
170  };
171 
172 } // namespace impactx
173 
174 #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:33
@ t
fixed t as the independent variable
s
Definition: ChrDrift.H:32
ChrDrift(amrex::ParticleReal ds, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, int nslice=1)
Definition: ChrDrift.H:47
ImpactXParticleContainer::ParticleType PType
Definition: ChrDrift.H:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT t, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py, amrex::ParticleReal &AMREX_RESTRICT pt, [[maybe_unused]] uint64_t &AMREX_RESTRICT idcpu, RefPart const &refpart) const
Definition: ChrDrift.H:74
static constexpr auto name
Definition: ChrDrift.H:33
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: alignment.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_out(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py) const
Definition: alignment.H:91
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition: alignment.H:120
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_in(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py) const
Definition: alignment.H:61
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition: alignment.H:130
Definition: beamoptic.H:149
Definition: nofinalize.H:22
Definition: thick.H:24
Thick(amrex::ParticleReal ds, int nslice)
Definition: thick.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: thick.H:53
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: thick.H:43
amrex::ParticleReal m_ds
Definition: thick.H:58