ImpactX
ShortRF.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_SHORTRF_H
11 #define IMPACTX_SHORTRF_H
12 
14 #include "mixin/beamoptic.H"
15 #include "mixin/thin.H"
16 
17 #include <AMReX_Extension.H>
18 #include <AMReX_REAL.H>
19 
20 #include <cmath>
21 
22 
23 namespace impactx
24 {
25  struct ShortRF
26  : public elements::BeamOptic<ShortRF>,
27  public elements::Thin
28  {
29  static constexpr auto name = "ShortRF";
31 
37  ShortRF( amrex::ParticleReal const V, amrex::ParticleReal const k )
38  : m_V(V), m_k(k)
39  {
40  }
41 
43  using BeamOptic::operator();
44 
56  PType& AMREX_RESTRICT p,
57  amrex::ParticleReal & AMREX_RESTRICT px,
58  amrex::ParticleReal & AMREX_RESTRICT py,
59  amrex::ParticleReal & AMREX_RESTRICT pt,
60  RefPart const & refpart) const {
61 
62  using namespace amrex::literals; // for _rt and _prt
63 
64  // access AoS data such as positions and cpu/id
65  amrex::ParticleReal const x = p.pos(0);
66  amrex::ParticleReal const y = p.pos(1);
67  amrex::ParticleReal const t = p.pos(2);
68 
69  // access reference particle values to find (beta*gamma)^2
70  amrex::ParticleReal const pt_ref = refpart.pt;
71  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
72 
73  // intialize output values of momenta
74  amrex::ParticleReal pxout = px;
75  amrex::ParticleReal pyout = py;
76  amrex::ParticleReal ptout = pt;
77 
78  // advance position and momentum
79  p.pos(0) = x;
80  pxout = px + m_k*m_V/(2.0_prt*betgam2)*x;
81 
82  p.pos(1) = y;
83  pyout = py + m_k*m_V/(2.0_prt*betgam2)*y;
84 
85  p.pos(2) = t;
86  ptout = pt - m_k*m_V*t;
87 
88  // assign updated momenta
89  px = pxout;
90  py = pyout;
91  pt = ptout;
92 
93  }
94 
96  using Thin::operator();
97 
98  private:
99  amrex::ParticleReal m_V;
100  amrex::ParticleReal m_k;
101  };
102 
103 } // namespace impactx
104 
105 #endif // IMPACTX_SHORTRF_H
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: ShortRF.H:55
Definition: ImpactX.cpp:31
Definition: ShortRF.H:25
Definition: beamoptic.H:134
ShortRF(amrex::ParticleReal const V, amrex::ParticleReal const k)
Definition: ShortRF.H:37
amrex::ParticleReal pt
energy deviation, normalized by rest energy
Definition: ReferenceParticle.H:39
Definition: thin.H:23
amrex::ParticleReal m_k
normalized (max) RF voltage drop.
Definition: ShortRF.H:100
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
static constexpr auto name
Definition: ShortRF.H:29
Definition: ReferenceParticle.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
amrex::ParticleReal m_V
Definition: ShortRF.H:99