WarpX
Loading...
Searching...
No Matches
ScaleFields.H
Go to the documentation of this file.
1#ifndef WARPX_PARTICLES_GATHER_SCALEFIELDS_H_
2#define WARPX_PARTICLES_GATHER_SCALEFIELDS_H_
3
5
6#include <AMReX_REAL.H>
7
8#include <limits>
9
14{
16 amrex::Real m_dt;
17 amrex::Real m_z_plane_previous;
18 amrex::Real m_vz_ave_boosted;
19 amrex::Real m_v_boost;
20
21 ScaleFields(bool do_scale) noexcept
22 : m_do_scale(do_scale)
23 {}
24
25 ScaleFields (bool do_scale, amrex::Real dt, amrex::Real z_plane_previous,
26 amrex::Real vz_ave_boosted, amrex::Real v_boost) noexcept
27 : m_do_scale(do_scale), m_dt(dt), m_z_plane_previous(z_plane_previous),
28 m_vz_ave_boosted(vz_ave_boosted), m_v_boost(v_boost)
29 {}
30
32 void operator () (amrex::ParticleReal /*xp*/,
33 amrex::ParticleReal /*yp*/,
34 amrex::ParticleReal zp,
35 amrex::ParticleReal& Exp,
36 amrex::ParticleReal& Eyp,
37 amrex::ParticleReal& Ezp,
38 amrex::ParticleReal& Bxp,
39 amrex::ParticleReal& Byp,
40 amrex::ParticleReal& Bzp) const noexcept
41 {
42 using namespace amrex::literals;
43
44 if (!m_do_scale) { return; }
45
46 // Scale the fields of particles about to cross the injection plane.
47 // This only approximates what should be happening. The particles
48 // should by advanced a fraction of a time step instead.
49 // Scaling the fields is much easier and may be good enough.
50
51 // The scaling factor corresponds to the fraction of time that
52 // the particles spends to the right of the injection plane,
53 // between (n-1/2)*dt and (n+1/2)*dt, which is the interval
54 // over which the velocity is updated, in the leap-frog velocity push.
55 // (Note that here, `zp` is the particle position at time n*dt)
56 amrex::Real dtscale = 0.5_rt - (m_z_plane_previous - zp)/(m_vz_ave_boosted + m_v_boost)/m_dt;
57 // If the particle stays to the left of the plane during the
58 // whole push, simply set the scaling factor to 0, and thus
59 // the velocity push leaves the velocity unchanged.
60 if (dtscale < 0._rt) {
61 dtscale = 0;
62 }
63 // Scale the fields.
64 if (dtscale < 1._rt)
65 {
66 Exp *= dtscale;
67 Eyp *= dtscale;
68 Ezp *= dtscale;
69 Bxp *= dtscale;
70 Byp *= dtscale;
71 Bzp *= dtscale;
72 }
73 }
74};
75
76#endif //WARPX_PARTICLES_GATHER_SCALEFIELDS_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
ScaleFields(bool do_scale, amrex::Real dt, amrex::Real z_plane_previous, amrex::Real vz_ave_boosted, amrex::Real v_boost) noexcept
Definition ScaleFields.H:25
ScaleFields(bool do_scale) noexcept
Definition ScaleFields.H:21
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal zp, amrex::ParticleReal &Exp, amrex::ParticleReal &Eyp, amrex::ParticleReal &Ezp, amrex::ParticleReal &Bxp, amrex::ParticleReal &Byp, amrex::ParticleReal &Bzp) const noexcept
Definition ScaleFields.H:32
amrex::Real m_dt
Definition ScaleFields.H:16
amrex::Real m_z_plane_previous
Definition ScaleFields.H:17
bool m_do_scale
Definition ScaleFields.H:15
amrex::Real m_v_boost
Definition ScaleFields.H:19
amrex::Real m_vz_ave_boosted
Definition ScaleFields.H:18