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/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 namespace impactx
22 {
23  struct ThinDipole
24  : public elements::BeamOptic<ThinDipole>,
25  public elements::Thin,
27  {
28  static constexpr auto name = "ThinDipole";
30 
31  static constexpr amrex::ParticleReal degree2rad = ablastr::constant::math::pi / 180.0;
32 
43  ThinDipole( amrex::ParticleReal const theta,
44  amrex::ParticleReal const rc)
45  : m_theta(theta * degree2rad), m_rc(rc)
46  {
47  }
48 
50  using BeamOptic::operator();
51 
63  PType& AMREX_RESTRICT p,
64  amrex::ParticleReal & AMREX_RESTRICT px,
65  amrex::ParticleReal & AMREX_RESTRICT py,
66  amrex::ParticleReal & AMREX_RESTRICT pt,
67  RefPart const & refpart) const {
68 
69  using namespace amrex::literals; // for _rt and _prt
70 
71  // access AoS data such as positions and cpu/id
72  amrex::ParticleReal const x = p.pos(RealAoS::x);
73  amrex::ParticleReal const y = p.pos(RealAoS::y);
74  amrex::ParticleReal const t = p.pos(RealAoS::t);
75 
76  // access reference particle to find relativistic beta
77  amrex::ParticleReal const beta_ref = refpart.beta();
78 
79  // intialize output values of momenta
80  amrex::ParticleReal pxout = px;
81  amrex::ParticleReal pyout = py;
82  amrex::ParticleReal ptout = pt;
83 
84  // compute the function expressing dp/p in terms of pt (labeled f in Ripken etc.)
85  amrex::ParticleReal f = -1.0_prt + sqrt(1.0_prt - 2.0_prt*pt/beta_ref + pow(pt,2));
86  amrex::ParticleReal fprime = (1.0_prt - beta_ref*pt)/(beta_ref*(1.0_prt + f));
87 
88  // compute the effective (equivalent) arc length and curvature
89  amrex::ParticleReal ds = m_theta*m_rc;
90  amrex::ParticleReal kx = 1.0_prt/m_rc;
91 
92  // advance position and momentum
93  p.pos(RealAoS::x) = x;
94  pxout = px - pow(kx,2)*ds*x + kx*ds*f; //eq (3.2b)
95 
96  p.pos(RealAoS::y) = y;
97  pyout = py;
98 
99  p.pos(RealAoS::t) = t + kx*x*ds*fprime; //eq (3.2e)
100  ptout = pt;
101 
102  // assign updated momenta
103  px = pxout;
104  py = pyout;
105  pt = ptout;
106 
107  }
108 
110  using Thin::operator();
111 
112  private:
113  amrex::ParticleReal m_theta;
114  amrex::ParticleReal m_rc;
115 
116  };
117 
118 } // namespace impactx
119 
120 #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:34
f
@ 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_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta() const
Definition: ReferenceParticle.H:64
Definition: ThinDipole.H:27
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:62
ImpactXParticleContainer::ParticleType PType
Definition: ThinDipole.H:29
amrex::ParticleReal m_rc
dipole bending angle (rad)
Definition: ThinDipole.H:114
amrex::ParticleReal m_theta
Definition: ThinDipole.H:113
static constexpr auto name
Definition: ThinDipole.H:28
static constexpr amrex::ParticleReal degree2rad
Definition: ThinDipole.H:31
ThinDipole(amrex::ParticleReal const theta, amrex::ParticleReal const rc)
Definition: ThinDipole.H:43
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