ImpactX
Loading...
Searching...
No Matches
Buncher.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_BUNCHER_H
11#define IMPACTX_BUNCHER_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 Buncher
33 : public mixin::Named,
34 public mixin::BeamOptic<Buncher>,
35 public mixin::LinearTransport<Buncher>,
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 = "Buncher";
45
56 amrex::ParticleReal V,
57 amrex::ParticleReal k,
58 amrex::ParticleReal dx = 0,
59 amrex::ParticleReal dy = 0,
60 amrex::ParticleReal rotation_degree = 0,
61 std::optional<std::string> name = std::nullopt
62 )
63 : Named(std::move(name)),
64 Alignment(dx, dy, rotation_degree),
65 m_V(V), m_k(k)
66 {
67 }
68
70 using BeamOptic::operator();
71
79 void compute_constants (RefPart const & refpart)
80 {
81 using namespace amrex::literals; // for _rt and _prt
83
84 Alignment::compute_constants(refpart);
85
86 // find beta*gamma^2
87 amrex::ParticleReal const betgam2 = powi<2>(refpart.pt) - 1.0_prt;
88
89 m_neg_kV = -m_k * m_V;
90 m_kV_r2bg2 = -m_neg_kV / (2.0_prt * betgam2);
91 }
92
107 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
110 T_Real & AMREX_RESTRICT x,
111 T_Real & AMREX_RESTRICT y,
112 T_Real & AMREX_RESTRICT t,
113 T_Real & AMREX_RESTRICT px,
114 T_Real & AMREX_RESTRICT py,
115 T_Real & AMREX_RESTRICT pt,
116 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
117 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
118 ) const
119 {
120 using namespace amrex::literals; // for _rt and _prt
121
122 // shift due to alignment errors of the element
123 shift_in(x, y, px, py);
124
125 // initialize output values of momenta
126 T_Real pxout = px;
127 T_Real pyout = py;
128 T_Real ptout = pt;
129
130 // advance position and momentum
131 pxout = px + m_kV_r2bg2 * x;
132 pyout = py + m_kV_r2bg2 * y;
133 ptout = pt + m_neg_kV * t;
134
135 // assign updated momenta
136 px = pxout;
137 py = pyout;
138 pt = ptout;
139
140 // undo shift due to alignment errors of the element
141 shift_out(x, y, px, py);
142 }
143
145 using Thin::operator();
146
148 using LinearTransport::operator();
149
156 Map6x6
157 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
158 {
159 using namespace amrex::literals; // for _rt and _prt
160 using amrex::Math::powi;
161
162 // find beta*gamma^2
163 amrex::ParticleReal const betgam2 = powi<2>(refpart.pt) - 1.0_prt;
164
165 amrex::ParticleReal const neg_kV = -m_k * m_V;
166 amrex::ParticleReal const kV_r2bg2 = -neg_kV / (2.0_prt * betgam2);
167
168 // initialize linear map matrix elements
170
171 // off-identity matrix elements
172 R(2,1) = kV_r2bg2;
173 R(4,3) = kV_r2bg2;
174 R(6,5) = neg_kV;
175
176 return R;
177 }
178
179 amrex::ParticleReal m_V;
180 amrex::ParticleReal m_k;
181
182 private:
183 // constants that are independent of the individually tracked particle,
184 // see: compute_constants() to refresh
185 amrex::ParticleReal m_neg_kV;
186 amrex::ParticleReal m_kV_r2bg2;
187 };
188
189} // namespace impactx
190
191#endif // IMPACTX_BUNCHER_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
constexpr T powi(T x) noexcept
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::ParticleReal pt
energy, normalized by rest energy
Definition ReferenceParticle.H:40
ImpactXParticleContainer::ParticleType PType
Definition Buncher.H:44
amrex::ParticleReal m_kV_r2bg2
-m_k*m_V
Definition Buncher.H:186
amrex::ParticleReal m_k
normalized (max) RF voltage drop.
Definition Buncher.H:180
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 Buncher.H:109
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition Buncher.H:157
static constexpr auto type
Definition Buncher.H:43
void compute_constants(RefPart const &refpart)
Definition Buncher.H:79
amrex::ParticleReal m_V
Definition Buncher.H:179
amrex::ParticleReal m_neg_kV
RF wavenumber in 1/m.
Definition Buncher.H:185
Buncher(amrex::ParticleReal V, amrex::ParticleReal k, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition Buncher.H:55
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