ImpactX
Quad.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_QUAD_H
11 #define IMPACTX_QUAD_H
12 
14 #include "mixin/beamoptic.H"
15 #include "mixin/beamoptic.H"
16 
17 #include <AMReX_Extension.H>
18 #include <AMReX_REAL.H>
19 
20 #include <cmath>
21 
22 
23 namespace impactx
24 {
25  struct Quad
26  : public elements::BeamOptic<Quad>,
27  public elements::Thick
28  {
29  static constexpr auto name = "Quad";
31 
41  Quad( amrex::ParticleReal const ds, amrex::ParticleReal const k,
42  int const nslice )
43  : Thick(ds, nslice), m_k(k)
44  {
45  }
46 
48  using BeamOptic::operator();
49 
60  PType& AMREX_RESTRICT p,
61  amrex::ParticleReal & AMREX_RESTRICT px,
62  amrex::ParticleReal & AMREX_RESTRICT py,
63  amrex::ParticleReal & AMREX_RESTRICT pt,
64  RefPart const & refpart) const {
65 
66  using namespace amrex::literals; // for _rt and _prt
67 
68  // access AoS data such as positions and cpu/id
69  amrex::ParticleReal const x = p.pos(0);
70  amrex::ParticleReal const y = p.pos(1);
71  amrex::ParticleReal const t = p.pos(2);
72 
73  // length of the current slice
74  amrex::ParticleReal const slice_ds = m_ds / nslice();
75 
76  // access reference particle values to find beta*gamma^2
77  amrex::ParticleReal const pt_ref = refpart.pt;
78  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
79 
80  // compute phase advance per unit length in s (in rad/m)
81  amrex::ParticleReal const omega = sqrt(std::abs(m_k));
82 
83  // intialize output values of momenta
84  amrex::ParticleReal pxout = px;
85  amrex::ParticleReal pyout = py;
86  amrex::ParticleReal ptout = pt;
87 
88  if(m_k > 0.0) {
89  // advance position and momentum (focusing quad)
90  p.pos(0) = cos(omega*slice_ds)*x + sin(omega*slice_ds)/omega*px;
91  pxout = -omega*sin(omega*slice_ds)*x + cos(omega*slice_ds)*px;
92 
93  p.pos(1) = cosh(omega*slice_ds)*y + sinh(omega*slice_ds)/omega*py;
94  pyout = omega*sinh(omega*slice_ds)*y + cosh(omega*slice_ds)*py;
95 
96  p.pos(2) = t + (slice_ds/betgam2)*pt;
97  // ptout = pt;
98  } else {
99  // advance position and momentum (defocusing quad)
100  p.pos(0) = cosh(omega*slice_ds)*x + sinh(omega*slice_ds)/omega*px;
101  pxout = omega*sinh(omega*slice_ds)*x + cosh(omega*slice_ds)*px;
102 
103  p.pos(1) = cos(omega*slice_ds)*y + sin(omega*slice_ds)/omega*py;
104  pyout = -omega*sin(omega*slice_ds)*y + cos(omega*slice_ds)*py;
105 
106  p.pos(2) = t + (slice_ds/betgam2)*pt;
107  // ptout = pt;
108  }
109 
110  // assign updated momenta
111  px = pxout;
112  py = pyout;
113  pt = ptout;
114 
115  }
116 
122  void operator() (RefPart & AMREX_RESTRICT refpart) const {
123 
124  using namespace amrex::literals; // for _rt and _prt
125 
126  // assign input reference particle values
127  amrex::ParticleReal const x = refpart.x;
128  amrex::ParticleReal const px = refpart.px;
129  amrex::ParticleReal const y = refpart.y;
130  amrex::ParticleReal const py = refpart.py;
131  amrex::ParticleReal const z = refpart.z;
132  amrex::ParticleReal const pz = refpart.pz;
133  amrex::ParticleReal const t = refpart.t;
134  amrex::ParticleReal const pt = refpart.pt;
135  amrex::ParticleReal const s = refpart.s;
136 
137  // length of the current slice
138  amrex::ParticleReal const slice_ds = m_ds / nslice();
139 
140  // assign intermediate parameter
141  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
142 
143  // advance position and momentum (straight element)
144  refpart.x = x + step*px;
145  refpart.y = y + step*py;
146  refpart.z = z + step*pz;
147  refpart.t = t - step*pt;
148 
149  // advance integrated path length
150  refpart.s = s + slice_ds;
151  }
152 
153  private:
154  amrex::ParticleReal m_k;
155  };
156 
157 } // namespace impactx
158 
159 #endif // IMPACTX_QUAD_H
Definition: Quad.H:25
Definition: ImpactX.cpp:31
Quad(amrex::ParticleReal const ds, amrex::ParticleReal const k, int const nslice)
Definition: Quad.H:41
amrex::ParticleReal m_k
Definition: Quad.H:154
Definition: beamoptic.H:134
static constexpr auto name
Definition: Quad.H:29
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:59
#define AMREX_GPU_HOST_DEVICE
Definition: thick.H:23
Thick(amrex::ParticleReal const ds, int const nslice)
Definition: thick.H:30
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 amrex::ParticleReal ds() const
Definition: thick.H:50
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: thick.H:40
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
amrex::ParticleReal m_ds
Definition: thick.H:56