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/named.H"
18#include "mixin/nofinalize.H"
19#include "mixin/pipeaperture.H"
20#include "mixin/thick.H"
21
22#include <AMReX_Extension.H>
23#include <AMReX_Math.H>
24#include <AMReX_REAL.H>
25#include <AMReX_SIMD.H>
26#include <AMReX_SmallMatrix.H>
27
28#include <cmath>
29#include <utility>
30
31
32namespace impactx::elements
33{
34 struct Drift
35 : public mixin::Named,
36 public mixin::BeamOptic<Drift>,
37 public mixin::LinearTransport<Drift>,
38 public mixin::Thick,
39 public mixin::Alignment,
41 public mixin::NoFinalize,
42 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
43 {
44 static constexpr auto type = "Drift";
46
59 amrex::ParticleReal ds,
60 amrex::ParticleReal dx = 0,
61 amrex::ParticleReal dy = 0,
62 amrex::ParticleReal rotation_degree = 0,
63 amrex::ParticleReal aperture_x = 0,
64 amrex::ParticleReal aperture_y = 0,
65 int nslice = 1,
66 std::optional<std::string> name = std::nullopt
67 )
68 : Named(std::move(name)),
69 Thick(ds, nslice),
70 Alignment(dx, dy, rotation_degree),
72 {
73 }
74
76 using BeamOptic::operator();
77
85 void compute_constants (RefPart const & refpart)
86 {
87 using namespace amrex::literals; // for _rt and _prt
89
90 Alignment::compute_constants(refpart);
91
92 // length of the current slice
94
95 // find beta*gamma^2
96 m_betgam2 = powi<2>(refpart.pt) - 1.0_prt;
97
99 }
100
114 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
117 T_Real & AMREX_RESTRICT x,
118 T_Real & AMREX_RESTRICT y,
119 T_Real & AMREX_RESTRICT t,
120 T_Real & AMREX_RESTRICT px,
121 T_Real & AMREX_RESTRICT py,
122 T_Real & AMREX_RESTRICT pt,
123 T_IdCpu & AMREX_RESTRICT idcpu,
124 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
125 ) const
126 {
127 using namespace amrex::literals; // for _rt and _prt
128
129 // shift due to alignment errors of the element
130 shift_in(x, y, px, py);
131
132 // initialize output values
133 T_Real xout = x;
134 T_Real yout = y;
135 T_Real tout = t;
136 T_Real pxout = px;
137 T_Real pyout = py;
138 T_Real ptout = pt;
139
140 // advance position and momentum (drift)
141 xout = x + m_slice_ds * px;
142 // pxout = px;
143 yout = y + m_slice_ds * py;
144 // pyout = py;
145 tout = t + m_slice_bg * pt;
146 // ptout = pt;
147
148 // assign updated values
149 x = xout;
150 y = yout;
151 t = tout;
152 px = pxout;
153 py = pyout;
154 pt = ptout;
155
156 // apply transverse aperture
157 apply_aperture(x, y, idcpu);
158
159 // undo shift due to alignment errors of the element
160 shift_out(x, y, px, py);
161 }
162
168 void operator() (RefPart & AMREX_RESTRICT refpart) const
169 {
170 using namespace amrex::literals; // for _rt and _prt
171 using amrex::Math::powi;
172
173 // assign input reference particle values
174 amrex::ParticleReal const x = refpart.x;
175 amrex::ParticleReal const px = refpart.px;
176 amrex::ParticleReal const y = refpart.y;
177 amrex::ParticleReal const py = refpart.py;
178 amrex::ParticleReal const z = refpart.z;
179 amrex::ParticleReal const pz = refpart.pz;
180 amrex::ParticleReal const t = refpart.t;
181 amrex::ParticleReal const pt = refpart.pt;
182 amrex::ParticleReal const s = refpart.s;
183
184 // length of the current slice
185 amrex::ParticleReal const slice_ds = m_ds / nslice();
186
187 // assign intermediate parameter
188 amrex::ParticleReal const step = slice_ds / std::sqrt(powi<2>(pt)-1.0_prt);
189
190 // advance position and momentum (drift)
191 refpart.x = x + step*px;
192 refpart.y = y + step*py;
193 refpart.z = z + step*pz;
194 refpart.t = t - step*pt;
195
196 // advance integrated path length
197 refpart.s = s + slice_ds;
198 }
199
201 using LinearTransport::operator();
202
208 Map6x6
209 transport_map (RefPart const & AMREX_RESTRICT refpart) const
210 {
211 using namespace amrex::literals; // for _rt and _prt
212 using amrex::Math::powi;
213
214 // length of the current slice
215 amrex::ParticleReal const slice_ds = m_ds / nslice();
216
217 // access reference particle values to find beta*gamma^2
218 amrex::ParticleReal const pt_ref = refpart.pt;
219 amrex::ParticleReal const betgam2 = powi<2>(pt_ref) - 1.0_prt;
220
221 // assign linear map matrix elements
223 R(1,2) = slice_ds;
224 R(3,4) = slice_ds;
225 R(5,6) = slice_ds / betgam2;
226
227 return R;
228 }
229
230 private:
231 // constants that are independent of the individually tracked particle,
232 // see: compute_constants() to refresh
233 amrex::ParticleReal m_slice_ds;
234 amrex::ParticleReal m_betgam2;
235 amrex::ParticleReal m_slice_bg;
236 };
237
238} // namespace impactx
239
240#endif // IMPACTX_DRIFT_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
constexpr T powi(T x) noexcept
Definition All.H:54
@ 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:31
amrex::ParticleReal pt
energy, normalized by rest energy
Definition ReferenceParticle.H:40
amrex::ParticleReal m_betgam2
m_ds / nslice();
Definition Drift.H:234
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:116
ImpactXParticleContainer::ParticleType PType
Definition Drift.H:45
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:58
amrex::ParticleReal m_slice_ds
Definition Drift.H:233
amrex::ParticleReal m_slice_bg
beta*gamma^2
Definition Drift.H:235
void compute_constants(RefPart const &refpart)
Definition Drift.H:85
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition Drift.H:209
static constexpr auto type
Definition Drift.H:44
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:219
Definition lineartransport.H:29
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 thick.H:24
Thick(amrex::ParticleReal ds, int nslice)
Definition thick.H:30
amrex::ParticleReal m_ds
Definition thick.H:58
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