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 
75  PType& AMREX_RESTRICT p,
76  amrex::ParticleReal & AMREX_RESTRICT px,
77  amrex::ParticleReal & AMREX_RESTRICT py,
78  amrex::ParticleReal & AMREX_RESTRICT pt,
79  [[maybe_unused]] RefPart const & refpart) const {
80 
81  using namespace amrex::literals; // for _rt and _prt
82 
83  // a complex type with two amrex::ParticleReal
85 
86  // shift due to alignment errors of the element
87  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
88 
89  // access AoS data such as positions and cpu/id
90  amrex::ParticleReal const x = p.pos(RealAoS::x);
91  amrex::ParticleReal const y = p.pos(RealAoS::y);
92  amrex::ParticleReal const t = p.pos(RealAoS::t);
93 
94  // access reference particle values to find (beta*gamma)^2
95  //amrex::ParticleReal const pt_ref = refpart.pt;
96  //amrex::ParticleReal const betgam2 = pow(pt_ref, 2) - 1.0_prt;
97 
98  // intialize output values of momenta
99  amrex::ParticleReal pxout = px;
100  amrex::ParticleReal pyout = py;
101  amrex::ParticleReal ptout = pt;
102 
103  // assign complex position zeta = (x + iy)/cnll
104  Complex zeta(x, y);
105  zeta = zeta/m_cnll;
106  Complex const re1(1.0_prt, 0.0_prt);
107  Complex const im1(0.0_prt, 1.0_prt);
108 
109  // compute croot = sqrt(1-zeta**2)
110  Complex croot = amrex::pow(zeta, 2);
111  croot = re1 - croot;
112  croot = amrex::sqrt(croot);
113 
114  // compute carcsin = arcsin(zeta)
115  Complex carcsin = im1*zeta + croot;
116  carcsin = -im1*amrex::log(carcsin);
117 
118  // compute complex function F'(zeta)
119  Complex dF = zeta/amrex::pow(croot, 2);
120  dF = dF + carcsin/amrex::pow(croot,3);
121 
122  // compute momentum kick
123  amrex::ParticleReal const kick = -m_knll/m_cnll;
124  amrex::ParticleReal const dpx = kick*dF.m_real;
125  amrex::ParticleReal const dpy = -kick*dF.m_imag;
126 
127  // advance position and momentum
128  p.pos(RealAoS::x) = x;
129  pxout = px + dpx;
130 
131  p.pos(RealAoS::y) = y;
132  pyout = py + dpy;
133 
134  p.pos(RealAoS::t) = t;
135  ptout = pt;
136 
137  // assign updated momenta
138  px = pxout;
139  py = pyout;
140  pt = ptout;
141 
142  // undo shift due to alignment errors of the element
143  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
144  }
145 
147  using Thin::operator();
148 
149  private:
150  amrex::ParticleReal m_knll;
151  amrex::ParticleReal m_cnll;
152  };
153 
154 } // namespace impactx
155 
156 #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:35
@ t
fixed t as the independent variable
Definition: NonlinearLens.H:32
amrex::ParticleReal m_knll
Definition: NonlinearLens.H:150
amrex::ParticleReal m_cnll
integrated strength of the nonlinear lens (m)
Definition: NonlinearLens.H:151
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()(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:74
static constexpr auto name
Definition: NonlinearLens.H:33
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:49
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:50
@ t
c * time-of-flight [m] (at fixed s)
Definition: ImpactXParticleContainer.H:51
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:135
Definition: nofinalize.H:22
Definition: thin.H:24