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/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 Drift
28  : public elements::BeamOptic<Drift>,
29  public elements::Thick,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "Drift";
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 
69  PType& AMREX_RESTRICT p,
70  amrex::ParticleReal & AMREX_RESTRICT px,
71  amrex::ParticleReal & AMREX_RESTRICT py,
72  amrex::ParticleReal & AMREX_RESTRICT pt,
73  RefPart const & refpart) const {
74 
75  using namespace amrex::literals; // for _rt and _prt
76 
77  // shift due to alignment errors of the element
78  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
79 
80  // access AoS data such as positions and cpu/id
81  amrex::ParticleReal const x = p.pos(RealAoS::x);
82  amrex::ParticleReal const y = p.pos(RealAoS::y);
83  amrex::ParticleReal const t = p.pos(RealAoS::t);
84 
85  // initialize output values of momenta
86  amrex::ParticleReal const pxout = px;
87  amrex::ParticleReal const pyout = py;
88  amrex::ParticleReal const ptout = pt;
89 
90  // length of the current slice
91  amrex::ParticleReal const slice_ds = m_ds / nslice();
92 
93  // access reference particle values to find beta*gamma^2
94  amrex::ParticleReal const pt_ref = refpart.pt;
95  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
96 
97  // advance position and momentum (drift)
98  p.pos(RealAoS::x) = x + slice_ds * px;
99  // pxout = px;
100  p.pos(RealAoS::y) = y + slice_ds * py;
101  // pyout = py;
102  p.pos(RealAoS::t) = t + (slice_ds/betgam2) * pt;
103  // ptout = pt;
104 
105  // assign updated momenta
106  px = pxout;
107  py = pyout;
108  pt = ptout;
109 
110  // undo shift due to alignment errors of the element
111  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
112  }
113 
119  void operator() (RefPart & AMREX_RESTRICT refpart) const {
120 
121  using namespace amrex::literals; // for _rt and _prt
122 
123  // assign input reference particle values
124  amrex::ParticleReal const x = refpart.x;
125  amrex::ParticleReal const px = refpart.px;
126  amrex::ParticleReal const y = refpart.y;
127  amrex::ParticleReal const py = refpart.py;
128  amrex::ParticleReal const z = refpart.z;
129  amrex::ParticleReal const pz = refpart.pz;
130  amrex::ParticleReal const t = refpart.t;
131  amrex::ParticleReal const pt = refpart.pt;
132  amrex::ParticleReal const s = refpart.s;
133 
134  // length of the current slice
135  amrex::ParticleReal const slice_ds = m_ds / nslice();
136 
137  // assign intermediate parameter
138  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
139 
140  // advance position and momentum (drift)
141  refpart.x = x + step*px;
142  refpart.y = y + step*py;
143  refpart.z = z + step*pz;
144  refpart.t = t - step*pt;
145 
146  // advance integrated path length
147  refpart.s = s + slice_ds;
148 
149  }
150  };
151 
152 } // namespace impactx
153 
154 #endif // IMPACTX_DRIFT_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: Drift.H:32
ImpactXParticleContainer::ParticleType PType
Definition: Drift.H:34
static constexpr auto name
Definition: Drift.H:33
Drift(amrex::ParticleReal ds, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, int nslice=1)
Definition: Drift.H:44
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:68
@ 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::ParticleReal pt
energy, normalized by rest energy
Definition: ReferenceParticle.H:39
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