ImpactX
Loading...
Searching...
No Matches
QuadEdge.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_QUADEDGE_H
11#define IMPACTX_QUADEDGE_H
12
14#include "mixin/alignment.H"
15#include "mixin/beamoptic.H"
16#include "mixin/thin.H"
18#include "mixin/named.H"
19#include "mixin/nofinalize.H"
20
21#include <AMReX_Extension.H>
22#include <AMReX_Math.H>
23#include <AMReX_REAL.H>
24#include <AMReX_SIMD.H>
25
26#include <cmath>
27#include <stdexcept>
28
29
30namespace impactx::elements
31{
32 struct QuadEdge
33 : public mixin::Named,
34 public mixin::BeamOptic<QuadEdge>,
35 public mixin::LinearTransport<QuadEdge>,
36 public mixin::Thin,
37 public mixin::Alignment,
38 public mixin::NoFinalize,
39 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
40 {
41 static constexpr auto type = "QuadEdge";
43
45 {
46 entry = 1,
47 exit = -1
48 };
49
76 int unit,
77 Location flag,
80 amrex::ParticleReal rotation_degree = 0,
81 std::optional<std::string> name = std::nullopt
82 )
83 : Named(std::move(name)),
84 Alignment(dx, dy, rotation_degree),
85 m_k(k), m_unit(unit), m_flag(flag)
86 {
87 }
88
90 void reverse ()
91 {
95 }
96
98 using BeamOptic::operator();
99
107 void compute_constants ([[maybe_unused]] RefPart const & refpart)
108 {
109 using namespace amrex::literals; // for _rt and _prt
110
111 Alignment::compute_constants(refpart);
112
113 // access reference particle values to find beta and gamma
114 m_beta = refpart.beta();
115 m_gamma = refpart.gamma();
116
117 // normalize quad units to MAD-X convention if needed
118 m_g = m_unit == 1 ? m_k / refpart.rigidity_Tm() : m_k;
119
120 // the global scale constant; sign depends on entry or exit
121 m_a = static_cast<amrex::ParticleReal>(m_flag) * (-1_prt * m_g / 12.0_prt);
122 }
123
138 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
141 T_Real & AMREX_RESTRICT x,
142 T_Real & AMREX_RESTRICT y,
143 [[maybe_unused]] T_Real & AMREX_RESTRICT t,
144 T_Real & AMREX_RESTRICT px,
145 T_Real & AMREX_RESTRICT py,
146 T_Real & AMREX_RESTRICT pt,
147 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
148 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
149 ) const
150 {
151
152 using namespace amrex::literals; // for _rt and _prt
153 using amrex::Math::powi;
154 using namespace std; // for cmath(float)
155
156 // shift due to alignment errors of the element
157 shift_in(x, y, px, py);
158
159 // compute particle momentum deviation delta + 1
160 T_Real const delta1 = sqrt(1_prt - 2_prt*pt/m_beta + powi<2>(pt));
161 T_Real a = m_a / delta1;
162
163 // initialize output values
164 T_Real xout = x;
165 T_Real yout = y;
166 T_Real tout = t;
167 T_Real pxout = px;
168 T_Real pyout = py;
169
170 // intermediate quantities to be used below
171 T_Real x2my2 = x*x - y*y;
172 T_Real x2py2 = x*x + y*y;
173 T_Real denominator = 1_prt - 9_prt*powi<2>(a)*powi<2>(x2my2);
174
175 // apply edge focusing (transverse phase space)
176 xout = x - a * (powi<3>(x) + 3_prt * x * powi<2>(y));
177 yout = y + a * (3_prt * powi<2>(x) * y + powi<3>(y));
178
179 pxout = (px + 3_prt*a*px*x2py2 - 6_prt*a*py*x*y) / denominator;
180 pyout = (py - 3_prt*a*py*x2py2 + 6_prt*a*px*x*y) / denominator;
181
182 // apply edge focusing (longitudinal phase space)
183 T_Real f4 = a * ( pxout * (powi<3>(x) + 3_prt*x*powi<2>(y))
184 - pyout * (powi<3>(y) + 3_prt*y*powi<2>(x)) );
185 tout = t + f4 * (pt - 1_prt/m_beta) / powi<2>(delta1);
186
187 // update output values
188 x = xout;
189 y = yout;
190 t = tout;
191 px = pxout;
192 py = pyout;
193
194 // undo shift due to alignment errors of the element
195 shift_out(x, y, px, py);
196 }
197
199 using Thin::operator();
200
202 using LinearTransport::operator();
203
210 Map6x6
211 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
212 {
213 using namespace amrex::literals; // for _rt and _prt
214
215 // initialize linear map matrix elements
217
218 return R;
219 }
220
222 int m_unit;
224
225 private:
226 // constants that are independent of the individually tracked particle,
227 // see: compute_constants() to refresh
232 };
233
234} // namespace impactx
235
237
238#endif // IMPACTX_QUADEDGE_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
@ 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
Definition QuadEdge.H:40
amrex::ParticleReal m_a
Definition QuadEdge.H:229
ImpactXParticleContainer::ParticleType PType
Definition QuadEdge.H:42
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 QuadEdge.H:140
amrex::ParticleReal m_k
Definition QuadEdge.H:221
int m_unit
quadrupole focusing strength
Definition QuadEdge.H:222
void compute_constants(RefPart const &refpart)
Definition QuadEdge.H:107
static constexpr auto type
Definition QuadEdge.H:41
amrex::ParticleReal m_beta
Definition QuadEdge.H:230
void reverse()
Definition QuadEdge.H:90
QuadEdge(amrex::ParticleReal k, int unit, Location flag, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition QuadEdge.H:74
amrex::ParticleReal m_gamma
Definition QuadEdge.H:231
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition QuadEdge.H:211
amrex::ParticleReal m_g
+1 for entry, or -1 for exit
Definition QuadEdge.H:228
Location m_flag
unit specification for quad strength
Definition QuadEdge.H:223
Location
Definition QuadEdge.H:45
@ exit
for leading (entry) fringe field
Definition QuadEdge.H:47
@ entry
Definition QuadEdge.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 thin.H:24