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
63 amrex::ParticleReal xkick,
64 amrex::ParticleReal ykick,
65 UnitSystem unit,
66 amrex::ParticleReal dx = 0,
67 amrex::ParticleReal dy = 0,
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
78 using BeamOptic::operator();
79
87 void compute_constants (RefPart const & refpart)
88 {
89 using namespace amrex::literals; // for _rt and _prt
90
91 Alignment::compute_constants(refpart);
92
93 // normalize quad units to MAD-X convention if needed
94 m_p_scale = m_unit == UnitSystem::Tm ? 1.0_prt / refpart.rigidity_Tm() : 1.0_prt;
95 }
96
111 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
114 T_Real & AMREX_RESTRICT x,
115 T_Real & AMREX_RESTRICT y,
116 T_Real & AMREX_RESTRICT t,
117 T_Real & AMREX_RESTRICT px,
118 T_Real & AMREX_RESTRICT py,
119 T_Real & AMREX_RESTRICT pt,
120 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
121 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
122 ) const
123 {
124 using namespace amrex::literals; // for _rt and _prt
125
126 // shift due to alignment errors of the element
127 shift_in(x, y, px, py);
128
129 // access position data
130 T_Real const xout = x;
131 T_Real const yout = y;
132 T_Real const tout = t;
133
134 // normalize quad units to MAD-X convention if needed
135 amrex::ParticleReal const dpx = m_xkick * m_p_scale;
136 amrex::ParticleReal const dpy = m_ykick * m_p_scale;
137
138 // initialize output values of momenta
139 T_Real pxout = px;
140 T_Real pyout = py;
141 T_Real ptout = pt;
142
143 // advance position and momentum
144 x = xout;
145 pxout = px + dpx;
146
147 y = yout;
148 pyout = py + dpy;
149
150 t = tout;
151 ptout = pt;
152
153 // assign updated momenta
154 px = pxout;
155 py = pyout;
156 pt = ptout;
157
158 // undo shift due to alignment errors of the element
159 shift_out(x, y, px, py);
160 }
161
163 using Thin::operator();
164
166 using LinearTransport::operator();
167
174 Map6x6
175 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
176 {
177 // an ideal kick does not affect the linear map
179
180 return R;
181 }
182
183 amrex::ParticleReal m_xkick;
184 amrex::ParticleReal m_ykick;
186
187 private:
188 // constants that are independent of the individually tracked particle,
189 // see: compute_constants() to refresh
190 amrex::ParticleReal m_p_scale; // either 1 or the inverse rigidity
191 };
192
193} // namespace impactx
194
195#endif // IMPACTX_KICKER_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
Definition All.H:54
@ 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 rigidity_Tm() const
Definition ReferenceParticle.H:203
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:87
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition Kicker.H:175
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:183
UnitSystem m_unit
vertical kick strength
Definition Kicker.H:185
amrex::ParticleReal m_ykick
horizontal kick strength
Definition Kicker.H:184
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:113
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:190
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 thin.H:24