8 #ifndef WARPX_CHARGEDEPOSITION_H_
9 #define WARPX_CHARGEDEPOSITION_H_
37 template <
int depos_order>
39 const amrex::ParticleReal *
const wp,
47 [[maybe_unused]]
int n_rz_azimuthal_modes)
49 using namespace amrex;
53 const bool do_ionization = ion_lev;
55 const amrex::Real invvol = dinv.
x*dinv.
y*dinv.
z;
68 amrex::Real wq = q*wp[ip]*invvol;
73 amrex::ParticleReal xp, yp, zp;
74 GetPosition(ip, xp, yp, zp);
78 #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_3D)
81 #if defined(WARPX_DIM_RZ)
82 const amrex::Real rp = std::sqrt(xp*xp + yp*yp);
83 const amrex::Real costheta = (rp > 0._rt ? xp/rp : 1._rt);
84 const amrex::Real sintheta = (rp > 0._rt ? yp/rp : 0._rt);
86 const amrex::Real
x = (rp - xyzmin.
x)*dinv.
x;
88 const amrex::Real
x = (xp - xyzmin.
x)*dinv.
x;
93 amrex::Real sx[depos_order + 1] = {0._rt};
95 if (rho_type[0] ==
NODE) {
96 i = compute_shape_factor(sx,
x);
97 }
else if (rho_type[0] == CELL) {
98 i = compute_shape_factor(sx,
x - 0.5_rt);
101 #if defined(WARPX_DIM_3D)
103 const amrex::Real y = (yp - xyzmin.
y)*dinv.
y;
104 amrex::Real sy[depos_order + 1] = {0._rt};
106 if (rho_type[1] ==
NODE) {
107 j = compute_shape_factor(sy, y);
108 }
else if (rho_type[1] == CELL) {
109 j = compute_shape_factor(sy, y - 0.5_rt);
113 const amrex::Real z = (zp - xyzmin.
z)*dinv.
z;
114 amrex::Real sz[depos_order + 1] = {0._rt};
116 if (rho_type[WARPX_ZINDEX] == NODE) {
117 k = compute_shape_factor(sz, z);
118 }
else if (rho_type[WARPX_ZINDEX] == CELL) {
119 k = compute_shape_factor(sz, z - 0.5_rt);
123 #if defined(WARPX_DIM_1D_Z)
124 for (
int iz=0;
iz<=depos_order;
iz++){
126 &rho_arr(lo.x+k+iz, 0, 0, 0),
129 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
130 for (
int iz=0;
iz<=depos_order;
iz++){
131 for (
int ix=0;
ix<=depos_order;
ix++){
133 &rho_arr(lo.x+
i+ix, lo.y+k+iz, 0, 0),
135 #if defined(WARPX_DIM_RZ)
137 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
146 #elif defined(WARPX_DIM_3D)
147 for (
int iz=0;
iz<=depos_order;
iz++){
148 for (
int iy=0;
iy<=depos_order;
iy++){
149 for (
int ix=0;
ix<=depos_order;
ix++){
151 &rho_arr(lo.x+
i+ix, lo.y+j+iy, lo.z+k+iz),
152 sx[ix]*sy[iy]*sz[iz]*wq);
182 template <
int depos_order>
184 const amrex::ParticleReal *
const wp,
188 const long np_to_deposit,
193 [[maybe_unused]]
const int n_rz_azimuthal_modes,
201 using namespace amrex;
205 #if !defined(AMREX_USE_GPU)
211 const bool do_ionization = ion_lev;
213 const amrex::Real invvol = dinv.
x*dinv.
y*dinv.
z;
216 auto rho_box = rho_fab.
box();
223 #if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
225 const auto domain = geom.
Domain();
230 sample_tbox_x.
grow(depos_order);
232 const auto npts = sample_tbox_x.
numPts();
234 const int nblocks = a_bins.
numBins();
236 const int threads_per_block = 256;
238 std::size_t shared_mem_bytes = npts*
sizeof(amrex::Real);
243 "Tile size too big for GPU shared memory charge deposition");
246 #if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
258 #if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
259 const int bin_id = blockIdx.x;
260 const unsigned int bin_start = offsets_ptr[bin_id];
261 const unsigned int bin_stop = offsets_ptr[bin_id+1];
263 if (bin_start == bin_stop) {
return; }
267 ParticleReal xp, yp, zp;
268 GetPosition(permutation[bin_start], xp, yp, zp);
269 #if defined(WARPX_DIM_3D)
271 int(amrex::Math::floor((yp-plo[1])*dinv.
y)),
272 int(amrex::Math::floor((zp-plo[2])*dinv.
z)));
273 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
275 int(amrex::Math::floor((zp-plo[1])*dinv.
z)));
276 #elif defined(WARPX_DIM_1D_Z)
279 iv += domain.smallEnd();
284 tbx.
grow(depos_order);
287 amrex::Real*
const shared = gsm.
dataPtr();
292 volatile amrex::Real* vs = shared;
293 for (
int i = threadIdx.x;
i < tbx.
numPts();
i += blockDim.x) {
301 #if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
303 for (
unsigned int ip_orig = bin_start + threadIdx.x; ip_orig < bin_stop; ip_orig += blockDim.x)
306 const unsigned int ip = permutation[ip_orig];
309 amrex::Real wq = q*wp[ip]*invvol;
314 amrex::ParticleReal xp, yp, zp;
315 GetPosition(ip, xp, yp, zp);
319 #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) || defined(WARPX_DIM_3D)
322 #if defined(WARPX_DIM_RZ)
323 const amrex::Real rp = std::sqrt(xp*xp + yp*yp);
324 amrex::Real costheta;
325 amrex::Real sintheta;
334 const amrex::Real
x = (rp - xyzmin.
x)*dinv.
x;
336 const amrex::Real
x = (xp - xyzmin.
x)*dinv.
x;
341 amrex::Real sx[depos_order + 1] = {0._rt};
343 if (rho_type[0] ==
NODE) {
344 i = compute_shape_factor(sx,
x);
345 }
else if (rho_type[0] == CELL) {
346 i = compute_shape_factor(sx,
x - 0.5_rt);
349 #if defined(WARPX_DIM_3D)
351 const amrex::Real y = (yp - xyzmin.
y)*dinv.
y;
352 amrex::Real sy[depos_order + 1] = {0._rt};
354 if (rho_type[1] ==
NODE) {
355 j = compute_shape_factor(sy, y);
356 }
else if (rho_type[1] == CELL) {
357 j = compute_shape_factor(sy, y - 0.5_rt);
361 const amrex::Real z = (zp - xyzmin.
z)*dinv.
z;
362 amrex::Real sz[depos_order + 1] = {0._rt};
364 if (rho_type[WARPX_ZINDEX] ==
NODE) {
365 k = compute_shape_factor(sz, z);
366 }
else if (rho_type[WARPX_ZINDEX] == CELL) {
367 k = compute_shape_factor(sz, z - 0.5_rt);
371 #if defined(WARPX_DIM_1D_Z)
372 for (
int iz=0;
iz<=depos_order;
iz++){
374 &buf(lo.
x+k+
iz, 0, 0, 0),
377 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
378 for (
int iz=0;
iz<=depos_order;
iz++){
379 for (
int ix=0;
ix<=depos_order;
ix++){
381 &buf(lo.
x+
i+
ix, lo.
y+k+
iz, 0, 0),
383 #if defined(WARPX_DIM_RZ)
385 for (
int imode=1 ; imode < n_rz_azimuthal_modes ; imode++) {
394 #elif defined(WARPX_DIM_3D)
395 for (
int iz=0;
iz<=depos_order;
iz++){
396 for (
int iy=0;
iy<=depos_order;
iy++){
397 for (
int ix=0;
ix<=depos_order;
ix++){
407 #if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
410 addLocalToGlobal(tbx, rho_arr, buf);
#define AMREX_D_DECL(a, b, c)
void doChargeDepositionShapeN(const GetParticlePosition< PIdx > &GetPosition, const amrex::ParticleReal *const wp, const int *ion_lev, amrex::FArrayBox &rho_fab, long np_to_deposit, const amrex::XDim3 &dinv, const amrex::XDim3 &xyzmin, amrex::Dim3 lo, amrex::Real q, [[maybe_unused]] int n_rz_azimuthal_modes)
Definition: ChargeDeposition.H:38
void doChargeDepositionSharedShapeN(const GetParticlePosition< PIdx > &GetPosition, const amrex::ParticleReal *const wp, const int *ion_lev, amrex::FArrayBox &rho_fab, const amrex::IntVect &ix_type, const long np_to_deposit, const amrex::XDim3 &dinv, const amrex::XDim3 &xyzmin, const amrex::Dim3 lo, const amrex::Real q, [[maybe_unused]]const int n_rz_azimuthal_modes, const amrex::DenseBins< WarpXParticleContainer::ParticleTileType::ParticleTileDataType > &a_bins, const amrex::Box &box, const amrex::Geometry &geom, const amrex::IntVect &a_tbox_max_size, const amrex::IntVect bin_size)
Definition: ChargeDeposition.H:183
#define WARPX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition: TextMsg.H:13
AMREX_FORCE_INLINE Array4< Real const > array() const noexcept
const Box & box() const noexcept
AMREX_GPU_HOST_DEVICE BoxND & grow(int i) noexcept
AMREX_GPU_HOST_DEVICE IntVectND< dim > type() const noexcept
AMREX_GPU_HOST_DEVICE Long numPts() const noexcept
index_type * offsetsPtr() noexcept
index_type * permutationPtr() noexcept
Long numBins() const noexcept
GpuArray< Real, AMREX_SPACEDIM > ProbLoArray() const noexcept
const Box & Domain() const noexcept
static std::size_t sharedMemPerBlock() noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AddNoRet(T *sum, T value) noexcept
gpuStream_t gpuStream() noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
void launch(T const &n, L &&f) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 end(BoxND< dim > const &box) noexcept
IntVectND< AMREX_SPACEDIM > IntVect
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 begin(BoxND< dim > const &box) noexcept
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... >, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int getTileIndex(const IntVect &iv, const Box &box, const bool a_do_tiling, const IntVect &a_tile_size, Box &tbx)
i
Definition: check_interp_points_and_weights.py:174
Definition: ShapeFactors.H:29
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T real() const noexcept
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE T imag() const noexcept
AMREX_GPU_DEVICE T * dataPtr() noexcept