ImpactX
ShortRF.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_SHORTRF_H
11 #define IMPACTX_SHORTRF_H
12 
14 #include "mixin/beamoptic.H"
15 #include "mixin/thin.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 ShortRF
27  : public elements::BeamOptic<ShortRF>,
28  public elements::Thin,
30  {
31  static constexpr auto name = "ShortRF";
33 
43  ShortRF( amrex::ParticleReal const V, amrex::ParticleReal const freq,
44  amrex::ParticleReal const phase )
45  : m_V(V), m_freq(freq), m_phase(phase)
46  {
47  }
48 
50  using BeamOptic::operator();
51 
63  PType& AMREX_RESTRICT p,
64  amrex::ParticleReal & AMREX_RESTRICT px,
65  amrex::ParticleReal & AMREX_RESTRICT py,
66  amrex::ParticleReal & AMREX_RESTRICT pt,
67  RefPart const & refpart) const {
68 
69  using namespace amrex::literals; // for _rt and _prt
70 
71  // access AoS data such as positions and cpu/id
72  amrex::ParticleReal const x = p.pos(RealAoS::x);
73  amrex::ParticleReal const y = p.pos(RealAoS::y);
74  amrex::ParticleReal const t = p.pos(RealAoS::t);
75 
76  // Define parameters and intermediate constants
79  amrex::ParticleReal const k = (2.0_prt*pi/c)*m_freq;
80  amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
81 
82  // access reference particle values (final, initial):
83  amrex::ParticleReal const ptf_ref = refpart.pt;
84  amrex::ParticleReal const pti_ref = ptf_ref + m_V*cos(phi);
85  amrex::ParticleReal const bgf = sqrt(pow(ptf_ref, 2) - 1.0_prt);
86  amrex::ParticleReal const bgi = sqrt(pow(pti_ref, 2) - 1.0_prt);
87 
88  // initial conversion from static to dynamic units:
89  px = px*bgi;
90  py = py*bgi;
91  pt = pt*bgi;
92 
93  // intialize output values of momenta
94  amrex::ParticleReal pxout = px;
95  amrex::ParticleReal pyout = py;
96  amrex::ParticleReal ptout = pt;
97 
98  // advance position and momentum in dynamic units
99  p.pos(RealAoS::x) = x;
100  pxout = px;
101 
102  p.pos(RealAoS::y) = y;
103  pyout = py;
104 
105  p.pos(RealAoS::t) = t;
106  ptout = pt - m_V*cos(k*t + phi) + m_V*cos(phi);
107 
108  // assign updated momenta
109  px = pxout;
110  py = pyout;
111  pt = ptout;
112 
113  // final conversion from dynamic to static units:
114  px = px/bgf;
115  py = py/bgf;
116  pt = pt/bgf;
117 
118  }
119 
121  using Thin::operator();
122 
128  void operator() (RefPart & AMREX_RESTRICT refpart) const {
129 
130  using namespace amrex::literals; // for _rt and _prt
131 
132  // assign input reference particle values
133  amrex::ParticleReal const x = refpart.x;
134  amrex::ParticleReal const px = refpart.px;
135  amrex::ParticleReal const y = refpart.y;
136  amrex::ParticleReal const py = refpart.py;
137  amrex::ParticleReal const z = refpart.z;
138  amrex::ParticleReal const pz = refpart.pz;
139  amrex::ParticleReal const t = refpart.t;
140  amrex::ParticleReal const pt = refpart.pt;
141 
142  // Define parameters and intermediate constants
144  amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
145 
146  // compute intial value of beta*gamma
147  amrex::ParticleReal const bgi = sqrt(pow(pt, 2) - 1.0_prt);
148 
149  // advance pt
150  refpart.pt = pt - m_V*cos(phi);
151 
152  // compute final value of beta*gamma
153  amrex::ParticleReal const ptf = refpart.pt;
154  amrex::ParticleReal const bgf = sqrt(pow(ptf, 2) - 1.0_prt);
155 
156  // advance position (x,y,z,t)
157  refpart.x = x;
158  refpart.y = y;
159  refpart.z = z;
160  refpart.t = t;
161 
162  // advance momentum (px,py,pz)
163  refpart.px = px*bgf/bgi;
164  refpart.py = py*bgf/bgi;
165  refpart.pz = pz*bgf/bgi;
166 
167  }
168 
169 
170  private:
171  amrex::ParticleReal m_V;
172  amrex::ParticleReal m_freq;
173  amrex::ParticleReal m_phase;
174  };
175 
176 } // namespace impactx
177 
178 #endif // IMPACTX_SHORTRF_H
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
static constexpr auto c
static constexpr amrex::Real pi
constexpr std::enable_if_t< std::is_floating_point< T >::value, T > pi()
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
c
@ 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, normalized by rest energy
Definition: ReferenceParticle.H:39
Definition: ShortRF.H:30
amrex::ParticleReal m_V
Definition: ShortRF.H:171
ShortRF(amrex::ParticleReal const V, amrex::ParticleReal const freq, amrex::ParticleReal const phase)
Definition: ShortRF.H:43
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: ShortRF.H:62
static constexpr auto name
Definition: ShortRF.H:31
amrex::ParticleReal m_phase
RF frequency in Hz.
Definition: ShortRF.H:173
ImpactXParticleContainer::ParticleType PType
Definition: ShortRF.H:32
amrex::ParticleReal m_freq
normalized (max) RF voltage drop.
Definition: ShortRF.H:172
Definition: beamoptic.H:135
Definition: nofinalize.H:22
Definition: thin.H:24