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
49
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 void reverse () { m_phi = -m_phi; }
75
77 using BeamOptic::operator();
78
86 void compute_constants (RefPart const & refpart)
87 {
88 Alignment::compute_constants(refpart);
89
90 // store sin(phi) and cos(phi)
91 auto const [sin_phi, cos_phi] = amrex::Math::sincos(m_phi);
92 m_sin_phi = sin_phi;
93 m_cos_phi = cos_phi;
94 }
95
110 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
113 T_Real & AMREX_RESTRICT x,
114 T_Real & AMREX_RESTRICT y,
115 T_Real & AMREX_RESTRICT t,
116 T_Real & AMREX_RESTRICT px,
117 T_Real & AMREX_RESTRICT py,
118 T_Real & AMREX_RESTRICT pt,
119 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
120 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
121 ) const
122 {
123 // shift due to alignment errors of the element
124 shift_in(x, y, px, py);
125
126 // initialize output values
127 T_Real xout = x;
128 T_Real yout = y;
129 T_Real tout = t;
130 T_Real pxout = px;
131 T_Real pyout = py;
132 T_Real ptout = pt;
133
134 // advance position and momentum
135 xout = x * m_cos_phi - y * m_sin_phi;
136 pxout = px * m_cos_phi - py * m_sin_phi;
137
138 yout = x * m_sin_phi + y * m_cos_phi;
139 pyout = px * m_sin_phi + py * m_cos_phi;
140
141 // tout = t;
142 // ptout = pt;
143
144 // assign updated values
145 x = xout;
146 y = yout;
147 t = tout;
148 px = pxout;
149 py = pyout;
150 pt = ptout;
151
152 // undo shift due to alignment errors of the element
153 shift_out(x, y, px, py);
154 }
155
157 using Thin::operator();
158
160 using LinearTransport::operator();
161
168 Map6x6
169 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
170 {
171 // store sin(phi) and cos(phi)
172 auto const [sin_phi, cos_phi] = amrex::Math::sincos(m_phi);
173
174 // assign linear map matrix elements
176 R(1,1) = cos_phi;
177 R(1,3) = -sin_phi;
178 R(2,2) = cos_phi;
179 R(2,4) = -sin_phi;
180 R(3,1) = sin_phi;
181 R(3,3) = cos_phi;
182 R(4,2) = sin_phi;
183 R(4,4) = cos_phi;
184
185 return R;
186 }
187
189
190 private:
191 // constants that are independent of the individually tracked particle,
192 // see: compute_constants() to refresh
194 };
195
196} // namespace impactx
197
199
200#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:60
static constexpr auto type
Definition PlaneXYRot.H:45
amrex::ParticleReal m_sin_phi
angle of rotation (rad)
Definition PlaneXYRot.H:193
void compute_constants(RefPart const &refpart)
Definition PlaneXYRot.H:86
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:112
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition PlaneXYRot.H:169
void reverse()
Definition PlaneXYRot.H:74
ImpactXParticleContainer::ParticleType PType
Definition PlaneXYRot.H:46
amrex::ParticleReal m_phi
Definition PlaneXYRot.H:188
amrex::ParticleReal m_cos_phi
Definition PlaneXYRot.H:193
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:436
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