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 
69  PType & AMREX_RESTRICT p,
70  amrex::ParticleReal & AMREX_RESTRICT px,
71  amrex::ParticleReal & AMREX_RESTRICT py,
72  amrex::ParticleReal & AMREX_RESTRICT pt,
73  RefPart const & refpart
74  ) const
75  {
76  using namespace amrex::literals; // for _rt and _prt
77 
78  // access AoS data such as positions and cpu/id
79  amrex::ParticleReal const x = p.pos(RealAoS::x);
80  amrex::ParticleReal const y = p.pos(RealAoS::y);
81  amrex::ParticleReal const t = p.pos(RealAoS::t);
82 
83  // access reference particle values to find beta:
84  amrex::ParticleReal const beta = refpart.beta();
85 
86  // intialize output values of momenta
87  amrex::ParticleReal pxout = px;
88  amrex::ParticleReal pyout = py;
89  amrex::ParticleReal ptout = pt;
90 
91  // store rotation angle and initial, final values of pz
92  amrex::ParticleReal const theta = m_phi_out - m_phi_in;
93  auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
94  auto const [sin_phi_in, cos_phi_in] = amrex::Math::sincos(m_phi_in);
95 
96  amrex::ParticleReal const pz = sqrt(1.0_prt - 2.0_prt*pt/beta
97  + pow(pt,2) - pow(py,2) - pow(px + sin_phi_in,2));
98  amrex::ParticleReal const pzf = pz*cos_theta - (px + sin_phi_in)*sin_theta;
99 
100  // advance position and momentum
101  p.pos(RealAoS::x) = x*pz/pzf;
102  pxout = px*cos_theta + (pz - cos_phi_in)*sin_theta;
103 
104  p.pos(RealAoS::y) = y + py*x*sin_theta/pzf;
105  pyout = py;
106 
107  p.pos(RealAoS::t) = t - (pt - 1.0_prt/beta)*x*sin_theta/pzf;
108  ptout = pt;
109 
110  // assign updated momenta
111  px = pxout;
112  py = pyout;
113  pt = ptout;
114  }
115 
117  using Thin::operator();
118 
119  private:
120  amrex::ParticleReal m_phi_in;
121  amrex::ParticleReal m_phi_out;
122  };
123 
124 } // namespace impactx
125 
126 #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:36
@ 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()(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:68
amrex::ParticleReal m_phi_out
normalized (max) RF voltage drop.
Definition: PRot.H:121
amrex::ParticleReal m_phi_in
Definition: PRot.H:120
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:48
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:49
@ t
c * time-of-flight [m] (at fixed s)
Definition: ImpactXParticleContainer.H:50
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