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