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 [[maybe_unused]] T_Real const & AMREX_RESTRICT x,
118 [[maybe_unused]] T_Real const & AMREX_RESTRICT y,
119 [[maybe_unused]] T_Real const & AMREX_RESTRICT t,
120 T_Real & AMREX_RESTRICT px,
121 T_Real & AMREX_RESTRICT py,
122 [[maybe_unused]] T_Real const & AMREX_RESTRICT pt,
123 [[maybe_unused]] T_IdCpu const & 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 // 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
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
160 using Thin::operator();
161
163 using LinearTransport::operator();
164
171 Map6x6
172 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
173 {
174 // an ideal kick does not affect the linear map
176
177 // apply the transverse rotation (roll) alignment error
178 return rotate_aligned_map(R);
179 }
180
184
185 private:
186 // constants that are independent of the individually tracked particle,
187 // see: compute_constants() to refresh
188 amrex::ParticleReal m_p_scale; // either 1 or the inverse rigidity
189 };
190
191} // namespace impactx
192
194
195#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:260
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T_Real const &AMREX_RESTRICT x, T_Real const &AMREX_RESTRICT y, T_Real const &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 Kicker.H:116
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:172
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:181
UnitSystem m_unit
vertical kick strength
Definition Kicker.H:183
amrex::ParticleReal m_ykick
horizontal kick strength
Definition Kicker.H:182
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:188
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