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
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 void reverse () { m_V = -m_V; }
73
75 using BeamOptic::operator();
76
84 void compute_constants (RefPart const & refpart)
85 {
86 using namespace amrex::literals; // for _rt and _prt
88
89 Alignment::compute_constants(refpart);
90
91 // Define parameters and intermediate constants
94 m_k = 2.0_prt * pi / c * m_freq;
95 m_phi = m_phase * pi / 180.0_prt;
96
97 // access reference particle values (final, initial):
98 amrex::ParticleReal const ptf_ref = refpart.pt;
99 m_V_cos_phi = m_V * std::cos(m_phi);
100 amrex::ParticleReal const pti_ref = ptf_ref + m_V_cos_phi;
101 m_bgf = std::sqrt(powi<2>(ptf_ref) - 1.0_prt);
102 m_bgi = std::sqrt(powi<2>(pti_ref) - 1.0_prt);
103 }
104
119 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
122 [[maybe_unused]] T_Real const & AMREX_RESTRICT x,
123 [[maybe_unused]] T_Real const & AMREX_RESTRICT y,
124 T_Real const & AMREX_RESTRICT t,
125 T_Real & AMREX_RESTRICT px,
126 T_Real & AMREX_RESTRICT py,
127 T_Real & AMREX_RESTRICT pt,
128 [[maybe_unused]] T_IdCpu const & AMREX_RESTRICT idcpu,
129 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
130 ) const
131 {
132
133 using namespace amrex::literals; // for _rt and _prt
134 using namespace std; // for cmath(float)
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
174 using Thin::operator();
175
181 void operator() (RefPart & AMREX_RESTRICT refpart) const
182 {
183 using namespace amrex::literals; // for _rt and _prt
184 using amrex::Math::powi;
185
186 // assign input reference particle values
187 amrex::ParticleReal const x = refpart.x;
188 amrex::ParticleReal const px = refpart.px;
189 amrex::ParticleReal const y = refpart.y;
190 amrex::ParticleReal const py = refpart.py;
191 amrex::ParticleReal const z = refpart.z;
192 amrex::ParticleReal const pz = refpart.pz;
193 amrex::ParticleReal const t = refpart.t;
194 amrex::ParticleReal const pt = refpart.pt;
195
196 // Define parameters and intermediate constants
198 amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
199
200 // compute initial value of beta*gamma
201 amrex::ParticleReal const bgi = std::sqrt(powi<2>(pt) - 1.0_prt);
202
203 // advance pt
204 refpart.pt = pt - m_V * std::cos(phi);
205
206 // compute final value of beta*gamma
207 amrex::ParticleReal const ptf = refpart.pt;
208 amrex::ParticleReal const bgf = std::sqrt(powi<2>(ptf) - 1.0_prt);
209
210 // advance position (x,y,z,t)
211 refpart.x = x;
212 refpart.y = y;
213 refpart.z = z;
214 refpart.t = t;
215
216 // advance momentum (px,py,pz)
217 refpart.px = px*bgf/bgi;
218 refpart.py = py*bgf/bgi;
219 refpart.pz = pz*bgf/bgi;
220
221 }
222
224 using LinearTransport::operator();
225
232 Map6x6
233 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
234 {
235 using namespace amrex::literals; // for _rt and _prt
236 using amrex::Math::powi;
237
238 // Define parameters and intermediate constants
241 amrex::ParticleReal const k = (2.0_prt*pi/c)*m_freq;
242 amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
243
244 // access reference particle values (final, initial):
245 amrex::ParticleReal const ptf_ref = refpart.pt;
246 amrex::ParticleReal const pti_ref = ptf_ref + m_V * std::cos(phi);
247 amrex::ParticleReal const bgf = std::sqrt(powi<2>(ptf_ref) - 1.0_prt);
248 amrex::ParticleReal const bgi = std::sqrt(powi<2>(pti_ref) - 1.0_prt);
249
250 // initialize transport matrix
252
253 // This is a nonlinear element: the linearized map is returned here.
254 // assign linear map matrix elements
255 R(2,2) = bgi/bgf;
256 R(4,4) = bgi/bgf;
257 R(6,5) = k*m_V*std::sin(phi)/bgf;
258 R(6,6) = bgi/bgf;
259
260 // apply the transverse rotation (roll) alignment error
261 return rotate_aligned_map(R);
262 }
263
267
268 private:
269 // constants that are independent of the individually tracked particle,
270 // see: compute_constants() to refresh
272 };
273
274} // namespace impactx
275
277
278#endif // IMPACTX_SHORTRF_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
#define IMPACTX_PUSH_EXTERN_TEMPLATE(ElementType)
Definition PushAll.H:78
amrex_particle_real ParticleReal
constexpr auto c
constexpr T powi(T x) noexcept
Definition All.H:56
@ 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:33
amrex::ParticleReal pt
energy, normalized by rest energy
Definition ReferenceParticle.H:42
Definition ShortRF.H:39
void compute_constants(RefPart const &refpart)
Definition ShortRF.H:84
amrex::ParticleReal m_V_cos_phi
Definition ShortRF.H:271
amrex::ParticleReal m_V
Definition ShortRF.H:264
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:265
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_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T_Real const &AMREX_RESTRICT x, T_Real const &AMREX_RESTRICT y, T_Real const &AMREX_RESTRICT t, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py, T_Real &AMREX_RESTRICT pt, T_IdCpu const &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition ShortRF.H:121
void reverse()
Definition ShortRF.H:72
amrex::ParticleReal m_phase
RF frequency in Hz.
Definition ShortRF.H:266
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ShortRF.H:233
amrex::ParticleReal m_bgf
Definition ShortRF.H:271
amrex::ParticleReal m_phi
Definition ShortRF.H:271
amrex::ParticleReal m_k
reference RF phase in degrees.
Definition ShortRF.H:271
amrex::ParticleReal m_bgi
Definition ShortRF.H:271
Definition alignment.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:179
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:263
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:39
Definition beamoptic.H:529
Definition lineartransport.H:50
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