ImpactX
ExactDrift.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_EXACTDRIFT_H
11 #define IMPACTX_EXACTDRIFT_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 ExactDrift
28  : public elements::BeamOptic<ExactDrift>,
29  public elements::Thick,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "ExactDrift";
35 
45  amrex::ParticleReal ds,
46  amrex::ParticleReal dx = 0,
47  amrex::ParticleReal dy = 0,
48  amrex::ParticleReal rotation_degree = 0,
49  int nslice = 1
50  )
51  : Thick(ds, nslice),
52  Alignment(dx, dy, rotation_degree)
53  {
54  }
55 
57  using BeamOptic::operator();
58 
70  PType& AMREX_RESTRICT p,
71  amrex::ParticleReal & AMREX_RESTRICT px,
72  amrex::ParticleReal & AMREX_RESTRICT py,
73  amrex::ParticleReal & AMREX_RESTRICT pt,
74  RefPart const & refpart) const {
75 
76  using namespace amrex::literals; // for _rt and _prt
77 
78  // shift due to alignment errors of the element
79  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
80 
81  // access AoS data such as positions and cpu/id
82  amrex::ParticleReal const x = p.pos(RealAoS::x);
83  amrex::ParticleReal const y = p.pos(RealAoS::y);
84  amrex::ParticleReal const t = p.pos(RealAoS::t);
85 
86  // initialize output values of momenta
87  amrex::ParticleReal const pxout = px;
88  amrex::ParticleReal const pyout = py;
89  amrex::ParticleReal const ptout = pt;
90 
91  // length of the current slice
92  amrex::ParticleReal const slice_ds = m_ds / nslice();
93 
94  // access reference particle values to find beta, beta*gamma
95  amrex::ParticleReal const bet = refpart.beta();
96  amrex::ParticleReal const betgam = refpart.beta_gamma();
97 
98  // compute the radical in the denominator (= pz):
99  amrex::ParticleReal const pzden = sqrt(pow(pt-1_prt/bet,2) -
100  1_prt/pow(betgam,2) - pow(px,2) - pow(py,2));
101 
102  // advance position and momentum (exact drift)
103  p.pos(RealAoS::x) = x + slice_ds * px / pzden;
104  // pxout = px;
105  p.pos(RealAoS::y) = y + slice_ds * py / pzden;
106  // pyout = py;
107  p.pos(RealAoS::t) = t - slice_ds * (1_prt/bet +
108  (pt-1_prt/bet)/pzden);
109  // ptout = pt;
110 
111  // assign updated momenta
112  px = pxout;
113  py = pyout;
114  pt = ptout;
115 
116  // undo shift due to alignment errors of the element
117  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
118  }
119 
125  void operator() (RefPart & AMREX_RESTRICT refpart) const {
126 
127  using namespace amrex::literals; // for _rt and _prt
128 
129  // assign input reference particle values
130  amrex::ParticleReal const x = refpart.x;
131  amrex::ParticleReal const px = refpart.px;
132  amrex::ParticleReal const y = refpart.y;
133  amrex::ParticleReal const py = refpart.py;
134  amrex::ParticleReal const z = refpart.z;
135  amrex::ParticleReal const pz = refpart.pz;
136  amrex::ParticleReal const t = refpart.t;
137  amrex::ParticleReal const pt = refpart.pt;
138  amrex::ParticleReal const s = refpart.s;
139 
140  // length of the current slice
141  amrex::ParticleReal const slice_ds = m_ds / nslice();
142 
143  // assign intermediate parameter
144  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
145 
146  // advance position and momentum (drift)
147  refpart.x = x + step*px;
148  refpart.y = y + step*py;
149  refpart.z = z + step*pz;
150  refpart.t = t - step*pt;
151 
152  // advance integrated path length
153  refpart.s = s + slice_ds;
154 
155  }
156  };
157 
158 } // namespace impactx
159 
160 #endif // IMPACTX_EXACTDRIFT_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: ExactDrift.H:32
ExactDrift(amrex::ParticleReal ds, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, int nslice=1)
Definition: ExactDrift.H:44
static constexpr auto name
Definition: ExactDrift.H:33
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: ExactDrift.H:69
ImpactXParticleContainer::ParticleType PType
Definition: ExactDrift.H:34
@ 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_gamma() const
Definition: ReferenceParticle.H:79
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition: ReferenceParticle.H:64
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