ImpactX
ThinDipole.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_THINDIPOLE_H
11 #define IMPACTX_THINDIPOLE_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 namespace impactx
23 {
24  struct ThinDipole
25  : public elements::BeamOptic<ThinDipole>,
26  public elements::Thin,
27  public elements::Alignment,
29  {
30  static constexpr auto name = "ThinDipole";
32 
33  static constexpr amrex::ParticleReal degree2rad = ablastr::constant::math::pi / 180.0;
34 
49  amrex::ParticleReal theta,
50  amrex::ParticleReal rc,
51  amrex::ParticleReal dx = 0,
52  amrex::ParticleReal dy = 0,
53  amrex::ParticleReal rotation_degree = 0
54  )
55  : Alignment(dx, dy, rotation_degree),
56  m_theta(theta * degree2rad),
57  m_rc(rc)
58  {
59  }
60 
62  using BeamOptic::operator();
63 
75  PType& AMREX_RESTRICT p,
76  amrex::ParticleReal & AMREX_RESTRICT px,
77  amrex::ParticleReal & AMREX_RESTRICT py,
78  amrex::ParticleReal & AMREX_RESTRICT pt,
79  RefPart const & refpart) const {
80 
81  using namespace amrex::literals; // for _rt and _prt
82 
83  // shift due to alignment errors of the element
84  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
85 
86  // access AoS data such as positions and cpu/id
87  amrex::ParticleReal const x = p.pos(RealAoS::x);
88  amrex::ParticleReal const y = p.pos(RealAoS::y);
89  amrex::ParticleReal const t = p.pos(RealAoS::t);
90 
91  // access reference particle to find relativistic beta
92  amrex::ParticleReal const beta_ref = refpart.beta();
93 
94  // intialize output values of momenta
95  amrex::ParticleReal pxout = px;
96  amrex::ParticleReal pyout = py;
97  amrex::ParticleReal ptout = pt;
98 
99  // compute the function expressing dp/p in terms of pt (labeled f in Ripken etc.)
100  amrex::ParticleReal f = -1.0_prt + sqrt(1.0_prt - 2.0_prt*pt/beta_ref + pow(pt,2));
101  amrex::ParticleReal fprime = (1.0_prt - beta_ref*pt)/(beta_ref*(1.0_prt + f));
102 
103  // compute the effective (equivalent) arc length and curvature
104  amrex::ParticleReal ds = m_theta*m_rc;
105  amrex::ParticleReal kx = 1.0_prt/m_rc;
106 
107  // advance position and momentum
108  p.pos(RealAoS::x) = x;
109  pxout = px - pow(kx,2)*ds*x + kx*ds*f; //eq (3.2b)
110 
111  p.pos(RealAoS::y) = y;
112  pyout = py;
113 
114  p.pos(RealAoS::t) = t + kx*x*ds*fprime; //eq (3.2e)
115  ptout = pt;
116 
117  // assign updated momenta
118  px = pxout;
119  py = pyout;
120  pt = ptout;
121 
122  // undo shift due to alignment errors of the element
123  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
124  }
125 
127  using Thin::operator();
128 
129  private:
130  amrex::ParticleReal m_theta;
131  amrex::ParticleReal m_rc;
132 
133  };
134 
135 } // namespace impactx
136 
137 #endif // IMPACTX_THINDIPOLE_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:36
@ t
fixed t as the independent variable
f
@ 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: ThinDipole.H:29
ThinDipole(amrex::ParticleReal theta, amrex::ParticleReal rc, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0)
Definition: ThinDipole.H:48
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: ThinDipole.H:74
ImpactXParticleContainer::ParticleType PType
Definition: ThinDipole.H:31
amrex::ParticleReal m_rc
dipole bending angle (rad)
Definition: ThinDipole.H:131
amrex::ParticleReal m_theta
Definition: ThinDipole.H:130
static constexpr auto name
Definition: ThinDipole.H:30
static constexpr amrex::ParticleReal degree2rad
Definition: ThinDipole.H:33
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:135
Definition: nofinalize.H:22
Definition: thin.H:24
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: thin.H:50