ImpactX
Loading...
Searching...
No Matches
ShortRF.H
Go to the documentation of this file.
1/* Copyright 2022-2026 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
28namespace impactx::elements
29{
30 struct ShortRF
31 : public mixin::Named,
32 public mixin::BeamOptic<ShortRF>,
33 public mixin::LinearTransport<ShortRF>,
34 public mixin::Thin,
35 public mixin::Alignment,
36 public mixin::NoFinalize,
37 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
38 {
39 static constexpr auto type = "ShortRF";
41
42 static constexpr amrex::ParticleReal DEFAULT_phase = -90;
43
64 std::optional<std::string> name = DEFAULT_name
65 )
66 : Named(std::move(name)),
67 Alignment(dx, dy, rotation_degree),
68 m_V(V), m_freq(freq), m_phase(phase)
69 {
70 }
71
73 void reverse () { m_V = -m_V; }
74
76 using BeamOptic::operator();
77
85 void compute_constants (RefPart const & refpart)
86 {
87 using namespace amrex::literals; // for _rt and _prt
89
90 Alignment::compute_constants(refpart);
91
92 // Define parameters and intermediate constants
95 m_k = 2.0_prt * pi / c * m_freq;
96 m_phi = m_phase * pi / 180.0_prt;
97
98 // access reference particle values (final, initial):
99 amrex::ParticleReal const ptf_ref = refpart.pt;
100 m_V_cos_phi = m_V * std::cos(m_phi);
101 amrex::ParticleReal const pti_ref = ptf_ref + m_V_cos_phi;
102 m_bgf = std::sqrt(powi<2>(ptf_ref) - 1.0_prt);
103 m_bgi = std::sqrt(powi<2>(pti_ref) - 1.0_prt);
104 }
105
120 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
123 [[maybe_unused]] T_Real const & AMREX_RESTRICT x,
124 [[maybe_unused]] T_Real const & AMREX_RESTRICT y,
125 T_Real const & AMREX_RESTRICT t,
126 T_Real & AMREX_RESTRICT px,
127 T_Real & AMREX_RESTRICT py,
128 T_Real & AMREX_RESTRICT pt,
129 [[maybe_unused]] T_IdCpu const & AMREX_RESTRICT idcpu,
130 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
131 ) const
132 {
133
134 using namespace amrex::literals; // for _rt and _prt
135 using namespace std; // for cmath(float)
136
137 // initial conversion from static to dynamic units:
138 px = px * m_bgi;
139 py = py * m_bgi;
140 pt = pt * m_bgi;
141
142 // initialize output values
143 // T_Real xout = x;
144 // T_Real yout = y;
145 // T_Real tout = t;
146 // T_Real pxout = px;
147 // T_Real pyout = py;
148 T_Real ptout = pt;
149
150 // advance position and momentum in dynamic units
151 // xout = x;
152 // pxout = px;
153
154 // yout = y;
155 // pyout = py;
156
157 // tout = t;
158 ptout = pt - m_V * cos(m_k * t + m_phi) + m_V_cos_phi;
159
160 // assign updated values
161 // x = xout;
162 // y = yout;
163 // t = tout;
164 // px = pxout;
165 // py = pyout;
166 pt = ptout;
167
168 // final conversion from dynamic to static units:
169 px = px / m_bgf;
170 py = py / m_bgf;
171 pt = pt / m_bgf;
172 }
173
175 using Thin::operator();
176
182 void operator() (RefPart & AMREX_RESTRICT refpart) const
183 {
184 using namespace amrex::literals; // for _rt and _prt
185 using amrex::Math::powi;
186
187 // assign input reference particle values
188 amrex::ParticleReal const x = refpart.x;
189 amrex::ParticleReal const px = refpart.px;
190 amrex::ParticleReal const y = refpart.y;
191 amrex::ParticleReal const py = refpart.py;
192 amrex::ParticleReal const z = refpart.z;
193 amrex::ParticleReal const pz = refpart.pz;
194 amrex::ParticleReal const t = refpart.t;
195 amrex::ParticleReal const pt = refpart.pt;
196
197 // Define parameters and intermediate constants
199 amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
200
201 // compute initial value of beta*gamma
202 amrex::ParticleReal const bgi = std::sqrt(powi<2>(pt) - 1.0_prt);
203
204 // advance pt
205 refpart.pt = pt - m_V * std::cos(phi);
206
207 // compute final value of beta*gamma
208 amrex::ParticleReal const ptf = refpart.pt;
209 amrex::ParticleReal const bgf = std::sqrt(powi<2>(ptf) - 1.0_prt);
210
211 // advance position (x,y,z,t)
212 refpart.x = x;
213 refpart.y = y;
214 refpart.z = z;
215 refpart.t = t;
216
217 // advance momentum (px,py,pz)
218 refpart.px = px*bgf/bgi;
219 refpart.py = py*bgf/bgi;
220 refpart.pz = pz*bgf/bgi;
221
222 }
223
225 using LinearTransport::operator();
226
233 Map6x6
234 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
235 {
236 using namespace amrex::literals; // for _rt and _prt
237 using amrex::Math::powi;
238
239 // Define parameters and intermediate constants
242 amrex::ParticleReal const k = (2.0_prt*pi/c)*m_freq;
243 amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
244
245 // access reference particle values (final, initial):
246 amrex::ParticleReal const ptf_ref = refpart.pt;
247 amrex::ParticleReal const pti_ref = ptf_ref + m_V * std::cos(phi);
248 amrex::ParticleReal const bgf = std::sqrt(powi<2>(ptf_ref) - 1.0_prt);
249 amrex::ParticleReal const bgi = std::sqrt(powi<2>(pti_ref) - 1.0_prt);
250
251 // initialize transport matrix
253
254 // This is a nonlinear element: the linearized map is returned here.
255 // assign linear map matrix elements
256 R(2,2) = bgi/bgf;
257 R(4,4) = bgi/bgf;
258 R(6,5) = k*m_V*std::sin(phi)/bgf;
259 R(6,6) = bgi/bgf;
260
261 // apply the transverse rotation (roll) alignment error
262 return rotate_aligned_map(R);
263 }
264
268
269 private:
270 // constants that are independent of the individually tracked particle,
271 // see: compute_constants() to refresh
273 };
274
275} // namespace impactx
276
278
279#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:55
@ 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:38
void compute_constants(RefPart const &refpart)
Definition ShortRF.H:85
amrex::ParticleReal m_V_cos_phi
Definition ShortRF.H:272
amrex::ParticleReal m_V
Definition ShortRF.H:265
ShortRF(amrex::ParticleReal V, amrex::ParticleReal freq, amrex::ParticleReal phase=DEFAULT_phase, amrex::ParticleReal dx=DEFAULT_dx, amrex::ParticleReal dy=DEFAULT_dy, amrex::ParticleReal rotation_degree=DEFAULT_rotation_degree, std::optional< std::string > name=DEFAULT_name)
Definition ShortRF.H:57
static constexpr auto type
Definition ShortRF.H:39
ImpactXParticleContainer::ParticleType PType
Definition ShortRF.H:40
amrex::ParticleReal m_freq
normalized (max) RF voltage drop.
Definition ShortRF.H:266
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:122
void reverse()
Definition ShortRF.H:73
amrex::ParticleReal m_phase
RF frequency in Hz.
Definition ShortRF.H:267
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ShortRF.H:234
amrex::ParticleReal m_bgf
Definition ShortRF.H:272
static constexpr amrex::ParticleReal DEFAULT_phase
Definition ShortRF.H:42
amrex::ParticleReal m_phi
Definition ShortRF.H:272
amrex::ParticleReal m_k
reference RF phase in degrees.
Definition ShortRF.H:272
amrex::ParticleReal m_bgi
Definition ShortRF.H:272
Definition alignment.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:193
static constexpr amrex::ParticleReal DEFAULT_dy
Definition alignment.H:34
static constexpr amrex::ParticleReal DEFAULT_dx
Definition alignment.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:183
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:267
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:43
static constexpr amrex::ParticleReal DEFAULT_rotation_degree
Definition alignment.H:35
Definition beamoptic.H:567
Definition lineartransport.H:50
Definition named.H:29
static constexpr std::nullopt_t DEFAULT_name
Definition named.H:30
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:59
AMREX_FORCE_INLINE std::string name() const
Definition named.H:124
Definition nofinalize.H:22
Definition thin.H:24