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
44 static constexpr amrex::ParticleReal degree2rad = ablastr::constant::math::pi / 180.0;
45
56 amrex::ParticleReal phi_in,
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 using BeamOptic::operator();
68
76 void compute_constants (RefPart const & refpart)
77 {
78 using namespace amrex::literals; // for _rt and _prt
79
80 // access reference particle values to find 1/beta
81 m_inv_beta = 1.0_prt / refpart.beta();
82
83 // store rotation angle and initial, final values of pz
84 amrex::ParticleReal const theta = m_phi_out - m_phi_in;
85 auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
86 m_sin_theta = sin_theta;
87 m_cos_theta = cos_theta;
88 auto const [sin_phi_in, cos_phi_in] = amrex::Math::sincos(m_phi_in);
89 m_sin_phi_in = sin_phi_in;
90 m_cos_phi_in = cos_phi_in;
91 }
92
107 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
110 T_Real & AMREX_RESTRICT x,
111 T_Real & AMREX_RESTRICT y,
112 T_Real & AMREX_RESTRICT t,
113 T_Real & AMREX_RESTRICT px,
114 T_Real & AMREX_RESTRICT py,
115 T_Real & AMREX_RESTRICT pt,
116 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
117 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
118 ) const
119 {
120 using namespace amrex::literals; // for _rt and _prt
121 using namespace std; // for cmath(float)
122 using amrex::Math::powi;
123
124 // initialize output values
125 T_Real xout = x;
126 T_Real yout = y;
127 T_Real tout = t;
128 T_Real pxout = px;
129 T_Real pyout = py;
130 T_Real ptout = pt;
131
132 T_Real const pz = sqrt(
133 1.0_prt -
134 2.0_prt * pt * m_inv_beta +
135 powi<2>(pt) -
136 powi<2>(py) -
137 powi<2>(px + m_sin_phi_in)
138 );
139 T_Real const pzf = pz * m_cos_theta - (px + m_sin_phi_in) * m_sin_theta;
140
141 // advance position and momentum
142 xout = x * pz / pzf;
143 pxout = px * m_cos_theta + (pz - m_cos_phi_in) * m_sin_theta;
144
145 yout = y + py * x * m_sin_theta / pzf;
146 pyout = py;
147
148 tout = t - (pt - m_inv_beta) * x * m_sin_theta / pzf;
149 ptout = pt;
150
151 // assign updated values
152 x = xout;
153 y = yout;
154 t = tout;
155 px = pxout;
156 py = pyout;
157 pt = ptout;
158 }
159
161 using Thin::operator();
162
164 using LinearTransport::operator();
165
172 Map6x6
173 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
174 {
175 throw std::runtime_error(std::string(type) + ": Envelope tracking is not yet implemented!");
176 return Map6x6::Identity();
177 }
178
179 amrex::ParticleReal m_phi_in;
180 amrex::ParticleReal m_phi_out;
181
182 private:
183 // constants that are independent of the individually tracked particle,
184 // see: compute_constants() to refresh
186 };
187
188} // namespace impactx
189
190#endif // IMPACTX_PROT_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
static constexpr amrex::Real pi
__host__ __device__ std::pair< double, double > sincos(double x)
constexpr T powi(T x) noexcept
Definition All.H:54
@ 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:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:94
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:185
static constexpr amrex::ParticleReal degree2rad
Definition PRot.H:44
amrex::ParticleReal m_phi_in
Definition PRot.H:179
static constexpr auto type
Definition PRot.H:41
amrex::ParticleReal m_cos_phi_in
Definition PRot.H:185
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:109
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition PRot.H:173
amrex::ParticleReal m_inv_beta
RF wavenumber in 1/m.
Definition PRot.H:185
amrex::ParticleReal m_sin_phi_in
Definition PRot.H:185
amrex::ParticleReal m_phi_out
normalized (max) RF voltage drop.
Definition PRot.H:180
ImpactXParticleContainer::ParticleType PType
Definition PRot.H:42
amrex::ParticleReal m_sin_theta
Definition PRot.H:185
void compute_constants(RefPart const &refpart)
Definition PRot.H:76
Definition beamoptic.H:219
Definition lineartransport.H:29
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