ImpactX
Loading...
Searching...
No Matches
ThinDipole.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_THINDIPOLE_H
11#define IMPACTX_THINDIPOLE_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 <AMReX_Extension.H>
22#include <AMReX_Math.H>
23#include <AMReX_REAL.H>
24#include <AMReX_SIMD.H>
25
26#include <cmath>
27#include <stdexcept>
28
29
30namespace impactx::elements
31{
33 : public mixin::Named,
34 public mixin::BeamOptic<ThinDipole>,
35 public mixin::LinearTransport<ThinDipole>,
36 public mixin::Thin,
37 public mixin::Alignment,
38 public mixin::NoFinalize,
39 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
40 {
41 static constexpr auto type = "ThinDipole";
43
44 static constexpr amrex::ParticleReal degree2rad = ablastr::constant::math::pi / 180.0;
45
61 amrex::ParticleReal theta,
62 amrex::ParticleReal rc,
63 amrex::ParticleReal dx = 0,
64 amrex::ParticleReal dy = 0,
65 amrex::ParticleReal rotation_degree = 0,
66 std::optional<std::string> name = std::nullopt
67 )
68 : Named(std::move(name)),
69 Alignment(dx, dy, rotation_degree),
70 m_theta(theta * degree2rad),
71 m_rc(rc)
72 {
73 }
74
76 using BeamOptic::operator();
77
85 void compute_constants (RefPart const & refpart)
86 {
87 using namespace amrex::literals; // for _rt and _prt
88
89 Alignment::compute_constants(refpart);
90
91 // access reference particle to find relativistic beta
92 m_beta = refpart.beta();
93
94 // compute the effective (equivalent) arc length and curvature
95 m_ds = m_theta * m_rc;
96 m_kx = 1.0_prt / m_rc;
97 }
98
113 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
116 T_Real & AMREX_RESTRICT x,
117 T_Real & AMREX_RESTRICT y,
118 T_Real & AMREX_RESTRICT t,
119 T_Real & AMREX_RESTRICT px,
120 T_Real & AMREX_RESTRICT py,
121 T_Real & AMREX_RESTRICT pt,
122 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
123 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
124 ) const
125 {
126 using namespace amrex::literals; // for _rt and _prt
127 using amrex::Math::powi;
128 using namespace std; // for cmath(float)
129
130 // shift due to alignment errors of the element
131 shift_in(x, y, px, py);
132
133 // access position data
134 T_Real const xout = x;
135 T_Real const yout = y;
136 T_Real const tout = t;
137
138 // initialize output values of momenta
139 T_Real pxout = px;
140 T_Real pyout = py;
141 T_Real ptout = pt;
142
143 // compute the function expressing dp/p in terms of pt (labeled f in Ripken etc.)
144 T_Real const f = -1.0_prt + sqrt(1.0_prt - 2.0_prt * pt / m_beta + powi<2>(pt));
145 T_Real const fprime = (1.0_prt - m_beta*pt) / (m_beta * (1.0_prt + f));
146
147 // advance position and momentum
148 x = xout;
149 pxout = px - powi<2>(m_kx) * m_ds * xout + m_kx * m_ds * f; //eq (3.2b)
150
151 y = yout;
152 pyout = py;
153
154 t = tout + m_kx * xout * m_ds * fprime; //eq (3.2e)
155 ptout = pt;
156
157 // assign updated momenta
158 px = pxout;
159 py = pyout;
160 pt = ptout;
161
162 // undo shift due to alignment errors of the element
163 shift_out(x, y, px, py);
164 }
165
167 using Thin::operator();
168
174 void operator() (RefPart & AMREX_RESTRICT refpart) const
175 {
176 // assign input reference particle values
177 amrex::ParticleReal const px = refpart.px;
178 amrex::ParticleReal const pz = refpart.pz;
179
180 // calculate expensive terms once
181 auto const [sin_theta, cos_theta] = amrex::Math::sincos(m_theta);
182
183 // advance position and momentum (thin dipole)
184 refpart.px = px*cos_theta - pz*sin_theta;
185 refpart.pz = pz*cos_theta + px*sin_theta;
186 }
187
189 using LinearTransport::operator();
190
197 Map6x6
198 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
199 {
200 throw std::runtime_error(std::string(type) + ": Envelope tracking is not yet implemented!");
201 return Map6x6::Identity();
202 }
203
204 amrex::ParticleReal m_theta;
205 amrex::ParticleReal m_rc;
206
207 private:
208 // constants that are independent of the individually tracked particle,
209 // see: compute_constants() to refresh
210 amrex::ParticleReal m_beta;
211 amrex::ParticleReal m_ds;
212 amrex::ParticleReal m_kx;
213 };
214
215} // namespace impactx
216
217#endif // IMPACTX_THINDIPOLE_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
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ThinDipole.H:198
amrex::ParticleReal m_kx
effective (equivalent) arc length
Definition ThinDipole.H:212
ThinDipole(amrex::ParticleReal theta, amrex::ParticleReal rc, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition ThinDipole.H:60
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 ThinDipole.H:115
static constexpr auto type
Definition ThinDipole.H:41
amrex::ParticleReal m_ds
beta of the reference particle
Definition ThinDipole.H:211
amrex::ParticleReal m_theta
Definition ThinDipole.H:204
amrex::ParticleReal m_rc
dipole bending angle (rad)
Definition ThinDipole.H:205
ImpactXParticleContainer::ParticleType PType
Definition ThinDipole.H:42
static constexpr amrex::ParticleReal degree2rad
Definition ThinDipole.H:44
void compute_constants(RefPart const &refpart)
Definition ThinDipole.H:85
amrex::ParticleReal m_beta
curvature radius (m)
Definition ThinDipole.H:210
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: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