ImpactX
Loading...
Searching...
No Matches
ChrDrift.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_CHRDRIFT_H
11#define IMPACTX_CHRDRIFT_H
12
14#include "mixin/alignment.H"
15#include "mixin/pipeaperture.H"
16#include "mixin/beamoptic.H"
17#include "mixin/thick.H"
19#include "mixin/spintransport.H"
20#include "mixin/named.H"
21#include "mixin/nofinalize.H"
22
23#include <AMReX_Extension.H>
24#include <AMReX_Math.H>
25#include <AMReX_REAL.H>
26#include <AMReX_SIMD.H>
27
28#include <cmath>
29#include <stdexcept>
30
31
32namespace impactx::elements
33{
34 struct ChrDrift
35 : public mixin::Named,
36 public mixin::BeamOptic<ChrDrift>,
37 public mixin::LinearTransport<ChrDrift>,
38 public mixin::Thick,
39 public mixin::Alignment,
42 public mixin::NoFinalize,
43 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
44 {
45 static constexpr auto type = "ChrDrift";
47
66 amrex::ParticleReal rotation_degree = 0,
69 int nslice = 1,
70 std::optional<std::string> name = std::nullopt
71 )
72 : Named(std::move(name)),
73 Thick(ds, nslice),
74 Alignment(dx, dy, rotation_degree),
76 {
77 }
78
80 void reverse () { Thick::reverse(); }
81
83 using BeamOptic::operator();
84
92 void compute_constants (RefPart const & refpart)
93 {
94 using namespace amrex::literals; // for _rt and _prt
96
97 Alignment::compute_constants(refpart);
98
99 // length of the current slice
100 m_slice_ds = m_ds / nslice();
101
102 // access reference particle values to find beta, gamma
103 m_beta = refpart.beta();
104 m_gamma = refpart.gamma();
105
106 m_const1 = 1_prt / (2_prt * powi<3>(m_beta) * powi<2>(m_gamma));
107 }
108
120 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
123 T_Real & AMREX_RESTRICT x,
124 T_Real & AMREX_RESTRICT y,
125 T_Real & AMREX_RESTRICT t,
126 T_Real & AMREX_RESTRICT px,
127 T_Real & AMREX_RESTRICT py,
128 T_Real & AMREX_RESTRICT pt,
129 T_IdCpu & AMREX_RESTRICT idcpu,
130 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
131 ) const
132 {
133 using namespace amrex::literals; // for _rt and _prt
134 using amrex::Math::powi;
135 using namespace std; // for cmath(float)
136
137 // shift due to alignment errors of the element
138 shift_in(x, y, px, py);
139
140 // access position data
141 T_Real const xout = x;
142 T_Real const yout = y;
143 T_Real const tout = t;
144
145 // initialize output values of momenta
146 T_Real const pxout = px;
147 T_Real const pyout = py;
148 T_Real const ptout = pt;
149
150 // compute particle momentum deviation delta + 1
151 T_Real const idelta1 = 1_prt / sqrt(1_prt - 2_prt*pt/m_beta + powi<2>(pt));
152
153 // advance transverse position and momentum (drift)
154 x = xout + m_slice_ds * px * idelta1;
155 // pxout = px;
156 y = yout + m_slice_ds * py * idelta1;
157 // pyout = py;
158
159 // the corresponding symplectic update to t
160 T_Real term = 2_prt * powi<2>(pt) + powi<2>(px) + powi<2>(py);
161 term = 2_prt - 4_prt*m_beta*pt + powi<2>(m_beta)*term;
162 term = -2_prt + powi<2>(m_gamma)*term;
163 term = (-1_prt+m_beta*pt)*term;
164 term = term * m_const1;
165 t = tout - m_slice_ds * (1_prt / m_beta + term * powi<3>(idelta1));
166 // ptout = pt;
167
168 // assign updated momenta
169 px = pxout;
170 py = pyout;
171 pt = ptout;
172
173 // apply transverse aperture
174 apply_aperture(x, y, idcpu);
175
176 // undo shift due to alignment errors of the element
177 shift_out(x, y, px, py);
178 }
179
185 void operator() (RefPart & AMREX_RESTRICT refpart) const
186 {
187 using namespace amrex::literals; // for _rt and _prt
188 using amrex::Math::powi;
189
190 // assign input reference particle values
191 amrex::ParticleReal const x = refpart.x;
192 amrex::ParticleReal const px = refpart.px;
193 amrex::ParticleReal const y = refpart.y;
194 amrex::ParticleReal const py = refpart.py;
195 amrex::ParticleReal const z = refpart.z;
196 amrex::ParticleReal const pz = refpart.pz;
197 amrex::ParticleReal const t = refpart.t;
198 amrex::ParticleReal const pt = refpart.pt;
199 amrex::ParticleReal const s = refpart.s;
200
201 // length of the current slice
202 amrex::ParticleReal const slice_ds = m_ds / nslice();
203
204 // assign intermediate parameter
205 amrex::ParticleReal const step = slice_ds /std::sqrt(powi<2>(pt)-1.0_prt);
206
207 // advance position and momentum (drift)
208 refpart.x = x + step*px;
209 refpart.y = y + step*py;
210 refpart.z = z + step*pz;
211 refpart.t = t - step*pt;
212
213 // advance integrated path length
214 refpart.s = s + slice_ds;
215 }
216
217
232 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
235 [[maybe_unused]] T_Real & AMREX_RESTRICT x,
236 [[maybe_unused]] T_Real & AMREX_RESTRICT y,
237 [[maybe_unused]] T_Real & AMREX_RESTRICT t,
238 [[maybe_unused]] T_Real & AMREX_RESTRICT px,
239 [[maybe_unused]] T_Real & AMREX_RESTRICT py,
240 [[maybe_unused]] T_Real & AMREX_RESTRICT pt,
241 [[maybe_unused]] T_Real & AMREX_RESTRICT sx,
242 [[maybe_unused]] T_Real & AMREX_RESTRICT sy,
243 [[maybe_unused]] T_Real & AMREX_RESTRICT sz,
244 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
245 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
246 ) const
247 {
248 // spin is unaffected
249
250 // phase space push
251 (*this)(x, y, t, px, py, pt, idcpu, refpart);
252
253 }
254
255
257 using LinearTransport::operator();
258
265 Map6x6
266 transport_map (RefPart const & AMREX_RESTRICT refpart) const
267 {
268 using namespace amrex::literals; // for _rt and _prt
269 using amrex::Math::powi;
270
271 // length of the current slice
272 amrex::ParticleReal const slice_ds = m_ds / nslice();
273
274 // access reference particle values to find beta*gamma^2
275 amrex::ParticleReal const pt_ref = refpart.pt;
276 amrex::ParticleReal const betgam2 = powi<2>(pt_ref) - 1_prt;
277
278 // assign linear map matrix elements
280 R(1,2) = slice_ds;
281 R(3,4) = slice_ds;
282 R(5,6) = slice_ds / betgam2;
283
284 return R;
285 }
286
287 private:
288 // constants that are independent of the individually tracked particle,
289 // see: compute_constants() to refresh
294 };
295
296} // namespace impactx
297
299
300#endif // IMPACTX_CHRDRIFT_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__ GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Definition All.H:56
@ s
fixed s as the independent variable
Definition ImpactXParticleContainer.H:37
@ 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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition ReferenceParticle.H:140
Definition ChrDrift.H:44
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void spin_and_phasespace_push(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_Real &AMREX_RESTRICT sx, T_Real &AMREX_RESTRICT sy, T_Real &AMREX_RESTRICT sz, T_IdCpu &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition ChrDrift.H:234
void compute_constants(RefPart const &refpart)
Definition ChrDrift.H:92
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ChrDrift.H:266
amrex::ParticleReal m_const1
Definition ChrDrift.H:293
ChrDrift(amrex::ParticleReal ds, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, amrex::ParticleReal aperture_x=0, amrex::ParticleReal aperture_y=0, int nslice=1, std::optional< std::string > name=std::nullopt)
Definition ChrDrift.H:62
ImpactXParticleContainer::ParticleType PType
Definition ChrDrift.H:46
amrex::ParticleReal m_beta
m_ds / nslice();
Definition ChrDrift.H:291
amrex::ParticleReal m_slice_ds
Definition ChrDrift.H:290
void reverse()
Definition ChrDrift.H:80
static constexpr auto type
Definition ChrDrift.H:45
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 ChrDrift.H:122
amrex::ParticleReal m_gamma
Definition ChrDrift.H:292
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 pipeaperture.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void apply_aperture(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_IdCpu &AMREX_RESTRICT idcpu) const
Definition pipeaperture.H:59
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_x() const
Definition pipeaperture.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_y() const
Definition pipeaperture.H:101
PipeAperture(amrex::ParticleReal aperture_x, amrex::ParticleReal aperture_y)
Definition pipeaperture.H:32
Definition spintransport.H:36
Definition thick.H:24
Thick(amrex::ParticleReal ds, int nslice)
Definition thick.H:30
amrex::ParticleReal m_ds
Definition thick.H:68
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition thick.H:53
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition thick.H:43