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/beamoptic.H"
16 #include "mixin/thin.H"
17 #include "mixin/nofinalize.H"
18 
20 #include <AMReX_Extension.H>
21 #include <AMReX_REAL.H>
22 
23 #include <cmath>
24 
25 namespace impactx
26 {
27  struct Aperture
28  : public elements::BeamOptic<Aperture>,
29  public elements::Thin,
31  {
32  static constexpr auto name = "Aperture";
34 
35  enum Shape
36  {
39  };
40 
48  Aperture (amrex::ParticleReal xmax,
49  amrex::ParticleReal ymax,
50  Shape shape)
51  : m_shape(shape), m_xmax(xmax), m_ymax(ymax)
52  {
53  }
54 
56  using BeamOptic::operator();
57 
69  PType& AMREX_RESTRICT p,
70  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT px,
71  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT py,
72  [[maybe_unused]] amrex::ParticleReal & AMREX_RESTRICT pt,
73  [[maybe_unused]] RefPart const & refpart) const
74  {
75  using namespace amrex::literals; // for _rt and _prt
76 
77  // access AoS data such as positions and cpu/id
78  amrex::ParticleReal const x = p.pos(RealAoS::x);
79  amrex::ParticleReal const y = p.pos(RealAoS::y);
80  auto const id = p.id();
81 
82  // scale horizontal and vertical coordinates
83  amrex::ParticleReal const u = x / m_xmax;
84  amrex::ParticleReal const v = y / m_ymax;
85 
86  // compare against the aperture boundary
87  switch (m_shape)
88  {
89  case Shape::rectangular : // default
90  if (pow(u,2)>1 || pow(v,2) > 1_prt) {
91  p.id() = -id;
92  }
93  break;
94 
95  case Shape::elliptical :
96  if (pow(u,2)+pow(v,2) > 1_prt) {
97  p.id() = -id;
98  }
99  break;
100  }
101  }
102 
104  using Thin::operator();
105 
106  private:
108  amrex::ParticleReal m_xmax;
109  amrex::ParticleReal m_ymax;
110 
111  };
112 
113 } // namespace impactx
114 
115 #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:34
xmax
Definition: Aperture.H:31
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:68
static constexpr auto name
Definition: Aperture.H:32
Shape m_shape
Definition: Aperture.H:107
ImpactXParticleContainer::ParticleType PType
Definition: Aperture.H:33
amrex::ParticleReal m_xmax
aperture type (rectangular, elliptical)
Definition: Aperture.H:108
Aperture(amrex::ParticleReal xmax, amrex::ParticleReal ymax, Shape shape)
Definition: Aperture.H:48
Shape
Definition: Aperture.H:36
@ elliptical
Definition: Aperture.H:38
@ rectangular
Definition: Aperture.H:37
amrex::ParticleReal m_ymax
maximum horizontal coordinate
Definition: Aperture.H:109
@ 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
Definition: ReferenceParticle.H:30
Definition: beamoptic.H:135
Definition: nofinalize.H:22
Definition: thin.H:24