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/named.H"
20#include "mixin/nofinalize.H"
21
22#include <AMReX_Extension.H>
23#include <AMReX_Math.H>
24#include <AMReX_REAL.H>
25#include <AMReX_SIMD.H>
26
27#include <cmath>
28#include <stdexcept>
29
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,
40 public mixin::NoFinalize,
41 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
42 {
43 static constexpr auto type = "ChrDrift";
45
61 amrex::ParticleReal ds,
62 amrex::ParticleReal dx = 0,
63 amrex::ParticleReal dy = 0,
64 amrex::ParticleReal rotation_degree = 0,
65 amrex::ParticleReal aperture_x = 0,
66 amrex::ParticleReal aperture_y = 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 using BeamOptic::operator();
79
87 void compute_constants (RefPart const & refpart)
88 {
89 using namespace amrex::literals; // for _rt and _prt
91
92 Alignment::compute_constants(refpart);
93
94 // length of the current slice
96
97 // access reference particle values to find beta, gamma
98 m_beta = refpart.beta();
99 m_gamma = refpart.gamma();
100
101 m_const1 = 1_prt / (2_prt * powi<3>(m_beta) * powi<2>(m_gamma));
102 }
103
115 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
118 T_Real & AMREX_RESTRICT x,
119 T_Real & AMREX_RESTRICT y,
120 T_Real & AMREX_RESTRICT t,
121 T_Real & AMREX_RESTRICT px,
122 T_Real & AMREX_RESTRICT py,
123 T_Real & AMREX_RESTRICT pt,
124 T_IdCpu & AMREX_RESTRICT idcpu,
125 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
126 ) const
127 {
128 using namespace amrex::literals; // for _rt and _prt
129 using amrex::Math::powi;
130 using namespace std; // for cmath(float)
131
132 // shift due to alignment errors of the element
133 shift_in(x, y, px, py);
134
135 // access position data
136 T_Real const xout = x;
137 T_Real const yout = y;
138 T_Real const tout = t;
139
140 // initialize output values of momenta
141 T_Real const pxout = px;
142 T_Real const pyout = py;
143 T_Real const ptout = pt;
144
145 // compute particle momentum deviation delta + 1
146 T_Real const idelta1 = 1_prt / sqrt(1_prt - 2_prt*pt/m_beta + powi<2>(pt));
147
148 // advance transverse position and momentum (drift)
149 x = xout + m_slice_ds * px * idelta1;
150 // pxout = px;
151 y = yout + m_slice_ds * py * idelta1;
152 // pyout = py;
153
154 // the corresponding symplectic update to t
155 T_Real term = 2_prt * powi<2>(pt) + powi<2>(px) + powi<2>(py);
156 term = 2_prt - 4_prt*m_beta*pt + powi<2>(m_beta)*term;
157 term = -2_prt + powi<2>(m_gamma)*term;
158 term = (-1_prt+m_beta*pt)*term;
159 term = term * m_const1;
160 t = tout - m_slice_ds * (1_prt / m_beta + term * powi<3>(idelta1));
161 // ptout = pt;
162
163 // assign updated momenta
164 px = pxout;
165 py = pyout;
166 pt = ptout;
167
168 // apply transverse aperture
169 apply_aperture(x, y, idcpu);
170
171 // undo shift due to alignment errors of the element
172 shift_out(x, y, px, py);
173 }
174
180 void operator() (RefPart & AMREX_RESTRICT refpart) const
181 {
182 using namespace amrex::literals; // for _rt and _prt
183 using amrex::Math::powi;
184
185 // assign input reference particle values
186 amrex::ParticleReal const x = refpart.x;
187 amrex::ParticleReal const px = refpart.px;
188 amrex::ParticleReal const y = refpart.y;
189 amrex::ParticleReal const py = refpart.py;
190 amrex::ParticleReal const z = refpart.z;
191 amrex::ParticleReal const pz = refpart.pz;
192 amrex::ParticleReal const t = refpart.t;
193 amrex::ParticleReal const pt = refpart.pt;
194 amrex::ParticleReal const s = refpart.s;
195
196 // length of the current slice
197 amrex::ParticleReal const slice_ds = m_ds / nslice();
198
199 // assign intermediate parameter
200 amrex::ParticleReal const step = slice_ds /std::sqrt(powi<2>(pt)-1.0_prt);
201
202 // advance position and momentum (drift)
203 refpart.x = x + step*px;
204 refpart.y = y + step*py;
205 refpart.z = z + step*pz;
206 refpart.t = t - step*pt;
207
208 // advance integrated path length
209 refpart.s = s + slice_ds;
210 }
211
213 using LinearTransport::operator();
214
221 Map6x6
222 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
223 {
224 throw std::runtime_error(std::string(type) + ": Envelope tracking is not yet implemented!");
225 return Map6x6::Identity();
226 }
227
228 private:
229 // constants that are independent of the individually tracked particle,
230 // see: compute_constants() to refresh
231 amrex::ParticleReal m_slice_ds;
232 amrex::ParticleReal m_beta;
233 amrex::ParticleReal m_gamma;
234 amrex::ParticleReal m_const1;
235 };
236
237} // namespace impactx
238
239#endif // IMPACTX_CHRDRIFT_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_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition ReferenceParticle.H:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal gamma() const
Definition ReferenceParticle.H:82
void compute_constants(RefPart const &refpart)
Definition ChrDrift.H:87
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition ChrDrift.H:222
amrex::ParticleReal m_const1
Definition ChrDrift.H:234
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:60
ImpactXParticleContainer::ParticleType PType
Definition ChrDrift.H:44
amrex::ParticleReal m_beta
m_ds / nslice();
Definition ChrDrift.H:232
amrex::ParticleReal m_slice_ds
Definition ChrDrift.H:231
static constexpr auto type
Definition ChrDrift.H:43
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:117
amrex::ParticleReal m_gamma
Definition ChrDrift.H:233
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