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
63 amrex::ParticleReal rotation_degree = 0,
64 std::optional<std::string> name = std::nullopt
65 )
66 : Named(std::move(name)),
67 Alignment(dx, dy, rotation_degree),
68 m_theta(theta * degree2rad),
69 m_rc(rc)
70 {
71 }
72
74 void reverse () { m_theta = -m_theta; }
75
77 using BeamOptic::operator();
78
86 void compute_constants (RefPart const & refpart)
87 {
88 using namespace amrex::literals; // for _rt and _prt
89
90 Alignment::compute_constants(refpart);
91
92 // access reference particle to find relativistic beta
93 m_beta = refpart.beta();
94
95 // compute the effective (equivalent) arc length and curvature
96 m_ds = m_theta * m_rc;
97 m_kx = 1.0_prt / m_rc;
98 }
99
114 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
117 T_Real const & AMREX_RESTRICT x,
118 [[maybe_unused]] T_Real const & AMREX_RESTRICT y,
119 T_Real & AMREX_RESTRICT t,
120 T_Real & AMREX_RESTRICT px,
121 [[maybe_unused]] T_Real const & AMREX_RESTRICT py,
122 T_Real const & AMREX_RESTRICT pt,
123 [[maybe_unused]] T_IdCpu const & AMREX_RESTRICT idcpu,
124 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
125 ) const
126 {
127 using namespace amrex::literals; // for _rt and _prt
128 using amrex::Math::powi;
129 using namespace std; // for cmath(float)
130
131 // access position data
132 T_Real const xout = x;
133 // T_Real const yout = y;
134 T_Real const tout = t;
135
136 // initialize output values of momenta
137 T_Real pxout = px;
138 // T_Real pyout = py;
139 // T_Real ptout = pt;
140
141 // compute the function expressing dp/p in terms of pt (labeled f in Ripken etc.)
142 T_Real const f = -1.0_prt + sqrt(1.0_prt - 2.0_prt * pt / m_beta + powi<2>(pt));
143 T_Real const fprime = (1.0_prt - m_beta*pt) / (m_beta * (1.0_prt + f));
144
145 // advance position and momentum
146 // x = xout;
147 pxout = px - powi<2>(m_kx) * m_ds * xout + m_kx * m_ds * f; //eq (3.2b)
148
149 // y = yout;
150 // pyout = py;
151
152 t = tout + m_kx * xout * m_ds * fprime; //eq (3.2e)
153 // ptout = pt;
154
155 // assign updated momenta
156 px = pxout;
157 // py = pyout;
158 // pt = ptout;
159 }
160
162 using Thin::operator();
163
169 void operator() (RefPart & AMREX_RESTRICT refpart) const
170 {
171 // assign input reference particle values
172 amrex::ParticleReal const px = refpart.px;
173 amrex::ParticleReal const pz = refpart.pz;
174
175 // calculate expensive terms once
176 auto const [sin_theta, cos_theta] = amrex::Math::sincos(m_theta);
177
178 // advance position and momentum (thin dipole)
179 refpart.px = px*cos_theta - pz*sin_theta;
180 refpart.pz = pz*cos_theta + px*sin_theta;
181 }
182
184 using LinearTransport::operator();
185
209 Map6x6
210 transport_map (RefPart const & AMREX_RESTRICT refpart) const
211 {
212 using namespace amrex::literals; // for _rt and _prt
213 using amrex::Math::powi;
214
215 amrex::ParticleReal const beta = refpart.beta();
216 amrex::ParticleReal const ds = m_theta * m_rc; // effective arc length
217 amrex::ParticleReal const kx = 1.0_prt / m_rc; // curvature
218
220 R(2,1) = -powi<2>(kx) * ds; // geometric focusing
221 R(2,6) = -kx * ds / beta; // chromatic dispersion kick
222 R(5,1) = +kx * ds / beta; // path-length coupling to x
223
224 // apply the transverse rotation (roll) alignment error
225 return rotate_aligned_map(R);
226 }
227
230
231 private:
232 // constants that are independent of the individually tracked particle,
233 // see: compute_constants() to refresh
237 };
238
239} // namespace impactx
240
242
243#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: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 ThinDipole.H:40
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ThinDipole.H:210
amrex::ParticleReal m_kx
effective (equivalent) arc length
Definition ThinDipole.H:236
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:58
static constexpr auto type
Definition ThinDipole.H:41
amrex::ParticleReal m_ds
beta of the reference particle
Definition ThinDipole.H:235
amrex::ParticleReal m_theta
Definition ThinDipole.H:228
amrex::ParticleReal m_rc
dipole bending angle (rad)
Definition ThinDipole.H:229
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:116
ImpactXParticleContainer::ParticleType PType
Definition ThinDipole.H:42
void compute_constants(RefPart const &refpart)
Definition ThinDipole.H:86
amrex::ParticleReal m_beta
curvature radius (m)
Definition ThinDipole.H:234
void reverse()
Definition ThinDipole.H:74
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:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:179
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:263
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:39
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition thin.H:60