ImpactX
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 
61  void shift_in (
62  amrex::ParticleReal & AMREX_RESTRICT x,
63  amrex::ParticleReal & AMREX_RESTRICT y,
64  amrex::ParticleReal & AMREX_RESTRICT px,
65  amrex::ParticleReal & AMREX_RESTRICT py
66  ) const
67  {
68  auto const [sin_rotation, cos_rotation] = amrex::Math::sincos(m_rotation);
69 
70  // position
71  amrex::ParticleReal const xc = x - m_dx;
72  amrex::ParticleReal const yc = y - m_dy;
73  x = xc * cos_rotation + yc * sin_rotation;
74  y = -xc * sin_rotation + yc * cos_rotation;
75 
76  // momentum
77  amrex::ParticleReal const pxc = px;
78  amrex::ParticleReal const pyc = py;
79  px = pxc * cos_rotation + pyc * sin_rotation;
80  py = -pxc * sin_rotation + pyc * cos_rotation;
81  }
82 
91  void shift_out (
92  amrex::ParticleReal & AMREX_RESTRICT x,
93  amrex::ParticleReal & AMREX_RESTRICT y,
94  amrex::ParticleReal & AMREX_RESTRICT px,
95  amrex::ParticleReal & AMREX_RESTRICT py
96  ) const
97  {
98  auto const [sin_rotation, cos_rotation] = amrex::Math::sincos(m_rotation);
99 
100  // position
101  amrex::ParticleReal const xc = x;
102  amrex::ParticleReal const yc = y;
103  x = xc * cos_rotation - yc * sin_rotation;
104  y = xc * sin_rotation + yc * cos_rotation;
105  x += m_dx;
106  y += m_dy;
107 
108  // momentum
109  amrex::ParticleReal const pxc = px;
110  amrex::ParticleReal const pyc = py;
111  px = pxc * cos_rotation - pyc * sin_rotation;
112  py = pxc * sin_rotation + pyc * cos_rotation;
113  }
114 
120  amrex::ParticleReal dx () const
121  {
122  return m_dx;
123  }
124 
130  amrex::ParticleReal dy () const
131  {
132  return m_dy;
133  }
134 
140  amrex::ParticleReal rotation () const
141  {
142  return m_rotation / degree2rad;
143  }
144 
145  amrex::ParticleReal m_dx = 0;
146  amrex::ParticleReal m_dy = 0;
147  amrex::ParticleReal m_rotation = 0;
148  };
149 
150 } // namespace impactx::elements
151 
152 #endif // IMPACTX_ELEMENTS_MIXIN_ALIGNMENT_H
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
static constexpr amrex::Real pi
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::pair< double, double > sincos(double x)
Definition: alignment.H:23
Definition: alignment.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_out(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py) const
Definition: alignment.H:91
Alignment(Alignment &&)=default
Alignment & operator=(Alignment const &)=default
amrex::ParticleReal m_dx
Definition: alignment.H:145
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition: alignment.H:120
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal rotation() const
Definition: alignment.H:140
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_in(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py) const
Definition: alignment.H:61
Alignment(Alignment const &)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition: alignment.H:130
static constexpr amrex::ParticleReal degree2rad
Definition: alignment.H:28
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition: alignment.H:36
amrex::ParticleReal m_rotation
vertical translation error [m]
Definition: alignment.H:147
amrex::ParticleReal m_dy
horizontal translation error [m]
Definition: alignment.H:146