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 
75  PType& AMREX_RESTRICT p,
76  amrex::ParticleReal & AMREX_RESTRICT px,
77  amrex::ParticleReal & AMREX_RESTRICT py,
78  amrex::ParticleReal & AMREX_RESTRICT pt,
79  RefPart const & refpart) const {
80 
81  using namespace amrex::literals; // for _rt and _prt
82 
83  // shift due to alignment errors of the element
84  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
85 
86  // access AoS data such as positions and cpu/id
87  amrex::ParticleReal const x = p.pos(RealAoS::x);
88  amrex::ParticleReal const y = p.pos(RealAoS::y);
89  amrex::ParticleReal const t = p.pos(RealAoS::t);
90 
91  // Define parameters and intermediate constants
94  amrex::ParticleReal const k = (2.0_prt*pi/c)*m_freq;
95  amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
96 
97  // access reference particle values (final, initial):
98  amrex::ParticleReal const ptf_ref = refpart.pt;
99  amrex::ParticleReal const pti_ref = ptf_ref + m_V*cos(phi);
100  amrex::ParticleReal const bgf = sqrt(pow(ptf_ref, 2) - 1.0_prt);
101  amrex::ParticleReal const bgi = sqrt(pow(pti_ref, 2) - 1.0_prt);
102 
103  // initial conversion from static to dynamic units:
104  px = px*bgi;
105  py = py*bgi;
106  pt = pt*bgi;
107 
108  // intialize output values of momenta
109  amrex::ParticleReal pxout = px;
110  amrex::ParticleReal pyout = py;
111  amrex::ParticleReal ptout = pt;
112 
113  // advance position and momentum in dynamic units
114  p.pos(RealAoS::x) = x;
115  pxout = px;
116 
117  p.pos(RealAoS::y) = y;
118  pyout = py;
119 
120  p.pos(RealAoS::t) = t;
121  ptout = pt - m_V*cos(k*t + phi) + m_V*cos(phi);
122 
123  // assign updated momenta
124  px = pxout;
125  py = pyout;
126  pt = ptout;
127 
128  // final conversion from dynamic to static units:
129  px = px/bgf;
130  py = py/bgf;
131  pt = pt/bgf;
132 
133  // undo shift due to alignment errors of the element
134  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
135  }
136 
138  using Thin::operator();
139 
145  void operator() (RefPart & AMREX_RESTRICT refpart) const {
146 
147  using namespace amrex::literals; // for _rt and _prt
148 
149  // assign input reference particle values
150  amrex::ParticleReal const x = refpart.x;
151  amrex::ParticleReal const px = refpart.px;
152  amrex::ParticleReal const y = refpart.y;
153  amrex::ParticleReal const py = refpart.py;
154  amrex::ParticleReal const z = refpart.z;
155  amrex::ParticleReal const pz = refpart.pz;
156  amrex::ParticleReal const t = refpart.t;
157  amrex::ParticleReal const pt = refpart.pt;
158 
159  // Define parameters and intermediate constants
161  amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
162 
163  // compute intial value of beta*gamma
164  amrex::ParticleReal const bgi = sqrt(pow(pt, 2) - 1.0_prt);
165 
166  // advance pt
167  refpart.pt = pt - m_V*cos(phi);
168 
169  // compute final value of beta*gamma
170  amrex::ParticleReal const ptf = refpart.pt;
171  amrex::ParticleReal const bgf = sqrt(pow(ptf, 2) - 1.0_prt);
172 
173  // advance position (x,y,z,t)
174  refpart.x = x;
175  refpart.y = y;
176  refpart.z = z;
177  refpart.t = t;
178 
179  // advance momentum (px,py,pz)
180  refpart.px = px*bgf/bgi;
181  refpart.py = py*bgf/bgi;
182  refpart.pz = pz*bgf/bgi;
183 
184  }
185 
186 
187  private:
188  amrex::ParticleReal m_V;
189  amrex::ParticleReal m_freq;
190  amrex::ParticleReal m_phase;
191  };
192 
193 } // namespace impactx
194 
195 #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:36
@ t
fixed t as the independent variable
c
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:48
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:49
@ t
c * time-of-flight [m] (at fixed s)
Definition: ImpactXParticleContainer.H:50
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:188
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:74
static constexpr auto name
Definition: ShortRF.H:33
amrex::ParticleReal m_phase
RF frequency in Hz.
Definition: ShortRF.H:190
ImpactXParticleContainer::ParticleType PType
Definition: ShortRF.H:34
amrex::ParticleReal m_freq
normalized (max) RF voltage drop.
Definition: ShortRF.H:189
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:135
Definition: nofinalize.H:22
Definition: thin.H:24