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/alignment.H"
15 #include "mixin/beamoptic.H"
16 #include "mixin/thick.H"
17 #include "mixin/nofinalize.H"
18 
19 #include <AMReX_Extension.H>
20 #include <AMReX_Math.H>
21 #include <AMReX_REAL.H>
22 
23 #include <cmath>
24 
25 
26 namespace impactx
27 {
28  struct Sol
29  : public elements::BeamOptic<Sol>,
30  public elements::Thick,
31  public elements::Alignment,
33  {
34  static constexpr auto name = "Sol";
36 
47  Sol (
48  amrex::ParticleReal ds,
49  amrex::ParticleReal ks,
50  amrex::ParticleReal dx = 0,
51  amrex::ParticleReal dy = 0,
52  amrex::ParticleReal rotation_degree = 0,
53  int nslice = 1
54  )
55  : Thick(ds, nslice),
56  Alignment(dx, dy, rotation_degree),
57  m_ks(ks)
58  {
59  }
60 
62  using BeamOptic::operator();
63 
77  amrex::ParticleReal & AMREX_RESTRICT x,
78  amrex::ParticleReal & AMREX_RESTRICT y,
79  amrex::ParticleReal & AMREX_RESTRICT t,
80  amrex::ParticleReal & AMREX_RESTRICT px,
81  amrex::ParticleReal & AMREX_RESTRICT py,
82  amrex::ParticleReal & AMREX_RESTRICT pt,
83  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
84  RefPart const & refpart
85  ) const
86  {
87  using namespace amrex::literals; // for _rt and _prt
88 
89  // shift due to alignment errors of the element
90  shift_in(x, y, px, py);
91 
92  // length of the current slice
93  amrex::ParticleReal const slice_ds = m_ds / nslice();
94 
95  // access reference particle values to find beta*gamma^2
96  amrex::ParticleReal const pt_ref = refpart.pt;
97  amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
98 
99  // compute phase advance per unit length (in rad/m) and
100  // rotation angle (in rad)
101  amrex::ParticleReal const alpha = m_ks / 2.0_prt;
102  amrex::ParticleReal const theta = alpha*slice_ds;
103 
104  // intialize output values
105  amrex::ParticleReal xout = x;
106  amrex::ParticleReal yout = y;
107  amrex::ParticleReal tout = t;
108  amrex::ParticleReal pxout = px;
109  amrex::ParticleReal pyout = py;
110  amrex::ParticleReal ptout = pt;
111 
112  // advance positions and momenta using map for focusing
113  auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
114  xout = cos_theta*x + sin_theta/alpha*px;
115  pxout = -alpha*sin_theta*x + cos_theta*px;
116 
117  yout = cos_theta*y + sin_theta/alpha*py;
118  pyout = -alpha*sin_theta*y + cos_theta*py;
119 
120  tout = t + (slice_ds/betgam2)*pt;
121  ptout = pt;
122 
123  // assign intermediate momenta
124  px = pxout;
125  py = pyout;
126  pt = ptout;
127 
128  // advance positions and momenta using map for rotation
129  x = cos_theta*xout + sin_theta*yout;
130  pxout = cos_theta*px + sin_theta*py;
131 
132  y = -sin_theta*xout + cos_theta*yout;
133  pyout = -sin_theta*px + cos_theta*py;
134 
135  t = tout;
136  ptout = pt;
137 
138  // assign updated values
139  px = pxout;
140  py = pyout;
141  pt = ptout;
142 
143  // undo shift due to alignment errors of the element
144  shift_out(x, y, px, py);
145  }
146 
152  void operator() (RefPart & AMREX_RESTRICT refpart) const
153  {
154  using namespace amrex::literals; // for _rt and _prt
155 
156  // assign input reference particle values
157  amrex::ParticleReal const x = refpart.x;
158  amrex::ParticleReal const px = refpart.px;
159  amrex::ParticleReal const y = refpart.y;
160  amrex::ParticleReal const py = refpart.py;
161  amrex::ParticleReal const z = refpart.z;
162  amrex::ParticleReal const pz = refpart.pz;
163  amrex::ParticleReal const t = refpart.t;
164  amrex::ParticleReal const pt = refpart.pt;
165  amrex::ParticleReal const s = refpart.s;
166 
167  // length of the current slice
168  amrex::ParticleReal const slice_ds = m_ds / nslice();
169 
170  // assign intermediate parameter
171  amrex::ParticleReal const step = slice_ds / sqrt(pow(pt,2)-1.0_prt);
172 
173  // advance position and momentum (straight element)
174  refpart.x = x + step*px;
175  refpart.y = y + step*py;
176  refpart.z = z + step*pz;
177  refpart.t = t - step*pt;
178 
179  // advance integrated path length
180  refpart.s = s + slice_ds;
181  }
182 
183  amrex::ParticleReal m_ks;
184  };
185 
186 } // namespace impactx
187 
188 #endif // IMPACTX_SOL_H
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
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
s
Definition: ReferenceParticle.H:30
amrex::ParticleReal pt
energy, normalized by rest energy
Definition: ReferenceParticle.H:39
Definition: Sol.H:33
static constexpr auto name
Definition: Sol.H:34
ImpactXParticleContainer::ParticleType PType
Definition: Sol.H:35
Sol(amrex::ParticleReal ds, amrex::ParticleReal ks, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, int nslice=1)
Definition: Sol.H:47
amrex::ParticleReal m_ks
Definition: Sol.H:183
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: Sol.H:76
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: thick.H:24
Thick(amrex::ParticleReal ds, int nslice)
Definition: thick.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: thick.H:53
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: thick.H:43
amrex::ParticleReal m_ds
Definition: thick.H:58