ImpactX
Sol.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_SOL_H
11 #define IMPACTX_SOL_H
12 
14 #include "mixin/beamoptic.H"
15 #include "mixin/beamoptic.H"
16 
17 #include <AMReX_Extension.H>
18 #include <AMReX_REAL.H>
19 
20 #include <cmath>
21 
22 
23 namespace impactx
24 {
25  struct Sol
26  : public elements::BeamOptic<Sol>,
27  public elements::Thick
28  {
29  static constexpr auto name = "Sol";
31 
39  Sol( amrex::ParticleReal const ds, amrex::ParticleReal const ks,
40  int const nslice )
41  : Thick(ds, nslice), m_ks(ks)
42  {
43  }
44 
46  using BeamOptic::operator();
47 
58  PType& AMREX_RESTRICT p,
59  amrex::ParticleReal & AMREX_RESTRICT px,
60  amrex::ParticleReal & AMREX_RESTRICT py,
61  amrex::ParticleReal & AMREX_RESTRICT pt,
62  RefPart const & refpart) const {
63 
64  using namespace amrex::literals; // for _rt and _prt
65 
66  // access AoS data such as positions and cpu/id
67  amrex::ParticleReal const x = p.pos(0);
68  amrex::ParticleReal const y = p.pos(1);
69  amrex::ParticleReal const t = p.pos(2);
70 
71  // length of the current slice
72  amrex::ParticleReal const slice_ds = m_ds / nslice();
73 
74  // access reference particle values to find beta*gamma^2
75  amrex::ParticleReal const pt_ref = refpart.pt;
76  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
77 
78  // compute phase advance per unit length (in rad/m) and
79  // rotation angle (in rad)
80  amrex::ParticleReal const alpha = m_ks/2.0_prt;
81  amrex::ParticleReal const theta = alpha*slice_ds;
82 
83  // intialize output values
84  amrex::ParticleReal xout = x;
85  amrex::ParticleReal yout = y;
86  amrex::ParticleReal tout = t;
87  amrex::ParticleReal pxout = px;
88  amrex::ParticleReal pyout = py;
89  amrex::ParticleReal ptout = pt;
90 
91  // advance positions and momenta using map for focusing
92  xout = cos(theta)*x + sin(theta)/alpha*px;
93  pxout = -alpha*sin(theta)*x + cos(theta)*px;
94 
95  yout = cos(theta)*y + sin(theta)/alpha*py;
96  pyout = -alpha*sin(theta)*y + cos(theta)*py;
97 
98  tout = t + (slice_ds/betgam2)*pt;
99  ptout = pt;
100 
101  // assign intermediate momenta
102  px = pxout;
103  py = pyout;
104  pt = ptout;
105 
106  // advance positions and momenta using map for rotation
107  p.pos(0) = cos(theta)*xout + sin(theta)*yout;
108  pxout = cos(theta)*px + sin(theta)*py;
109 
110  p.pos(1) = -sin(theta)*xout + cos(theta)*yout;
111  pyout = -sin(theta)*px + cos(theta)*py;
112 
113  p.pos(2) = tout;
114  ptout = pt;
115 
116  // assign updated momenta
117  px = pxout;
118  py = pyout;
119  pt = ptout;
120 
121  }
122 
128  void operator() (RefPart & AMREX_RESTRICT refpart) const {
129 
130  using namespace amrex::literals; // for _rt and _prt
131 
132  // assign input reference particle values
133  amrex::ParticleReal const x = refpart.x;
134  amrex::ParticleReal const px = refpart.px;
135  amrex::ParticleReal const y = refpart.y;
136  amrex::ParticleReal const py = refpart.py;
137  amrex::ParticleReal const z = refpart.z;
138  amrex::ParticleReal const pz = refpart.pz;
139  amrex::ParticleReal const t = refpart.t;
140  amrex::ParticleReal const pt = refpart.pt;
141  amrex::ParticleReal const s = refpart.s;
142 
143  // length of the current slice
144  amrex::ParticleReal const slice_ds = m_ds / nslice();
145 
146  // assign intermediate parameter
147  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
148 
149  // advance position and momentum (straight element)
150  refpart.x = x + step*px;
151  refpart.y = y + step*py;
152  refpart.z = z + step*pz;
153  refpart.t = t - step*pt;
154 
155  // advance integrated path length
156  refpart.s = s + slice_ds;
157  }
158 
159  private:
160  amrex::ParticleReal m_ks;
161  };
162 
163 } // namespace impactx
164 
165 #endif // IMPACTX_SOL_H
amrex::ParticleReal m_ks
Definition: Sol.H:160
Definition: ImpactX.cpp:31
Sol(amrex::ParticleReal const ds, amrex::ParticleReal const ks, int const nslice)
Definition: Sol.H:39
Definition: beamoptic.H:134
amrex::ParticleReal pt
energy deviation, normalized by rest energy
Definition: ReferenceParticle.H:39
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
Definition: thick.H:23
static constexpr auto name
Definition: Sol.H:29
Thick(amrex::ParticleReal const ds, int const nslice)
Definition: thick.H:30
Definition: ReferenceParticle.H:29
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 amrex::ParticleReal ds() const
Definition: thick.H:50
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: thick.H:40
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
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: Sol.H:57
Definition: Sol.H:25
amrex::ParticleReal m_ds
Definition: thick.H:56