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/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 {
28  : public elements::BeamOptic<NonlinearLens>,
29  public elements::Thin,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "NonlinearLens";
35 
50  amrex::ParticleReal knll,
51  amrex::ParticleReal cnll,
52  amrex::ParticleReal dx = 0,
53  amrex::ParticleReal dy = 0,
54  amrex::ParticleReal rotation_degree = 0
55  )
56  : Alignment(dx, dy, rotation_degree),
57  m_knll(knll), m_cnll(cnll)
58  {
59  }
60 
62  using BeamOptic::operator();
63 
78  amrex::ParticleReal & AMREX_RESTRICT x,
79  amrex::ParticleReal & AMREX_RESTRICT y,
80  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT t,
81  amrex::ParticleReal & AMREX_RESTRICT px,
82  amrex::ParticleReal & AMREX_RESTRICT py,
83  amrex::ParticleReal & AMREX_RESTRICT pt,
84  [[maybe_unused]] uint64_t & AMREX_RESTRICT idcpu,
85  [[maybe_unused]] RefPart const & refpart
86  ) const
87  {
88  using namespace amrex::literals; // for _rt and _prt
89 
90  // a complex type with two amrex::ParticleReal
92 
93  // shift due to alignment errors of the element
94  shift_in(x, y, px, py);
95 
96  // access reference particle values to find (beta*gamma)^2
97  //amrex::ParticleReal const pt_ref = refpart.pt;
98  //amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
99 
100  // intialize output values
101  amrex::ParticleReal xout = x;
102  amrex::ParticleReal yout = y;
103  amrex::ParticleReal tout = t;
104  amrex::ParticleReal pxout = px;
105  amrex::ParticleReal pyout = py;
106  amrex::ParticleReal ptout = pt;
107 
108  // assign complex position zeta = (x + iy)/cnll
109  Complex zeta(x, y);
110  zeta = zeta/m_cnll;
111  Complex const re1(1.0_prt, 0.0_prt);
112  Complex const im1(0.0_prt, 1.0_prt);
113 
114  // compute croot = sqrt(1-zeta**2)
115  Complex croot = amrex::pow(zeta, 2);
116  croot = re1 - croot;
117  croot = amrex::sqrt(croot);
118 
119  // compute carcsin = arcsin(zeta)
120  Complex carcsin = im1*zeta + croot;
121  carcsin = -im1*amrex::log(carcsin);
122 
123  // compute complex function F'(zeta)
124  Complex dF = zeta/amrex::pow(croot, 2);
125  dF = dF + carcsin/amrex::pow(croot,3);
126 
127  // compute momentum kick
128  amrex::ParticleReal const kick = -m_knll/m_cnll;
129  amrex::ParticleReal const dpx = kick*dF.m_real;
130  amrex::ParticleReal const dpy = -kick*dF.m_imag;
131 
132  // advance position and momentum
133  // xout = x;
134  pxout = px + dpx;
135 
136  // yout = y;
137  pyout = py + dpy;
138 
139  // tout = t;
140  ptout = pt;
141 
142  // assign updated values
143  x = xout;
144  y = yout;
145  t = tout;
146  px = pxout;
147  py = pyout;
148  pt = ptout;
149 
150  // undo shift due to alignment errors of the element
151  shift_out(x, y, px, py);
152  }
153 
155  using Thin::operator();
156 
157  amrex::ParticleReal m_knll;
158  amrex::ParticleReal m_cnll;
159  };
160 
161 } // namespace impactx
162 
163 #endif // IMPACTX_NONLINEARLENS_H
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real dF(const amrex::Array4< amrex::Real > &U_minus, const amrex::Array4< amrex::Real > &U_plus, int i, int j, int k, amrex::Real clight, int comp, int dir)
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:33
@ t
fixed t as the independent variable
Definition: NonlinearLens.H:32
amrex::ParticleReal m_knll
Definition: NonlinearLens.H:157
amrex::ParticleReal m_cnll
integrated strength of the nonlinear lens (m)
Definition: NonlinearLens.H:158
ImpactXParticleContainer::ParticleType PType
Definition: NonlinearLens.H:34
NonlinearLens(amrex::ParticleReal knll, amrex::ParticleReal cnll, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0)
Definition: NonlinearLens.H:49
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: NonlinearLens.H:77
static constexpr auto name
Definition: NonlinearLens.H:33
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