ImpactX
Loading...
Searching...
No Matches
DipEdge.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_DIPEDGE_H
11#define IMPACTX_DIPEDGE_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 DipEdge
33 : public mixin::Named,
34 public mixin::BeamOptic<DipEdge>,
35 public mixin::LinearTransport<DipEdge>,
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 = "DipEdge";
45
65 amrex::ParticleReal psi,
66 amrex::ParticleReal rc,
67 amrex::ParticleReal g,
68 amrex::ParticleReal K2,
69 amrex::ParticleReal dx = 0,
70 amrex::ParticleReal dy = 0,
71 amrex::ParticleReal rotation_degree = 0,
72 std::optional<std::string> name = std::nullopt
73 )
74 : Named(std::move(name)),
75 Alignment(dx, dy, rotation_degree),
76 m_psi(psi), m_rc(rc), m_g(g), m_K2(K2)
77 {
78 }
79
81 using BeamOptic::operator();
82
90 void compute_constants ([[maybe_unused]] RefPart const & refpart)
91 {
92 using namespace amrex::literals; // for _rt and _prt
94
95 Alignment::compute_constants(refpart);
96
97 // edge focusing matrix elements (zero gap)
98 m_R21 = std::tan(m_psi) / m_rc;
99
100 // first-order effect of nonzero gap
101 auto const [sin_psi, cos_psi] = amrex::Math::sincos(m_psi);
102 amrex::ParticleReal const vf = (1.0_prt + powi<2>(sin_psi))
103 / powi<3>(cos_psi)
104 * m_g * m_K2 / powi<2>(m_rc);
105
106 m_R43 = vf - m_R21;
107 }
108
123 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
126 T_Real & AMREX_RESTRICT x,
127 T_Real & AMREX_RESTRICT y,
128 [[maybe_unused]] T_Real & AMREX_RESTRICT t,
129 T_Real & AMREX_RESTRICT px,
130 T_Real & AMREX_RESTRICT py,
131 [[maybe_unused]] T_Real & AMREX_RESTRICT pt,
132 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
133 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
134 ) const
135 {
136
137 using namespace amrex::literals; // for _rt and _prt
138
139 // shift due to alignment errors of the element
140 shift_in(x, y, px, py);
141
142 // apply edge focusing
143 px = px + m_R21 * x;
144 py = py + m_R43 * y;
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
162 Map6x6
163 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
164 {
165 using namespace amrex::literals; // for _rt and _prt
166 using amrex::Math::powi;
167
168 // initialize linear map matrix elements
170
171 // edge focusing matrix elements (zero gap)
172 amrex::ParticleReal const R21 = std::tan(m_psi) / m_rc;
173
174 // first-order effect of nonzero gap
175 auto const [sin_psi, cos_psi] = amrex::Math::sincos(m_psi);
176 amrex::ParticleReal const vf = (1.0_prt + powi<2>(sin_psi))
177 / powi<3>(cos_psi)
178 * m_g * m_K2 / powi<2>(m_rc);
179
180 amrex::ParticleReal const R43 = vf - R21;
181
182 // set non-identity matrix elements
183 R(2,1) = R21;
184 R(4,3) = R43;
185
186 return R;
187 }
188
189 amrex::ParticleReal m_psi;
190 amrex::ParticleReal m_rc;
191 amrex::ParticleReal m_g;
192 amrex::ParticleReal m_K2;
193
194 private:
195 // constants that are independent of the individually tracked particle,
196 // see: compute_constants() to refresh
197 amrex::ParticleReal m_R21, m_R43;
198 };
199
200} // namespace impactx
201
202#endif // IMPACTX_DIPEDGE_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
__host__ __device__ std::pair< double, double > sincos(double x)
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_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 DipEdge.H:125
static constexpr auto type
Definition DipEdge.H:43
amrex::ParticleReal m_g
bend radius in m
Definition DipEdge.H:191
amrex::ParticleReal m_R21
fringe field integral
Definition DipEdge.H:197
amrex::ParticleReal m_R43
Definition DipEdge.H:197
amrex::ParticleReal m_K2
gap parameter in m
Definition DipEdge.H:192
DipEdge(amrex::ParticleReal psi, amrex::ParticleReal rc, amrex::ParticleReal g, amrex::ParticleReal K2, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition DipEdge.H:64
void compute_constants(RefPart const &refpart)
Definition DipEdge.H:90
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition DipEdge.H:163
amrex::ParticleReal m_psi
Definition DipEdge.H:189
amrex::ParticleReal m_rc
pole face angle in rad
Definition DipEdge.H:190
ImpactXParticleContainer::ParticleType PType
Definition DipEdge.H:44
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