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
48 static constexpr amrex::ParticleReal degree2rad = ablastr::constant::math::pi / 180.0;
49
61 amrex::ParticleReal phi,
62 amrex::ParticleReal dx = 0,
63 amrex::ParticleReal dy = 0,
64 amrex::ParticleReal rotation_degree = 0,
65 std::optional<std::string> name = std::nullopt
66 )
67 : Named(std::move(name)),
68 Alignment(dx, dy, rotation_degree),
69 m_phi(phi * degree2rad)
70 {
71 }
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 T_Real & AMREX_RESTRICT t,
113 T_Real & AMREX_RESTRICT px,
114 T_Real & AMREX_RESTRICT py,
115 T_Real & AMREX_RESTRICT pt,
116 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
117 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
118 ) const
119 {
120 // shift due to alignment errors of the element
121 shift_in(x, y, px, py);
122
123 // initialize output values
124 T_Real xout = x;
125 T_Real yout = y;
126 T_Real tout = t;
127 T_Real pxout = px;
128 T_Real pyout = py;
129 T_Real ptout = pt;
130
131 // advance position and momentum
132 xout = x * m_cos_phi - y * m_sin_phi;
133 pxout = px * m_cos_phi - py * m_sin_phi;
134
135 yout = x * m_sin_phi + y * m_cos_phi;
136 pyout = px * m_sin_phi + py * m_cos_phi;
137
138 // tout = t;
139 // ptout = pt;
140
141 // assign updated values
142 x = xout;
143 y = yout;
144 t = tout;
145 px = pxout;
146 py = pyout;
147 pt = ptout;
148
149 // undo shift due to alignment errors of the element
150 shift_out(x, y, px, py);
151 }
152
154 using Thin::operator();
155
157 using LinearTransport::operator();
158
165 Map6x6
166 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
167 {
168 // store sin(phi) and cos(phi)
169 auto const [sin_phi, cos_phi] = amrex::Math::sincos(m_phi);
170
171 // assign linear map matrix elements
173 R(1,1) = cos_phi;
174 R(1,3) = -sin_phi;
175 R(2,2) = cos_phi;
176 R(2,4) = -sin_phi;
177 R(3,1) = sin_phi;
178 R(3,3) = cos_phi;
179 R(4,2) = sin_phi;
180 R(4,4) = cos_phi;
181
182 return R;
183 }
184
185 amrex::ParticleReal m_phi;
186
187 private:
188 // constants that are independent of the individually tracked particle,
189 // see: compute_constants() to refresh
190 amrex::ParticleReal m_sin_phi, m_cos_phi;
191 };
192
193} // namespace impactx
194
195#endif // IMPACTX_PLANE_XYROT_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
static constexpr amrex::Real pi
__host__ __device__ std::pair< double, double > sincos(double x)
Definition All.H:54
@ 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:31
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:60
static constexpr auto type
Definition PlaneXYRot.H:45
amrex::ParticleReal m_sin_phi
angle of rotation (rad)
Definition PlaneXYRot.H:190
void compute_constants(RefPart const &refpart)
Definition PlaneXYRot.H:83
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT t, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py, T_Real &AMREX_RESTRICT pt, T_IdCpu &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition PlaneXYRot.H:109
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition PlaneXYRot.H:166
ImpactXParticleContainer::ParticleType PType
Definition PlaneXYRot.H:46
amrex::ParticleReal m_phi
Definition PlaneXYRot.H:185
amrex::ParticleReal m_cos_phi
Definition PlaneXYRot.H:190
static constexpr amrex::ParticleReal degree2rad
Definition PlaneXYRot.H:48
Definition alignment.H:27
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:146
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
Definition beamoptic.H:219
Definition lineartransport.H:29
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