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