ImpactX
Loading...
Searching...
No Matches
pipeaperture.H
Go to the documentation of this file.
1/* Copyright 2022-2026 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 {
29
38 )
39 {
40 using namespace amrex::literals; // for _prt
41
42 m_inv_aperture_x = aperture_x > 0_prt ? 1_prt / aperture_x : 0_prt;
43 m_inv_aperture_y = aperture_y > 0_prt ? 1_prt / aperture_y : 0_prt;
44 }
45
46 PipeAperture () = default;
47 PipeAperture (PipeAperture const &) = default;
51
52 ~PipeAperture () = default;
53
60 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
63 T_Real & AMREX_RESTRICT x,
64 T_Real & AMREX_RESTRICT y,
65 T_IdCpu & AMREX_RESTRICT idcpu
66 ) const
67 {
68 using namespace amrex::literals; // for _rt and _prt
70 namespace stdx = amrex::simd::stdx;
71
72 // skip aperture application if aperture_x <= 0 or aperture_y <= 0
73 if (m_inv_aperture_x > 0_prt && m_inv_aperture_y > 0_prt) {
74
75 // scale horizontal and vertical coordinates
76 // performance optimization: we intentionally store the inverse of
77 // the aperture, so we can do a quick multiplication (instead of a
78 // costly division) here.
79 T_Real const u = x * m_inv_aperture_x;
80 T_Real const v = y * m_inv_aperture_y;
81
82 // compare against the aperture boundary
83 auto const mask = u*u + v*v > 1_prt;
85 }
86 }
87
94 {
95 using namespace amrex::literals; // for _prt
96 return m_inv_aperture_x > 0_prt ? 1_prt / m_inv_aperture_x : 0_prt;
97 }
98
105 {
106 using namespace amrex::literals; // for _prt
107 return m_inv_aperture_y > 0_prt ? 1_prt / m_inv_aperture_y : 0_prt;
108 }
109
110 // performance optimization: we intentionally store the inverse of
111 // the aperture, so we can do a quick multiplication instead of a costly
112 // division in the comparison operation per particle
115 };
116
117} // namespace impactx::elements::mixin
118
119#endif // IMPACTX_ELEMENTS_MIXIN_PIPE_APERTURE_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
Array4< int const > mask
amrex_particle_real ParticleReal
constexpr T powi(T x) noexcept
Definition alignment.H:25
__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:62
PipeAperture(PipeAperture const &)=default
amrex::ParticleReal m_inv_aperture_x
Definition pipeaperture.H:113
static constexpr amrex::ParticleReal DEFAULT_aperture_x
Definition pipeaperture.H:27
PipeAperture & operator=(PipeAperture const &)=default
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_x() const
Definition pipeaperture.H:93
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal aperture_y() const
Definition pipeaperture.H:104
static constexpr amrex::ParticleReal DEFAULT_aperture_y
Definition pipeaperture.H:28
PipeAperture(amrex::ParticleReal aperture_x, amrex::ParticleReal aperture_y)
Definition pipeaperture.H:35
amrex::ParticleReal m_inv_aperture_y
inverse of the horizontal aperture size [1/m]
Definition pipeaperture.H:114