33 Kokkos::View<const float*, CpMem> invMass,
34 Kokkos::View<
const float* [3],
CpMem> invInertia,
35 Kokkos::View<
const float* [3],
CpMem> velPred,
36 Kokkos::View<
const float* [3],
CpMem> angVelPred,
37 Kokkos::View<const int*, CpMem> realIdx,
42 "peclet::dem::fric_accum", Kokkos::RangePolicy<CpExec>(space, 0, numContacts),
43 KOKKOS_LAMBDA(
int idx) {
49 const int idA = c.
bodyA;
50 const float invMA = invMass(idA);
53 const F3 invIA =
ldF3(invInertia, idA);
57 const float approach = -
dot3(
sub3(vAc, vWall), n);
60 const float w_n = computeW(rA, n, invMA, invIA);
62 contacts(idx).friction_lambda_n += approach / w_n;
65 const int realA = realIdx(c.
bodyA), realB = realIdx(c.
bodyB);
68 const float invMA = invMass(realA), invMB = invMass(realB);
69 const F3 invIA =
ldF3(invInertia, realA), invIB =
ldF3(invInertia, realB);
75 const float approach = -
dot3(vrel, n);
78 const float w_n = computeW(rA, n, invMA, invIA) + computeW(rB, n, invMB, invIB);
80 contacts(idx).friction_lambda_n += approach / w_n;
88 Kokkos::View<const float*, CpMem> invMass,
89 Kokkos::View<
const float* [3],
CpMem> invInertia,
90 Kokkos::View<
const float* [3],
CpMem> velPred,
91 Kokkos::View<
const float* [3],
CpMem> angVelPred,
95 Kokkos::deep_copy(space, planeFriction, 0.0f);
97 "peclet::dem::fric_plane_load", Kokkos::RangePolicy<CpExec>(space, 0, numContacts),
98 KOKKOS_LAMBDA(
int idx) {
102 const int idA = c.
bodyA;
103 const float invMA = invMass(idA);
106 const F3 invIA =
ldF3(invInertia, idA);
112 const float approach = -
dot3(
sub3(vAc, vWall), n);
113 if (approach <= 0.0f)
115 const float w_n = computeW(rA, n, invMA, invIA);
116 contacts(idx).friction_lambda_n = (w_n > 1e-6f) ? approach / w_n : 0.0f;
117 Kokkos::atomic_max(&planeFriction(idA, 0), approach / invMA);
124 int numContacts, Kokkos::View<const int*, CpMem> realIdx,
127 Kokkos::parallel_for(
128 "peclet::dem::fric_count", Kokkos::RangePolicy<CpExec>(space, 0, numContacts),
129 KOKKOS_LAMBDA(
int idx) {
133 Kokkos::atomic_add(&planeFriction(realIdx(c.
bodyA), 1), 1.0f);
135 Kokkos::atomic_add(&planeFriction(realIdx(c.
bodyB), 1), 1.0f);
143 Kokkos::View<const ContactC*, CpMem> contacts,
int numContacts,
144 Kokkos::View<const float*, CpMem> invMass, Kokkos::View<
const float* [3],
CpMem> invInertia,
145 Kokkos::View<
const float* [3],
CpMem> velPred, Kokkos::View<
const float* [3],
CpMem> angVelPred,
146 Kokkos::View<const int*, CpMem> realIdx,
FrManifoldCounts planeFriction,
float frictionDynamic,
147 Kokkos::View<
float* [3],
CpMem> deltaVel, Kokkos::View<
float* [3],
CpMem> deltaAngVel) {
149 Kokkos::deep_copy(space, deltaVel, 0.0f);
150 Kokkos::deep_copy(space, deltaAngVel, 0.0f);
151 Kokkos::parallel_for(
152 "peclet::dem::fric_solve", Kokkos::RangePolicy<CpExec>(space, 0, numContacts),
153 KOKKOS_LAMBDA(
int idx) {
156 if (lambda_n <= 0.0f)
159 const int realA = realIdx(idA);
160 const int realB = (idB >= 0) ? realIdx(idB) : -1;
161 const float invMA = invMass(realA);
162 const float invMB = (idB >= 0) ? invMass(realB) : 0.0f;
163 const F3 invIA =
ldF3(invInertia, realA);
164 const F3 invIB = (idB >= 0) ?
ldF3(invInertia, realB) :
F3{0, 0, 0};
174 const F3 vrel =
sub3(vAc, vBc);
175 const float vn =
dot3(vrel, n);
177 const float vt_len = Kokkos::sqrt(
dot3(vt, vt));
180 const F3 t =
scale3(vt, 1.0f / vt_len);
183 const float w_t = invMA + invMB + rnA.
x * rnA.
x * invIA.
x + rnA.
y * rnA.
y * invIA.
y +
184 rnA.
z * rnA.
z * invIA.
z + rnB.x * rnB.x * invIB.
x +
185 rnB.y * rnB.y * invIB.
y + rnB.z * rnB.z * invIB.
z;
191 const float bound = lambda_n;
192 const float nA = planeFriction(realA, 1);
193 const float nB = (idB >= 0) ? planeFriction(realB, 1) : 0.0f;
194 const float inv_n = 1.0f / Kokkos::fmax(Kokkos::fmax(nA, nB), 1.0f);
195 float lt = -vt_len / w_t;
199 const float maxf = mu * bound;
204 Kokkos::atomic_add(&deltaVel(realA, 0), t.
x * lt * invMA);
205 Kokkos::atomic_add(&deltaVel(realA, 1), t.
y * lt * invMA);
206 Kokkos::atomic_add(&deltaVel(realA, 2), t.
z * lt * invMA);
207 Kokkos::atomic_add(&deltaAngVel(realA, 0), rnA.
x * invIA.
x * lt);
208 Kokkos::atomic_add(&deltaAngVel(realA, 1), rnA.
y * invIA.
y * lt);
209 Kokkos::atomic_add(&deltaAngVel(realA, 2), rnA.
z * invIA.
z * lt);
211 Kokkos::atomic_add(&deltaVel(realB, 0), -t.
x * lt * invMB);
212 Kokkos::atomic_add(&deltaVel(realB, 1), -t.
y * lt * invMB);
213 Kokkos::atomic_add(&deltaVel(realB, 2), -t.
z * lt * invMB);
214 Kokkos::atomic_add(&deltaAngVel(realB, 0), -rnB.x * invIB.
x * lt);
215 Kokkos::atomic_add(&deltaAngVel(realB, 1), -rnB.y * invIB.
y * lt);
216 Kokkos::atomic_add(&deltaAngVel(realB, 2), -rnB.z * invIB.
z * lt);
void computePlaneLoadKokkos(Kokkos::View< ContactC *, CpMem > contacts, int numContacts, Kokkos::View< const float *, CpMem > invMass, Kokkos::View< const float *[3], CpMem > invInertia, Kokkos::View< const float *[3], CpMem > velPred, Kokkos::View< const float *[3], CpMem > angVelPred, FrManifoldCounts planeFriction)
Plane (idB<0) one-shot loads.
void accumulateNormalImpulseKokkos(Kokkos::View< ContactC *, CpMem > contacts, int numContacts, Kokkos::View< const float *, CpMem > invMass, Kokkos::View< const float *[3], CpMem > invInertia, Kokkos::View< const float *[3], CpMem > velPred, Kokkos::View< const float *[3], CpMem > angVelPred, Kokkos::View< const int *, CpMem > realIdx, float growthRate)
Force-chain normal load, accumulated over the velocity iterations: contacts(idx).friction_lambda_n +=...
void solveContactFrictionKokkos(Kokkos::View< const ContactC *, CpMem > contacts, int numContacts, Kokkos::View< const float *, CpMem > invMass, Kokkos::View< const float *[3], CpMem > invInertia, Kokkos::View< const float *[3], CpMem > velPred, Kokkos::View< const float *[3], CpMem > angVelPred, Kokkos::View< const int *, CpMem > realIdx, FrManifoldCounts planeFriction, float frictionDynamic, Kokkos::View< float *[3], CpMem > deltaVel, Kokkos::View< float *[3], CpMem > deltaAngVel)
One count-averaged Coulomb friction sweep.
void countFrictionContactsKokkos(Kokkos::View< const ContactC *, CpMem > contacts, int numContacts, Kokkos::View< const int *, CpMem > realIdx, FrManifoldCounts planeFriction)
Per-body active-contact count into planeFriction(:,1).