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_REAL.H>
22 
23 #include <cmath>
24 
25 
26 namespace impactx
27 {
28  struct PRot
29  : public elements::BeamOptic<PRot>,
30  public elements::Thin,
32  {
33  static constexpr auto name = "PRot";
35 
36  static constexpr amrex::ParticleReal degree2rad = ablastr::constant::math::pi / 180.0;
37 
46  PRot( amrex::ParticleReal const phi_in, amrex::ParticleReal const phi_out )
47  : m_phi_in(phi_in * degree2rad), m_phi_out(phi_out * degree2rad)
48  {
49  }
50 
52  using BeamOptic::operator();
53 
65  PType& AMREX_RESTRICT p,
66  amrex::ParticleReal & AMREX_RESTRICT px,
67  amrex::ParticleReal & AMREX_RESTRICT py,
68  amrex::ParticleReal & AMREX_RESTRICT pt,
69  RefPart const & refpart) const {
70 
71  using namespace amrex::literals; // for _rt and _prt
72 
73  // access AoS data such as positions and cpu/id
74  amrex::ParticleReal const x = p.pos(RealAoS::x);
75  amrex::ParticleReal const y = p.pos(RealAoS::y);
76  amrex::ParticleReal const t = p.pos(RealAoS::t);
77 
78  // access reference particle values to find beta:
79  amrex::ParticleReal const beta = refpart.beta();
80 
81  // intialize output values of momenta
82  amrex::ParticleReal pxout = px;
83  amrex::ParticleReal pyout = py;
84  amrex::ParticleReal ptout = pt;
85 
86  // store rotation angle and initial, final values of pz
87  amrex::ParticleReal theta = m_phi_out - m_phi_in;
88  amrex::ParticleReal pz = sqrt(1.0_prt - 2.0_prt*pt/beta
89  + pow(pt,2) - pow(py,2) - pow(px + sin(m_phi_in),2));
90  amrex::ParticleReal pzf = pz*cos(theta) - (px +
91  sin(m_phi_in))*sin(theta);
92 
93  // advance position and momentum
94  p.pos(RealAoS::x) = x*pz/pzf;
95  pxout = px*cos(theta) + (pz - cos(m_phi_in))*sin(theta);
96 
97  p.pos(RealAoS::y) = y + py*x*sin(theta)/pzf;
98  pyout = py;
99 
100  p.pos(RealAoS::t) = t - (pt - 1.0_prt/beta)*x*sin(theta)/pzf;
101  ptout = pt;
102 
103  // assign updated momenta
104  px = pxout;
105  py = pyout;
106  pt = ptout;
107 
108  }
109 
111  using Thin::operator();
112 
113  private:
114  amrex::ParticleReal m_phi_in;
115  amrex::ParticleReal m_phi_out;
116  };
117 
118 } // namespace impactx
119 
120 #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 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:32
Definition: PRot.H:32
ImpactXParticleContainer::ParticleType PType
Definition: PRot.H:34
static constexpr amrex::ParticleReal degree2rad
Definition: PRot.H:36
static constexpr auto name
Definition: PRot.H:33
PRot(amrex::ParticleReal const phi_in, amrex::ParticleReal const phi_out)
Definition: PRot.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(PType &AMREX_RESTRICT p, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py, amrex::ParticleReal &AMREX_RESTRICT pt, RefPart const &refpart) const
Definition: PRot.H:64
amrex::ParticleReal m_phi_out
normalized (max) RF voltage drop.
Definition: PRot.H:115
amrex::ParticleReal m_phi_in
Definition: PRot.H:114
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:42
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:43
@ t
c * time-of-flight [m] (at fixed s)
Definition: ImpactXParticleContainer.H:44
Definition: ReferenceParticle.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition: ReferenceParticle.H:64
Definition: beamoptic.H:135
Definition: nofinalize.H:22
Definition: thin.H:24