47 Kokkos::View<const int*, CpMem> realIdx,
float growthRate,
48 bool dedupTwins =
true) {
49 const Kokkos::View<const float*, CpMem> invMass = bodies.
invMass;
50 const Kokkos::View<const float* [3], CpMem> invInertia = bodies.
invInertia;
51 const Kokkos::View<const float* [3], CpMem> velPred = pred.
velPred;
52 const Kokkos::View<const float* [3], CpMem> angVelPred = pred.
angVelPred;
56 "peclet::dem::fric_accum", Kokkos::RangePolicy<CpExec>(space, 0, numContacts),
57 KOKKOS_LAMBDA(
int idx) {
63 const int idA = c.
bodyA;
64 const float invMA = invMass(idA);
67 const F3 invIA =
ldF3(invInertia, idA);
71 const float approach = -
dot3(
sub3(vAc, vWall), n);
74 const float w_n = computeW(rA, n, invMA, invIA);
76 contacts(idx).friction_lambda_n += approach / w_n;
79 const int realA = realIdx(c.
bodyA), realB = realIdx(c.
bodyB);
80 if (dedupTwins && realA > realB)
82 const float invMA = invMass(realA), invMB = invMass(realB);
83 const F3 invIA =
ldF3(invInertia, realA), invIB =
ldF3(invInertia, realB);
90 const float approach = -
dot3(vrel, n);
93 const float w_n = computeW(rA, n, invMA, invIA) + computeW(rB, n, invMB, invIB);
95 contacts(idx).friction_lambda_n += approach / w_n;
105 const Kokkos::View<const float*, CpMem> invMass = bodies.
invMass;
106 const Kokkos::View<const float* [3], CpMem> invInertia = bodies.
invInertia;
107 const Kokkos::View<const float* [3], CpMem> velPred = pred.
velPred;
108 const Kokkos::View<const float* [3], CpMem> angVelPred = pred.
angVelPred;
111 Kokkos::deep_copy(space, planeFriction, 0.0f);
112 Kokkos::parallel_for(
113 "peclet::dem::fric_plane_load", Kokkos::RangePolicy<CpExec>(space, 0, numContacts),
114 KOKKOS_LAMBDA(
int idx) {
118 const int idA = c.
bodyA;
119 const float invMA = invMass(idA);
122 const F3 invIA =
ldF3(invInertia, idA);
128 const float approach = -
dot3(
sub3(vAc, vWall), n);
129 if (approach <= 0.0f)
131 const float w_n = computeW(rA, n, invMA, invIA);
132 contacts(idx).friction_lambda_n = (w_n > 1e-6f) ? approach / w_n : 0.0f;
133 Kokkos::atomic_max(&planeFriction(idA, 0), approach / invMA);
172 Kokkos::View<const int*, CpMem> realIdx,
175 const Kokkos::View<const float*, CpMem> invMass = bodies.
invMass;
176 const Kokkos::View<const float* [3], CpMem> invInertia = bodies.
invInertia;
177 const Kokkos::View<const float* [4], CpMem> quat = bodies.
quat;
178 const Kokkos::View<const float* [3], CpMem> velPred = pred.
velPred;
179 const Kokkos::View<const float* [3], CpMem> angVelPred = pred.
angVelPred;
180 const Kokkos::View<float* [3], CpMem> deltaVel = delta.
deltaVel;
181 const Kokkos::View<float* [3], CpMem> deltaAngVel = delta.
deltaAngVel;
183 Kokkos::deep_copy(space, deltaVel, 0.0f);
184 Kokkos::deep_copy(space, deltaAngVel, 0.0f);
185 Kokkos::parallel_for(
186 "peclet::dem::fric_solve", Kokkos::RangePolicy<CpExec>(space, 0, numContacts),
187 KOKKOS_LAMBDA(
int idx) {
190 if (lambda_n <= 0.0f)
193 const int realA = realIdx(idA);
194 const int realB = (idB >= 0) ? realIdx(idB) : -1;
195 const float invMA = invMass(realA);
196 const float invMB = (idB >= 0) ? invMass(realB) : 0.0f;
197 const F3 invIA =
ldF3(invInertia, realA);
198 const F3 invIB = (idB >= 0) ?
ldF3(invInertia, realB) :
F3{0, 0, 0};
211 const F3 vrel =
sub3(vAc, vBc);
212 const float vn =
dot3(vrel, n);
214 const float vt_len = Kokkos::sqrt(
dot3(vt, vt));
217 const F3 t =
scale3(vt, 1.0f / vt_len);
221 const bool isoA = invIA.
x == invIA.
y && invIA.
y == invIA.
z;
222 const bool isoB = invIB.
x == invIB.
y && invIB.
y == invIB.
z;
223 F4 qA{0, 0, 0, 1}, qB{0, 0, 0, 1};
225 qA =
F4{quat(realA, 0), quat(realA, 1), quat(realA, 2), quat(realA, 3)};
227 qB =
F4{quat(realB, 0), quat(realB, 1), quat(realB, 2), quat(realB, 3)};
228 const float w_t = (isoA && isoB)
229 ? invMA + invMB + rnA.
x * rnA.
x * invIA.
x + rnA.
y * rnA.
y * invIA.
y +
230 rnA.
z * rnA.
z * invIA.
z + rnB.x * rnB.x * invIB.
x +
231 rnB.y * rnB.y * invIB.
y + rnB.z * rnB.z * invIB.
z
240 const float bound = lambda_n;
241 const float nA = planeFriction(realA, 1);
242 const float nB = (idB >= 0) ? planeFriction(realB, 1) : 0.0f;
243 const float inv_n = 1.0f / Kokkos::fmax(Kokkos::fmax(nA, nB), 1.0f);
244 float lt = -vt_len / w_t;
248 const float maxf = mu * bound;
253 Kokkos::atomic_add(&deltaVel(realA, 0), t.
x * lt * invMA);
254 Kokkos::atomic_add(&deltaVel(realA, 1), t.
y * lt * invMA);
255 Kokkos::atomic_add(&deltaVel(realA, 2), t.
z * lt * invMA);
257 Kokkos::atomic_add(&deltaAngVel(realA, 0), rnA.
x * invIA.
x * lt);
258 Kokkos::atomic_add(&deltaAngVel(realA, 1), rnA.
y * invIA.
y * lt);
259 Kokkos::atomic_add(&deltaAngVel(realA, 2), rnA.
z * invIA.
z * lt);
263 Kokkos::atomic_add(&deltaAngVel(realA, 0), dww.
x);
264 Kokkos::atomic_add(&deltaAngVel(realA, 1), dww.
y);
265 Kokkos::atomic_add(&deltaAngVel(realA, 2), dww.
z);
268 Kokkos::atomic_add(&deltaVel(realB, 0), -t.
x * lt * invMB);
269 Kokkos::atomic_add(&deltaVel(realB, 1), -t.
y * lt * invMB);
270 Kokkos::atomic_add(&deltaVel(realB, 2), -t.
z * lt * invMB);
272 Kokkos::atomic_add(&deltaAngVel(realB, 0), -rnB.x * invIB.
x * lt);
273 Kokkos::atomic_add(&deltaAngVel(realB, 1), -rnB.y * invIB.
y * lt);
274 Kokkos::atomic_add(&deltaAngVel(realB, 2), -rnB.z * invIB.
z * lt);
278 Kokkos::atomic_add(&deltaAngVel(realB, 0), dww.
x);
279 Kokkos::atomic_add(&deltaAngVel(realB, 1), dww.
y);
280 Kokkos::atomic_add(&deltaAngVel(realB, 2), dww.
z);
void solveContactFriction(Kokkos::View< const ContactC *, CpMem > contacts, int numContacts, const BodyState &bodies, const BodyPred &pred, Kokkos::View< const int *, CpMem > realIdx, FrManifoldCounts planeFriction, float frictionDynamic, const BodyDelta &delta)
One count-averaged Coulomb friction sweep.
void accumulateNormalImpulse(Kokkos::View< ContactC *, CpMem > contacts, int numContacts, const BodyState &bodies, const BodyPred &pred, Kokkos::View< const int *, CpMem > realIdx, float growthRate, bool dedupTwins=true)
Force-chain normal load, accumulated over the velocity iterations: contacts(idx).friction_lambda_n +=...
The solve's per-body accumulators: position/orientation and velocity corrections and the per-body con...
The substep's predicted body state (Particles::bodyPred()).
A body's state, one row per particle slot (Particles::bodyState()).