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, false>,
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
45
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 void reverse () { m_theta = -m_theta; }
77
79 using BeamOptic::operator();
80
88 void compute_constants (RefPart const & refpart)
89 {
90 using namespace amrex::literals; // for _rt and _prt
91
92 Alignment::compute_constants(refpart);
93
94 // access reference particle to find relativistic beta
95 m_beta = refpart.beta();
96
97 // compute the effective (equivalent) arc length and curvature
98 m_ds = m_theta * m_rc;
99 m_kx = 1.0_prt / m_rc;
100 }
101
116 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
119 T_Real & AMREX_RESTRICT x,
120 T_Real & AMREX_RESTRICT y,
121 T_Real & AMREX_RESTRICT t,
122 T_Real & AMREX_RESTRICT px,
123 T_Real & AMREX_RESTRICT py,
124 T_Real & AMREX_RESTRICT pt,
125 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
126 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
127 ) const
128 {
129 using namespace amrex::literals; // for _rt and _prt
130 using amrex::Math::powi;
131 using namespace std; // for cmath(float)
132
133 // shift due to alignment errors of the element
134 shift_in(x, y, px, py);
135
136 // access position data
137 T_Real const xout = x;
138 T_Real const yout = y;
139 T_Real const tout = t;
140
141 // initialize output values of momenta
142 T_Real pxout = px;
143 T_Real pyout = py;
144 T_Real ptout = pt;
145
146 // compute the function expressing dp/p in terms of pt (labeled f in Ripken etc.)
147 T_Real const f = -1.0_prt + sqrt(1.0_prt - 2.0_prt * pt / m_beta + powi<2>(pt));
148 T_Real const fprime = (1.0_prt - m_beta*pt) / (m_beta * (1.0_prt + f));
149
150 // advance position and momentum
151 x = xout;
152 pxout = px - powi<2>(m_kx) * m_ds * xout + m_kx * m_ds * f; //eq (3.2b)
153
154 y = yout;
155 pyout = py;
156
157 t = tout + m_kx * xout * m_ds * fprime; //eq (3.2e)
158 ptout = pt;
159
160 // assign updated momenta
161 px = pxout;
162 py = pyout;
163 pt = ptout;
164
165 // undo shift due to alignment errors of the element
166 shift_out(x, y, px, py);
167 }
168
170 using Thin::operator();
171
177 void operator() (RefPart & AMREX_RESTRICT refpart) const
178 {
179 // assign input reference particle values
180 amrex::ParticleReal const px = refpart.px;
181 amrex::ParticleReal const pz = refpart.pz;
182
183 // calculate expensive terms once
184 auto const [sin_theta, cos_theta] = amrex::Math::sincos(m_theta);
185
186 // advance position and momentum (thin dipole)
187 refpart.px = px*cos_theta - pz*sin_theta;
188 refpart.pz = pz*cos_theta + px*sin_theta;
189 }
190
192 using LinearTransport::operator();
193
200 Map6x6
201 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
202 {
203 throw std::runtime_error(std::string(type) + ": Envelope tracking is not yet implemented!");
204 return Map6x6::Identity();
205 }
206
209
210 private:
211 // constants that are independent of the individually tracked particle,
212 // see: compute_constants() to refresh
216 };
217
218} // namespace impactx
219
221
222#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
__host__ __device__ std::pair< double, double > sincos(double x)
constexpr T powi(T x) noexcept
__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:152
Definition ThinDipole.H:40
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ThinDipole.H:201
amrex::ParticleReal m_kx
effective (equivalent) arc length
Definition ThinDipole.H:215
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:118
static constexpr auto type
Definition ThinDipole.H:41
amrex::ParticleReal m_ds
beta of the reference particle
Definition ThinDipole.H:214
amrex::ParticleReal m_theta
Definition ThinDipole.H:207
amrex::ParticleReal m_rc
dipole bending angle (rad)
Definition ThinDipole.H:208
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:88
amrex::ParticleReal m_beta
curvature radius (m)
Definition ThinDipole.H:213
void reverse()
Definition ThinDipole.H:76
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:436
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