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/alignment.H"
15 #include "mixin/beamoptic.H"
16 #include "mixin/thin.H"
17 #include "mixin/nofinalize.H"
18 
19 #include <AMReX_Extension.H>
20 #include <AMReX_REAL.H>
21 
22 #include <cmath>
23 
24 
25 namespace impactx
26 {
27  struct Buncher
28  : public elements::BeamOptic<Buncher>,
29  public elements::Thin,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "Buncher";
35 
45  amrex::ParticleReal V,
46  amrex::ParticleReal k,
47  amrex::ParticleReal dx = 0,
48  amrex::ParticleReal dy = 0,
49  amrex::ParticleReal rotation_degree = 0
50  )
51  : Alignment(dx, dy, rotation_degree),
52  m_V(V), m_k(k)
53  {
54  }
55 
57  using BeamOptic::operator();
58 
73  amrex::ParticleReal & AMREX_RESTRICT x,
74  amrex::ParticleReal & AMREX_RESTRICT y,
75  amrex::ParticleReal & AMREX_RESTRICT t,
76  amrex::ParticleReal & AMREX_RESTRICT px,
77  amrex::ParticleReal & AMREX_RESTRICT py,
78  amrex::ParticleReal & AMREX_RESTRICT pt,
79  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
80  RefPart const & refpart) const {
81 
82  using namespace amrex::literals; // for _rt and _prt
83 
84  // shift due to alignment errors of the element
85  shift_in(x, y, px, py);
86 
87  // access reference particle values to find (beta*gamma)^2
88  amrex::ParticleReal const pt_ref = refpart.pt;
89  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
90 
91  // intialize output values of momenta
92  amrex::ParticleReal pxout = px;
93  amrex::ParticleReal pyout = py;
94  amrex::ParticleReal ptout = pt;
95 
96  // advance position and momentum
97  pxout = px + m_k*m_V/(2.0_prt*betgam2)*x;
98  pyout = py + m_k*m_V/(2.0_prt*betgam2)*y;
99  ptout = pt - m_k*m_V*t;
100 
101  // assign updated momenta
102  px = pxout;
103  py = pyout;
104  pt = ptout;
105 
106  // undo shift due to alignment errors of the element
107  shift_out(x, y, px, py);
108  }
109 
111  using Thin::operator();
112 
113  amrex::ParticleReal m_V;
114  amrex::ParticleReal m_k;
115  };
116 
117 } // namespace impactx
118 
119 #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:33
@ t
fixed t as the independent variable
Definition: Buncher.H:32
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: Buncher.H:72
Buncher(amrex::ParticleReal V, amrex::ParticleReal k, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0)
Definition: Buncher.H:44
amrex::ParticleReal m_V
Definition: Buncher.H:113
static constexpr auto name
Definition: Buncher.H:33
amrex::ParticleReal m_k
normalized (max) RF voltage drop.
Definition: Buncher.H:114
ImpactXParticleContainer::ParticleType PType
Definition: Buncher.H:34
Definition: ReferenceParticle.H:30
amrex::ParticleReal pt
energy, normalized by rest energy
Definition: ReferenceParticle.H:39
Definition: alignment.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_out(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py) const
Definition: alignment.H:91
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition: alignment.H:120
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void shift_in(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py) const
Definition: alignment.H:61
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition: alignment.H:130
Definition: beamoptic.H:149
Definition: nofinalize.H:22
Definition: thin.H:24