ImpactX
NonlinearLens.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_NONLINEARLENS_H
11 #define IMPACTX_NONLINEARLENS_H
12 
14 #include "mixin/beamoptic.H"
15 #include "mixin/thin.H"
16 
17 #include <AMReX_Extension.H>
18 #include <AMReX_REAL.H>
19 #include <AMReX_GpuComplex.H>
20 
21 #include <cmath>
22 
23 namespace impactx
24 {
26  : public elements::BeamOptic<NonlinearLens>,
27  public elements::Thin
28  {
29  static constexpr auto name = "NonlinearLens";
31 
42  NonlinearLens( amrex::ParticleReal const knll,
43  amrex::ParticleReal const cnll )
44  : m_knll(knll), m_cnll(cnll)
45  {
46  }
47 
49  using BeamOptic::operator();
50 
62  PType& AMREX_RESTRICT p,
63  amrex::ParticleReal & AMREX_RESTRICT px,
64  amrex::ParticleReal & AMREX_RESTRICT py,
65  amrex::ParticleReal & AMREX_RESTRICT pt,
66  [[maybe_unused]] RefPart const & refpart) const {
67 
68  using namespace amrex::literals; // for _rt and _prt
69 
70  // a complex type with two amrex::ParticleReal
72 
73  // access AoS data such as positions and cpu/id
74  amrex::ParticleReal const x = p.pos(0);
75  amrex::ParticleReal const y = p.pos(1);
76  amrex::ParticleReal const t = p.pos(2);
77 
78  // access reference particle values to find (beta*gamma)^2
79  //amrex::ParticleReal const pt_ref = refpart.pt;
80  //amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
81 
82  // intialize output values of momenta
83  amrex::ParticleReal pxout = px;
84  amrex::ParticleReal pyout = py;
85  amrex::ParticleReal ptout = pt;
86 
87  // assign complex position zeta = x + iy
88  Complex zeta(x, y);
89  Complex re1(1.0_prt, 0.0_prt);
90  Complex im1(0.0_prt, 1.0_prt);
91 
92  // compute croot = sqrt(1-zeta**2)
93  Complex croot = amrex::pow(zeta, 2);
94  croot = re1 - croot;
95  croot = amrex::sqrt(croot);
96 
97  // compute carcsin = arcsin(zeta)
98  Complex carcsin = im1*zeta + croot;
99  carcsin = -im1*amrex::log(carcsin);
100 
101  // compute complex function F'(zeta)
102  Complex dF = zeta/amrex::pow(croot, 2);
103  dF = dF + carcsin/amrex::pow(croot,3);
104 
105  // compute momentum kick
106  amrex::ParticleReal kick = -m_knll/m_cnll;
107  amrex::ParticleReal dpx = kick*dF.m_real;
108  amrex::ParticleReal dpy = -kick*dF.m_imag;
109 
110  // advance position and momentum
111  p.pos(0) = x;
112  pxout = px + dpx;
113 
114  p.pos(1) = y;
115  pyout = py + dpy;
116 
117  p.pos(2) = t;
118  ptout = pt;
119 
120  // assign updated momenta
121  px = pxout;
122  py = pyout;
123  pt = ptout;
124 
125  }
126 
128  using Thin::operator();
129 
130  private:
131  amrex::ParticleReal m_knll;
132  amrex::ParticleReal m_cnll;
133  };
134 
135 } // namespace impactx
136 
137 #endif // IMPACTX_NONLINEARLENS_H
static constexpr auto name
Definition: NonlinearLens.H:29
Definition: ImpactX.cpp:31
NonlinearLens(amrex::ParticleReal const knll, amrex::ParticleReal const cnll)
Definition: NonlinearLens.H:42
amrex::ParticleReal m_cnll
integrated strength of the nonlinear lens (m)
Definition: NonlinearLens.H:132
Definition: beamoptic.H:134
Definition: NonlinearLens.H:25
Definition: thin.H:23
#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:61
#define AMREX_GPU_HOST_DEVICE
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:131
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
fftw_complex Complex