ImpactX
ChrPlasmaLens.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_CHRPLASMALENS_H
11 #define IMPACTX_CHRPLASMALENS_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 {
28  : public elements::BeamOptic<ChrPlasmaLens>,
29  public elements::Thick,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "ChrPlasmaLens";
35 
54  amrex::ParticleReal ds,
55  amrex::ParticleReal k,
56  int unit,
57  amrex::ParticleReal dx = 0,
58  amrex::ParticleReal dy = 0,
59  amrex::ParticleReal rotation_degree = 0,
60  int nslice = 1
61  )
62  : Thick(ds, nslice),
63  Alignment(dx, dy, rotation_degree),
64  m_k(k), m_unit(unit)
65  {
66  }
67 
69  using BeamOptic::operator();
70 
81  PType& AMREX_RESTRICT p,
82  amrex::ParticleReal & AMREX_RESTRICT px,
83  amrex::ParticleReal & AMREX_RESTRICT py,
84  amrex::ParticleReal & AMREX_RESTRICT pt,
85  RefPart const & refpart
86  ) const
87  {
88  using namespace amrex::literals; // for _rt and _prt
89 
90  // shift due to alignment errors of the element
91  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
92 
93  // access AoS data such as positions and cpu/id
94  amrex::ParticleReal const x = p.pos(RealAoS::x);
95  amrex::ParticleReal const y = p.pos(RealAoS::y);
96  amrex::ParticleReal const t = p.pos(RealAoS::t);
97 
98  // length of the current slice
99  amrex::ParticleReal const slice_ds = m_ds / nslice();
100 
101  // access reference particle values to find beta
102  amrex::ParticleReal const bet = refpart.beta();
103 
104  // normalize focusing strength units to MAD-X convention if needed
105  amrex::ParticleReal g = m_k;
106  if (m_unit == 1) {
107  g = m_k / refpart.rigidity_Tm();
108  }
109 
110  // compute particle momentum deviation delta + 1
111  amrex::ParticleReal delta1;
112  delta1 = sqrt(1_prt - 2_prt*pt/bet + pow(pt,2));
113  amrex::ParticleReal const delta = delta1 - 1_prt;
114 
115  // compute phase advance per unit length in s (in rad/m)
116  // chromatic dependence on delta is included
117  amrex::ParticleReal const omega = sqrt(std::abs(g)/delta1);
118 
119  // intialize output values of momenta
120  amrex::ParticleReal pxout = px;
121  amrex::ParticleReal pyout = py;
122  amrex::ParticleReal const ptout = pt;
123 
124  // paceholder variables
125  amrex::ParticleReal q1 = x;
126  amrex::ParticleReal q2 = y;
127  amrex::ParticleReal p1 = px;
128  amrex::ParticleReal p2 = py;
129 
130  // advance transverse position and momentum (focusing)
131  p.pos(RealAoS::x) = cos(omega*slice_ds)*x +
132  sin(omega*slice_ds)/(omega*delta1)*px;
133  pxout = -omega*delta1*sin(omega*slice_ds)*x + cos(omega*slice_ds)*px;
134 
135  p.pos(RealAoS::y) = cos(omega*slice_ds)*y +
136  sin(omega*slice_ds)/(omega*delta1)*py;
137  pyout = -omega*delta1*sin(omega*slice_ds)*y + cos(omega*slice_ds)*py;
138 
139  // advance longitudinal position and momentum
140 
141  // the corresponding symplectic update to t
142  amrex::ParticleReal const term = pt + delta/bet;
143  amrex::ParticleReal const t0 = t - term*slice_ds/delta1;
144 
145  amrex::ParticleReal const w = omega*delta1;
146  amrex::ParticleReal const term1 = -(pow(p2,2)-pow(q2,2)*pow(w,2))*sin(2_prt*slice_ds*omega);
147  amrex::ParticleReal const term2 = -(pow(p1,2)-pow(q1,2)*pow(w,2))*sin(2_prt*slice_ds*omega);
148  amrex::ParticleReal const term3 = -2_prt*q2*p2*w*cos(2_prt*slice_ds*omega);
149  amrex::ParticleReal const term4 = -2_prt*q1*p1*w*cos(2_prt*slice_ds*omega);
150  amrex::ParticleReal const term5 = 2_prt*omega*(q1*p1*delta1 + q2*p2*delta1
151  -(pow(p1,2)+pow(p2,2))*slice_ds - (pow(q1,2)+pow(q2,2))*pow(w,2)*slice_ds);
152  p.pos(RealAoS::t) = t0 + (-1_prt+bet*pt)/(8_prt*bet*pow(delta1,3)*omega)
153  *(term1+term2+term3+term4+term5);
154 
155  // ptout = pt;
156 
157  // assign updated momenta
158  px = pxout;
159  py = pyout;
160  pt = ptout;
161 
162  // undo shift due to alignment errors of the element
163  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
164  }
165 
171  void operator() (RefPart & AMREX_RESTRICT refpart) const
172  {
173  using namespace amrex::literals; // for _rt and _prt
174 
175  // assign input reference particle values
176  amrex::ParticleReal const x = refpart.x;
177  amrex::ParticleReal const px = refpart.px;
178  amrex::ParticleReal const y = refpart.y;
179  amrex::ParticleReal const py = refpart.py;
180  amrex::ParticleReal const z = refpart.z;
181  amrex::ParticleReal const pz = refpart.pz;
182  amrex::ParticleReal const t = refpart.t;
183  amrex::ParticleReal const pt = refpart.pt;
184  amrex::ParticleReal const s = refpart.s;
185 
186  // length of the current slice
187  amrex::ParticleReal const slice_ds = m_ds / nslice();
188 
189  // assign intermediate parameter
190  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
191 
192  // advance position and momentum (straight element)
193  refpart.x = x + step*px;
194  refpart.y = y + step*py;
195  refpart.z = z + step*pz;
196  refpart.t = t - step*pt;
197 
198  // advance integrated path length
199  refpart.s = s + slice_ds;
200  }
201 
202  amrex::ParticleReal m_k;
203  int m_unit;
204  };
205 
206 } // namespace impactx
207 
208 #endif // IMPACTX_CHRPLASMALENS_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
tuple w
Definition: ChrPlasmaLens.H:32
static constexpr auto name
Definition: ChrPlasmaLens.H:33
ImpactXParticleContainer::ParticleType PType
Definition: ChrPlasmaLens.H:34
int m_unit
focusing strength in 1/m^2 (or T/m)
Definition: ChrPlasmaLens.H:203
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: ChrPlasmaLens.H:80
ChrPlasmaLens(amrex::ParticleReal ds, amrex::ParticleReal k, int unit, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, int nslice=1)
Definition: ChrPlasmaLens.H:53
amrex::ParticleReal m_k
Definition: ChrPlasmaLens.H:202
@ 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 rigidity_Tm() const
Definition: ReferenceParticle.H:169
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