9#ifndef DEM_PERIODICITY_HPP
10#define DEM_PERIODICITY_HPP
12#include <Kokkos_Core.hpp>
30 const double innerX = (dom.
size.
x - 2.0f * sx > 0.0f) ? (dom.
size.
x - 2.0f * sx) : 0.0;
31 const double innerY = (dom.
size.
y - 2.0f * sy > 0.0f) ? (dom.
size.
y - 2.0f * sy) : 0.0;
32 const double innerZ = (dom.
size.
z - 2.0f * sz > 0.0f) ? (dom.
size.
z - 2.0f * sz) : 0.0;
33 const double volTotal =
static_cast<double>(dom.
size.
x) * dom.
size.
y * dom.
size.
z;
36 const double ghostFraction = (volTotal - innerX * innerY * innerZ) / volTotal;
37 const double estGhosts = (ghostFraction > 0.5) ? nReal * 32.0 : nReal * ghostFraction * 4.0;
38 return nReal +
static_cast<int>(estGhosts) + 4096;
47 Kokkos::View<int, CpMem> topGhost,
Vi gid =
Vi{},
48 Kokkos::View<unsigned char*, CpMem> materialId = {}) {
49 const V3 pos = bodies.
pos, vel = bodies.
vel, angVel = bodies.
angVel;
51 const V4 quat = bodies.
quat;
59 "peclet::dem::generate_ghosts", Kokkos::RangePolicy<CpExec>(space, 0, numReal),
60 KOKKOS_LAMBDA(
int i) {
61 const F3 p =
ldF3(pos, i);
63 ? ((p.x < dom.
min.
x + skin) ? 1 : ((p.x > dom.
max.
x - skin) ? -1 : 0))
66 ? ((p.y < dom.
min.
y + skin) ? 1 : ((p.y > dom.
max.
y - skin) ? -1 : 0))
69 ? ((p.z < dom.
min.
z + skin) ? 1 : ((p.z > dom.
max.
z - skin) ? -1 : 0))
71 const int ax[2] = {0, sx}, ay[2] = {0, sy}, az[2] = {0, sz};
72 const int nx = (sx == 0) ? 1 : 2, ny = (sy == 0) ? 1 : 2, nz = (sz == 0) ? 1 : 2;
74 const F3 pPred =
ldF3(posPred, i);
75 for (
int a = 0; a < nx; ++a)
76 for (
int b = 0; b < ny; ++b)
77 for (
int c = 0; c < nz; ++c) {
78 const int ix = ax[a], iy = ay[b], iz = az[c];
79 if (ix == 0 && iy == 0 && iz == 0)
81 const int slot = Kokkos::atomic_fetch_add(&topGhost(), 1);
82 if (slot >= capacity) {
83 Kokkos::atomic_add(&topGhost(), -1);
88 st3(posPred, slot,
add3(pPred, shift));
89 invMass(slot) = invMass(i);
91 st3(velPred, slot,
ldF3(velPred, i));
93 st4(quatPred, slot,
ldF4(quatPred, i));
94 st3(angVel, slot,
ldF3(angVel, i));
95 st3(angVelPred, slot,
ldF3(angVelPred, i));
96 scale(slot) = scale(i);
97 shapeId(slot) = shapeId(i);
98 realIndices(slot) = i;
99 if (gid.extent(0) > 0)
104 if (materialId.extent(0) > 0)
105 materialId(slot) = materialId(i);
dem — portable POD types + math + analytic SDFs shared by the Kokkos kernel ports.
dem — portable (Kokkos) time integration kernels (integration.cu).
void st3(const V3 &v, int i, F3 a)
void st4(const V4 &v, int i, F4 a)
Kokkos::View< float *, CpMem > Vf
Kokkos::View< int *, CpMem > Vi
void generateGhosts(int numReal, int capacity, Domain dom, float skin, const BodyState &bodies, const BodyPred &pred, Vi realIndices, Kokkos::View< int, CpMem > topGhost, Vi gid=Vi{}, Kokkos::View< unsigned char *, CpMem > materialId={})
Generate periodic ghosts for particles [0,numReal).
F3 ldF3(const V &v, int i)
Kokkos::DefaultExecutionSpace CpExec
Kokkos::View< float *[3], CpMem > V3
F4 ldF4(const V &v, int i)
Kokkos::View< float *[4], CpMem > V4
int calculateGhostCapacity(int nReal, Domain dom, float skin)
Padded particle-array capacity that leaves room for the periodic ghosts generateGhosts will emit: the...
The substep's predicted body state (Particles::bodyPred()).
Kokkos::View< float *[3], CpMem > velPred
Kokkos::View< float *[3], CpMem > angVelPred
Kokkos::View< float *[3], CpMem > posPred
Kokkos::View< float *[4], CpMem > quatPred
A body's state, one row per particle slot (Particles::bodyState()).
Kokkos::View< float *[3], CpMem > pos
Kokkos::View< float *, CpMem > scale
Kokkos::View< float *, CpMem > invMass
Kokkos::View< int *, CpMem > shapeId
Kokkos::View< float *[3], CpMem > angVel
Kokkos::View< float *[4], CpMem > quat
Kokkos::View< float *[3], CpMem > vel