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/alignment.H"
15 #include "mixin/beamoptic.H"
16 #include "mixin/thin.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 {
27  struct ShortRF
28  : public elements::BeamOptic<ShortRF>,
29  public elements::Thin,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "ShortRF";
35 
49  amrex::ParticleReal V,
50  amrex::ParticleReal freq,
51  amrex::ParticleReal phase,
52  amrex::ParticleReal dx = 0,
53  amrex::ParticleReal dy = 0,
54  amrex::ParticleReal rotation_degree = 0
55  )
56  : Alignment(dx, dy, rotation_degree),
57  m_V(V), m_freq(freq), m_phase(phase)
58  {
59  }
60 
62  using BeamOptic::operator();
63 
78  amrex::ParticleReal & AMREX_RESTRICT x,
79  amrex::ParticleReal & AMREX_RESTRICT y,
80  amrex::ParticleReal & AMREX_RESTRICT t,
81  amrex::ParticleReal & AMREX_RESTRICT px,
82  amrex::ParticleReal & AMREX_RESTRICT py,
83  amrex::ParticleReal & AMREX_RESTRICT pt,
84  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
85  RefPart const & refpart
86  ) const
87  {
88 
89  using namespace amrex::literals; // for _rt and _prt
90 
91  // shift due to alignment errors of the element
92  shift_in(x, y, px, py);
93 
94  // Define parameters and intermediate constants
97  amrex::ParticleReal const k = (2.0_prt*pi/c)*m_freq;
98  amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
99 
100  // access reference particle values (final, initial):
101  amrex::ParticleReal const ptf_ref = refpart.pt;
102  amrex::ParticleReal const pti_ref = ptf_ref + m_V*cos(phi);
103  amrex::ParticleReal const bgf = sqrt(pow(ptf_ref, 2) - 1.0_prt);
104  amrex::ParticleReal const bgi = sqrt(pow(pti_ref, 2) - 1.0_prt);
105 
106  // initial conversion from static to dynamic units:
107  px = px*bgi;
108  py = py*bgi;
109  pt = pt*bgi;
110 
111  // intialize output values
112  amrex::ParticleReal xout = x;
113  amrex::ParticleReal yout = y;
114  amrex::ParticleReal tout = t;
115  amrex::ParticleReal pxout = px;
116  amrex::ParticleReal pyout = py;
117  amrex::ParticleReal ptout = pt;
118 
119  // advance position and momentum in dynamic units
120  // xout = x;
121  pxout = px;
122 
123  // yout = y;
124  pyout = py;
125 
126  // tout = t;
127  ptout = pt - m_V*cos(k*t + phi) + m_V*cos(phi);
128 
129  // assign updated values
130  x = xout;
131  y = yout;
132  t = tout;
133  px = pxout;
134  py = pyout;
135  pt = ptout;
136 
137  // final conversion from dynamic to static units:
138  px = px/bgf;
139  py = py/bgf;
140  pt = pt/bgf;
141 
142  // undo shift due to alignment errors of the element
143  shift_out(x, y, px, py);
144  }
145 
147  using Thin::operator();
148 
154  void operator() (RefPart & AMREX_RESTRICT refpart) const
155  {
156  using namespace amrex::literals; // for _rt and _prt
157 
158  // assign input reference particle values
159  amrex::ParticleReal const x = refpart.x;
160  amrex::ParticleReal const px = refpart.px;
161  amrex::ParticleReal const y = refpart.y;
162  amrex::ParticleReal const py = refpart.py;
163  amrex::ParticleReal const z = refpart.z;
164  amrex::ParticleReal const pz = refpart.pz;
165  amrex::ParticleReal const t = refpart.t;
166  amrex::ParticleReal const pt = refpart.pt;
167 
168  // Define parameters and intermediate constants
170  amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
171 
172  // compute intial value of beta*gamma
173  amrex::ParticleReal const bgi = sqrt(pow(pt, 2) - 1.0_prt);
174 
175  // advance pt
176  refpart.pt = pt - m_V*cos(phi);
177 
178  // compute final value of beta*gamma
179  amrex::ParticleReal const ptf = refpart.pt;
180  amrex::ParticleReal const bgf = sqrt(pow(ptf, 2) - 1.0_prt);
181 
182  // advance position (x,y,z,t)
183  refpart.x = x;
184  refpart.y = y;
185  refpart.z = z;
186  refpart.t = t;
187 
188  // advance momentum (px,py,pz)
189  refpart.px = px*bgf/bgi;
190  refpart.py = py*bgf/bgi;
191  refpart.pz = pz*bgf/bgi;
192 
193  }
194 
195  amrex::ParticleReal m_V;
196  amrex::ParticleReal m_freq;
197  amrex::ParticleReal m_phase;
198  };
199 
200 } // namespace impactx
201 
202 #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
@ t
fixed t as the independent variable
c
Definition: ReferenceParticle.H:30
amrex::ParticleReal pt
energy, normalized by rest energy
Definition: ReferenceParticle.H:39
Definition: ShortRF.H:32
amrex::ParticleReal m_V
Definition: ShortRF.H:195
static constexpr auto name
Definition: ShortRF.H:33
amrex::ParticleReal m_phase
RF frequency in Hz.
Definition: ShortRF.H:197
ImpactXParticleContainer::ParticleType PType
Definition: ShortRF.H:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT t, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py, amrex::ParticleReal &AMREX_RESTRICT pt, [[maybe_unused]] uint64_t &AMREX_RESTRICT idcpu, RefPart const &refpart) const
Definition: ShortRF.H:77
amrex::ParticleReal m_freq
normalized (max) RF voltage drop.
Definition: ShortRF.H:196
ShortRF(amrex::ParticleReal V, amrex::ParticleReal freq, amrex::ParticleReal phase, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0)
Definition: ShortRF.H:48
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:149
Definition: nofinalize.H:22
Definition: thin.H:24