ImpactX
Loading...
Searching...
No Matches
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/named.H"
18#include "mixin/nofinalize.H"
20
21#include <AMReX_Extension.H>
22#include <AMReX_Math.H>
23#include <AMReX_REAL.H>
24#include <AMReX_SIMD.H>
25
26#include <cmath>
27
28
29namespace impactx::elements
30{
31 struct ShortRF
32 : public mixin::Named,
33 public mixin::BeamOptic<ShortRF>,
34 public mixin::LinearTransport<ShortRF>,
35 public mixin::Thin,
36 public mixin::Alignment,
37 public mixin::NoFinalize,
38 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
39 {
40 static constexpr auto type = "ShortRF";
42
57 amrex::ParticleReal V,
58 amrex::ParticleReal freq,
59 amrex::ParticleReal phase,
60 amrex::ParticleReal dx = 0,
61 amrex::ParticleReal dy = 0,
62 amrex::ParticleReal rotation_degree = 0,
63 std::optional<std::string> name = std::nullopt
64 )
65 : Named(std::move(name)),
66 Alignment(dx, dy, rotation_degree),
67 m_V(V), m_freq(freq), m_phase(phase)
68 {
69 }
70
72 using BeamOptic::operator();
73
81 void compute_constants (RefPart const & refpart)
82 {
83 using namespace amrex::literals; // for _rt and _prt
85
86 Alignment::compute_constants(refpart);
87
88 // Define parameters and intermediate constants
91 m_k = 2.0_prt * pi / c * m_freq;
92 m_phi = m_phase * pi / 180.0_prt;
93
94 // access reference particle values (final, initial):
95 amrex::ParticleReal const ptf_ref = refpart.pt;
96 m_V_cos_phi = m_V * std::cos(m_phi);
97 amrex::ParticleReal const pti_ref = ptf_ref + m_V_cos_phi;
98 m_bgf = std::sqrt(powi<2>(ptf_ref) - 1.0_prt);
99 m_bgi = std::sqrt(powi<2>(pti_ref) - 1.0_prt);
100 }
101
116 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
119 T_Real & AMREX_RESTRICT x,
120 T_Real & AMREX_RESTRICT y,
121 T_Real & AMREX_RESTRICT t,
122 T_Real & AMREX_RESTRICT px,
123 T_Real & AMREX_RESTRICT py,
124 T_Real & AMREX_RESTRICT pt,
125 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
126 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
127 ) const
128 {
129
130 using namespace amrex::literals; // for _rt and _prt
131 using namespace std; // for cmath(float)
132
133 // shift due to alignment errors of the element
134 shift_in(x, y, px, py);
135
136 // initial conversion from static to dynamic units:
137 px = px * m_bgi;
138 py = py * m_bgi;
139 pt = pt * m_bgi;
140
141 // initialize output values
142 T_Real xout = x;
143 T_Real yout = y;
144 T_Real tout = t;
145 T_Real pxout = px;
146 T_Real pyout = py;
147 T_Real ptout = pt;
148
149 // advance position and momentum in dynamic units
150 // xout = x;
151 pxout = px;
152
153 // yout = y;
154 pyout = py;
155
156 // tout = t;
157 ptout = pt - m_V * cos(m_k * t + m_phi) + m_V_cos_phi;
158
159 // assign updated values
160 x = xout;
161 y = yout;
162 t = tout;
163 px = pxout;
164 py = pyout;
165 pt = ptout;
166
167 // final conversion from dynamic to static units:
168 px = px / m_bgf;
169 py = py / m_bgf;
170 pt = pt / m_bgf;
171
172 // undo shift due to alignment errors of the element
173 shift_out(x, y, px, py);
174 }
175
177 using Thin::operator();
178
184 void operator() (RefPart & AMREX_RESTRICT refpart) const
185 {
186 using namespace amrex::literals; // for _rt and _prt
187 using amrex::Math::powi;
188
189 // assign input reference particle values
190 amrex::ParticleReal const x = refpart.x;
191 amrex::ParticleReal const px = refpart.px;
192 amrex::ParticleReal const y = refpart.y;
193 amrex::ParticleReal const py = refpart.py;
194 amrex::ParticleReal const z = refpart.z;
195 amrex::ParticleReal const pz = refpart.pz;
196 amrex::ParticleReal const t = refpart.t;
197 amrex::ParticleReal const pt = refpart.pt;
198
199 // Define parameters and intermediate constants
201 amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
202
203 // compute initial value of beta*gamma
204 amrex::ParticleReal const bgi = std::sqrt(powi<2>(pt) - 1.0_prt);
205
206 // advance pt
207 refpart.pt = pt - m_V * std::cos(phi);
208
209 // compute final value of beta*gamma
210 amrex::ParticleReal const ptf = refpart.pt;
211 amrex::ParticleReal const bgf = std::sqrt(powi<2>(ptf) - 1.0_prt);
212
213 // advance position (x,y,z,t)
214 refpart.x = x;
215 refpart.y = y;
216 refpart.z = z;
217 refpart.t = t;
218
219 // advance momentum (px,py,pz)
220 refpart.px = px*bgf/bgi;
221 refpart.py = py*bgf/bgi;
222 refpart.pz = pz*bgf/bgi;
223
224 }
225
227 using LinearTransport::operator();
228
235 Map6x6
236 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
237 {
238 using namespace amrex::literals; // for _rt and _prt
239 using amrex::Math::powi;
240
241 // Define parameters and intermediate constants
244 amrex::ParticleReal const k = (2.0_prt*pi/c)*m_freq;
245 amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
246
247 // access reference particle values (final, initial):
248 amrex::ParticleReal const ptf_ref = refpart.pt;
249 amrex::ParticleReal const pti_ref = ptf_ref + m_V * std::cos(phi);
250 amrex::ParticleReal const bgf = std::sqrt(powi<2>(ptf_ref) - 1.0_prt);
251 amrex::ParticleReal const bgi = std::sqrt(powi<2>(pti_ref) - 1.0_prt);
252
253 // initialize transport matrix
255
256 // This is a nonlinear element: the linearized map is returned here.
257 // assign linear map matrix elements
258 R(2,2) = bgi/bgf;
259 R(4,4) = bgi/bgf;
260 R(6,5) = k*m_V*std::sin(phi)/bgf;
261 R(6,6) = bgi/bgf;
262
263 return R;
264 }
265
266 amrex::ParticleReal m_V;
267 amrex::ParticleReal m_freq;
268 amrex::ParticleReal m_phase;
269
270 private:
271 // constants that are independent of the individually tracked particle,
272 // see: compute_constants() to refresh
273 amrex::ParticleReal m_k, m_phi, m_V_cos_phi, m_bgi, m_bgf;
274 };
275
276} // namespace impactx
277
278#endif // IMPACTX_SHORTRF_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
static constexpr auto c
static constexpr amrex::Real pi
constexpr T powi(T x) noexcept
Definition All.H:54
@ t
fixed t as the independent variable
Definition ImpactXParticleContainer.H:38
amrex::SmallMatrix< amrex::ParticleReal, 6, 6, amrex::Order::F, 1 > Map6x6
Definition CovarianceMatrix.H:20
static constexpr __host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > Identity() noexcept
Definition ReferenceParticle.H:31
amrex::ParticleReal pt
energy, normalized by rest energy
Definition ReferenceParticle.H:40
void compute_constants(RefPart const &refpart)
Definition ShortRF.H:81
amrex::ParticleReal m_V_cos_phi
Definition ShortRF.H:273
amrex::ParticleReal m_V
Definition ShortRF.H:266
static constexpr auto type
Definition ShortRF.H:40
ImpactXParticleContainer::ParticleType PType
Definition ShortRF.H:41
amrex::ParticleReal m_freq
normalized (max) RF voltage drop.
Definition ShortRF.H:267
ShortRF(amrex::ParticleReal V, amrex::ParticleReal freq, amrex::ParticleReal phase, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition ShortRF.H:56
amrex::ParticleReal m_phase
RF frequency in Hz.
Definition ShortRF.H:268
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ShortRF.H:236
amrex::ParticleReal m_bgf
Definition ShortRF.H:273
amrex::ParticleReal m_phi
Definition ShortRF.H:273
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT t, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py, T_Real &AMREX_RESTRICT pt, T_IdCpu &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition ShortRF.H:118
amrex::ParticleReal m_k
reference RF phase in degrees.
Definition ShortRF.H:273
amrex::ParticleReal m_bgi
Definition ShortRF.H:273
Definition alignment.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_out(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py) const
Definition alignment.H:109
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:146
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:136
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_in(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py) const
Definition alignment.H:78
Definition beamoptic.H:219
Definition lineartransport.H:29
Definition named.H:29
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:57
AMREX_FORCE_INLINE std::string name() const
Definition named.H:122
Definition nofinalize.H:22
Definition thin.H:24