ImpactX
Quad.H
Go to the documentation of this file.
1 /* Copyright 2022 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_QUAD_H
11 #define IMPACTX_QUAD_H
12 
14 
15 #include <AMReX_Extension.H>
16 #include <AMReX_REAL.H>
17 
18 #include <cmath>
19 
20 
21 namespace impactx
22 {
23  struct Quad
24  {
25  static constexpr auto name = "Quad";
27 
37  Quad( amrex::ParticleReal const ds, amrex::ParticleReal const k,
38  int const nslice )
39  : m_ds(ds), m_k(k), m_nslice(nslice)
40  {
41  }
42 
53  PType& AMREX_RESTRICT p,
54  amrex::ParticleReal & AMREX_RESTRICT px,
55  amrex::ParticleReal & AMREX_RESTRICT py,
56  amrex::ParticleReal & AMREX_RESTRICT pt,
57  RefPart const & refpart) const {
58 
59  using namespace amrex::literals; // for _rt and _prt
60 
61  // access AoS data such as positions and cpu/id
62  amrex::ParticleReal const x = p.pos(0);
63  amrex::ParticleReal const y = p.pos(1);
64  amrex::ParticleReal const t = p.pos(2);
65 
66  // length of the current slice
67  amrex::ParticleReal const slice_ds = m_ds / nslice();
68 
69  // access reference particle values to find beta*gamma^2
70  amrex::ParticleReal const pt_ref = refpart.pt;
71  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
72 
73  // compute phase advance per unit length in s (in rad/m)
74  amrex::ParticleReal const omega = sqrt(std::abs(m_k));
75 
76  // intialize output values of momenta
77  amrex::ParticleReal pxout = px;
78  amrex::ParticleReal pyout = py;
79  amrex::ParticleReal ptout = pt;
80 
81  if(m_k > 0.0) {
82  // advance position and momentum (focusing quad)
83  p.pos(0) = cos(omega*slice_ds)*x + sin(omega*slice_ds)/omega*px;
84  pxout = -omega*sin(omega*slice_ds)*x + cos(omega*slice_ds)*px;
85 
86  p.pos(1) = cosh(omega*slice_ds)*y + sinh(omega*slice_ds)/omega*py;
87  pyout = omega*sinh(omega*slice_ds)*y + cosh(omega*slice_ds)*py;
88 
89  p.pos(2) = t + (slice_ds/betgam2)*pt;
90  // ptout = pt;
91  } else {
92  // advance position and momentum (defocusing quad)
93  p.pos(0) = cosh(omega*slice_ds)*x + sinh(omega*slice_ds)/omega*px;
94  pxout = omega*sinh(omega*slice_ds)*x + cosh(omega*slice_ds)*px;
95 
96  p.pos(1) = cos(omega*slice_ds)*y + sin(omega*slice_ds)/omega*py;
97  pyout = -omega*sin(omega*slice_ds)*y + cos(omega*slice_ds)*py;
98 
99  p.pos(2) = t + (slice_ds/betgam2)*pt;
100  // ptout = pt;
101  }
102 
103  // assign updated momenta
104  px = pxout;
105  py = pyout;
106  pt = ptout;
107 
108  }
109 
115  void operator() (RefPart & AMREX_RESTRICT refpart) const {
116 
117  using namespace amrex::literals; // for _rt and _prt
118 
119  // assign input reference particle values
120  amrex::ParticleReal const x = refpart.x;
121  amrex::ParticleReal const px = refpart.px;
122  amrex::ParticleReal const y = refpart.y;
123  amrex::ParticleReal const py = refpart.py;
124  amrex::ParticleReal const z = refpart.z;
125  amrex::ParticleReal const pz = refpart.pz;
126  amrex::ParticleReal const t = refpart.t;
127  amrex::ParticleReal const pt = refpart.pt;
128  amrex::ParticleReal const s = refpart.s;
129 
130  // length of the current slice
131  amrex::ParticleReal const slice_ds = m_ds / nslice();
132 
133  // assign intermediate parameter
134  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
135 
136  // advance position and momentum (straight element)
137  refpart.x = x + step*px;
138  refpart.y = y + step*py;
139  refpart.z = z + step*pz;
140  refpart.t = t - step*pt;
141 
142  // advance integrated path length
143  refpart.s = s + slice_ds;
144  }
145 
151  int nslice () const
152  {
153  return m_nslice;
154  }
155 
161  amrex::ParticleReal ds () const
162  {
163  return m_ds;
164  }
165 
166  private:
167  amrex::ParticleReal m_ds;
168  amrex::ParticleReal m_k;
169  int m_nslice;
170  };
171 
172 } // namespace impactx
173 
174 #endif // IMPACTX_QUAD_H
Definition: Quad.H:23
Definition: ImpactX.cpp:31
Quad(amrex::ParticleReal const ds, amrex::ParticleReal const k, int const nslice)
Definition: Quad.H:37
amrex::ParticleReal m_k
segment length in m
Definition: Quad.H:168
static constexpr auto name
Definition: Quad.H:25
amrex::ParticleReal pt
energy deviation, normalized by rest energy
Definition: ReferenceParticle.H:39
#define AMREX_FORCE_INLINE
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: Quad.H:52
#define AMREX_GPU_HOST_DEVICE
int m_nslice
quadrupole strength in 1/m
Definition: Quad.H:169
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: Quad.H:161
amrex::ParticleReal m_ds
Definition: Quad.H:167
Definition: ReferenceParticle.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
s
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: Quad.H:151
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept