32 Kokkos::View<const float*, CpMem> invMass,
33 Kokkos::View<
const float* [3],
CpMem> invInertia,
34 Kokkos::View<
const float* [4],
CpMem> quat,
35 Kokkos::View<
const float* [3],
CpMem> velPred,
36 Kokkos::View<
const float* [3],
CpMem> angVelPred,
37 Kokkos::View<const int*, CpMem> realIdx,
float growthRate,
38 float restitutionNormal, Kokkos::View<
float* [3],
CpMem> deltaVel,
39 Kokkos::View<
float* [3],
CpMem> deltaAngVel) {
44 "peclet::dem::solve_velocity", Kokkos::RangePolicy<CpExec>(space, 0, numManifolds),
45 KOKKOS_LAMBDA(
int idx) {
51 const int realA = realIdx(idA);
59 const float invMassA = invMass(realA);
60 const float invMassB = (idB >= 0) ? invMass(realB) : 0.0f;
61 const F3 invIA = ld3(invInertia, realA);
62 const F3 invIB = (idB >= 0) ? ld3(invInertia, realB) :
F3{0, 0, 0};
63 const F4 qA =
F4{quat(realA, 0), quat(realA, 1), quat(realA, 2), quat(realA, 3)};
64 const F4 qB = (idB >= 0)
65 ?
F4{quat(realB, 0), quat(realB, 1), quat(realB, 2), quat(realB, 3)}
68 const F3 vA = ld3(velPred, realA), wA = ld3(angVelPred, realA);
69 F3 vB{0, 0, 0}, wB{0, 0, 0};
71 vB = ld3(velPred, realB);
72 wB = ld3(angVelPred, realB);
79 const float invN = 1.0f /
static_cast<float>(m.
num_points);
84 float restitution = restitutionNormal;
94 const float lenN = Kokkos::sqrt(
dot3(Nsum, Nsum));
105 const F3 diffCenters = (idB < 0) ? rAavg :
sub3(rAavg, rBavg);
106 const F3 vGrowth =
scale3(diffCenters, growthRate);
108 float vn =
dot3(vA, Nsum) +
dot3(wA, TauA) +
dot3(vB,
F3{-Nsum.
x, -Nsum.y, -Nsum.z}) +
110 vn +=
dot3(vGrowth, Nsum);
112 const float alignment =
dot3(Nsum, diffCenters);
113 if (alignment > 0.0f) {
121 const float Nsq =
dot3(Nsum, Nsum);
122 const float wA_n = Nsq * invMassA + genInvMass(TauA, invIA, qA);
123 const float wB_n = Nsq * invMassB + genInvMass(TauB, invIB, qB);
124 const float wTotal = wA_n + wB_n;
128 const float lambda = (-restitution * vn - vn) / wTotal;
130 const F3 Jlin =
scale3(Nsum, lambda);
131 const F3 JangA =
scale3(TauA, lambda);
132 const F3 JangB =
scale3(TauB, lambda);
135 Kokkos::atomic_add(&deltaVel(realA, 0), Jlin.
x * invMassA);
136 Kokkos::atomic_add(&deltaVel(realA, 1), Jlin.
y * invMassA);
137 Kokkos::atomic_add(&deltaVel(realA, 2), Jlin.
z * invMassA);
141 const F3 dwl{Jl.
x * invIA.
x, Jl.
y * invIA.
y, Jl.
z * invIA.
z};
143 Kokkos::atomic_add(&deltaAngVel(realA, 0), dww.
x);
144 Kokkos::atomic_add(&deltaAngVel(realA, 1), dww.
y);
145 Kokkos::atomic_add(&deltaAngVel(realA, 2), dww.
z);
148 Kokkos::atomic_add(&deltaVel(realB, 0), -Jlin.
x * invMassB);
149 Kokkos::atomic_add(&deltaVel(realB, 1), -Jlin.
y * invMassB);
150 Kokkos::atomic_add(&deltaVel(realB, 2), -Jlin.
z * invMassB);
152 const F3 dwl{Jl.
x * invIB.
x, Jl.
y * invIB.
y, Jl.
z * invIB.
z};
154 Kokkos::atomic_add(&deltaAngVel(realB, 0), dww.
x);
155 Kokkos::atomic_add(&deltaAngVel(realB, 1), dww.
y);
156 Kokkos::atomic_add(&deltaAngVel(realB, 2), dww.
z);
void solveVelocityKokkos(Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, Kokkos::View< const float *, CpMem > invMass, Kokkos::View< const float *[3], CpMem > invInertia, Kokkos::View< const float *[4], CpMem > quat, Kokkos::View< const float *[3], CpMem > velPred, Kokkos::View< const float *[3], CpMem > angVelPred, Kokkos::View< const int *, CpMem > realIdx, float growthRate, float restitutionNormal, Kokkos::View< float *[3], CpMem > deltaVel, Kokkos::View< float *[3], CpMem > deltaAngVel)
Accumulate normal-restitution velocity deltas for numManifolds manifolds.