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 
78  amrex::ParticleReal & AMREX_RESTRICT x,
79  amrex::ParticleReal & AMREX_RESTRICT y,
80  amrex::ParticleReal & AMREX_RESTRICT t,
81  amrex::ParticleReal & AMREX_RESTRICT px,
82  amrex::ParticleReal & AMREX_RESTRICT py,
83  amrex::ParticleReal & AMREX_RESTRICT pt,
84  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
85  RefPart const & refpart
86  ) const
87  {
88  using namespace amrex::literals; // for _rt and _prt
89 
90  // shift due to alignment errors of the element
91  shift_in(x, y, px, py);
92 
93  // access position data
94  amrex::ParticleReal const xout = x;
95  amrex::ParticleReal const yout = y;
96  amrex::ParticleReal const tout = t;
97 
98  // access reference particle to find relativistic beta
99  amrex::ParticleReal const beta_ref = refpart.beta();
100 
101  // intialize output values of momenta
102  amrex::ParticleReal pxout = px;
103  amrex::ParticleReal pyout = py;
104  amrex::ParticleReal ptout = pt;
105 
106  // compute the function expressing dp/p in terms of pt (labeled f in Ripken etc.)
107  amrex::ParticleReal f = -1.0_prt + sqrt(1.0_prt - 2.0_prt*pt/beta_ref + pow(pt,2));
108  amrex::ParticleReal fprime = (1.0_prt - beta_ref*pt)/(beta_ref*(1.0_prt + f));
109 
110  // compute the effective (equivalent) arc length and curvature
111  amrex::ParticleReal ds = m_theta*m_rc;
112  amrex::ParticleReal kx = 1.0_prt/m_rc;
113 
114  // advance position and momentum
115  x = xout;
116  pxout = px - pow(kx,2) * ds * xout + kx * ds * f; //eq (3.2b)
117 
118  y = yout;
119  pyout = py;
120 
121  t = tout + kx * xout * ds * fprime; //eq (3.2e)
122  ptout = pt;
123 
124  // assign updated momenta
125  px = pxout;
126  py = pyout;
127  pt = ptout;
128 
129  // undo shift due to alignment errors of the element
130  shift_out(x, y, px, py);
131  }
132 
134  using Thin::operator();
135 
141  void operator() (RefPart & AMREX_RESTRICT refpart) const
142  {
143  // assign input reference particle values
144  amrex::ParticleReal const px = refpart.px;
145  amrex::ParticleReal const pz = refpart.pz;
146 
147  // calculate expensive terms once
148  auto const [sin_theta, cos_theta] = amrex::Math::sincos(m_theta);
149 
150  // advance position and momentum (thin dipole)
151  refpart.px = px*cos_theta - pz*sin_theta;
152  refpart.pz = pz*cos_theta + px*sin_theta;
153  }
154 
155  amrex::ParticleReal m_theta;
156  amrex::ParticleReal m_rc;
157 
158  };
159 
160 } // namespace impactx
161 
162 #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 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:33
@ t
fixed t as the independent variable
f
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
ImpactXParticleContainer::ParticleType PType
Definition: ThinDipole.H:31
amrex::ParticleReal m_rc
dipole bending angle (rad)
Definition: ThinDipole.H:156
amrex::ParticleReal m_theta
Definition: ThinDipole.H:155
static constexpr auto name
Definition: ThinDipole.H:30
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: ThinDipole.H:77
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:149
Definition: nofinalize.H:22
Definition: thin.H:24
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: thin.H:50