ImpactX
PRot.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_PROT_H
11 #define IMPACTX_PROT_H
12 
14 #include "mixin/beamoptic.H"
15 #include "mixin/thin.H"
16 #include "mixin/nofinalize.H"
17 
18 #include <ablastr/constant.H>
19 
20 #include <AMReX_Extension.H>
21 #include <AMReX_Math.H>
22 #include <AMReX_REAL.H>
23 
24 #include <cmath>
25 
26 
27 namespace impactx
28 {
29  struct PRot
30  : public elements::BeamOptic<PRot>,
31  public elements::Thin,
33  {
34  static constexpr auto name = "PRot";
36 
37  static constexpr amrex::ParticleReal degree2rad = ablastr::constant::math::pi / 180.0;
38 
47  PRot (
48  amrex::ParticleReal phi_in,
49  amrex::ParticleReal phi_out
50  )
51  : m_phi_in(phi_in * degree2rad), m_phi_out(phi_out * degree2rad)
52  {
53  }
54 
56  using BeamOptic::operator();
57 
72  amrex::ParticleReal & AMREX_RESTRICT x,
73  amrex::ParticleReal & AMREX_RESTRICT y,
74  amrex::ParticleReal & AMREX_RESTRICT t,
75  amrex::ParticleReal & AMREX_RESTRICT px,
76  amrex::ParticleReal & AMREX_RESTRICT py,
77  amrex::ParticleReal & AMREX_RESTRICT pt,
78  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
79  RefPart const & refpart
80  ) const
81  {
82  using namespace amrex::literals; // for _rt and _prt
83 
84  // access reference particle values to find beta:
85  amrex::ParticleReal const beta = refpart.beta();
86 
87  // intialize output values
88  amrex::ParticleReal xout = x;
89  amrex::ParticleReal yout = y;
90  amrex::ParticleReal tout = t;
91  amrex::ParticleReal pxout = px;
92  amrex::ParticleReal pyout = py;
93  amrex::ParticleReal ptout = pt;
94 
95  // store rotation angle and initial, final values of pz
96  amrex::ParticleReal const theta = m_phi_out - m_phi_in;
97  auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
98  auto const [sin_phi_in, cos_phi_in] = amrex::Math::sincos(m_phi_in);
99 
100  amrex::ParticleReal const pz = sqrt(1.0_prt - 2.0_prt*pt/beta
101  + pow(pt,2) - pow(py,2) - pow(px + sin_phi_in,2));
102  amrex::ParticleReal const pzf = pz*cos_theta - (px + sin_phi_in)*sin_theta;
103 
104  // advance position and momentum
105  xout = x*pz/pzf;
106  pxout = px*cos_theta + (pz - cos_phi_in)*sin_theta;
107 
108  yout = y + py*x*sin_theta/pzf;
109  pyout = py;
110 
111  tout = t - (pt - 1.0_prt/beta)*x*sin_theta/pzf;
112  ptout = pt;
113 
114  // assign updated values
115  x = xout;
116  y = yout;
117  t = tout;
118  px = pxout;
119  py = pyout;
120  pt = ptout;
121  }
122 
124  using Thin::operator();
125 
126  amrex::ParticleReal m_phi_in;
127  amrex::ParticleReal m_phi_out;
128  };
129 
130 } // namespace impactx
131 
132 #endif // IMPACTX_PROT_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)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Definition: ImpactX.cpp:33
@ t
fixed t as the independent variable
beta
Definition: PRot.H:33
PRot(amrex::ParticleReal phi_in, amrex::ParticleReal phi_out)
Definition: PRot.H:47
ImpactXParticleContainer::ParticleType PType
Definition: PRot.H:35
static constexpr amrex::ParticleReal degree2rad
Definition: PRot.H:37
static constexpr auto name
Definition: PRot.H:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT t, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py, amrex::ParticleReal &AMREX_RESTRICT pt, [[maybe_unused]] uint64_t &AMREX_RESTRICT idcpu, RefPart const &refpart) const
Definition: PRot.H:71
amrex::ParticleReal m_phi_out
normalized (max) RF voltage drop.
Definition: PRot.H:127
amrex::ParticleReal m_phi_in
Definition: PRot.H:126
Definition: ReferenceParticle.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition: ReferenceParticle.H:64
Definition: beamoptic.H:149
Definition: nofinalize.H:22
Definition: thin.H:24