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/beamoptic.H"
15 #include "mixin/thick.H"
16 #include "mixin/nofinalize.H"
17 
18 #include <AMReX_Extension.H>
19 #include <AMReX_REAL.H>
20 
21 #include <cmath>
22 
23 
24 namespace impactx
25 {
26  struct ChrAcc
27  : public elements::BeamOptic<ChrAcc>,
28  public elements::Thick,
30  {
31  static constexpr auto name = "ChrAcc";
33 
46  ChrAcc( amrex::ParticleReal const ds, amrex::ParticleReal const ez,
47  amrex::ParticleReal const bz, int const nslice )
48  : Thick(ds, nslice), m_ez(ez), m_bz(bz)
49  {
50  }
51 
53  using BeamOptic::operator();
54 
65  PType& AMREX_RESTRICT p,
66  amrex::ParticleReal & AMREX_RESTRICT px,
67  amrex::ParticleReal & AMREX_RESTRICT py,
68  amrex::ParticleReal & AMREX_RESTRICT pt,
69  RefPart const & refpart) const {
70 
71  using namespace amrex::literals; // for _rt and _prt
72 
73  // access AoS data such as positions and cpu/id
74  amrex::ParticleReal const x = p.pos(RealAoS::x);
75  amrex::ParticleReal const y = p.pos(RealAoS::y);
76  amrex::ParticleReal const t = p.pos(RealAoS::t);
77 
78  // length of the current slice
79  amrex::ParticleReal const slice_ds = m_ds / nslice();
80 
81  // access reference particle values (final, initial):
82  amrex::ParticleReal const ptf_ref = refpart.pt;
83  amrex::ParticleReal const pti_ref = ptf_ref + m_ez*slice_ds;
84  amrex::ParticleReal const bgf = sqrt(pow(ptf_ref, 2) - 1.0_prt);
85  amrex::ParticleReal const bgi = sqrt(pow(pti_ref, 2) - 1.0_prt);
86 
87  // initial conversion from static to dynamic units:
88  px = px*bgi;
89  py = py*bgi;
90  pt = pt*bgi;
91 
92  // compute intermediate quantities related to acceleration
93  amrex::ParticleReal const pti_tot = pti_ref + pt;
94  amrex::ParticleReal const ptf_tot = ptf_ref + pt;
95  amrex::ParticleReal const pzi_tot = sqrt(pow(pti_tot,2)-1_prt);
96  amrex::ParticleReal const pzf_tot = sqrt(pow(ptf_tot,2)-1_prt);
97  amrex::ParticleReal const pzi_ref = sqrt(pow(pti_ref,2)-1_prt);
98  amrex::ParticleReal const pzf_ref = sqrt(pow(ptf_ref,2)-1_prt);
99 
100  amrex::ParticleReal const numer = -ptf_tot + pzf_tot;
101  amrex::ParticleReal const denom = -pti_tot + pzi_tot;
102 
103  // compute focusing constant (1/m) and rotation angle (in rad)
104  amrex::ParticleReal const alpha = m_bz/2.0_prt;
105  amrex::ParticleReal const theta = alpha/m_ez*log(numer/denom);
106 
107  // intialize output values
108  amrex::ParticleReal xout = x;
109  amrex::ParticleReal yout = y;
110  amrex::ParticleReal tout = t;
111  amrex::ParticleReal pxout = px;
112  amrex::ParticleReal pyout = py;
113  amrex::ParticleReal ptout = pt;
114 
115  // advance positions and momenta using map for focusing
116  xout = cos(theta)*x + sin(theta)/alpha*px;
117  pxout = -alpha*sin(theta)*x + cos(theta)*px;
118 
119  yout = cos(theta)*y + sin(theta)/alpha*py;
120  pyout = -alpha*sin(theta)*y + cos(theta)*py;
121 
122  // the correct symplectic update for t
123  tout = t + (pzf_tot - pzf_ref - pzi_tot + pzi_ref)/m_ez;
124  tout = tout + (1_prt/pzi_tot - 1_prt/pzf_tot)*(pow(py-alpha*x,2)+pow(px+alpha*y,2))/(2_prt*m_ez);
125  ptout = pt;
126 
127  // assign intermediate momenta
128  px = pxout;
129  py = pyout;
130  pt = ptout;
131 
132  // advance positions and momenta using map for rotation
133  p.pos(RealAoS::x) = cos(theta)*xout + sin(theta)*yout;
134  pxout = cos(theta)*px + sin(theta)*py;
135 
136  p.pos(RealAoS::y) = -sin(theta)*xout + cos(theta)*yout;
137  pyout = -sin(theta)*px + cos(theta)*py;
138 
139  p.pos(RealAoS::t) = tout;
140  ptout = pt;
141 
142  // assign updated momenta
143  px = pxout;
144  py = pyout;
145  pt = ptout;
146 
147  // final conversion from dynamic to static units:
148  px = px/bgf;
149  py = py/bgf;
150  pt = pt/bgf;
151 
152  }
153 
159  void operator() (RefPart & AMREX_RESTRICT refpart) const {
160 
161  using namespace amrex::literals; // for _rt and _prt
162 
163  // assign input reference particle values
164  amrex::ParticleReal const x = refpart.x;
165  amrex::ParticleReal const px = refpart.px;
166  amrex::ParticleReal const y = refpart.y;
167  amrex::ParticleReal const py = refpart.py;
168  amrex::ParticleReal const z = refpart.z;
169  amrex::ParticleReal const pz = refpart.pz;
170  amrex::ParticleReal const t = refpart.t;
171  amrex::ParticleReal const pt = refpart.pt;
172  amrex::ParticleReal const s = refpart.s;
173 
174  // length of the current slice
175  amrex::ParticleReal const slice_ds = m_ds / nslice();
176 
177  // compute intial value of beta*gamma
178  amrex::ParticleReal const bgi = sqrt(pow(pt, 2) - 1.0_prt);
179 
180  // advance pt (uniform acceleration)
181  refpart.pt = pt - m_ez*slice_ds;
182 
183  // compute final value of beta*gamma
184  amrex::ParticleReal const ptf = refpart.pt;
185  amrex::ParticleReal const bgf = sqrt(pow(ptf, 2) - 1.0_prt);
186 
187  // update t
188  refpart.t = t + (bgf - bgi)/m_ez;
189 
190  // advance position (x,y,z)
191  refpart.x = x + slice_ds*px/bgi;
192  refpart.y = y + slice_ds*py/bgi;
193  refpart.z = z + slice_ds*pz/bgi;
194 
195  // advance momentum (px,py,pz)
196  refpart.px = px*bgf/bgi;
197  refpart.py = py*bgf/bgi;
198  refpart.pz = pz*bgf/bgi;
199 
200  // advance integrated path length
201  refpart.s = s + slice_ds;
202  }
203 
204  private:
205  amrex::ParticleReal m_ez;
206  amrex::ParticleReal m_bz;
207  };
208 
209 } // namespace impactx
210 
211 #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:32
s
Definition: ChrUniformAcc.H:30
ChrAcc(amrex::ParticleReal const ds, amrex::ParticleReal const ez, amrex::ParticleReal const bz, int const nslice)
Definition: ChrUniformAcc.H:46
amrex::ParticleReal m_bz
electric field strength in 1/m
Definition: ChrUniformAcc.H:206
ImpactXParticleContainer::ParticleType PType
Definition: ChrUniformAcc.H:32
amrex::ParticleReal m_ez
Definition: ChrUniformAcc.H:205
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: ChrUniformAcc.H:64
static constexpr auto name
Definition: ChrUniformAcc.H:31
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:42
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:43
@ t
c * time-of-flight [m] (at fixed s)
Definition: ImpactXParticleContainer.H:44
Definition: ReferenceParticle.H:30
amrex::ParticleReal pt
energy deviation, normalized by rest energy
Definition: ReferenceParticle.H:39
Definition: beamoptic.H:135
Definition: nofinalize.H:22
Definition: thick.H:24
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: thick.H:50
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: thick.H:40
amrex::ParticleReal m_ds
Definition: thick.H:56
Thick(amrex::ParticleReal const ds, int const nslice)
Definition: thick.H:30