ImpactX
Loading...
Searching...
No Matches
ThinDipole.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_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
29namespace impactx::elements
30{
32 : public mixin::Named,
33 public mixin::BeamOptic<ThinDipole>,
34 public mixin::LinearTransport<ThinDipole>,
35 public mixin::Thin,
36 public mixin::Alignment,
37 public mixin::NoFinalize,
38 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
39 {
40 static constexpr auto type = "ThinDipole";
42
63 std::optional<std::string> name = DEFAULT_name
64 )
65 : Named(std::move(name)),
66 Alignment(dx, dy, rotation_degree),
67 m_theta(theta * degree2rad),
68 m_rc(rc)
69 {
70 }
71
73 void reverse () { m_theta = -m_theta; }
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 const & AMREX_RESTRICT x,
117 [[maybe_unused]] T_Real const & AMREX_RESTRICT y,
118 T_Real & AMREX_RESTRICT t,
119 T_Real & AMREX_RESTRICT px,
120 [[maybe_unused]] T_Real const & AMREX_RESTRICT py,
121 T_Real const & AMREX_RESTRICT pt,
122 [[maybe_unused]] T_IdCpu const & 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 // access position data
131 T_Real const xout = x;
132 // T_Real const yout = y;
133 T_Real const tout = t;
134
135 // initialize output values of momenta
136 T_Real pxout = px;
137 // T_Real pyout = py;
138 // T_Real ptout = pt;
139
140 // compute the function expressing dp/p in terms of pt (labeled f in Ripken etc.)
141 T_Real const f = -1.0_prt + sqrt(1.0_prt - 2.0_prt * pt / m_beta + powi<2>(pt));
142 T_Real const fprime = (1.0_prt - m_beta*pt) / (m_beta * (1.0_prt + f));
143
144 // advance position and momentum
145 // x = xout;
146 pxout = px - powi<2>(m_kx) * m_ds * xout + m_kx * m_ds * f; //eq (3.2b)
147
148 // y = yout;
149 // pyout = py;
150
151 t = tout + m_kx * xout * m_ds * fprime; //eq (3.2e)
152 // ptout = pt;
153
154 // assign updated momenta
155 px = pxout;
156 // py = pyout;
157 // pt = ptout;
158 }
159
161 using Thin::operator();
162
168 void operator() (RefPart & AMREX_RESTRICT refpart) const
169 {
170 // assign input reference particle values
171 amrex::ParticleReal const px = refpart.px;
172 amrex::ParticleReal const pz = refpart.pz;
173
174 // calculate expensive terms once
175 auto const [sin_theta, cos_theta] = amrex::Math::sincos(m_theta);
176
177 // advance position and momentum (thin dipole)
178 refpart.px = px*cos_theta - pz*sin_theta;
179 refpart.pz = pz*cos_theta + px*sin_theta;
180 }
181
183 using LinearTransport::operator();
184
208 Map6x6
209 transport_map (RefPart const & AMREX_RESTRICT refpart) const
210 {
211 using namespace amrex::literals; // for _rt and _prt
212 using amrex::Math::powi;
213
214 amrex::ParticleReal const beta = refpart.beta();
215 amrex::ParticleReal const ds = m_theta * m_rc; // effective arc length
216 amrex::ParticleReal const kx = 1.0_prt / m_rc; // curvature
217
219 R(2,1) = -powi<2>(kx) * ds; // geometric focusing
220 R(2,6) = -kx * ds / beta; // chromatic dispersion kick
221 R(5,1) = +kx * ds / beta; // path-length coupling to x
222
223 // apply the transverse rotation (roll) alignment error
224 return rotate_aligned_map(R);
225 }
226
229
230 private:
231 // constants that are independent of the individually tracked particle,
232 // see: compute_constants() to refresh
236 };
237
238} // namespace impactx
239
241
242#endif // IMPACTX_THINDIPOLE_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 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 ThinDipole.H:39
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ThinDipole.H:209
amrex::ParticleReal m_kx
effective (equivalent) arc length
Definition ThinDipole.H:235
ThinDipole(amrex::ParticleReal theta, amrex::ParticleReal rc, amrex::ParticleReal dx=DEFAULT_dx, amrex::ParticleReal dy=DEFAULT_dy, amrex::ParticleReal rotation_degree=DEFAULT_rotation_degree, std::optional< std::string > name=DEFAULT_name)
Definition ThinDipole.H:57
static constexpr auto type
Definition ThinDipole.H:40
amrex::ParticleReal m_ds
beta of the reference particle
Definition ThinDipole.H:234
amrex::ParticleReal m_theta
Definition ThinDipole.H:227
amrex::ParticleReal m_rc
dipole bending angle (rad)
Definition ThinDipole.H:228
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T_Real const &AMREX_RESTRICT x, T_Real const &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 ThinDipole.H:115
ImpactXParticleContainer::ParticleType PType
Definition ThinDipole.H:41
void compute_constants(RefPart const &refpart)
Definition ThinDipole.H:85
amrex::ParticleReal m_beta
curvature radius (m)
Definition ThinDipole.H:233
void reverse()
Definition ThinDipole.H:73
Definition alignment.H:29
static constexpr amrex::ParticleReal degree2rad
Definition alignment.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:193
static constexpr amrex::ParticleReal DEFAULT_dy
Definition alignment.H:34
static constexpr amrex::ParticleReal DEFAULT_dx
Definition alignment.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:183
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:267
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:43
static constexpr amrex::ParticleReal DEFAULT_rotation_degree
Definition alignment.H:35
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition thin.H:60