Hipace
GetAndSetPosition.H
Go to the documentation of this file.
1 /* Copyright 2020-2021
2  *
3  * This file is part of HiPACE++.
4  *
5  * Authors: MaxThevenet, Severin Diederichs
6  * License: BSD-3-Clause-LBNL
7  */
8 /* Copyright 2019 David Grote, Maxence Thevenet, Remi Lehe
9  * Weiqun Zhang
10  *
11  * This file is part of WarpX.
12  *
13  * License: BSD-3-Clause-LBNL
14  */
15 #ifndef HIPACE_GETANDSETPOSITION_H_
16 #define HIPACE_GETANDSETPOSITION_H_
17 
19 
20 #include <AMReX.H>
21 #include <AMReX_REAL.H>
22 
23 #include <limits>
24 
25 
29 template <class T_ParTile>
31 {
32  using RType = amrex::ParticleReal;
33  using PTDType = typename T_ParTile::ParticleTileDataType;
34 
37  int m_is_per;
38 
42  EnforceBCandSetPos (const amrex::Geometry& geom) noexcept
43  {
44 
45  m_plo = geom.ProbLoArray();
46  m_phi = geom.ProbHiArray();
47  auto is_per = geom.isPeriodicArray();
48  m_is_per = is_per[0];
49  AMREX_ALWAYS_ASSERT(is_per[0] == is_per[1]);
50  }
51 
60  bool operator() (const PTDType& ptd, const int ip, RType& x, RType& y) const noexcept
61  {
62  using namespace amrex::literals;
63 
64  auto p = ptd[ip];
65 
66  p.pos(0) = x;
67  p.pos(1) = y;
68 
69  // TODO: The second m_phi should be amrex::Geometry RoundoffHiArray(),
70  // however there is no Geometry object to get this.
71  const bool shifted = enforcePeriodic(p, m_plo, m_phi, m_plo, m_phi, {true, true, false});
72  const bool invalid = (shifted && !m_is_per);
73  if (invalid) {
74  ptd.rdata(PlasmaIdx::w)[ip] = 0.0_rt;
75  p.id().make_invalid();
76  }
77  x = p.pos(0);
78  y = p.pos(1);
79  return invalid;
80  }
81 
90  bool operator() (const PTDType& ptd, const int ip, RType& x, RType& y, RType& z) const noexcept
91  {
92  using namespace amrex::literals;
93 
94  auto p = ptd[ip];
95 
96  p.pos(0) = x;
97  p.pos(1) = y;
98  p.pos(2) = z;
99 
100  // TODO: The second m_phi should be amrex::Geometry RoundoffHiArray(),
101  // however there is no Geometry object to get this.
102  const bool shifted = enforcePeriodic(p, m_plo, m_phi, m_plo, m_phi, {true, true, false});
103  const bool invalid = (shifted && !m_is_per);
104  if (invalid) {
105  ptd.rdata(BeamIdx::w)[ip] = 0.0_rt;
106  p.id().make_invalid();
107  }
108  x = p.pos(0);
109  y = p.pos(1);
110  z = p.pos(2);
111  return invalid;
112  }
113 };
114 
115 #endif // HIPACE_GETANDSETPOSITION_H_
#define AMREX_ALWAYS_ASSERT(EX)
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool enforcePeriodic(P &p, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &plo, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &phi, amrex::GpuArray< amrex::ParticleReal, AMREX_SPACEDIM > const &rlo, amrex::GpuArray< amrex::ParticleReal, AMREX_SPACEDIM > const &rhi, amrex::GpuArray< int, AMREX_SPACEDIM > const &is_per) noexcept
@ w
Definition: BeamParticleContainer.H:27
Functor that can be used to apply the boundary conditions to the macroparticles inside a ParallelFor ...
Definition: GetAndSetPosition.H:31
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_plo
Definition: GetAndSetPosition.H:35
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > m_phi
Definition: GetAndSetPosition.H:36
EnforceBCandSetPos(const amrex::Geometry &geom) noexcept
Definition: GetAndSetPosition.H:42
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool operator()(const PTDType &ptd, const int ip, RType &x, RType &y) const noexcept
set position and enforces the boundary condition to the plasma particle at index ip and returns if th...
Definition: GetAndSetPosition.H:60
typename T_ParTile::ParticleTileDataType PTDType
Definition: GetAndSetPosition.H:33
int m_is_per
Definition: GetAndSetPosition.H:37
amrex::ParticleReal RType
Definition: GetAndSetPosition.H:32
@ w
Definition: PlasmaParticleContainer.H:25