ImpactX
Aperture.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_APERTURE_H
11 #define IMPACTX_APERTURE_H
12 
13 
15 #include "mixin/alignment.H"
16 #include "mixin/beamoptic.H"
17 #include "mixin/thin.H"
18 #include "mixin/nofinalize.H"
19 
21 #include <AMReX_Extension.H>
22 #include <AMReX_REAL.H>
23 
24 #include <cmath>
25 
26 namespace impactx
27 {
28  struct Aperture
29  : public elements::BeamOptic<Aperture>,
30  public elements::Thin,
31  public elements::Alignment,
33  {
34  static constexpr auto name = "Aperture";
36 
37  enum Shape
38  {
41  };
42 
54  amrex::ParticleReal xmax,
55  amrex::ParticleReal ymax,
56  Shape shape,
57  amrex::ParticleReal dx = 0,
58  amrex::ParticleReal dy = 0,
59  amrex::ParticleReal rotation_degree = 0
60  )
61  : Alignment(dx, dy, rotation_degree),
62  m_shape(shape), m_xmax(xmax), m_ymax(ymax)
63  {
64  }
65 
67  using BeamOptic::operator();
68 
80  PType& AMREX_RESTRICT p,
81  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT px,
82  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT py,
83  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT pt,
84  [[maybe_unused]] RefPart const & refpart) const
85  {
86  using namespace amrex::literals; // for _rt and _prt
87 
88  // shift due to alignment errors of the element
89  shift_in(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
90 
91  // access AoS data such as positions and cpu/id
92  amrex::ParticleReal const x = p.pos(RealAoS::x);
93  amrex::ParticleReal const y = p.pos(RealAoS::y);
94  auto const id = p.id();
95 
96  // scale horizontal and vertical coordinates
97  amrex::ParticleReal const u = x / m_xmax;
98  amrex::ParticleReal const v = y / m_ymax;
99 
100  // compare against the aperture boundary
101  switch (m_shape)
102  {
103  case Shape::rectangular : // default
104  if (pow(u,2)>1 || pow(v,2) > 1_prt) {
105  p.id() = -id;
106  }
107  break;
108 
109  case Shape::elliptical :
110  if (pow(u,2)+pow(v,2) > 1_prt) {
111  p.id() = -id;
112  }
113  break;
114  }
115 
116  // undo shift due to alignment errors of the element
117  shift_out(p.pos(RealAoS::x), p.pos(RealAoS::y), px, py);
118  }
119 
121  using Thin::operator();
122 
123  private:
125  amrex::ParticleReal m_xmax;
126  amrex::ParticleReal m_ymax;
127 
128  };
129 
130 } // namespace impactx
131 
132 #endif // IMPACTX_APERTURE_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
xmax
Definition: Aperture.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(PType &AMREX_RESTRICT p, [[maybe_unused]] amrex::ParticleReal &AMREX_RESTRICT px, [[maybe_unused]] amrex::ParticleReal &AMREX_RESTRICT py, [[maybe_unused]] amrex::ParticleReal &AMREX_RESTRICT pt, [[maybe_unused]] RefPart const &refpart) const
Definition: Aperture.H:79
static constexpr auto name
Definition: Aperture.H:34
Shape m_shape
Definition: Aperture.H:124
ImpactXParticleContainer::ParticleType PType
Definition: Aperture.H:35
amrex::ParticleReal m_xmax
aperture type (rectangular, elliptical)
Definition: Aperture.H:125
Aperture(amrex::ParticleReal xmax, amrex::ParticleReal ymax, Shape shape, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0)
Definition: Aperture.H:53
Shape
Definition: Aperture.H:38
@ elliptical
Definition: Aperture.H:40
@ rectangular
Definition: Aperture.H:39
amrex::ParticleReal m_ymax
maximum horizontal coordinate
Definition: Aperture.H:126
@ 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