ImpactX
Loading...
Searching...
No Matches
alignment.H
Go to the documentation of this file.
1/* Copyright 2022-2026 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: Axel Huebl
8 * License: BSD-3-Clause-LBNL
9 */
10#ifndef IMPACTX_ELEMENTS_MIXIN_ALIGNMENT_H
11#define IMPACTX_ELEMENTS_MIXIN_ALIGNMENT_H
12
15
16#include <ablastr/constant.H>
17
18#include <AMReX_Math.H>
19#include <AMReX_Extension.H>
20#include <AMReX_REAL.H>
21#include <AMReX_SmallMatrix.H>
22
23
25{
28 struct Alignment
29 {
32
33 static constexpr amrex::ParticleReal DEFAULT_dx = 0;
34 static constexpr amrex::ParticleReal DEFAULT_dy = 0;
36
46 amrex::ParticleReal rotation_degree
47 )
48 : m_dx(dx), m_dy(dy), m_rotation(rotation_degree * degree2rad)
49 {
50 }
51
52 Alignment () = default;
53 Alignment (Alignment const &) = default;
54 Alignment& operator= (Alignment const &) = default;
55 Alignment (Alignment&&) = default;
56 Alignment& operator= (Alignment&& rhs) = default;
57
58 ~Alignment () = default;
59
67 void compute_constants ([[maybe_unused]] RefPart const & refpart)
68 {
69 auto const [sin_rotation, cos_rotation] = amrex::Math::sincos(m_rotation);
70 m_sin_rotation = sin_rotation;
71 m_cos_rotation = cos_rotation;
72 }
73
83 template<typename T_Real>
85 void shift_in (
86 T_Real & AMREX_RESTRICT x,
87 T_Real & AMREX_RESTRICT y,
88 T_Real & AMREX_RESTRICT px,
89 T_Real & AMREX_RESTRICT py
90 ) const
91 {
92 // position
93 T_Real const xc = x - m_dx;
94 T_Real const yc = y - m_dy;
95 x = xc * m_cos_rotation + yc * m_sin_rotation;
96 y = -xc * m_sin_rotation + yc * m_cos_rotation;
97
98 // momentum
99 T_Real const pxc = px;
100 T_Real const pyc = py;
101 px = pxc * m_cos_rotation + pyc * m_sin_rotation;
102 py = -pxc * m_sin_rotation + pyc * m_cos_rotation;
103 }
104
112 template<typename T_Real>
115 T_Real & AMREX_RESTRICT sx,
116 T_Real & AMREX_RESTRICT sy
117 ) const
118 {
119 T_Real const sxc = sx;
120 T_Real const syc = sy;
121 sx = sxc * m_cos_rotation + syc * m_sin_rotation;
122 sy = -sxc * m_sin_rotation + syc * m_cos_rotation;
123 }
124
134 template<typename T_Real>
137 T_Real & AMREX_RESTRICT x,
138 T_Real & AMREX_RESTRICT y,
139 T_Real & AMREX_RESTRICT px,
140 T_Real & AMREX_RESTRICT py
141 ) const
142 {
143 // position
144 T_Real const xc = x;
145 T_Real const yc = y;
146 x = xc * m_cos_rotation - yc * m_sin_rotation;
147 y = xc * m_sin_rotation + yc * m_cos_rotation;
148 x += m_dx;
149 y += m_dy;
150
151 // momentum
152 T_Real const pxc = px;
153 T_Real const pyc = py;
154 px = pxc * m_cos_rotation - pyc * m_sin_rotation;
155 py = pxc * m_sin_rotation + pyc * m_cos_rotation;
156 }
157
165 template<typename T_Real>
168 T_Real & AMREX_RESTRICT sx,
169 T_Real & AMREX_RESTRICT sy
170 ) const
171 {
172 T_Real const sxc = sx;
173 T_Real const syc = sy;
174 sx = sxc * m_cos_rotation - syc * m_sin_rotation;
175 sy = sxc * m_sin_rotation + syc * m_cos_rotation;
176 }
177
184 {
185 return m_dx;
186 }
187
194 {
195 return m_dy;
196 }
197
204 {
205 return m_rotation / degree2rad;
206 }
207
218 bool misaligned () const
219 {
220 return (m_dx != amrex::ParticleReal(0)) ||
221 (m_dy != amrex::ParticleReal(0)) ||
223 }
224
240 Map6x6
242 {
243 auto const [sin_rotation, cos_rotation] = amrex::Math::sincos(m_rotation);
244
246 A(1, 1) = cos_rotation; A(1, 3) = -sin_rotation;
247 A(3, 1) = sin_rotation; A(3, 3) = cos_rotation;
248 A(2, 2) = cos_rotation; A(2, 4) = -sin_rotation;
249 A(4, 2) = sin_rotation; A(4, 4) = cos_rotation;
250 return A;
251 }
252
266 Map6x6
267 rotate_aligned_map (Map6x6 const & R) const
268 {
269 if (m_rotation == amrex::ParticleReal(0)) { return R; }
270 Map6x6 const A = rotation_map();
271 return A * R * A.transpose();
272 }
273
277
278 private:
279 // constants that are independent of the individually tracked particle,
280 // see: compute_constants() to refresh
283 };
284
285} // namespace impactx::elements::mixin
286
287#endif // IMPACTX_ELEMENTS_MIXIN_ALIGNMENT_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
amrex_particle_real ParticleReal
__host__ __device__ std::pair< double, double > sincos(double x)
Definition alignment.H:25
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
__host__ __device__ SmallMatrix< T, NCols, NRows, ORDER, StartIndex > transpose() const
Definition ReferenceParticle.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void rotate_out(T_Real &AMREX_RESTRICT sx, T_Real &AMREX_RESTRICT sy) const
Definition alignment.H:167
amrex::ParticleReal m_dy
horizontal translation error [m]
Definition alignment.H:275
Alignment(Alignment &&)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void rotate_in(T_Real &AMREX_RESTRICT sx, T_Real &AMREX_RESTRICT sy) const
Definition alignment.H:114
amrex::ParticleReal m_sin_rotation
rotation error in the transverse plane [rad]
Definition alignment.H:281
amrex::ParticleReal m_cos_rotation
std::sin(m_rotation)
Definition alignment.H:282
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:136
void compute_constants(RefPart const &refpart)
Definition alignment.H:67
amrex::ParticleReal m_rotation
vertical translation error [m]
Definition alignment.H:276
static constexpr amrex::ParticleReal degree2rad
Definition alignment.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:193
static constexpr amrex::ParticleReal DEFAULT_dy
Definition alignment.H:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rotation() const
Definition alignment.H:203
static constexpr amrex::ParticleReal DEFAULT_dx
Definition alignment.H:33
amrex::ParticleReal m_dx
Definition alignment.H:274
Alignment(Alignment const &)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:183
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotate_aligned_map(Map6x6 const &R) const
Definition alignment.H:267
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool misaligned() const
Definition alignment.H:218
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:43
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotation_map() const
Definition alignment.H:241
static constexpr amrex::ParticleReal DEFAULT_rotation_degree
Definition alignment.H:35
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:85
Alignment & operator=(Alignment const &)=default