ImpactX
Loading...
Searching...
No Matches
PRot.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_PROT_H
11#define IMPACTX_PROT_H
12
14#include "mixin/beamoptic.H"
15#include "mixin/thin.H"
17#include "mixin/named.H"
18#include "mixin/nofinalize.H"
19
20#include <ablastr/constant.H>
21
22#include <AMReX_Extension.H>
23#include <AMReX_Math.H>
24#include <AMReX_REAL.H>
25#include <AMReX_SIMD.H>
26
27#include <cmath>
28#include <stdexcept>
29
30
31namespace impactx::elements
32{
33 struct PRot
34 : public mixin::Named,
35 public mixin::BeamOptic<PRot>,
36 public mixin::LinearTransport<PRot>,
37 public mixin::Thin,
38 public mixin::NoFinalize,
39 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
40 {
41 static constexpr auto type = "PRot";
43
45
57 amrex::ParticleReal phi_out,
58 std::optional<std::string> name = std::nullopt
59 )
60 : Named(std::move(name)),
61 m_phi_in(phi_in * degree2rad),
62 m_phi_out(phi_out * degree2rad)
63 {
64 }
65
67 void reverse () { std::swap(m_phi_in, m_phi_out); }
68
70 using BeamOptic::operator();
71
79 void compute_constants (RefPart const & refpart)
80 {
81 using namespace amrex::literals; // for _rt and _prt
82
83 // access reference particle values to find 1/beta
84 m_inv_beta = 1.0_prt / refpart.beta();
85
86 // store rotation angle and initial, final values of pz
88 auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
89 m_sin_theta = sin_theta;
90 m_cos_theta = cos_theta;
91 auto const [sin_phi_in, cos_phi_in] = amrex::Math::sincos(m_phi_in);
92 m_sin_phi_in = sin_phi_in;
93 m_cos_phi_in = cos_phi_in;
94 }
95
110 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
113 T_Real & AMREX_RESTRICT x,
114 T_Real & AMREX_RESTRICT y,
115 T_Real & AMREX_RESTRICT t,
116 T_Real & AMREX_RESTRICT px,
117 T_Real & AMREX_RESTRICT py,
118 T_Real & AMREX_RESTRICT pt,
119 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
120 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
121 ) const
122 {
123 using namespace amrex::literals; // for _rt and _prt
124 using namespace std; // for cmath(float)
125 using amrex::Math::powi;
126
127 // initialize output values
128 T_Real xout = x;
129 T_Real yout = y;
130 T_Real tout = t;
131 T_Real pxout = px;
132 T_Real pyout = py;
133 T_Real ptout = pt;
134
135 T_Real const pz = sqrt(
136 1.0_prt -
137 2.0_prt * pt * m_inv_beta +
138 powi<2>(pt) -
139 powi<2>(py) -
140 powi<2>(px + m_sin_phi_in)
141 );
142 T_Real const pzf = pz * m_cos_theta - (px + m_sin_phi_in) * m_sin_theta;
143
144 // advance position and momentum
145 xout = x * pz / pzf;
146 pxout = px * m_cos_theta + (pz - m_cos_phi_in) * m_sin_theta;
147
148 yout = y + py * x * m_sin_theta / pzf;
149 pyout = py;
150
151 tout = t - (pt - m_inv_beta) * x * m_sin_theta / pzf;
152 ptout = pt;
153
154 // assign updated values
155 x = xout;
156 y = yout;
157 t = tout;
158 px = pxout;
159 py = pyout;
160 pt = ptout;
161 }
162
164 using Thin::operator();
165
167 using LinearTransport::operator();
168
202 Map6x6
203 transport_map (RefPart const & AMREX_RESTRICT refpart) const
204 {
205 using namespace amrex::literals; // for _rt and _prt
206
207 amrex::ParticleReal const beta = refpart.beta();
208
209 // Precompute trigonometric quantities.
210 amrex::ParticleReal const theta = m_phi_out - m_phi_in;
211 auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
212 (void) cos_theta; // not needed for the linear map
213 auto const [sin_phi_in, cos_phi_in] = amrex::Math::sincos(m_phi_in);
214 (void) sin_phi_in;
215 auto const [sin_phi_out, cos_phi_out] = amrex::Math::sincos(m_phi_out);
216 (void) sin_phi_out;
217
219 R(1,1) = cos_phi_in / cos_phi_out;
220 R(2,2) = cos_phi_out / cos_phi_in;
221 R(2,6) = -sin_theta / (beta * cos_phi_in);
222 R(5,1) = +sin_theta / (beta * cos_phi_out);
223
224 return R;
225 }
226
229
230 private:
231 // constants that are independent of the individually tracked particle,
232 // see: compute_constants() to refresh
234 };
235
236} // namespace impactx
237
239
240#endif // IMPACTX_PROT_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
__host__ __device__ std::pair< double, double > sincos(double x)
constexpr T powi(T x) noexcept
__host__ __device__ GpuComplex< T > sqrt(const GpuComplex< T > &a_z) 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_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:152
Definition PRot.H:40
PRot(amrex::ParticleReal phi_in, amrex::ParticleReal phi_out, std::optional< std::string > name=std::nullopt)
Definition PRot.H:55
amrex::ParticleReal m_cos_theta
Definition PRot.H:233
static constexpr amrex::ParticleReal degree2rad
Definition PRot.H:44
amrex::ParticleReal m_phi_in
Definition PRot.H:227
static constexpr auto type
Definition PRot.H:41
amrex::ParticleReal m_cos_phi_in
Definition PRot.H:233
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 PRot.H:112
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition PRot.H:203
amrex::ParticleReal m_inv_beta
RF wavenumber in 1/m.
Definition PRot.H:233
void reverse()
Definition PRot.H:67
amrex::ParticleReal m_sin_phi_in
Definition PRot.H:233
amrex::ParticleReal m_phi_out
normalized (max) RF voltage drop.
Definition PRot.H:228
ImpactXParticleContainer::ParticleType PType
Definition PRot.H:42
amrex::ParticleReal m_sin_theta
Definition PRot.H:233
void compute_constants(RefPart const &refpart)
Definition PRot.H:79
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