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 
72  PType& AMREX_RESTRICT p,
73  amrex::ParticleReal & AMREX_RESTRICT px,
74  amrex::ParticleReal & AMREX_RESTRICT py,
75  amrex::ParticleReal & AMREX_RESTRICT pt,
76  RefPart const & refpart) const {
77 
78  using namespace amrex::literals; // for _rt and _prt
79 
80  // shift due to alignment errors of the element
81  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
82 
83  // access AoS data such as positions and cpu/id
84  amrex::ParticleReal const x = p.pos(RealAoS::x);
85  amrex::ParticleReal const y = p.pos(RealAoS::y);
86  amrex::ParticleReal const t = p.pos(RealAoS::t);
87 
88  // initialize output values of momenta
89  amrex::ParticleReal const pxout = px;
90  amrex::ParticleReal const pyout = py;
91  amrex::ParticleReal const ptout = pt;
92 
93  // length of the current slice
94  amrex::ParticleReal const slice_ds = m_ds / nslice();
95 
96  // access reference particle values to find beta, gamma
97  amrex::ParticleReal const bet = refpart.beta();
98  amrex::ParticleReal const gam = refpart.gamma();
99 
100  // compute particle momentum deviation delta + 1
101  amrex::ParticleReal delta1;
102  delta1 = sqrt(1_prt - 2_prt*pt/bet + pow(pt,2));
103 
104  // advance transverse position and momentum (drift)
105  p.pos(RealAoS::x) = x + slice_ds * px / delta1;
106  // pxout = px;
107  p.pos(RealAoS::y) = y + slice_ds * py / delta1;
108  // pyout = py;
109 
110  // the corresponding symplectic update to t
111  amrex::ParticleReal term = 2_prt*pow(pt,2)+pow(px,2)+pow(py,2);
112  term = 2_prt - 4_prt*bet*pt + pow(bet,2)*term;
113  term = -2_prt + pow(gam,2)*term;
114  term = (-1_prt+bet*pt)*term;
115  term = term/(2_prt*pow(bet,3)*pow(gam,2));
116  p.pos(RealAoS::t) = t - slice_ds*(1_prt/bet + term/pow(delta1,3));
117  // ptout = pt;
118 
119  // assign updated momenta
120  px = pxout;
121  py = pyout;
122  pt = ptout;
123 
124  // undo shift due to alignment errors of the element
125  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
126  }
127 
133  void operator() (RefPart & AMREX_RESTRICT refpart) const {
134 
135  using namespace amrex::literals; // for _rt and _prt
136 
137  // assign input reference particle values
138  amrex::ParticleReal const x = refpart.x;
139  amrex::ParticleReal const px = refpart.px;
140  amrex::ParticleReal const y = refpart.y;
141  amrex::ParticleReal const py = refpart.py;
142  amrex::ParticleReal const z = refpart.z;
143  amrex::ParticleReal const pz = refpart.pz;
144  amrex::ParticleReal const t = refpart.t;
145  amrex::ParticleReal const pt = refpart.pt;
146  amrex::ParticleReal const s = refpart.s;
147 
148  // length of the current slice
149  amrex::ParticleReal const slice_ds = m_ds / nslice();
150 
151  // assign intermediate parameter
152  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
153 
154  // advance position and momentum (drift)
155  refpart.x = x + step*px;
156  refpart.y = y + step*py;
157  refpart.z = z + step*pz;
158  refpart.t = t - step*pt;
159 
160  // advance integrated path length
161  refpart.s = s + slice_ds;
162 
163  }
164  };
165 
166 } // namespace impactx
167 
168 #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:35
@ 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()(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:71
static constexpr auto name
Definition: ChrDrift.H:33
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:49
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:50
@ t
c * time-of-flight [m] (at fixed s)
Definition: ImpactXParticleContainer.H:51
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:135
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