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
14
15#include <ablastr/constant.H>
16
17#include <AMReX_Math.H>
18#include <AMReX_Extension.H>
19#include <AMReX_REAL.H>
20
21
23{
26 struct Alignment
27 {
28 static constexpr amrex::ParticleReal degree2rad = ablastr::constant::math::pi / 180.0;
29
37 amrex::ParticleReal dx,
38 amrex::ParticleReal dy,
39 amrex::ParticleReal rotation_degree
40 )
41 : m_dx(dx), m_dy(dy), m_rotation(rotation_degree * degree2rad)
42 {
43 }
44
45 Alignment () = default;
46 Alignment (Alignment const &) = default;
47 Alignment& operator= (Alignment const &) = default;
48 Alignment (Alignment&&) = default;
49 Alignment& operator= (Alignment&& rhs) = default;
50
51 ~Alignment () = default;
52
60 void compute_constants ([[maybe_unused]] RefPart const & refpart)
61 {
62 auto const [sin_rotation, cos_rotation] = amrex::Math::sincos(m_rotation);
63 m_sin_rotation = sin_rotation;
64 m_cos_rotation = cos_rotation;
65 }
66
76 template<typename T_Real>
78 void shift_in (
79 T_Real & AMREX_RESTRICT x,
80 T_Real & AMREX_RESTRICT y,
81 T_Real & AMREX_RESTRICT px,
82 T_Real & AMREX_RESTRICT py
83 ) const
84 {
85 // position
86 T_Real const xc = x - m_dx;
87 T_Real const yc = y - m_dy;
88 x = xc * m_cos_rotation + yc * m_sin_rotation;
89 y = -xc * m_sin_rotation + yc * m_cos_rotation;
90
91 // momentum
92 T_Real const pxc = px;
93 T_Real const pyc = py;
94 px = pxc * m_cos_rotation + pyc * m_sin_rotation;
95 py = -pxc * m_sin_rotation + pyc * m_cos_rotation;
96 }
97
107 template<typename T_Real>
110 T_Real & AMREX_RESTRICT x,
111 T_Real & AMREX_RESTRICT y,
112 T_Real & AMREX_RESTRICT px,
113 T_Real & AMREX_RESTRICT py
114 ) const
115 {
116 // position
117 T_Real const xc = x;
118 T_Real const yc = y;
119 x = xc * m_cos_rotation - yc * m_sin_rotation;
120 y = xc * m_sin_rotation + yc * m_cos_rotation;
121 x += m_dx;
122 y += m_dy;
123
124 // momentum
125 T_Real const pxc = px;
126 T_Real const pyc = py;
127 px = pxc * m_cos_rotation - pyc * m_sin_rotation;
128 py = pxc * m_sin_rotation + pyc * m_cos_rotation;
129 }
130
136 amrex::ParticleReal dx () const
137 {
138 return m_dx;
139 }
140
146 amrex::ParticleReal dy () const
147 {
148 return m_dy;
149 }
150
156 amrex::ParticleReal rotation () const
157 {
158 return m_rotation / degree2rad;
159 }
160
161 amrex::ParticleReal m_dx = 0;
162 amrex::ParticleReal m_dy = 0;
163 amrex::ParticleReal m_rotation = 0;
164
165 private:
166 // constants that are independent of the individually tracked particle,
167 // see: compute_constants() to refresh
168 amrex::ParticleReal m_sin_rotation;
169 amrex::ParticleReal m_cos_rotation;
170 };
171
172} // namespace impactx::elements::mixin
173
174#endif // IMPACTX_ELEMENTS_MIXIN_ALIGNMENT_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
static constexpr amrex::Real pi
__host__ __device__ std::pair< double, double > sincos(double x)
Definition alignment.H:23
Definition ReferenceParticle.H:31
amrex::ParticleReal m_dy
horizontal translation error [m]
Definition alignment.H:162
Alignment(Alignment &&)=default
amrex::ParticleReal m_sin_rotation
rotation error in the transverse plane [rad]
Definition alignment.H:168
amrex::ParticleReal m_cos_rotation
std::sin(m_rotation)
Definition alignment.H:169
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
void compute_constants(RefPart const &refpart)
Definition alignment.H:60
amrex::ParticleReal m_rotation
vertical translation error [m]
Definition alignment.H:163
static constexpr amrex::ParticleReal degree2rad
Definition alignment.H:28
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:146
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rotation() const
Definition alignment.H:156
amrex::ParticleReal m_dx
Definition alignment.H:161
Alignment(Alignment const &)=default
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
Alignment & operator=(Alignment const &)=default