ImpactX
Loading...
Searching...
No Matches
ExactDrift.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_EXACTDRIFT_H
11#define IMPACTX_EXACTDRIFT_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{
35 : public mixin::Named,
36 public mixin::BeamOptic<ExactDrift>,
37 public mixin::LinearTransport<ExactDrift>,
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 = "ExactDrift";
47
63 amrex::ParticleReal rotation_degree = 0,
66 int nslice = 1,
67 std::optional<std::string> name = std::nullopt
68 )
69 : Named(std::move(name)),
70 Thick(ds, nslice),
71 Alignment(dx, dy, rotation_degree),
73 {
74 }
75
77 void reverse () { Thick::reverse(); }
78
80 using BeamOptic::operator();
81
89 void compute_constants (RefPart const & refpart)
90 {
91 using namespace amrex::literals; // for _rt and _prt
93
94 Alignment::compute_constants(refpart);
95
96 // length of the current slice
98
99 // access reference particle values to find beta, 1/(beta*gamma)**2
100 m_ibeta = 1_prt / refpart.beta();
101 m_ibetagam2 = 1_prt / powi<2>(refpart.beta_gamma());
102 }
103
118 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
121 T_Real & AMREX_RESTRICT x,
122 T_Real & AMREX_RESTRICT y,
123 T_Real & AMREX_RESTRICT t,
124 T_Real & AMREX_RESTRICT px,
125 T_Real & AMREX_RESTRICT py,
126 T_Real & AMREX_RESTRICT pt,
127 T_IdCpu & AMREX_RESTRICT idcpu,
128 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
129 ) const
130 {
131 using namespace amrex::literals; // for _rt and _prt
132 using namespace std; // for cmath(float)
133 using amrex::Math::powi;
134
135 // shift due to alignment errors of the element
136 shift_in(x, y, px, py);
137
138 // initialize output values
139 T_Real const xout = x;
140 T_Real const yout = y;
141 T_Real const tout = t;
142
143 // initialize output values of momenta
144 T_Real const pxout = px;
145 T_Real const pyout = py;
146 T_Real const ptout = pt;
147
148 // compute the radical in the denominator (= pz):
149 T_Real const inv_pzden = 1_prt / sqrt(
150 powi<2>(pt - m_ibeta) -
152 powi<2>(px) -
153 powi<2>(py)
154 );
155
156 // advance position and momentum (exact drift)
157 x = xout + m_slice_ds * px * inv_pzden;
158 // pxout = px;
159 y = yout + m_slice_ds * py * inv_pzden;
160 // pyout = py;
161 t = tout - m_slice_ds * (m_ibeta + (pt - m_ibeta) * inv_pzden);
162 // ptout = pt;
163
164 // assign updated momenta
165 px = pxout;
166 py = pyout;
167 pt = ptout;
168
169 // apply transverse aperture
170 apply_aperture(x, y, idcpu);
171
172 // undo shift due to alignment errors of the element
173 shift_out(x, y, px, py);
174 }
175
181 void operator() (RefPart & AMREX_RESTRICT refpart) const
182 {
183 using namespace amrex::literals; // for _rt and _prt
184 using amrex::Math::powi;
185
186 // assign input reference particle values
187 amrex::ParticleReal const x = refpart.x;
188 amrex::ParticleReal const px = refpart.px;
189 amrex::ParticleReal const y = refpart.y;
190 amrex::ParticleReal const py = refpart.py;
191 amrex::ParticleReal const z = refpart.z;
192 amrex::ParticleReal const pz = refpart.pz;
193 amrex::ParticleReal const t = refpart.t;
194 amrex::ParticleReal const pt = refpart.pt;
195 amrex::ParticleReal const s = refpart.s;
196
197 // length of the current slice
198 amrex::ParticleReal const slice_ds = m_ds / nslice();
199
200 // assign intermediate parameter
201 amrex::ParticleReal const step = slice_ds /std::sqrt(powi<2>(pt)-1.0_prt);
202
203 // advance position and momentum (drift)
204 refpart.x = x + step*px;
205 refpart.y = y + step*py;
206 refpart.z = z + step*pz;
207 refpart.t = t - step*pt;
208
209 // advance integrated path length
210 refpart.s = s + slice_ds;
211 }
212
213
228 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
231 [[maybe_unused]] T_Real & AMREX_RESTRICT x,
232 [[maybe_unused]] T_Real & AMREX_RESTRICT y,
233 [[maybe_unused]] T_Real & AMREX_RESTRICT t,
234 [[maybe_unused]] T_Real & AMREX_RESTRICT px,
235 [[maybe_unused]] T_Real & AMREX_RESTRICT py,
236 [[maybe_unused]] T_Real & AMREX_RESTRICT pt,
237 [[maybe_unused]] T_Real & AMREX_RESTRICT sx,
238 [[maybe_unused]] T_Real & AMREX_RESTRICT sy,
239 [[maybe_unused]] T_Real & AMREX_RESTRICT sz,
240 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
241 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
242 ) const
243 {
244 // spin is unaffected
245
246 // phase space push
247 (*this)(x, y, t, px, py, pt, idcpu, refpart);
248 }
249
250
252 using LinearTransport::operator();
253
260 Map6x6
261 transport_map (RefPart const & AMREX_RESTRICT refpart) const
262 {
263 using namespace amrex::literals; // for _rt and _prt
264 using amrex::Math::powi;
265
266 // length of the current slice
267 amrex::ParticleReal const slice_ds = m_ds / nslice();
268
269 // access reference particle values to find beta*gamma^2
270 amrex::ParticleReal const pt_ref = refpart.pt;
271 amrex::ParticleReal const betgam2 = powi<2>(pt_ref) - 1_prt;
272
273 // assign linear map matrix elements
275 R(1,2) = slice_ds;
276 R(3,4) = slice_ds;
277 R(5,6) = slice_ds / betgam2;
278
279 return R;
280 }
281
282 private:
283 // constants that are independent of the individually tracked particle,
284 // see: compute_constants() to refresh
287 };
288
289} // namespace impactx
290
292
293#endif // IMPACTX_EXACTDRIFT_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_gamma() const
Definition ReferenceParticle.H:168
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:152
Definition ExactDrift.H:44
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 ExactDrift.H:120
static constexpr auto type
Definition ExactDrift.H:45
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ExactDrift.H:261
amrex::ParticleReal m_slice_ds
Definition ExactDrift.H:285
ImpactXParticleContainer::ParticleType PType
Definition ExactDrift.H:46
void compute_constants(RefPart const &refpart)
Definition ExactDrift.H:89
amrex::ParticleReal m_ibetagam2
Definition ExactDrift.H:286
amrex::ParticleReal m_ibeta
m_ds / nslice();
Definition ExactDrift.H:286
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 ExactDrift.H:230
void reverse()
Definition ExactDrift.H:77
ExactDrift(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 ExactDrift.H:59
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