ImpactX
Loading...
Searching...
No Matches
TaperedPL.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_TAPEREDPL_H
11#define IMPACTX_TAPEREDPL_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 TaperedPL
33 : public mixin::Named,
34 public mixin::BeamOptic<TaperedPL>,
35 public mixin::LinearTransport<TaperedPL>,
36 public mixin::Thin,
37 public mixin::Alignment,
39 // At least on Intel AVX512, there is a small overhead to vectorize this element, see
40 // https://github.com/BLAST-ImpactX/impactx/pull/1002
41 // public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
42 {
43 static constexpr auto type = "TaperedPL";
45
64 int unit,
67 amrex::ParticleReal rotation_degree = 0,
68 std::optional<std::string> name = std::nullopt
69 )
70 : Named(std::move(name)),
71 Alignment(dx, dy, rotation_degree),
72 m_k(k), m_taper(taper), m_unit(unit)
73 {
74 }
75
77 void reverse () { m_k = -m_k; }
78
80 using BeamOptic::operator();
81
94 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
97 T_Real & AMREX_RESTRICT x,
98 T_Real & AMREX_RESTRICT y,
99 T_Real & AMREX_RESTRICT t,
100 T_Real & AMREX_RESTRICT px,
101 T_Real & AMREX_RESTRICT py,
102 T_Real & AMREX_RESTRICT pt,
103 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
104 RefPart const & AMREX_RESTRICT refpart
105 ) const
106 {
107 using namespace amrex::literals; // for _rt and _prt
108 using amrex::Math::powi;
109 using namespace std; // for cmath(float)
110
111 // shift due to alignment errors of the element
112 shift_in(x, y, px, py);
113
114 // normalize focusing strength units to MAD-X convention if needed
116 if (m_unit == 1) {
117 g = m_k / refpart.rigidity_Tm();
118 }
119
120 // initialize output values
121 T_Real xout = x;
122 T_Real yout = y;
123 T_Real tout = t;
124 T_Real pxout = px;
125 T_Real pyout = py;
126 T_Real ptout = pt;
127
128 // advance position and momentum
129 xout = x;
130 pxout = px - g * ( x + m_taper*0.5_prt * (powi<2>(x) + powi<2>(y)) );
131
132 yout = y;
133 pyout = py - g * ( y + m_taper * x * y );
134
135 tout = t;
136 ptout = pt;
137
138 // assign updated values
139 x = xout;
140 y = yout;
141 t = tout;
142 px = pxout;
143 py = pyout;
144 pt = ptout;
145
146 // undo shift due to alignment errors of the element
147 shift_out(x, y, px, py);
148 }
149
151 using Thin::operator();
152
154 using LinearTransport::operator();
155
190 Map6x6
191 transport_map (RefPart const & AMREX_RESTRICT refpart) const
192 {
193 using namespace amrex::literals; // for _rt and _prt
194
195 // Normalize focusing strength to MAD-X convention if needed.
196 amrex::ParticleReal const g = (m_unit == 1)
197 ? m_k / refpart.rigidity_Tm()
198 : m_k;
199
200 // Linearized axisymmetric focusing kick; taper is quadratic
201 // and therefore absent from the linear map.
203 R(2,1) = -g;
204 R(4,3) = -g;
205
206 return R;
207 }
208
211 int m_unit;
212 };
213
214} // namespace impactx
215
217
218#endif // IMPACTX_TAPEREDPL_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
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 TaperedPL.H:42
amrex::ParticleReal m_k
Definition TaperedPL.H:209
static constexpr auto type
Definition TaperedPL.H:43
ImpactXParticleContainer::ParticleType PType
Definition TaperedPL.H:44
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition TaperedPL.H:191
TaperedPL(amrex::ParticleReal k, amrex::ParticleReal taper, int unit, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition TaperedPL.H:61
void reverse()
Definition TaperedPL.H:77
amrex::ParticleReal m_taper
linear focusing strength (field gradient)
Definition TaperedPL.H:210
int m_unit
horizontal taper parameter
Definition TaperedPL.H:211
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 TaperedPL.H:96
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