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 T_Real & AMREX_RESTRICT x,
123 T_Real & AMREX_RESTRICT y,
124 T_Real & 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 & 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 // shift due to alignment errors of the element
137 shift_in(x, y, px, py);
138
139 // initial conversion from static to dynamic units:
140 px = px * m_bgi;
141 py = py * m_bgi;
142 pt = pt * m_bgi;
143
144 // initialize output values
145 T_Real xout = x;
146 T_Real yout = y;
147 T_Real tout = t;
148 T_Real pxout = px;
149 T_Real pyout = py;
150 T_Real ptout = pt;
151
152 // advance position and momentum in dynamic units
153 // xout = x;
154 pxout = px;
155
156 // yout = y;
157 pyout = py;
158
159 // tout = t;
160 ptout = pt - m_V * cos(m_k * t + m_phi) + m_V_cos_phi;
161
162 // assign updated values
163 x = xout;
164 y = yout;
165 t = tout;
166 px = pxout;
167 py = pyout;
168 pt = ptout;
169
170 // final conversion from dynamic to static units:
171 px = px / m_bgf;
172 py = py / m_bgf;
173 pt = pt / m_bgf;
174
175 // undo shift due to alignment errors of the element
176 shift_out(x, y, px, py);
177 }
178
180 using Thin::operator();
181
187 void operator() (RefPart & AMREX_RESTRICT refpart) const
188 {
189 using namespace amrex::literals; // for _rt and _prt
190 using amrex::Math::powi;
191
192 // assign input reference particle values
193 amrex::ParticleReal const x = refpart.x;
194 amrex::ParticleReal const px = refpart.px;
195 amrex::ParticleReal const y = refpart.y;
196 amrex::ParticleReal const py = refpart.py;
197 amrex::ParticleReal const z = refpart.z;
198 amrex::ParticleReal const pz = refpart.pz;
199 amrex::ParticleReal const t = refpart.t;
200 amrex::ParticleReal const pt = refpart.pt;
201
202 // Define parameters and intermediate constants
204 amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
205
206 // compute initial value of beta*gamma
207 amrex::ParticleReal const bgi = std::sqrt(powi<2>(pt) - 1.0_prt);
208
209 // advance pt
210 refpart.pt = pt - m_V * std::cos(phi);
211
212 // compute final value of beta*gamma
213 amrex::ParticleReal const ptf = refpart.pt;
214 amrex::ParticleReal const bgf = std::sqrt(powi<2>(ptf) - 1.0_prt);
215
216 // advance position (x,y,z,t)
217 refpart.x = x;
218 refpart.y = y;
219 refpart.z = z;
220 refpart.t = t;
221
222 // advance momentum (px,py,pz)
223 refpart.px = px*bgf/bgi;
224 refpart.py = py*bgf/bgi;
225 refpart.pz = pz*bgf/bgi;
226
227 }
228
230 using LinearTransport::operator();
231
238 Map6x6
239 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
240 {
241 using namespace amrex::literals; // for _rt and _prt
242 using amrex::Math::powi;
243
244 // Define parameters and intermediate constants
247 amrex::ParticleReal const k = (2.0_prt*pi/c)*m_freq;
248 amrex::ParticleReal const phi = m_phase*(pi/180.0_prt);
249
250 // access reference particle values (final, initial):
251 amrex::ParticleReal const ptf_ref = refpart.pt;
252 amrex::ParticleReal const pti_ref = ptf_ref + m_V * std::cos(phi);
253 amrex::ParticleReal const bgf = std::sqrt(powi<2>(ptf_ref) - 1.0_prt);
254 amrex::ParticleReal const bgi = std::sqrt(powi<2>(pti_ref) - 1.0_prt);
255
256 // initialize transport matrix
258
259 // This is a nonlinear element: the linearized map is returned here.
260 // assign linear map matrix elements
261 R(2,2) = bgi/bgf;
262 R(4,4) = bgi/bgf;
263 R(6,5) = k*m_V*std::sin(phi)/bgf;
264 R(6,6) = bgi/bgf;
265
266 return R;
267 }
268
272
273 private:
274 // constants that are independent of the individually tracked particle,
275 // see: compute_constants() to refresh
277 };
278
279} // namespace impactx
280
282
283#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:276
amrex::ParticleReal m_V
Definition ShortRF.H:269
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:270
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
void reverse()
Definition ShortRF.H:72
amrex::ParticleReal m_phase
RF frequency in Hz.
Definition ShortRF.H:271
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ShortRF.H:239
amrex::ParticleReal m_bgf
Definition ShortRF.H:276
amrex::ParticleReal m_phi
Definition ShortRF.H:276
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:121
amrex::ParticleReal m_k
reference RF phase in degrees.
Definition ShortRF.H:276
amrex::ParticleReal m_bgi
Definition ShortRF.H:276
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:436
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