ImpactX
Loading...
Searching...
No Matches
alignment.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: 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
42 amrex::ParticleReal rotation_degree
43 )
44 : m_dx(dx), m_dy(dy), m_rotation(rotation_degree * degree2rad)
45 {
46 }
47
48 Alignment () = default;
49 Alignment (Alignment const &) = default;
50 Alignment& operator= (Alignment const &) = default;
51 Alignment (Alignment&&) = default;
52 Alignment& operator= (Alignment&& rhs) = default;
53
54 ~Alignment () = default;
55
63 void compute_constants ([[maybe_unused]] RefPart const & refpart)
64 {
65 auto const [sin_rotation, cos_rotation] = amrex::Math::sincos(m_rotation);
66 m_sin_rotation = sin_rotation;
67 m_cos_rotation = cos_rotation;
68 }
69
79 template<typename T_Real>
81 void shift_in (
82 T_Real & AMREX_RESTRICT x,
83 T_Real & AMREX_RESTRICT y,
84 T_Real & AMREX_RESTRICT px,
85 T_Real & AMREX_RESTRICT py
86 ) const
87 {
88 // position
89 T_Real const xc = x - m_dx;
90 T_Real const yc = y - m_dy;
91 x = xc * m_cos_rotation + yc * m_sin_rotation;
92 y = -xc * m_sin_rotation + yc * m_cos_rotation;
93
94 // momentum
95 T_Real const pxc = px;
96 T_Real const pyc = py;
97 px = pxc * m_cos_rotation + pyc * m_sin_rotation;
98 py = -pxc * m_sin_rotation + pyc * m_cos_rotation;
99 }
100
108 template<typename T_Real>
111 T_Real & AMREX_RESTRICT sx,
112 T_Real & AMREX_RESTRICT sy
113 ) const
114 {
115 T_Real const sxc = sx;
116 T_Real const syc = sy;
117 sx = sxc * m_cos_rotation + syc * m_sin_rotation;
118 sy = -sxc * m_sin_rotation + syc * m_cos_rotation;
119 }
120
130 template<typename T_Real>
133 T_Real & AMREX_RESTRICT x,
134 T_Real & AMREX_RESTRICT y,
135 T_Real & AMREX_RESTRICT px,
136 T_Real & AMREX_RESTRICT py
137 ) const
138 {
139 // position
140 T_Real const xc = x;
141 T_Real const yc = y;
142 x = xc * m_cos_rotation - yc * m_sin_rotation;
143 y = xc * m_sin_rotation + yc * m_cos_rotation;
144 x += m_dx;
145 y += m_dy;
146
147 // momentum
148 T_Real const pxc = px;
149 T_Real const pyc = py;
150 px = pxc * m_cos_rotation - pyc * m_sin_rotation;
151 py = pxc * m_sin_rotation + pyc * m_cos_rotation;
152 }
153
161 template<typename T_Real>
164 T_Real & AMREX_RESTRICT sx,
165 T_Real & AMREX_RESTRICT sy
166 ) const
167 {
168 T_Real const sxc = sx;
169 T_Real const syc = sy;
170 sx = sxc * m_cos_rotation - syc * m_sin_rotation;
171 sy = sxc * m_sin_rotation + syc * m_cos_rotation;
172 }
173
180 {
181 return m_dx;
182 }
183
190 {
191 return m_dy;
192 }
193
200 {
201 return m_rotation / degree2rad;
202 }
203
214 bool misaligned () const
215 {
216 return (m_dx != amrex::ParticleReal(0)) ||
217 (m_dy != amrex::ParticleReal(0)) ||
219 }
220
236 Map6x6
238 {
239 auto const [sin_rotation, cos_rotation] = amrex::Math::sincos(m_rotation);
240
242 A(1, 1) = cos_rotation; A(1, 3) = -sin_rotation;
243 A(3, 1) = sin_rotation; A(3, 3) = cos_rotation;
244 A(2, 2) = cos_rotation; A(2, 4) = -sin_rotation;
245 A(4, 2) = sin_rotation; A(4, 4) = cos_rotation;
246 return A;
247 }
248
262 Map6x6
263 rotate_aligned_map (Map6x6 const & R) const
264 {
265 if (m_rotation == amrex::ParticleReal(0)) { return R; }
266 Map6x6 const A = rotation_map();
267 return A * R * A.transpose();
268 }
269
273
274 private:
275 // constants that are independent of the individually tracked particle,
276 // see: compute_constants() to refresh
279 };
280
281} // namespace impactx::elements::mixin
282
283#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:163
amrex::ParticleReal m_dy
horizontal translation error [m]
Definition alignment.H:271
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:110
amrex::ParticleReal m_sin_rotation
rotation error in the transverse plane [rad]
Definition alignment.H:277
amrex::ParticleReal m_cos_rotation
std::sin(m_rotation)
Definition alignment.H:278
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:132
void compute_constants(RefPart const &refpart)
Definition alignment.H:63
amrex::ParticleReal m_rotation
vertical translation error [m]
Definition alignment.H:272
static constexpr amrex::ParticleReal degree2rad
Definition alignment.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rotation() const
Definition alignment.H:199
amrex::ParticleReal m_dx
Definition alignment.H:270
Alignment(Alignment const &)=default
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool misaligned() const
Definition alignment.H:214
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:39
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 rotation_map() const
Definition alignment.H:237
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:81
Alignment & operator=(Alignment const &)=default