ImpactX
Loading...
Searching...
No Matches
ChrDrift.H
Go to the documentation of this file.
1/* Copyright 2022-2026 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
31namespace impactx::elements
32{
33 struct ChrDrift
34 : public mixin::Named,
35 public mixin::BeamOptic<ChrDrift>,
36 public mixin::LinearTransport<ChrDrift>,
37 public mixin::Thick,
38 public mixin::Alignment,
41 public mixin::NoFinalize,
42 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
43 {
44 static constexpr auto type = "ChrDrift";
46
77
79 void reverse () { Thick::reverse(); }
80
82 using BeamOptic::operator();
83
91 void compute_constants (RefPart const & refpart)
92 {
93 using namespace amrex::literals; // for _rt and _prt
95
96 Alignment::compute_constants(refpart);
97
98 // length of the current slice
100
101 // access reference particle values to find beta, gamma
102 m_beta = refpart.beta();
103 amrex::ParticleReal const gamma = refpart.gamma();
104
105 m_const1 = 1_prt / (2_prt * powi<3>(m_beta) * powi<2>(gamma));
106 }
107
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 const & AMREX_RESTRICT px,
126 T_Real const & AMREX_RESTRICT py,
127 T_Real const & AMREX_RESTRICT pt,
128 [[maybe_unused]] T_IdCpu const & AMREX_RESTRICT idcpu,
129 RefPart const & AMREX_RESTRICT refpart
130 ) const
131 {
132 using namespace amrex::literals; // for _rt and _prt
133 using amrex::Math::powi;
134 using namespace std; // for cmath(float)
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 const pxout = px;
143 // T_Real const pyout = py;
144 // T_Real const ptout = pt;
145
146 // compute particle momentum deviation delta + 1
147 T_Real const idelta1 = 1_prt / sqrt(1_prt - 2_prt*pt/m_beta + powi<2>(pt));
148
149 // advance transverse position and momentum (drift)
150 x = xout + m_slice_ds * px * idelta1;
151 // pxout = px;
152 y = yout + m_slice_ds * py * idelta1;
153 // pyout = py;
154
155 // the corresponding symplectic update to t
156 T_Real term = 2_prt * powi<2>(pt) + powi<2>(px) + powi<2>(py);
157 term = 2_prt - 4_prt*m_beta*pt + powi<2>(m_beta)*term;
158 term = -2_prt + powi<2>(refpart.gamma())*term;
159 term = (-1_prt+m_beta*pt)*term;
160 term = term * m_const1;
161 t = tout - m_slice_ds * (1_prt / m_beta + term * powi<3>(idelta1));
162 // ptout = pt;
163
164 // assign updated momenta
165 // px = pxout;
166 // py = pyout;
167 // pt = ptout;
168 }
169
175 void operator() (RefPart & AMREX_RESTRICT refpart) const
176 {
177 using namespace amrex::literals; // for _rt and _prt
178 using amrex::Math::powi;
179
180 // assign input reference particle values
181 amrex::ParticleReal const x = refpart.x;
182 amrex::ParticleReal const px = refpart.px;
183 amrex::ParticleReal const y = refpart.y;
184 amrex::ParticleReal const py = refpart.py;
185 amrex::ParticleReal const z = refpart.z;
186 amrex::ParticleReal const pz = refpart.pz;
187 amrex::ParticleReal const t = refpart.t;
188 amrex::ParticleReal const pt = refpart.pt;
189 amrex::ParticleReal const s = refpart.s;
190
191 // length of the current slice
192 amrex::ParticleReal const slice_ds = m_ds / nslice();
193
194 // assign intermediate parameter
195 amrex::ParticleReal const step = slice_ds /std::sqrt(powi<2>(pt)-1.0_prt);
196
197 // advance position and momentum (drift)
198 refpart.x = x + step*px;
199 refpart.y = y + step*py;
200 refpart.z = z + step*pz;
201 refpart.t = t - step*pt;
202
203 // advance integrated path length
204 refpart.s = s + slice_ds;
205 }
206
221 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
224 T_Real & AMREX_RESTRICT x,
225 T_Real & AMREX_RESTRICT y,
226 T_Real & AMREX_RESTRICT t,
227 T_Real const & AMREX_RESTRICT px,
228 T_Real const & AMREX_RESTRICT py,
229 T_Real const & AMREX_RESTRICT pt,
230 [[maybe_unused]] T_Real const & AMREX_RESTRICT sx,
231 [[maybe_unused]] T_Real const & AMREX_RESTRICT sy,
232 [[maybe_unused]] T_Real const & AMREX_RESTRICT sz,
233 T_IdCpu const & AMREX_RESTRICT idcpu,
234 RefPart const & AMREX_RESTRICT refpart
235 ) const
236 {
237 // spin is unaffected
238
239 // phase space push
240 (*this)(x, y, t, px, py, pt, idcpu, refpart);
241
242 }
243
245 using LinearTransport::operator();
246
253 Map6x6
254 transport_map (RefPart const & AMREX_RESTRICT refpart) const
255 {
256 using namespace amrex::literals; // for _rt and _prt
257 using amrex::Math::powi;
258
259 // length of the current slice
260 amrex::ParticleReal const slice_ds = m_ds / nslice();
261
262 // access reference particle values to find beta*gamma^2
263 amrex::ParticleReal const pt_ref = refpart.pt;
264 amrex::ParticleReal const betgam2 = powi<2>(pt_ref) - 1_prt;
265
266 // assign linear map matrix elements
268 R(1,2) = slice_ds;
269 R(3,4) = slice_ds;
270 R(5,6) = slice_ds / betgam2;
271
272 // apply the transverse rotation (roll) alignment error
273 return rotate_aligned_map(R);
274 }
275
276 private:
277 // constants that are independent of the individually tracked particle,
278 // see: compute_constants() to refresh
282 };
283
284} // namespace impactx
285
287
288#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:55
@ 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:151
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition ReferenceParticle.H:139
Definition ChrDrift.H:43
void compute_constants(RefPart const &refpart)
Definition ChrDrift.H:91
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ChrDrift.H:254
amrex::ParticleReal m_const1
Definition ChrDrift.H:281
ImpactXParticleContainer::ParticleType PType
Definition ChrDrift.H:45
amrex::ParticleReal m_beta
m_ds / nslice();
Definition ChrDrift.H:280
ChrDrift(amrex::ParticleReal ds, amrex::ParticleReal dx=DEFAULT_dx, amrex::ParticleReal dy=DEFAULT_dy, amrex::ParticleReal rotation_degree=DEFAULT_rotation_degree, amrex::ParticleReal aperture_x=DEFAULT_aperture_x, amrex::ParticleReal aperture_y=DEFAULT_aperture_y, int nslice=DEFAULT_nslice, std::optional< std::string > name=DEFAULT_name)
Definition ChrDrift.H:61
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 const &AMREX_RESTRICT px, T_Real const &AMREX_RESTRICT py, T_Real const &AMREX_RESTRICT pt, T_Real const &AMREX_RESTRICT sx, T_Real const &AMREX_RESTRICT sy, T_Real const &AMREX_RESTRICT sz, T_IdCpu const &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition ChrDrift.H:223
amrex::ParticleReal m_slice_ds
Definition ChrDrift.H:279
void reverse()
Definition ChrDrift.H:79
static constexpr auto type
Definition ChrDrift.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 const &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 ChrDrift.H:121
Definition alignment.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:193
static constexpr amrex::ParticleReal DEFAULT_dy
Definition alignment.H:34
static constexpr amrex::ParticleReal DEFAULT_dx
Definition alignment.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:183
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:267
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:43
static constexpr amrex::ParticleReal DEFAULT_rotation_degree
Definition alignment.H:35
Definition beamoptic.H:567
Definition lineartransport.H:50
Definition named.H:29
static constexpr std::nullopt_t DEFAULT_name
Definition named.H:30
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:59
AMREX_FORCE_INLINE std::string name() const
Definition named.H:124
Definition nofinalize.H:22
Definition pipeaperture.H:26
static constexpr amrex::ParticleReal DEFAULT_aperture_x
Definition pipeaperture.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_x() const
Definition pipeaperture.H:93
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_y() const
Definition pipeaperture.H:104
static constexpr amrex::ParticleReal DEFAULT_aperture_y
Definition pipeaperture.H:28
PipeAperture(amrex::ParticleReal aperture_x, amrex::ParticleReal aperture_y)
Definition pipeaperture.H:35
Definition spintransport.H:36
Definition thick.H:24
static constexpr int DEFAULT_nslice
Definition thick.H:25
Thick(amrex::ParticleReal ds, int nslice)
Definition thick.H:32
amrex::ParticleReal m_ds
Definition thick.H:70
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition thick.H:55
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition thick.H:45