ImpactX
Sbend.H
Go to the documentation of this file.
1 /* Copyright 2022 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_SBEND_H
11 #define IMPACTX_SBEND_H
12 
14 
15 #include <AMReX_Extension.H>
16 #include <AMReX_REAL.H>
17 
18 #include <cmath>
19 
20 
21 namespace impactx
22 {
23  struct Sbend
24  {
25  static constexpr auto name = "Sbend";
27 
34  Sbend( amrex::ParticleReal const ds, amrex::ParticleReal const rc,
35  int const nslice)
36  : m_ds(ds), m_rc(rc), m_nslice(nslice)
37  {
38  }
39 
50  PType& AMREX_RESTRICT p,
51  amrex::ParticleReal & AMREX_RESTRICT px,
52  amrex::ParticleReal & AMREX_RESTRICT py,
53  amrex::ParticleReal & AMREX_RESTRICT pt,
54  RefPart const refpart) const {
55 
56  using namespace amrex::literals; // for _rt and _prt
57 
58  // access AoS data such as positions and cpu/id
59  amrex::ParticleReal const x = p.pos(0);
60  amrex::ParticleReal const y = p.pos(1);
61  amrex::ParticleReal const t = p.pos(2);
62 
63  // initialize output values of momenta
64  amrex::ParticleReal pxout = px;
65  amrex::ParticleReal pyout = py;
66  amrex::ParticleReal ptout = pt;
67 
68  // length of the current slice
69  amrex::ParticleReal const slice_ds = m_ds / nslice();
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  amrex::ParticleReal const bet = sqrt(betgam2/(1.0_prt + betgam2));
75  amrex::ParticleReal const theta = slice_ds/m_rc;
76 
77  // advance position and momentum (sector bend)
78 
79  p.pos(0) = cos(theta)*x + m_rc*sin(theta)*px
80  - (m_rc/bet)*(1.0_prt - cos(theta))*pt;
81 
82  pxout = -sin(theta)/m_rc*x + cos(theta)*px - sin(theta)/bet*pt;
83 
84  p.pos(1) = y + m_rc*theta*py;
85 
86  // pyout = py;
87 
88  p.pos(2) = sin(theta)/bet*x + m_rc/bet*(1.0_prt - cos(theta))*px + t
89  + m_rc*(-theta+sin(theta)/(bet*bet))*pt;
90 
91  // ptout = pt;
92 
93  // assign updated momenta
94  px = pxout;
95  py = pyout;
96  pt = ptout;
97 
98  }
99 
106  RefPart & AMREX_RESTRICT refpart) const {
107 
108  using namespace amrex::literals; // for _rt and _prt
109 
110  // assign input reference particle values
111  amrex::ParticleReal const x = refpart.x;
112  amrex::ParticleReal const px = refpart.px;
113  amrex::ParticleReal const y = refpart.y;
114  amrex::ParticleReal const py = refpart.py;
115  amrex::ParticleReal const z = refpart.z;
116  amrex::ParticleReal const pz = refpart.pz;
117  amrex::ParticleReal const t = refpart.t;
118  amrex::ParticleReal const pt = refpart.pt;
119  amrex::ParticleReal const s = refpart.s;
120 
121  // length of the current slice
122  amrex::ParticleReal const slice_ds = m_ds / nslice();
123 
124  // assign intermediate parameter
125  amrex::ParticleReal const theta = slice_ds/m_rc;
126  amrex::ParticleReal const B = sqrt(pow(pt,2)-1.0_prt)/m_rc;
127 
128  // advance position and momentum (bend)
129  refpart.px = px*cos(theta) - pz*sin(theta);
130  refpart.py = py;
131  refpart.pz = pz*cos(theta) + px*sin(theta);
132  refpart.pt = pt;
133 
134  refpart.x = x + (refpart.pz - pz)/B;
135  refpart.y = y + (theta/B)*py;
136  refpart.z = z - (refpart.px - px)/B;
137  refpart.t = t - (theta/B)*pt;
138 
139  // advance integrated path length
140  refpart.s = s + slice_ds;
141 
142  }
143 
149  int nslice () const
150  {
151  return m_nslice;
152  }
153 
159  amrex::ParticleReal ds () const
160  {
161  return m_ds;
162  }
163 
164  private:
165  amrex::ParticleReal m_ds;
166  amrex::ParticleReal m_rc;
167  int m_nslice;
168  };
169 
170 } // namespace impactx
171 
172 #endif // IMPACTX_SBEND_H
def x
Definition: ImpactX.cpp:31
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: Sbend.H:49
amrex::ParticleReal pt
energy deviation, normalized by rest energy
Definition: ReferenceParticle.H:38
def z
int m_nslice
bend radius in m
Definition: Sbend.H:167
#define AMREX_FORCE_INLINE
static constexpr auto name
Definition: Sbend.H:25
Definition: Sbend.H:23
#define AMREX_GPU_HOST_DEVICE
amrex::ParticleReal m_rc
segment length in m
Definition: Sbend.H:166
amrex::ParticleReal m_ds
Definition: Sbend.H:165
Definition: ReferenceParticle.H:28
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
s
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: Sbend.H:149
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: Sbend.H:159
Sbend(amrex::ParticleReal const ds, amrex::ParticleReal const rc, int const nslice)
Definition: Sbend.H:34