ImpactX
DipEdge.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_DIPEDGE_H
11 #define IMPACTX_DIPEDGE_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 
22 #include <cmath>
23 
24 
25 namespace impactx
26 {
27  struct DipEdge
28  : public elements::BeamOptic<DipEdge>,
29  public elements::Thin,
30  public elements::Alignment,
32  {
33  static constexpr auto name = "DipEdge";
35 
54  amrex::ParticleReal psi,
55  amrex::ParticleReal rc,
56  amrex::ParticleReal g,
57  amrex::ParticleReal K2,
58  amrex::ParticleReal dx = 0,
59  amrex::ParticleReal dy = 0,
60  amrex::ParticleReal rotation_degree = 0
61  )
62  : Alignment(dx, dy, rotation_degree),
63  m_psi(psi), m_rc(rc), m_g(g), m_K2(K2)
64  {
65  }
66 
68  using BeamOptic::operator();
69 
81  PType& AMREX_RESTRICT p,
82  amrex::ParticleReal & AMREX_RESTRICT px,
83  amrex::ParticleReal & AMREX_RESTRICT py,
84  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT pt,
85  [[maybe_unused]] RefPart const & refpart) const {
86 
87  using namespace amrex::literals; // for _rt and _prt
88 
89  // shift due to alignment errors of the element
90  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
91 
92  // access AoS data such as positions and cpu/id
93  amrex::ParticleReal const x = p.pos(RealAoS::x);
94  amrex::ParticleReal const y = p.pos(RealAoS::y);
95 
96  // access reference particle values if needed
97 
98  // edge focusing matrix elements (zero gap)
99  amrex::ParticleReal const R21 = tan(m_psi)/m_rc;
100  amrex::ParticleReal R43 = -R21;
101  amrex::ParticleReal vf = 0;
102 
103  // first-order effect of nonzero gap
104  vf = (1.0_prt + pow(sin(m_psi),2))/(pow(cos(m_psi),3));
105  vf *= m_g * m_K2/(pow(m_rc,2));
106  R43 += vf;
107 
108  // apply edge focusing
109  px = px + R21*x;
110  py = py + R43*y;
111 
112  // undo shift due to alignment errors of the element
113  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
114  }
115 
117  using Thin::operator();
118 
119  private:
120  amrex::ParticleReal m_psi;
121  amrex::ParticleReal m_rc;
122  amrex::ParticleReal m_g;
123  amrex::ParticleReal m_K2;
124  };
125 
126 } // namespace impactx
127 
128 #endif // IMPACTX_DIPEDGE_H
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
Definition: ImpactX.cpp:36
Definition: DipEdge.H:32
static constexpr auto name
Definition: DipEdge.H:33
amrex::ParticleReal m_psi
Definition: DipEdge.H:120
ImpactXParticleContainer::ParticleType PType
Definition: DipEdge.H:34
amrex::ParticleReal m_rc
pole face angle in rad
Definition: DipEdge.H:121
amrex::ParticleReal m_K2
gap parameter in m
Definition: DipEdge.H:123
amrex::ParticleReal m_g
bend radius in m
Definition: DipEdge.H:122
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(PType &AMREX_RESTRICT p, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py, [[maybe_unused]] amrex::ParticleReal &AMREX_RESTRICT pt, [[maybe_unused]] RefPart const &refpart) const
Definition: DipEdge.H:80
DipEdge(amrex::ParticleReal psi, amrex::ParticleReal rc, amrex::ParticleReal g, amrex::ParticleReal K2, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0)
Definition: DipEdge.H:53
@ x
position in x [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:48
@ y
position in y [m] (at fixed s OR fixed t)
Definition: ImpactXParticleContainer.H:49
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