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
114 m_beta = refpart.beta();
115
116 // normalize quad units to MAD-X convention if needed
117 m_g = m_unit == 1 ? m_k / refpart.rigidity_Tm() : m_k;
118
119 // the global scale constant; sign depends on entry or exit
120 m_a = static_cast<amrex::ParticleReal>(m_flag) * (-1_prt * m_g / 12.0_prt);
121 }
122
137 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
140 T_Real & AMREX_RESTRICT x,
141 T_Real & AMREX_RESTRICT y,
142 T_Real & AMREX_RESTRICT t,
143 T_Real & AMREX_RESTRICT px,
144 T_Real & AMREX_RESTRICT py,
145 T_Real const & AMREX_RESTRICT pt,
146 [[maybe_unused]] T_IdCpu const & AMREX_RESTRICT idcpu,
147 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
148 ) const
149 {
150
151 using namespace amrex::literals; // for _rt and _prt
152 using amrex::Math::powi;
153 using namespace std; // for cmath(float)
154
155 // compute particle momentum deviation delta + 1
156 T_Real const delta1 = sqrt(1_prt - 2_prt*pt/m_beta + powi<2>(pt));
157 T_Real const a = m_a / delta1;
158
159 // initialize output values
160 T_Real xout = x;
161 T_Real yout = y;
162 T_Real tout = t;
163 T_Real pxout = px;
164 T_Real pyout = py;
165
166 // intermediate quantities to be used below
167 T_Real const x2my2 = x*x - y*y;
168 T_Real const x2py2 = x*x + y*y;
169 T_Real const denominator = 1_prt - 9_prt*powi<2>(a)*powi<2>(x2my2);
170
171 // apply edge focusing (transverse phase space)
172 xout = x - a * (powi<3>(x) + 3_prt * x * powi<2>(y));
173 yout = y + a * (3_prt * powi<2>(x) * y + powi<3>(y));
174
175 pxout = (px + 3_prt*a*px*x2py2 - 6_prt*a*py*x*y) / denominator;
176 pyout = (py - 3_prt*a*py*x2py2 + 6_prt*a*px*x*y) / denominator;
177
178 // apply edge focusing (longitudinal phase space)
179 T_Real const f4 = a * ( pxout * (powi<3>(x) + 3_prt*x*powi<2>(y))
180 - pyout * (powi<3>(y) + 3_prt*y*powi<2>(x)) );
181 tout = t + f4 * (pt - 1_prt/m_beta) / powi<2>(delta1);
182
183 // update output values
184 x = xout;
185 y = yout;
186 t = tout;
187 px = pxout;
188 py = pyout;
189 }
190
192 using Thin::operator();
193
195 using LinearTransport::operator();
196
203 Map6x6
204 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
205 {
206 using namespace amrex::literals; // for _rt and _prt
207
208 // initialize linear map matrix elements
210
211 // apply the transverse rotation (roll) alignment error
212 return rotate_aligned_map(R);
213 }
214
216 int m_unit;
218
219 private:
220 // constants that are independent of the individually tracked particle,
221 // see: compute_constants() to refresh
225 };
226
227} // namespace impactx
228
230
231#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:223
ImpactXParticleContainer::ParticleType PType
Definition QuadEdge.H:42
amrex::ParticleReal m_k
Definition QuadEdge.H:215
int m_unit
quadrupole focusing strength
Definition QuadEdge.H:216
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:224
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_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 const &AMREX_RESTRICT pt, T_IdCpu const &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition QuadEdge.H:139
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition QuadEdge.H:204
amrex::ParticleReal m_g
+1 for entry, or -1 for exit
Definition QuadEdge.H:222
Location m_flag
unit specification for quad strength
Definition QuadEdge.H:217
Location
Definition QuadEdge.H:45
@ exit
for leading (entry) fringe field
Definition QuadEdge.H:47
@ entry
Definition QuadEdge.H:46
Definition alignment.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:179
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:263
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:39
Definition beamoptic.H:529
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