ImpactX
Loading...
Searching...
No Matches
PlaneXYRot.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: Chad Mitchell, Axel Huebl
8 * License: BSD-3-Clause-LBNL
9 */
10#ifndef IMPACTX_PLANE_XYROT_H
11#define IMPACTX_PLANE_XYROT_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 <ablastr/constant.H>
22
23#include <AMReX_Extension.H>
24#include <AMReX_Math.H>
25#include <AMReX_REAL.H>
26#include <AMReX_SIMD.H>
27
28#include <cmath>
29#include <stdexcept>
30
31namespace impactx::elements
32{
34 : public mixin::Named,
35 public mixin::BeamOptic<PlaneXYRot>,
36 public mixin::LinearTransport<PlaneXYRot>,
37 public mixin::Thin,
38 public mixin::Alignment,
40 // At least on Intel AVX512, there is a small overhead to vectorize this element, see
41 // https://github.com/BLAST-ImpactX/impactx/pull/1002
42 // public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
43 {
44 static constexpr auto type = "PlaneXYRot";
46
62 std::optional<std::string> name = DEFAULT_name
63 )
64 : Named(std::move(name)),
65 Alignment(dx, dy, rotation_degree),
66 m_phi(phi * degree2rad)
67 {
68 }
69
71 void reverse () { m_phi = -m_phi; }
72
74 using BeamOptic::operator();
75
83 void compute_constants (RefPart const & refpart)
84 {
85 Alignment::compute_constants(refpart);
86
87 // store sin(phi) and cos(phi)
88 auto const [sin_phi, cos_phi] = amrex::Math::sincos(m_phi);
89 m_sin_phi = sin_phi;
90 m_cos_phi = cos_phi;
91 }
92
107 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
110 T_Real & AMREX_RESTRICT x,
111 T_Real & AMREX_RESTRICT y,
112 [[maybe_unused]] T_Real const & AMREX_RESTRICT t,
113 T_Real & AMREX_RESTRICT px,
114 T_Real & AMREX_RESTRICT py,
115 [[maybe_unused]] T_Real const & AMREX_RESTRICT pt,
116 [[maybe_unused]] T_IdCpu const & AMREX_RESTRICT idcpu,
117 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
118 ) const
119 {
120 // initialize output values
121 T_Real xout = x;
122 T_Real yout = y;
123 // T_Real tout = t;
124 T_Real pxout = px;
125 T_Real pyout = py;
126 // T_Real ptout = pt;
127
128 // advance position and momentum
129 xout = x * m_cos_phi - y * m_sin_phi;
130 pxout = px * m_cos_phi - py * m_sin_phi;
131
132 yout = x * m_sin_phi + y * m_cos_phi;
133 pyout = px * m_sin_phi + py * m_cos_phi;
134
135 // tout = t;
136 // ptout = pt;
137
138 // assign updated values
139 x = xout;
140 y = yout;
141 // t = tout;
142 px = pxout;
143 py = pyout;
144 // pt = ptout;
145 }
146
148 using Thin::operator();
149
151 using LinearTransport::operator();
152
159 Map6x6
160 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
161 {
162 // store sin(phi) and cos(phi)
163 auto const [sin_phi, cos_phi] = amrex::Math::sincos(m_phi);
164
165 // assign linear map matrix elements
167 R(1,1) = cos_phi;
168 R(1,3) = -sin_phi;
169 R(2,2) = cos_phi;
170 R(2,4) = -sin_phi;
171 R(3,1) = sin_phi;
172 R(3,3) = cos_phi;
173 R(4,2) = sin_phi;
174 R(4,4) = cos_phi;
175
176 // apply the transverse rotation (roll) alignment error
177 return rotate_aligned_map(R);
178 }
179
181
182 private:
183 // constants that are independent of the individually tracked particle,
184 // see: compute_constants() to refresh
186 };
187
188} // namespace impactx
189
191
192#endif // IMPACTX_PLANE_XYROT_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
#define IMPACTX_PUSH_EXTERN_TEMPLATE(ElementType)
Definition PushAll.H:78
amrex_particle_real ParticleReal
__host__ __device__ std::pair< double, double > sincos(double x)
Definition All.H:55
@ 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:33
Definition PlaneXYRot.H:43
PlaneXYRot(amrex::ParticleReal phi, amrex::ParticleReal dx=DEFAULT_dx, amrex::ParticleReal dy=DEFAULT_dy, amrex::ParticleReal rotation_degree=DEFAULT_rotation_degree, std::optional< std::string > name=DEFAULT_name)
Definition PlaneXYRot.H:57
static constexpr auto type
Definition PlaneXYRot.H:44
amrex::ParticleReal m_sin_phi
angle of rotation (rad)
Definition PlaneXYRot.H:185
void compute_constants(RefPart const &refpart)
Definition PlaneXYRot.H:83
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition PlaneXYRot.H:160
void reverse()
Definition PlaneXYRot.H:71
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real const &AMREX_RESTRICT t, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py, T_Real const &AMREX_RESTRICT pt, T_IdCpu const &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition PlaneXYRot.H:109
ImpactXParticleContainer::ParticleType PType
Definition PlaneXYRot.H:45
amrex::ParticleReal m_phi
Definition PlaneXYRot.H:180
amrex::ParticleReal m_cos_phi
Definition PlaneXYRot.H:185
Definition alignment.H:29
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
static constexpr amrex::ParticleReal DEFAULT_dx
Definition alignment.H:33
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
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:43
static constexpr amrex::ParticleReal DEFAULT_rotation_degree
Definition alignment.H:35
Definition beamoptic.H:567
Definition lineartransport.H:50
Definition named.H:29
static constexpr std::nullopt_t DEFAULT_name
Definition named.H:30
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:59
AMREX_FORCE_INLINE std::string name() const
Definition named.H:124
Definition nofinalize.H:22
Definition thin.H:24