ImpactX
Loading...
Searching...
No Matches
Kicker.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_KICKER_H
11#define IMPACTX_KICKER_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_REAL.H>
23#include <AMReX_SIMD.H>
24
25#include <cmath>
26#include <stdexcept>
27
28
29namespace impactx::elements
30{
31 struct Kicker
32 : public mixin::Named,
33 public mixin::BeamOptic<Kicker>,
34 public mixin::LinearTransport<Kicker>,
35 public mixin::Thin,
36 public mixin::Alignment,
38 // At least on Intel AVX512, there is a small overhead to vectorize this element, see
39 // https://github.com/BLAST-ImpactX/impactx/pull/1002
40 // public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
41 {
42 static constexpr auto type = "Kicker";
44
46 {
48 Tm = 1
49 };
50
65 UnitSystem unit,
68 amrex::ParticleReal rotation_degree = 0,
69 std::optional<std::string> name = std::nullopt
70 )
71 : Named(std::move(name)),
72 Alignment(dx, dy, rotation_degree),
73 m_xkick(xkick), m_ykick(ykick), m_unit(unit)
74 {
75 }
76
79
81 using BeamOptic::operator();
82
90 void compute_constants (RefPart const & refpart)
91 {
92 using namespace amrex::literals; // for _rt and _prt
93
94 Alignment::compute_constants(refpart);
95
96 // normalize quad units to MAD-X convention if needed
97 m_p_scale = m_unit == UnitSystem::Tm ? 1.0_prt / refpart.rigidity_Tm() : 1.0_prt;
98 }
99
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 [[maybe_unused]] 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 // access position data
133 T_Real const xout = x;
134 T_Real const yout = y;
135 T_Real const tout = t;
136
137 // normalize quad units to MAD-X convention if needed
140
141 // initialize output values of momenta
142 T_Real pxout = px;
143 T_Real pyout = py;
144 T_Real ptout = pt;
145
146 // advance position and momentum
147 x = xout;
148 pxout = px + dpx;
149
150 y = yout;
151 pyout = py + dpy;
152
153 t = tout;
154 ptout = pt;
155
156 // assign updated momenta
157 px = pxout;
158 py = pyout;
159 pt = ptout;
160
161 // undo shift due to alignment errors of the element
162 shift_out(x, y, px, py);
163 }
164
166 using Thin::operator();
167
169 using LinearTransport::operator();
170
177 Map6x6
178 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
179 {
180 // an ideal kick does not affect the linear map
182
183 return R;
184 }
185
189
190 private:
191 // constants that are independent of the individually tracked particle,
192 // see: compute_constants() to refresh
193 amrex::ParticleReal m_p_scale; // either 1 or the inverse rigidity
194 };
195
196} // namespace impactx
197
199
200#endif // IMPACTX_KICKER_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
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rigidity_Tm() const
Definition ReferenceParticle.H:261
Definition Kicker.H:41
Kicker(amrex::ParticleReal xkick, amrex::ParticleReal ykick, UnitSystem unit, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition Kicker.H:62
void compute_constants(RefPart const &refpart)
Definition Kicker.H:90
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition Kicker.H:178
void reverse()
Definition Kicker.H:78
UnitSystem
Definition Kicker.H:46
@ Tm
in units of the magnetic rigidity of the reference particle
Definition Kicker.H:48
@ dimensionless
Definition Kicker.H:47
ImpactXParticleContainer::ParticleType PType
Definition Kicker.H:43
amrex::ParticleReal m_xkick
Definition Kicker.H:186
UnitSystem m_unit
vertical kick strength
Definition Kicker.H:188
amrex::ParticleReal m_ykick
horizontal kick strength
Definition Kicker.H:187
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 Kicker.H:116
static constexpr auto type
Definition Kicker.H:42
amrex::ParticleReal m_p_scale
Kicks are for 0 dimensionless, or for 1 in T-m.".
Definition Kicker.H:193
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