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