WarpX
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 {
15  bool m_do_scale;
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  const amrex::Real dtscale = 1._rt - (m_z_plane_previous - zp)/(m_vz_ave_boosted + m_v_boost)/m_dt;
51  if (0._rt < dtscale && dtscale < 1._rt)
52  {
53  Exp *= dtscale;
54  Eyp *= dtscale;
55  Ezp *= dtscale;
56  Bxp *= dtscale;
57  Byp *= dtscale;
58  Bzp *= dtscale;
59  }
60  }
61 };
62 
63 #endif //WARPX_PARTICLES_GATHER_SCALEFIELDS_H_
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
float dt
Definition: stencil.py:442
Functor that scales E and B by a factor before pushing the particles. This is used for rigid injectio...
Definition: ScaleFields.H:14
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