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