ImpactX
NonlinearLens.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_NONLINEARLENS_H
11 #define IMPACTX_NONLINEARLENS_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 {
24  {
25  static constexpr auto name = "NonlinearLens";
27 
38  NonlinearLens( amrex::ParticleReal const knll,
39  amrex::ParticleReal const cnll )
40  : m_knll(knll), m_cnll(cnll)
41  {
42  }
43 
55  PType& AMREX_RESTRICT p,
56  amrex::ParticleReal & AMREX_RESTRICT px,
57  amrex::ParticleReal & AMREX_RESTRICT py,
58  amrex::ParticleReal & AMREX_RESTRICT pt,
59  [[maybe_unused]] RefPart const & refpart) const {
60 
61  using namespace amrex::literals; // for _rt and _prt
62 
63  // a complex type with two amrex::ParticleReal
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  // access reference particle values to find (beta*gamma)^2
72  //amrex::ParticleReal const pt_ref = refpart.pt;
73  //amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
74 
75  // intialize output values of momenta
76  amrex::ParticleReal pxout = px;
77  amrex::ParticleReal pyout = py;
78  amrex::ParticleReal ptout = pt;
79 
80  // assign complex position zeta = x + iy
81  Complex zeta(x, y);
82  Complex re1(1.0_prt, 0.0_prt);
83  Complex im1(0.0_prt, 1.0_prt);
84 
85  // compute croot = sqrt(1-zeta**2)
86  Complex croot = amrex::pow(zeta, 2);
87  croot = re1 - croot;
88  croot = amrex::sqrt(croot);
89 
90  // compute carcsin = arcsin(zeta)
91  Complex carcsin = im1*zeta + croot;
92  carcsin = -im1*amrex::log(carcsin);
93 
94  // compute complex function F'(zeta)
95  Complex dF = zeta/amrex::pow(croot, 2);
96  dF = dF + carcsin/amrex::pow(croot,3);
97 
98  // compute momentum kick
99  amrex::ParticleReal kick = -m_knll/m_cnll;
100  amrex::ParticleReal dpx = kick*dF.m_real;
101  amrex::ParticleReal dpy = -kick*dF.m_imag;
102 
103  // advance position and momentum
104  p.pos(0) = x;
105  pxout = px + dpx;
106 
107  p.pos(1) = y;
108  pyout = py + dpy;
109 
110  p.pos(2) = t;
111  ptout = pt;
112 
113  // assign updated momenta
114  px = pxout;
115  py = pyout;
116  pt = ptout;
117 
118  }
119 
125  void operator() ([[maybe_unused]] RefPart & AMREX_RESTRICT refpart) const {
126 
127  // nothing to do: this is a zero-length element
128  }
129 
135  int nslice () const
136  {
137  return 1;
138  }
139 
145  amrex::ParticleReal ds () const
146  {
147  using namespace amrex::literals;
148  return 0.0_prt;
149  }
150 
151  private:
152  amrex::ParticleReal m_knll;
153  amrex::ParticleReal m_cnll;
154  };
155 
156 } // namespace impactx
157 
158 #endif // IMPACTX_NONLINEARLENS_H
static constexpr auto name
Definition: NonlinearLens.H:25
Definition: ImpactX.cpp:31
NonlinearLens(amrex::ParticleReal const knll, amrex::ParticleReal const cnll)
Definition: NonlinearLens.H:38
amrex::ParticleReal m_cnll
integrated strength of the nonlinear lens (m)
Definition: NonlinearLens.H:153
Definition: NonlinearLens.H:23
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition: NonlinearLens.H:145
#define AMREX_FORCE_INLINE
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: NonlinearLens.H:54
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition: NonlinearLens.H:135
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > log(const GpuComplex< T > &a_z) noexcept
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_knll
Definition: NonlinearLens.H:152
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
fftw_complex Complex