ImpactX
ChrUniformAcc.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_CHRACC_H
11 #define IMPACTX_CHRACC_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 ChrAcc
28  : public elements::BeamOptic<ChrAcc>,
29  public elements::Thick,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "ChrAcc";
35 
52  amrex::ParticleReal ds,
53  amrex::ParticleReal ez,
54  amrex::ParticleReal bz,
55  amrex::ParticleReal dx = 0,
56  amrex::ParticleReal dy = 0,
57  amrex::ParticleReal rotation_degree = 0,
58  int nslice = 1
59  )
60  : Thick(ds, nslice),
61  Alignment(dx, dy, rotation_degree),
62  m_ez(ez), m_bz(bz)
63  {
64  }
65 
67  using BeamOptic::operator();
68 
82  amrex::ParticleReal & AMREX_RESTRICT x,
83  amrex::ParticleReal & AMREX_RESTRICT y,
84  amrex::ParticleReal & AMREX_RESTRICT t,
85  amrex::ParticleReal & AMREX_RESTRICT px,
86  amrex::ParticleReal & AMREX_RESTRICT py,
87  amrex::ParticleReal & AMREX_RESTRICT pt,
88  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
89  RefPart const & refpart
90  ) const
91  {
92  using namespace amrex::literals; // for _rt and _prt
93 
94  // shift due to alignment errors of the element
95  shift_in(x, y, px, py);
96 
97  // length of the current slice
98  amrex::ParticleReal const slice_ds = m_ds / nslice();
99 
100  // access reference particle values (final, initial):
101  amrex::ParticleReal const ptf_ref = refpart.pt;
102  amrex::ParticleReal const pti_ref = ptf_ref + m_ez*slice_ds;
103  amrex::ParticleReal const bgf = sqrt(pow(ptf_ref, 2) - 1.0_prt);
104  amrex::ParticleReal const bgi = sqrt(pow(pti_ref, 2) - 1.0_prt);
105 
106  // initial conversion from static to dynamic units:
107  px = px*bgi;
108  py = py*bgi;
109  pt = pt*bgi;
110 
111  // compute intermediate quantities related to acceleration
112  amrex::ParticleReal const pti_tot = pti_ref + pt;
113  amrex::ParticleReal const ptf_tot = ptf_ref + pt;
114  amrex::ParticleReal const pzi_tot = sqrt(pow(pti_tot,2)-1_prt);
115  amrex::ParticleReal const pzf_tot = sqrt(pow(ptf_tot,2)-1_prt);
116  amrex::ParticleReal const pzi_ref = sqrt(pow(pti_ref,2)-1_prt);
117  amrex::ParticleReal const pzf_ref = sqrt(pow(ptf_ref,2)-1_prt);
118 
119  amrex::ParticleReal const numer = -ptf_tot + pzf_tot;
120  amrex::ParticleReal const denom = -pti_tot + pzi_tot;
121 
122  // compute focusing constant (1/m) and rotation angle (in rad)
123  amrex::ParticleReal const alpha = m_bz/2.0_prt;
124  amrex::ParticleReal const theta = alpha/m_ez*log(numer/denom);
125 
126  // intialize output values
127  amrex::ParticleReal xout = x;
128  amrex::ParticleReal yout = y;
129  amrex::ParticleReal tout = t;
130  amrex::ParticleReal pxout = px;
131  amrex::ParticleReal pyout = py;
132  amrex::ParticleReal ptout = pt;
133 
134  // advance positions and momenta using map for focusing
135  xout = cos(theta)*x + sin(theta)/alpha*px;
136  pxout = -alpha*sin(theta)*x + cos(theta)*px;
137 
138  yout = cos(theta)*y + sin(theta)/alpha*py;
139  pyout = -alpha*sin(theta)*y + cos(theta)*py;
140 
141  // the correct symplectic update for t
142  tout = t + (pzf_tot - pzf_ref - pzi_tot + pzi_ref)/m_ez;
143  tout = tout + (1_prt/pzi_tot - 1_prt/pzf_tot)*(pow(py-alpha*x,2)+pow(px+alpha*y,2))/(2_prt*m_ez);
144  ptout = pt;
145 
146  // assign intermediate momenta
147  px = pxout;
148  py = pyout;
149  pt = ptout;
150 
151  // advance positions and momenta using map for rotation
152  x = cos(theta)*xout + sin(theta)*yout;
153  pxout = cos(theta)*px + sin(theta)*py;
154 
155  y = -sin(theta)*xout + cos(theta)*yout;
156  pyout = -sin(theta)*px + cos(theta)*py;
157 
158  t = tout;
159  ptout = pt;
160 
161  // assign updated momenta
162  px = pxout;
163  py = pyout;
164  pt = ptout;
165 
166  // final conversion from dynamic to static units:
167  px = px/bgf;
168  py = py/bgf;
169  pt = pt/bgf;
170 
171  // undo shift due to alignment errors of the element
172  shift_out(x, y, px, py);
173  }
174 
180  void operator() (RefPart & AMREX_RESTRICT refpart) const
181  {
182  using namespace amrex::literals; // for _rt and _prt
183 
184  // assign input reference particle values
185  amrex::ParticleReal const x = refpart.x;
186  amrex::ParticleReal const px = refpart.px;
187  amrex::ParticleReal const y = refpart.y;
188  amrex::ParticleReal const py = refpart.py;
189  amrex::ParticleReal const z = refpart.z;
190  amrex::ParticleReal const pz = refpart.pz;
191  amrex::ParticleReal const t = refpart.t;
192  amrex::ParticleReal const pt = refpart.pt;
193  amrex::ParticleReal const s = refpart.s;
194 
195  // length of the current slice
196  amrex::ParticleReal const slice_ds = m_ds / nslice();
197 
198  // compute intial value of beta*gamma
199  amrex::ParticleReal const bgi = sqrt(pow(pt, 2) - 1.0_prt);
200 
201  // advance pt (uniform acceleration)
202  refpart.pt = pt - m_ez*slice_ds;
203 
204  // compute final value of beta*gamma
205  amrex::ParticleReal const ptf = refpart.pt;
206  amrex::ParticleReal const bgf = sqrt(pow(ptf, 2) - 1.0_prt);
207 
208  // update t
209  refpart.t = t + (bgf - bgi)/m_ez;
210 
211  // advance position (x,y,z)
212  refpart.x = x + slice_ds*px/bgi;
213  refpart.y = y + slice_ds*py/bgi;
214  refpart.z = z + slice_ds*pz/bgi;
215 
216  // advance momentum (px,py,pz)
217  refpart.px = px*bgf/bgi;
218  refpart.py = py*bgf/bgi;
219  refpart.pz = pz*bgf/bgi;
220 
221  // advance integrated path length
222  refpart.s = s + slice_ds;
223  }
224 
225  amrex::ParticleReal m_ez;
226  amrex::ParticleReal m_bz;
227  };
228 
229 } // namespace impactx
230 
231 #endif // IMPACTX_CHRACC_H
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > log(const GpuComplex< T > &a_z) noexcept
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: ChrUniformAcc.H:32
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: ChrUniformAcc.H:81
amrex::ParticleReal m_bz
electric field strength in 1/m
Definition: ChrUniformAcc.H:226
ImpactXParticleContainer::ParticleType PType
Definition: ChrUniformAcc.H:34
amrex::ParticleReal m_ez
Definition: ChrUniformAcc.H:225
ChrAcc(amrex::ParticleReal ds, amrex::ParticleReal ez, amrex::ParticleReal bz, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, int nslice=1)
Definition: ChrUniformAcc.H:51
static constexpr auto name
Definition: ChrUniformAcc.H:33
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: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