WarpX
Loading...
Searching...
No Matches
HardEdged_K.H
Go to the documentation of this file.
1/* Copyright 2022 David Grote
2 *
3 * This file is part of WarpX.
4 *
5 * License: BSD-3-Clause-LBNL
6 */
7#ifndef WARPX_ACCELERATORLATTICE_LATTICEELEMENTS_HARDEDGED_K_H_
8#define WARPX_ACCELERATORLATTICE_LATTICEELEMENTS_HARDEDGED_K_H_
9
10#include "Utils/WarpXConst.H"
11
12#include <AMReX_REAL.H>
13
25amrex::ParticleReal hard_edged_fraction(const amrex::ParticleReal z,
26 const amrex::ParticleReal zpvdt,
27 const amrex::ParticleReal zs,
28 const amrex::ParticleReal ze)
29{
30
31 using namespace amrex::literals;
32
33 // This allows vz to be positive or negative
34 amrex::ParticleReal const zl = std::min(z, zpvdt);
35 amrex::ParticleReal const zr = std::max(z, zpvdt);
36
37 // Calculate the residence correction
38 // frac will be 1 if the step is completely inside the lens, between 0 and 1
39 // when entering or leaving the lens, and otherwise 0.
40 // This accounts for the case when particles step over the element without landing in it.
41 // This assumes that vzp != 0.
42 amrex::ParticleReal const zl_bounded = std::min(std::max(zl, zs), ze);
43 amrex::ParticleReal const zr_bounded = std::min(std::max(zr, zs), ze);
44 const amrex::ParticleReal frac = (zr_bounded - zl_bounded)/(zr - zl);
45
46 return frac;
47}
48
49#endif // WARPX_ACCELERATORLATTICE_LATTICEELEMENTS_HARDEDGED_K_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal hard_edged_fraction(const amrex::ParticleReal z, const amrex::ParticleReal zpvdt, const amrex::ParticleReal zs, const amrex::ParticleReal ze)
Calculate the residence correction, the fraction of the time step the particle spends inside of the h...
Definition HardEdged_K.H:25