ImpactX
Multipole.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_MULTIPOLE_H
11 #define IMPACTX_MULTIPOLE_H
12 
14 #include "mixin/alignment.H"
15 #include "mixin/beamoptic.H"
16 #include "mixin/thin.H"
17 #include "mixin/nofinalize.H"
18 
19 #include <AMReX_Extension.H>
20 #include <AMReX_REAL.H>
21 #include <AMReX_GpuComplex.H>
22 
23 #include <cmath>
24 
25 namespace impactx
26 {
27  struct Multipole
28  : public elements::BeamOptic<Multipole>,
29  public elements::Thin,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "Multipole";
35 
46  int multipole,
47  amrex::ParticleReal K_normal,
48  amrex::ParticleReal K_skew,
49  amrex::ParticleReal dx = 0,
50  amrex::ParticleReal dy = 0,
51  amrex::ParticleReal rotation_degree = 0
52  )
53  : Alignment(dx, dy, rotation_degree),
54  m_multipole(multipole), m_Kn(K_normal), m_Ks(K_skew)
55  {
56  // compute factorial of multipole index
57  int const m = m_multipole - 1;
58  m_mfactorial = 1;
59  for( int n = 1; n < m + 1; n = n + 1 ) {
60  m_mfactorial *= n;
61  }
62  }
63 
65  using BeamOptic::operator();
66 
81  amrex::ParticleReal & AMREX_RESTRICT x,
82  amrex::ParticleReal & AMREX_RESTRICT y,
83  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT t,
84  amrex::ParticleReal & AMREX_RESTRICT px,
85  amrex::ParticleReal & AMREX_RESTRICT py,
86  amrex::ParticleReal & AMREX_RESTRICT pt,
87  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
88  [[maybe_unused]] RefPart const & refpart
89  ) const
90  {
91  using namespace amrex::literals; // for _rt and _prt
92 
93  // shift due to alignment errors of the element
94  shift_in(x, y, px, py);
95 
96  // a complex type with two amrex::ParticleReal
98 
99  // access reference particle values to find (beta*gamma)^2
100  //amrex::ParticleReal const pt_ref = refpart.pt;
101  //amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
102 
103  // intialize output values
104  amrex::ParticleReal xout = x;
105  amrex::ParticleReal yout = y;
106  amrex::ParticleReal tout = t;
107  amrex::ParticleReal pxout = px;
108  amrex::ParticleReal pyout = py;
109  amrex::ParticleReal ptout = pt;
110 
111  // assign complex position and complex multipole strength
112  Complex const zeta(x, y);
113  Complex const alpha(m_Kn, m_Ks);
114 
115  // compute complex momentum kick
116  int const m = m_multipole - 1;
117  Complex kick = amrex::pow(zeta, m);
118  kick *= alpha;
119  amrex::ParticleReal const dpx = -1.0_prt*kick.m_real/m_mfactorial;
120  amrex::ParticleReal const dpy = kick.m_imag/m_mfactorial;
121 
122  // advance position and momentum
123  // xout = x;
124  pxout = px + dpx;
125 
126  // yout = y;
127  pyout = py + dpy;
128 
129  // tout = t;
130  ptout = pt;
131 
132  // assign updated values
133  x = xout;
134  y = yout;
135  t = tout;
136  px = pxout;
137  py = pyout;
138  pt = ptout;
139 
140  // undo shift due to alignment errors of the element
141  shift_out(x, y, px, py);
142  }
143 
145  using Thin::operator();
146 
149  amrex::ParticleReal m_Kn;
150  amrex::ParticleReal m_Ks;
151 
152  };
153 
154 } // namespace impactx
155 
156 #endif // IMPACTX_MULTIPOLE_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
Definition: ImpactX.cpp:33
@ t
fixed t as the independent variable
int n
Definition: Multipole.H:32
amrex::ParticleReal m_Kn
factorial of multipole index
Definition: Multipole.H:149
int m_mfactorial
multipole index
Definition: Multipole.H:148
ImpactXParticleContainer::ParticleType PType
Definition: Multipole.H:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, [[maybe_unused]] 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, [[maybe_unused]] RefPart const &refpart) const
Definition: Multipole.H:80
amrex::ParticleReal m_Ks
integrated normal multipole coefficient
Definition: Multipole.H:150
static constexpr auto name
Definition: Multipole.H:33
Multipole(int multipole, amrex::ParticleReal K_normal, amrex::ParticleReal K_skew, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0)
Definition: Multipole.H:45
int m_multipole
Definition: Multipole.H:147
Definition: ReferenceParticle.H:30
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: thin.H:24