ImpactX
Loading...
Searching...
No Matches
Drift.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_DRIFT_H
11#define IMPACTX_DRIFT_H
12
14#include "mixin/alignment.H"
15#include "mixin/beamoptic.H"
17#include "mixin/spintransport.H"
18#include "mixin/named.H"
19#include "mixin/nofinalize.H"
20#include "mixin/pipeaperture.H"
21#include "mixin/thick.H"
22
23#include <AMReX_Extension.H>
24#include <AMReX_Math.H>
25#include <AMReX_REAL.H>
26#include <AMReX_SIMD.H>
27#include <AMReX_SmallMatrix.H>
28
29#include <cmath>
30#include <utility>
31
32
33namespace impactx::elements
34{
35 struct Drift
36 : public mixin::Named,
37 public mixin::BeamOptic<Drift>,
38 public mixin::LinearTransport<Drift>,
39 public mixin::Thick,
40 public mixin::Alignment,
43 public mixin::NoFinalize,
44 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
45 {
46 static constexpr auto type = "Drift";
48
64 amrex::ParticleReal rotation_degree = 0,
67 int nslice = 1,
68 std::optional<std::string> name = std::nullopt
69 )
70 : Named(std::move(name)),
71 Thick(ds, nslice),
72 Alignment(dx, dy, rotation_degree),
74 {
75 }
76
78 void reverse () { Thick::reverse(); }
79
81 using BeamOptic::operator();
82
90 void compute_constants (RefPart const & refpart)
91 {
92 using namespace amrex::literals; // for _rt and _prt
94
95 Alignment::compute_constants(refpart);
96
97 // length of the current slice
99
100 // find beta*gamma^2
101 m_betgam2 = powi<2>(refpart.pt) - 1.0_prt;
102
104 }
105
119 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
122 T_Real & AMREX_RESTRICT x,
123 T_Real & AMREX_RESTRICT y,
124 T_Real & AMREX_RESTRICT t,
125 T_Real & AMREX_RESTRICT px,
126 T_Real & AMREX_RESTRICT py,
127 T_Real & AMREX_RESTRICT pt,
128 T_IdCpu & AMREX_RESTRICT idcpu,
129 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
130 ) const
131 {
132 using namespace amrex::literals; // for _rt and _prt
133
134 // shift due to alignment errors of the element
135 shift_in(x, y, px, py);
136
137 // initialize output values
138 T_Real xout = x;
139 T_Real yout = y;
140 T_Real tout = t;
141 T_Real pxout = px;
142 T_Real pyout = py;
143 T_Real ptout = pt;
144
145 // advance position and momentum (drift)
146 xout = x + m_slice_ds * px;
147 // pxout = px;
148 yout = y + m_slice_ds * py;
149 // pyout = py;
150 tout = t + m_slice_bg * pt;
151 // ptout = pt;
152
153 // assign updated values
154 x = xout;
155 y = yout;
156 t = tout;
157 px = pxout;
158 py = pyout;
159 pt = ptout;
160
161 // apply transverse aperture
162 apply_aperture(x, y, idcpu);
163
164 // undo shift due to alignment errors of the element
165 shift_out(x, y, px, py);
166 }
167
173 void operator() (RefPart & AMREX_RESTRICT refpart) const
174 {
175 using namespace amrex::literals; // for _rt and _prt
176 using amrex::Math::powi;
177
178 // assign input reference particle values
179 amrex::ParticleReal const x = refpart.x;
180 amrex::ParticleReal const px = refpart.px;
181 amrex::ParticleReal const y = refpart.y;
182 amrex::ParticleReal const py = refpart.py;
183 amrex::ParticleReal const z = refpart.z;
184 amrex::ParticleReal const pz = refpart.pz;
185 amrex::ParticleReal const t = refpart.t;
186 amrex::ParticleReal const pt = refpart.pt;
187 amrex::ParticleReal const s = refpart.s;
188
189 // length of the current slice
190 amrex::ParticleReal const slice_ds = m_ds / nslice();
191
192 // assign intermediate parameter
193 amrex::ParticleReal const step = slice_ds / std::sqrt(powi<2>(pt)-1.0_prt);
194
195 // advance position and momentum (drift)
196 refpart.x = x + step*px;
197 refpart.y = y + step*py;
198 refpart.z = z + step*pz;
199 refpart.t = t - step*pt;
200
201 // advance integrated path length
202 refpart.s = s + slice_ds;
203 }
204
205
220 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
223 [[maybe_unused]] T_Real & AMREX_RESTRICT x,
224 [[maybe_unused]] T_Real & AMREX_RESTRICT y,
225 [[maybe_unused]] T_Real & AMREX_RESTRICT t,
226 [[maybe_unused]] T_Real & AMREX_RESTRICT px,
227 [[maybe_unused]] T_Real & AMREX_RESTRICT py,
228 [[maybe_unused]] T_Real & AMREX_RESTRICT pt,
229 [[maybe_unused]] T_Real & AMREX_RESTRICT sx,
230 [[maybe_unused]] T_Real & AMREX_RESTRICT sy,
231 [[maybe_unused]] T_Real & AMREX_RESTRICT sz,
232 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
233 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
234 ) const
235 {
236 // spin is unaffected
237
238 // phase space push
239 (*this)(x, y, t, px, py, pt, idcpu, refpart);
240
241 }
242
243
245 using LinearTransport::operator();
246
252 Map6x6
253 transport_map (RefPart const & AMREX_RESTRICT refpart) const
254 {
255 using namespace amrex::literals; // for _rt and _prt
256 using amrex::Math::powi;
257
258 // length of the current slice
259 amrex::ParticleReal const slice_ds = m_ds / nslice();
260
261 // access reference particle values to find beta*gamma^2
262 amrex::ParticleReal const pt_ref = refpart.pt;
263 amrex::ParticleReal const betgam2 = powi<2>(pt_ref) - 1.0_prt;
264
265 // assign linear map matrix elements
267 R(1,2) = slice_ds;
268 R(3,4) = slice_ds;
269 R(5,6) = slice_ds / betgam2;
270
271 return R;
272 }
273
274 private:
275 // constants that are independent of the individually tracked particle,
276 // see: compute_constants() to refresh
280 };
281
282} // namespace impactx
283
285
286#endif // IMPACTX_DRIFT_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
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::ParticleReal pt
energy, normalized by rest energy
Definition ReferenceParticle.H:42
Definition Drift.H:45
amrex::ParticleReal m_betgam2
m_ds / nslice();
Definition Drift.H:278
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 Drift.H:121
void reverse()
Definition Drift.H:78
ImpactXParticleContainer::ParticleType PType
Definition Drift.H:47
Drift(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 Drift.H:60
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 Drift.H:222
amrex::ParticleReal m_slice_ds
Definition Drift.H:277
amrex::ParticleReal m_slice_bg
beta*gamma^2
Definition Drift.H:279
void compute_constants(RefPart const &refpart)
Definition Drift.H:90
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition Drift.H:253
static constexpr auto type
Definition Drift.H:46
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