ImpactX
Loading...
Searching...
No Matches
PRot.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_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
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
55 amrex::ParticleReal phi_out,
56 std::optional<std::string> name = DEFAULT_name
57 )
58 : Named(std::move(name)),
59 m_phi_in(phi_in * mixin::Alignment::degree2rad),
60 m_phi_out(phi_out * mixin::Alignment::degree2rad)
61 {
62 }
63
65 void reverse () { std::swap(m_phi_in, m_phi_out); }
66
68 using BeamOptic::operator();
69
77 void compute_constants (RefPart const & refpart)
78 {
79 using namespace amrex::literals; // for _rt and _prt
80
81 // access reference particle values to find 1/beta
82 m_inv_beta = 1.0_prt / refpart.beta();
83
84 // store rotation angle and initial, final values of pz
86 auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
87 m_sin_theta = sin_theta;
88 m_cos_theta = cos_theta;
89 auto const [sin_phi_in, cos_phi_in] = amrex::Math::sincos(m_phi_in);
90 m_sin_phi_in = sin_phi_in;
91 m_cos_phi_in = cos_phi_in;
92 }
93
108 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
111 T_Real & AMREX_RESTRICT x,
112 T_Real & AMREX_RESTRICT y,
113 T_Real & AMREX_RESTRICT t,
114 T_Real & AMREX_RESTRICT px,
115 T_Real const & AMREX_RESTRICT py,
116 T_Real const & AMREX_RESTRICT pt,
117 [[maybe_unused]] T_IdCpu const & AMREX_RESTRICT idcpu,
118 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
119 ) const
120 {
121 using namespace amrex::literals; // for _rt and _prt
122 using namespace std; // for cmath(float)
123 using amrex::Math::powi;
124
125 // initialize output values
126 T_Real xout = x;
127 T_Real yout = y;
128 T_Real tout = t;
129 T_Real pxout = px;
130 // T_Real pyout = py;
131 // T_Real ptout = pt;
132
133 T_Real const pz = sqrt(
134 1.0_prt -
135 2.0_prt * pt * m_inv_beta +
136 powi<2>(pt) -
137 powi<2>(py) -
138 powi<2>(px + m_sin_phi_in)
139 );
140 T_Real const pzf = pz * m_cos_theta - (px + m_sin_phi_in) * m_sin_theta;
141
142 // advance position and momentum
143 xout = x * pz / pzf;
144 pxout = px * m_cos_theta + (pz - m_cos_phi_in) * m_sin_theta;
145
146 yout = y + py * x * m_sin_theta / pzf;
147 // pyout = py;
148
149 tout = t - (pt - m_inv_beta) * x * m_sin_theta / pzf;
150 // ptout = pt;
151
152 // assign updated values
153 x = xout;
154 y = yout;
155 t = tout;
156 px = pxout;
157 // py = pyout;
158 // pt = ptout;
159 }
160
162 using Thin::operator();
163
165 using LinearTransport::operator();
166
200 Map6x6
201 transport_map (RefPart const & AMREX_RESTRICT refpart) const
202 {
203 using namespace amrex::literals; // for _rt and _prt
204
205 amrex::ParticleReal const beta = refpart.beta();
206
207 // Precompute trigonometric quantities.
208 amrex::ParticleReal const theta = m_phi_out - m_phi_in;
209 auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
210 (void) cos_theta; // not needed for the linear map
211 auto const [sin_phi_in, cos_phi_in] = amrex::Math::sincos(m_phi_in);
212 (void) sin_phi_in;
213 auto const [sin_phi_out, cos_phi_out] = amrex::Math::sincos(m_phi_out);
214 (void) sin_phi_out;
215
217 R(1,1) = cos_phi_in / cos_phi_out;
218 R(2,2) = cos_phi_out / cos_phi_in;
219 R(2,6) = -sin_theta / (beta * cos_phi_in);
220 R(5,1) = +sin_theta / (beta * cos_phi_out);
221
222 return R;
223 }
224
227
228 private:
229 // constants that are independent of the individually tracked particle,
230 // see: compute_constants() to refresh
232 };
233
234} // namespace impactx
235
237
238#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: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_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:151
Definition PRot.H:40
amrex::ParticleReal m_cos_theta
Definition PRot.H:231
amrex::ParticleReal m_phi_in
Definition PRot.H:225
static constexpr auto type
Definition PRot.H:41
amrex::ParticleReal m_cos_phi_in
Definition PRot.H:231
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:110
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition PRot.H:201
amrex::ParticleReal m_inv_beta
RF wavenumber in 1/m.
Definition PRot.H:231
void reverse()
Definition PRot.H:65
amrex::ParticleReal m_sin_phi_in
Definition PRot.H:231
amrex::ParticleReal m_phi_out
normalized (max) RF voltage drop.
Definition PRot.H:226
ImpactXParticleContainer::ParticleType PType
Definition PRot.H:42
amrex::ParticleReal m_sin_theta
Definition PRot.H:231
PRot(amrex::ParticleReal phi_in, amrex::ParticleReal phi_out, std::optional< std::string > name=DEFAULT_name)
Definition PRot.H:53
void compute_constants(RefPart const &refpart)
Definition PRot.H:77
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