ImpactX
Multipole.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_MULTIPOLE_H
11 #define IMPACTX_MULTIPOLE_H
12 
14 
15 #include <AMReX_Extension.H>
16 #include <AMReX_REAL.H>
17 #include <AMReX_GpuComplex.H>
18 
19 #include <cmath>
20 
21 namespace impactx
22 {
23  struct Multipole
24  {
25  static constexpr auto name = "Multipole";
27 
34  Multipole( int const multipole,
35  amrex::ParticleReal const K_normal,
36  amrex::ParticleReal const K_skew )
37  : m_multipole(multipole), m_Kn(K_normal), m_Ks(K_skew)
38  {
39  // compute factorial of multipole index
40  int const m = m_multipole - 1;
41  m_mfactorial = 1;
42  for( int n = 1; n < m + 1; n = n + 1 ) {
43  m_mfactorial *= n;
44  }
45  }
46 
58  PType& AMREX_RESTRICT p,
59  amrex::ParticleReal & AMREX_RESTRICT px,
60  amrex::ParticleReal & AMREX_RESTRICT py,
61  amrex::ParticleReal & AMREX_RESTRICT pt,
62  [[maybe_unused]] RefPart const & refpart) const {
63 
64  using namespace amrex::literals; // for _rt and _prt
65 
66  // a complex type with two amrex::ParticleReal
68 
69  // access AoS data such as positions and cpu/id
70  amrex::ParticleReal const x = p.pos(0);
71  amrex::ParticleReal const y = p.pos(1);
72  amrex::ParticleReal const t = p.pos(2);
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  // intialize output values of momenta
79  amrex::ParticleReal pxout = px;
80  amrex::ParticleReal pyout = py;
81  amrex::ParticleReal ptout = pt;
82 
83  // assign complex position and complex multipole strength
84  Complex const zeta(x, y);
85  Complex const alpha(m_Kn, m_Ks);
86 
87  // compute complex momentum kick
88  int const m = m_multipole - 1;
89  Complex kick = amrex::pow(zeta, m);
90  kick *= alpha;
91  amrex::ParticleReal const dpx = -1.0_prt*kick.m_real/m_mfactorial;
92  amrex::ParticleReal const dpy = kick.m_imag/m_mfactorial;
93 
94  // advance position and momentum
95  p.pos(0) = x;
96  pxout = px + dpx;
97 
98  p.pos(1) = y;
99  pyout = py + dpy;
100 
101  p.pos(2) = t;
102  ptout = pt;
103 
104  // assign updated momenta
105  px = pxout;
106  py = pyout;
107  pt = ptout;
108 
109  }
110 
116  void operator() ([[maybe_unused]] RefPart & AMREX_RESTRICT refpart) const {
117 
118  // nothing to do: this is a zero-length element
119  }
120 
126  int nslice () const
127  {
128  return 1;
129  }
130 
136  amrex::ParticleReal ds () const
137  {
138  using namespace amrex::literals;
139  return 0.0_prt;
140  }
141 
142  private:
145  amrex::ParticleReal m_Kn;
146  amrex::ParticleReal m_Ks;
147 
148  };
149 
150 } // namespace impactx
151 
152 #endif // IMPACTX_MULTIPOLE_H
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, [[maybe_unused]] RefPart const &refpart) const
Definition: Multipole.H:57
int m_multipole
Definition: Multipole.H:143
Definition: ImpactX.cpp:31
int m_mfactorial
multipole index
Definition: Multipole.H:144
Multipole(int const multipole, amrex::ParticleReal const K_normal, amrex::ParticleReal const K_skew)
Definition: Multipole.H:34
Definition: Multipole.H:23
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
int n
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: Multipole.H:136
amrex::ParticleReal m_Ks
integrated normal multipole coefficient
Definition: Multipole.H:146
Definition: ReferenceParticle.H:29
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
amrex::ParticleReal m_Kn
factorial of multipole index
Definition: Multipole.H:145
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: Multipole.H:126
fftw_complex Complex
static constexpr auto name
Definition: Multipole.H:25