ImpactX
Loading...
Searching...
No Matches
pipeaperture.H
Go to the documentation of this file.
1/* Copyright 2022-2025 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: Axel Huebl, Chad Mitchell, Alexander Sinn
8 * License: BSD-3-Clause-LBNL
9 */
10#ifndef IMPACTX_ELEMENTS_MIXIN_PIPE_APERTURE_H
11#define IMPACTX_ELEMENTS_MIXIN_PIPE_APERTURE_H
12
13#include <AMReX_Extension.H>
14#include <AMReX_GpuQualifiers.H>
15#include <AMReX_Math.H>
16#include <AMReX_Particle.H>
17#include <AMReX_REAL.H>
18#include <AMReX_SIMD.H>
19
20
22{
26 {
33 amrex::ParticleReal aperture_x,
34 amrex::ParticleReal aperture_y
35 )
36 {
37 using namespace amrex::literals; // for _prt
38
39 m_inv_aperture_x = aperture_x > 0_prt ? 1_prt / aperture_x : 0_prt;
40 m_inv_aperture_y = aperture_y > 0_prt ? 1_prt / aperture_y : 0_prt;
41 }
42
43 PipeAperture () = default;
44 PipeAperture (PipeAperture const &) = default;
48
49 ~PipeAperture () = default;
50
57 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
60 T_Real & AMREX_RESTRICT x,
61 T_Real & AMREX_RESTRICT y,
62 T_IdCpu & AMREX_RESTRICT idcpu
63 ) const
64 {
65 using namespace amrex::literals; // for _rt and _prt
67 namespace stdx = amrex::simd::stdx;
68
69 // skip aperture application if aperture_x <= 0 or aperture_y <= 0
70 if (m_inv_aperture_x > 0_prt && m_inv_aperture_y > 0_prt) {
71
72 // scale horizontal and vertical coordinates
73 // performance optimization: we intentionally store the inverse of
74 // the aperture, so we can do a quick multiplication (instead of a
75 // costly division) here.
76 T_Real const u = x * m_inv_aperture_x;
77 T_Real const v = y * m_inv_aperture_y;
78
79 // compare against the aperture boundary
80 auto const mask = u*u + v*v > 1_prt;
82 }
83 }
84
90 amrex::ParticleReal aperture_x () const
91 {
92 using namespace amrex::literals; // for _prt
93 return m_inv_aperture_x > 0_prt ? 1_prt / m_inv_aperture_x : 0_prt;
94 }
95
101 amrex::ParticleReal aperture_y () const
102 {
103 using namespace amrex::literals; // for _prt
104 return m_inv_aperture_y > 0_prt ? 1_prt / m_inv_aperture_y : 0_prt;
105 }
106
107 // performance optimization: we intentionally store the inverse of
108 // the aperture, so we can do a quick multiplication instead of a costly
109 // division in the comparison operation per particle
110 amrex::ParticleReal m_inv_aperture_x = 0;
111 amrex::ParticleReal m_inv_aperture_y = 0;
112 };
113
114} // namespace impactx::elements::mixin
115
116#endif // IMPACTX_ELEMENTS_MIXIN_PIPE_APERTURE_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
Array4< int const > mask
constexpr T powi(T x) noexcept
Definition alignment.H:23
__host__ __device__ void make_invalid() const noexcept
PipeAperture(PipeAperture &&)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void apply_aperture(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_IdCpu &AMREX_RESTRICT idcpu) const
Definition pipeaperture.H:59
PipeAperture(PipeAperture const &)=default
amrex::ParticleReal m_inv_aperture_x
Definition pipeaperture.H:110
PipeAperture & operator=(PipeAperture const &)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_x() const
Definition pipeaperture.H:90
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_y() const
Definition pipeaperture.H:101
PipeAperture(amrex::ParticleReal aperture_x, amrex::ParticleReal aperture_y)
Definition pipeaperture.H:32
amrex::ParticleReal m_inv_aperture_y
inverse of the horizontal aperture size [1/m]
Definition pipeaperture.H:111