ImpactX
Loading...
Searching...
No Matches
PlaneXYRot.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: 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
31
32namespace impactx::elements
33{
35 : public mixin::Named,
36 public mixin::BeamOptic<PlaneXYRot>,
37 public mixin::LinearTransport<PlaneXYRot>,
38 public mixin::Thin,
39 public mixin::Alignment,
41 // At least on Intel AVX512, there is a small overhead to vectorize this element, see
42 // https://github.com/BLAST-ImpactX/impactx/pull/1002
43 // public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
44 {
45 static constexpr auto type = "PlaneXYRot";
47
62 amrex::ParticleReal rotation_degree = 0,
63 std::optional<std::string> name = std::nullopt
64 )
65 : Named(std::move(name)),
66 Alignment(dx, dy, rotation_degree),
67 m_phi(phi * degree2rad)
68 {
69 }
70
72 void reverse () { m_phi = -m_phi; }
73
75 using BeamOptic::operator();
76
84 void compute_constants (RefPart const & refpart)
85 {
86 Alignment::compute_constants(refpart);
87
88 // store sin(phi) and cos(phi)
89 auto const [sin_phi, cos_phi] = amrex::Math::sincos(m_phi);
90 m_sin_phi = sin_phi;
91 m_cos_phi = cos_phi;
92 }
93
108 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
111 T_Real & AMREX_RESTRICT x,
112 T_Real & AMREX_RESTRICT y,
113 [[maybe_unused]] T_Real const & AMREX_RESTRICT t,
114 T_Real & AMREX_RESTRICT px,
115 T_Real & AMREX_RESTRICT py,
116 [[maybe_unused]] T_Real const & AMREX_RESTRICT pt,
117 [[maybe_unused]] T_IdCpu const & AMREX_RESTRICT idcpu,
118 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
119 ) const
120 {
121 // initialize output values
122 T_Real xout = x;
123 T_Real yout = y;
124 // T_Real tout = t;
125 T_Real pxout = px;
126 T_Real pyout = py;
127 // T_Real ptout = pt;
128
129 // advance position and momentum
130 xout = x * m_cos_phi - y * m_sin_phi;
131 pxout = px * m_cos_phi - py * m_sin_phi;
132
133 yout = x * m_sin_phi + y * m_cos_phi;
134 pyout = px * m_sin_phi + py * m_cos_phi;
135
136 // tout = t;
137 // ptout = pt;
138
139 // assign updated values
140 x = xout;
141 y = yout;
142 // t = tout;
143 px = pxout;
144 py = pyout;
145 // pt = ptout;
146 }
147
149 using Thin::operator();
150
152 using LinearTransport::operator();
153
160 Map6x6
161 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
162 {
163 // store sin(phi) and cos(phi)
164 auto const [sin_phi, cos_phi] = amrex::Math::sincos(m_phi);
165
166 // assign linear map matrix elements
168 R(1,1) = cos_phi;
169 R(1,3) = -sin_phi;
170 R(2,2) = cos_phi;
171 R(2,4) = -sin_phi;
172 R(3,1) = sin_phi;
173 R(3,3) = cos_phi;
174 R(4,2) = sin_phi;
175 R(4,4) = cos_phi;
176
177 // apply the transverse rotation (roll) alignment error
178 return rotate_aligned_map(R);
179 }
180
182
183 private:
184 // constants that are independent of the individually tracked particle,
185 // see: compute_constants() to refresh
187 };
188
189} // namespace impactx
190
192
193#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:56
@ 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:44
PlaneXYRot(amrex::ParticleReal phi, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition PlaneXYRot.H:58
static constexpr auto type
Definition PlaneXYRot.H:45
amrex::ParticleReal m_sin_phi
angle of rotation (rad)
Definition PlaneXYRot.H:186
void compute_constants(RefPart const &refpart)
Definition PlaneXYRot.H:84
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition PlaneXYRot.H:161
void reverse()
Definition PlaneXYRot.H:72
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:110
ImpactXParticleContainer::ParticleType PType
Definition PlaneXYRot.H:46
amrex::ParticleReal m_phi
Definition PlaneXYRot.H:181
amrex::ParticleReal m_cos_phi
Definition PlaneXYRot.H:186
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:189
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
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:39
Definition beamoptic.H:529
Definition lineartransport.H:50
Definition named.H:29
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:57
AMREX_FORCE_INLINE std::string name() const
Definition named.H:122
Definition nofinalize.H:22
Definition thin.H:24