7#ifndef DEM_SOLVE_COPIES_HPP
8#define DEM_SOLVE_COPIES_HPP
12#include <Kokkos_Core.hpp>
13#include <Kokkos_Sort.hpp>
49 v = V(Kokkos::view_alloc(Kokkos::WithoutInitializing, std::string(label)), n + n / 2 + 64);
55 Kokkos::View<const int*, CpMem> realIdx,
56 Kokkos::View<const int*, CpMem> color, Kokkos::View<int*, CpMem> eA,
57 Kokkos::View<int*, CpMem> eB) {
59 "peclet::dem::copies_vel_ends", Kokkos::RangePolicy<CpExec>(0, nm), KOKKOS_LAMBDA(
int e) {
61 const bool act = color(e) != -2;
62 eA(e) = act ? realIdx(m.
bodyA) : -1;
63 eB(e) = (act && m.
bodyB >= 0) ? realIdx(m.
bodyB) : -1;
70 int nu, Kokkos::View<const int*, CpMem> color,
71 Kokkos::View<int*, CpMem> eA, Kokkos::View<int*, CpMem> eB) {
73 "peclet::dem::copies_pos_ends", Kokkos::RangePolicy<CpExec>(0, nu), KOKKOS_LAMBDA(
int u) {
75 const bool act = color(u) != -2;
76 eA(u) = act ? c.
bodyA : -1;
82inline void vertexDegree(Kokkos::View<const int*, CpMem> eA, Kokkos::View<const int*, CpMem> eB,
83 int nE,
int nV, Kokkos::View<int*, CpMem> deg) {
84 Kokkos::deep_copy(Kokkos::subview(deg, Kokkos::pair<int, int>(0, nV)), 0);
86 "peclet::dem::copies_degree", Kokkos::RangePolicy<CpExec>(0, nE), KOKKOS_LAMBDA(
int e) {
88 Kokkos::atomic_add(°(eA(e)), 1);
90 Kokkos::atomic_add(°(eB(e)), 1);
101inline void buildHubCopies(Kokkos::View<const int*, CpMem> eA, Kokkos::View<const int*, CpMem> eB,
102 int nE,
int nV,
int slotBase, Kokkos::View<const int*, CpMem> deg,
105 using Kokkos::view_alloc;
106 using Kokkos::WithoutInitializing;
111 growCopyView(H.
slotA,
static_cast<std::size_t
>(nE),
"peclet::dem::copies_slotA");
112 growCopyView(H.
slotB,
static_cast<std::size_t
>(nE),
"peclet::dem::copies_slotB");
113 Kokkos::deep_copy(space, Kokkos::subview(H.
slotA, Kokkos::pair<int, int>(0, nE)), -1);
114 Kokkos::deep_copy(space, Kokkos::subview(H.
slotB, Kokkos::pair<int, int>(0, nE)), -1);
115 Kokkos::View<int*, CpMem> hubId(
116 view_alloc(space,
"peclet::dem::copies_hubid", WithoutInitializing), nV);
118 Kokkos::parallel_scan(
119 "peclet::dem::copies_hub_scan", Kokkos::RangePolicy<CpExec>(space, 0, nV),
120 KOKKOS_LAMBDA(
int v,
int& run,
const bool final) {
121#if defined(PECLET_DEM_TEST_MUTANT) && PECLET_DEM_TEST_MUTANT == 3
122 const bool hub =
false;
127 hubId(v) = hub ? run : -1;
137 growCopyView(H.
hubS,
static_cast<std::size_t
>(nHubs),
"peclet::dem::copies_hubs");
140 Kokkos::parallel_for(
141 "peclet::dem::copies_hub_list", Kokkos::RangePolicy<CpExec>(space, 0, nV),
142 KOKKOS_LAMBDA(
int v) {
143 const int h = hubId(v);
149 Kokkos::View<int*, CpMem> copyOff(
150 view_alloc(space,
"peclet::dem::copies_off", WithoutInitializing), nHubs);
151 Kokkos::View<int*, CpMem> degOff(
152 view_alloc(space,
"peclet::dem::copies_doff", WithoutInitializing), nHubs);
153 int nCopies = 0, nEntries = 0, maxDeg = 0;
154 Kokkos::parallel_scan(
155 "peclet::dem::copies_off_scan", Kokkos::RangePolicy<CpExec>(space, 0, nHubs),
156 KOKKOS_LAMBDA(
int h,
int& run,
const bool final) {
162 Kokkos::parallel_scan(
163 "peclet::dem::copies_doff_scan", Kokkos::RangePolicy<CpExec>(space, 0, nHubs),
164 KOKKOS_LAMBDA(
int h,
int& run,
const bool final) {
170 Kokkos::parallel_reduce(
171 "peclet::dem::copies_maxdeg", Kokkos::RangePolicy<CpExec>(space, 0, nHubs),
172 KOKKOS_LAMBDA(
int h,
int& m) {
176 Kokkos::Max<int>(maxDeg));
183 Kokkos::View<std::uint64_t*, CpMem> keys(
184 view_alloc(space,
"peclet::dem::copies_keys", WithoutInitializing), nEntries);
185 Kokkos::View<int, CpMem> cursor(
"peclet::dem::copies_cursor");
186 Kokkos::parallel_for(
187 "peclet::dem::copies_entries", Kokkos::RangePolicy<CpExec>(space, 0, nE),
188 KOKKOS_LAMBDA(
int e) {
189 const int ends[2] = {eA(e), eB(e)};
190 for (
int end = 0; end < 2; ++end) {
191 const int v = ends[end];
192 if (v < 0 || hubId(v) < 0)
194 const int p = Kokkos::atomic_fetch_add(&cursor(), 1);
195 keys(p) = (
static_cast<std::uint64_t
>(hubId(v)) << 33) |
196 (
static_cast<std::uint64_t
>(
static_cast<unsigned>(e)) << 1) |
197 static_cast<std::uint64_t
>(end);
200 Kokkos::sort(space, keys);
202 "peclet::dem::copies_base");
206 Kokkos::parallel_for(
207 "peclet::dem::copies_assign", Kokkos::RangePolicy<CpExec>(space, 0, nEntries),
208 KOKKOS_LAMBDA(
int p) {
209 const std::uint64_t k = keys(p);
210 const int h =
static_cast<int>(k >> 33);
211 const int e =
static_cast<int>((k >> 1) & 0xFFFFFFFFull);
212 const int end =
static_cast<int>(k & 1ull);
214 const int c = (p - degOff(h)) % s;
215 const int slot = (c == 0) ? hv(h) : slotBase + copyOff(h) + c - 1;
221 cb(copyOff(h) + c - 1) = hv(h);
241inline void buildCopyGroups(Kokkos::View<const int*, CpMem> realIdx,
int span,
int numReal,
242 Kokkos::View<const int*, CpMem> deg,
244 bool identityBodies =
false) {
246 using Kokkos::view_alloc;
247 using Kokkos::WithoutInitializing;
253 Kokkos::View<int*, CpMem> cnt(
"peclet::dem::copies_cnt", span);
254 Kokkos::parallel_for(
255 "peclet::dem::copies_grp_cnt", Kokkos::RangePolicy<CpExec>(space, 0, nQ),
256 KOKKOS_LAMBDA(
int qi) {
257 const int o = identityBodies ? ((qi < span) ? qi : cb(qi - span))
258 : ((qi < span) ? realIdx(qi) : realIdx(cb(qi - span)));
259 Kokkos::atomic_add(&cnt(o), 1);
261 Kokkos::View<std::uint64_t*, CpMem> keys(
262 view_alloc(space,
"peclet::dem::copies_gkeys", WithoutInitializing), nQ);
264 Kokkos::parallel_reduce(
265 "peclet::dem::copies_grp_keys", Kokkos::RangePolicy<CpExec>(space, 0, nQ),
266 KOKKOS_LAMBDA(
int qi,
int& acc) {
267 const int q = (qi < span) ? qi : base + (qi - span);
268 const int o = identityBodies ? ((qi < span) ? qi : cb(qi - span))
269 : ((qi < span) ? realIdx(qi) : realIdx(cb(qi - span)));
271 keys(qi) = (
static_cast<std::uint64_t
>(
static_cast<unsigned>(o)) << 32) |
272 static_cast<unsigned>(q);
275 keys(qi) = ~std::uint64_t(0);
282 Kokkos::sort(space, keys);
291 const bool haveShift = imageShift.extent(0) > 0;
293 Kokkos::parallel_scan(
294 "peclet::dem::copies_grp_scan", Kokkos::RangePolicy<CpExec>(space, 0, nMem),
295 KOKKOS_LAMBDA(
int p,
int& run,
const bool final) {
296 const bool isNew = (p == 0) || ((keys(p) >> 32) != (keys(p - 1) >> 32));
298 const int q =
static_cast<int>(keys(p) & 0xFFFFFFFFull);
300 const int b = (q < base) ? q : cb(q - base);
301 F3 sh{0.0f, 0.0f, 0.0f};
302 if (haveShift && b >= numReal && b < span)
303 sh =
F3{imageShift(b, 0), imageShift(b, 1), imageShift(b, 2)};
307 ga(p) = (q >= base || deg(q) > 0) ? 1 : 0;
315 Kokkos::deep_copy(space, Kokkos::subview(gs, nG), nMem);
317 growCopyView(H.
seedX,
static_cast<std::size_t
>(nG),
"peclet::dem::copies_seedx");
318 growCopyView(H.
seedW,
static_cast<std::size_t
>(nG),
"peclet::dem::copies_seedw");
320 Kokkos::parallel_for(
321 "peclet::dem::copies_grp_k", Kokkos::RangePolicy<CpExec>(space, 0, nG), KOKKOS_LAMBDA(
int g) {
323 for (
int p = gs(g); p < gs(g + 1); ++p)
325 gk(g) = k > 0 ? k : 1;
335 Kokkos::View<const float*, CpMem> invMass,
336 Kokkos::View<
const float* [3],
CpMem> invInertia) {
344 Kokkos::parallel_for(
345 "peclet::dem::copies_solve_views", Kokkos::RangePolicy<CpExec>(space, 0, nSlots),
346 KOKKOS_LAMBDA(
int q) {
347 const bool own = q < static_cast<int>(invMass.extent(0));
348 ims(q) = own ? invMass(q) : 0.0f;
349 for (
int c = 0; c < 3; ++c)
350 iis(q, c) = own ? invInertia(q, c) : 0.0f;
356 Kokkos::parallel_for(
357 "peclet::dem::copies_solve_split", Kokkos::RangePolicy<CpExec>(space, 0, H.
nGroups),
358 KOKKOS_LAMBDA(
int g) {
359 const int b = gq(gs(g));
361 const float kf =
static_cast<float>(k);
362 const float m = kf * invMass(b);
363 const float i0 = kf * invInertia(b, 0), i1 = kf * invInertia(b, 1),
364 i2 = kf * invInertia(b, 2);
365 for (
int p = gs(g); p < gs(g + 1); ++p) {
371 spl(q) = k > 1 ? 1 : 0;
388 Kokkos::parallel_for(
389 "peclet::dem::copies_seed_state", Kokkos::RangePolicy<CpExec>(0, H.
nCopies),
390 KOKKOS_LAMBDA(
int c) {
391 const int q = base + c, b = cb(c);
392 for (
int j = 0; j < 4; ++j) {
393 quat(q, j) = quat(b, j);
394 quatPred(q, j) = quatPred(b, j);
396 for (
int j = 0; j < 3; ++j)
397 invI(q, j) = invI(b, j);
398 grounded(q) = grounded(b);
409 Kokkos::View<
float* [3],
CpMem> w, Kokkos::View<float*, CpMem> orphan,
410 Kokkos::View<float*, CpMem> orphanPeak,
bool shareFromBase =
false) {
419 const bool haveW = w.extent(0) > 0;
420 const bool haveO = orphan.extent(0) > 0;
421 Kokkos::parallel_for(
422 "peclet::dem::copies_mark", Kokkos::RangePolicy<CpExec>(0, H.
nGroups), KOKKOS_LAMBDA(
int g) {
423 const int b = gq(gs(g));
424 for (
int c = 0; c < 3; ++c) {
429 float share = 0.0f, pk = 0.0f;
431 share = shareFromBase ? orphan(b) : orphan(b) /
static_cast<float>(gk(g));
434 for (
int p = gs(g); p < gs(g + 1); ++p) {
437 for (
int c = 0; c < 3; ++c) {
438 x(q, c) = sx(g, c) + gsh(p, c);
460 Kokkos::View<
float* [3],
CpMem> w, Kokkos::View<float*, CpMem> orphan,
461 Kokkos::View<float*, CpMem> orphanPeak,
462 Kokkos::View<float, CpMem> consensus = {}) {
472 const bool haveW = w.extent(0) > 0;
473 const bool haveO = orphan.extent(0) > 0;
474 const bool haveC = consensus.data() !=
nullptr;
475 Kokkos::parallel_for(
476 "peclet::dem::copies_fold", Kokkos::RangePolicy<CpExec>(space, 0, H.
nGroups),
477 KOKKOS_LAMBDA(
int g) {
478 const float kf =
static_cast<float>(gk(g));
479 float tx[3] = {0.0f, 0.0f, 0.0f}, tw[3] = {0.0f, 0.0f, 0.0f};
480 float oSum = 0.0f, oPk = 0.0f;
481 for (
int p = gs(g); p < gs(g + 1); ++p) {
485 for (
int c = 0; c < 3; ++c) {
486 tx[c] += x(q, c) - (sx(g, c) + gsh(p, c));
488 tw[c] += w(q, c) - sw(g, c);
492 oPk = Kokkos::fmax(oPk, orphanPeak(q));
496 for (
int c = 0; c < 3; ++c) {
497#if defined(PECLET_DEM_TEST_MUTANT) && PECLET_DEM_TEST_MUTANT == 2
498 nx[c] = sx(g, c) + tx[c];
499 nw[c] = haveW ? sw(g, c) + tw[c] : 0.0f;
501 nx[c] = sx(g, c) + tx[c] / kf;
502 nw[c] = haveW ? sw(g, c) + tw[c] / kf : 0.0f;
505 const float share = oSum / kf;
508 for (
int p = gs(g); p < gs(g + 1); ++p) {
513 for (
int c = 0; c < 3; ++c) {
514 const float e = tx[c] / kf - (x(q, c) - (sx(g, c) + gsh(p, c)));
517 cmax = Kokkos::fmax(cmax, Kokkos::sqrt(s2));
520 Kokkos::atomic_max(&consensus(), cmax);
522 for (
int p = gs(g); p < gs(g + 1); ++p) {
524 for (
int c = 0; c < 3; ++c) {
525 x(q, c) = nx[c] + gsh(p, c);
540 Kokkos::View<
float* [3],
CpMem> w) {
546 Kokkos::parallel_for(
547 "peclet::dem::copies_reseed", Kokkos::RangePolicy<CpExec>(space, 0, H.
nGroups),
548 KOKKOS_LAMBDA(
int g) {
549 const int b = gq(gs(g));
550 for (
int p = gs(g) + 1; p < gs(g + 1); ++p) {
552 for (
int c = 0; c < 3; ++c) {
553 x(q, c) = x(b, c) + gsh(p, c);
563 if (H.
nGroups <= 0 || orphan.extent(0) == 0)
568 Kokkos::parallel_for(
569 "peclet::dem::copies_unfold", Kokkos::RangePolicy<CpExec>(0, H.
nGroups),
570 KOKKOS_LAMBDA(
int g) {
572 for (
int p = gs(g); p < gs(g + 1); ++p)
575 orphan(gq(gs(g))) = s;
585 Kokkos::View<const int*, CpMem> realIdx,
587 Kokkos::View<unsigned char*, CpMem> hit,
int nSlots) {
589 Kokkos::deep_copy(space, Kokkos::subview(hit, Kokkos::pair<int, int>(0, nSlots)),
590 static_cast<unsigned char>(0));
591 Kokkos::parallel_for(
592 "peclet::dem::activity_vel", Kokkos::RangePolicy<CpExec>(space, 0, nm), KOKKOS_LAMBDA(
int e) {
596 Kokkos::atomic_store(&hit(ov.
slotA(e, realIdx(m.
bodyA))),
static_cast<unsigned char>(1));
598 Kokkos::atomic_store(&hit(ov.
slotB(e, realIdx(m.
bodyB))),
static_cast<unsigned char>(1));
607 Kokkos::View<unsigned char*, CpMem> hit,
int nSlots) {
609 Kokkos::deep_copy(space, Kokkos::subview(hit, Kokkos::pair<int, int>(0, nSlots)),
610 static_cast<unsigned char>(0));
611 Kokkos::parallel_for(
612 "peclet::dem::activity_pos", Kokkos::RangePolicy<CpExec>(space, 0, nu), KOKKOS_LAMBDA(
int u) {
616 Kokkos::atomic_store(&hit(ov.
slotA(u, c.
bodyA)),
static_cast<unsigned char>(1));
618 Kokkos::atomic_store(&hit(ov.
slotB(u, c.
bodyB)),
static_cast<unsigned char>(1));
626inline void finishActivity(Kokkos::View<const unsigned char*, CpMem> hit,
int nSlots,
630 Kokkos::parallel_for(
631 "peclet::dem::activity_a", Kokkos::RangePolicy<CpExec>(space, 0, nAll),
632 KOKKOS_LAMBDA(
int q) { a(q) = q < nSlots ? static_cast<int>(hit(q)) : 0; });
638 Kokkos::parallel_for(
639 "peclet::dem::activity_groups", Kokkos::RangePolicy<CpExec>(space, 0, H.
nGroups),
640 KOKKOS_LAMBDA(
int g) {
642 for (
int p = gs(g); p < gs(g + 1); ++p) {
643 const unsigned char h = hit(gq(p));
647 gk(g) = n > 0 ? n : 1;
659 Kokkos::View<const float*, CpMem> invMass,
660 Kokkos::View<
const float* [3],
CpMem> invInertia,
661 Kokkos::View<const int*, CpMem> kRank) {
671 const bool haveCopies = H.
nCopies > 0;
672 Kokkos::parallel_for(
673 "peclet::dem::rankk_solve_views", Kokkos::RangePolicy<CpExec>(space, 0, nSlots),
674 KOKKOS_LAMBDA(
int q) {
675 const int b = (haveCopies && q >= base) ? cb(q - base) : q;
676 const int k = kRank(b);
678 const float kf =
static_cast<float>(k);
679 ims(q) = kf * invMass(b);
680 for (
int c = 0; c < 3; ++c)
681 iis(q, c) = kf * invInertia(b, c);
685 for (
int c = 0; c < 3; ++c)
686 iis(q, c) = invInertia(b, c);
696 Kokkos::View<const int*, CpMem> k, Kokkos::View<const int*, CpMem> a,
697 int n, Kokkos::View<float*, CpMem> out) {
698 Kokkos::parallel_for(
699 "peclet::dem::inv_mass_coarse", Kokkos::RangePolicy<CpExec>(0, n), KOKKOS_LAMBDA(
int q) {
700 const int aq = a(q) > 1 ? a(q) : 1;
701 const float ratio =
static_cast<float>(k(q)) /
static_cast<float>(aq);
702 out(q) = invMass(q) * ratio;
712 Kokkos::View<const int*, CpMem> k,
713 Kokkos::View<const int*, CpMem> a,
int n,
714 Kokkos::View<
float* [3],
CpMem> out) {
715 Kokkos::parallel_for(
716 "peclet::dem::inv_inertia_coarse", Kokkos::RangePolicy<CpExec>(0, n), KOKKOS_LAMBDA(
int q) {
717 const int aq = a(q) > 1 ? a(q) : 1;
718 const float ratio =
static_cast<float>(k(q)) /
static_cast<float>(aq);
719 for (
int c = 0; c < 3; ++c)
720 out(q, c) = invInertia(q, c) * ratio;
728 int nGroups1, Kokkos::View<const int*, CpMem> a) {
729 if (nV <= 0 || nGroups1 <= 0)
731 Kokkos::View<int*, CpMem> cnt(
"peclet::dem::ml_inact_cnt", nGroups1);
732 Kokkos::parallel_for(
733 "peclet::dem::ml_inact_hist", Kokkos::RangePolicy<CpExec>(0, nV),
734 KOKKOS_LAMBDA(
int v) { Kokkos::atomic_add(&cnt(parent(off + v)), 1); });
736 Kokkos::parallel_reduce(
737 "peclet::dem::ml_inact_count", Kokkos::RangePolicy<CpExec>(0, nV),
738 KOKKOS_LAMBDA(
int v,
int& acc) {
739 if (a(v) == 0 && cnt(parent(off + v)) >= 2)
752 Kokkos::parallel_reduce(
753 "peclet::dem::copies_count_split", Kokkos::RangePolicy<CpExec>(0, H.
nGroups),
754 KOKKOS_LAMBDA(
int g,
int& acc) { acc += gk(g) > 1 ? 1 : 0; }, n);
763 int nGroups1, Kokkos::View<const unsigned char*, CpMem> split) {
764 if (nV <= 0 || nGroups1 <= 0 || split.extent(0) <
static_cast<std::size_t
>(nV))
766 Kokkos::View<int*, CpMem> cnt(
"peclet::dem::ml_agg_cnt", nGroups1);
767 Kokkos::parallel_for(
768 "peclet::dem::ml_agg_hist", Kokkos::RangePolicy<CpExec>(0, nV),
769 KOKKOS_LAMBDA(
int v) { Kokkos::atomic_add(&cnt(parent(off + v)), 1); });
771 Kokkos::parallel_reduce(
772 "peclet::dem::ml_agg_count", Kokkos::RangePolicy<CpExec>(0, nV),
773 KOKKOS_LAMBDA(
int v,
int& acc) {
774 if (split(v) != 0 && cnt(parent(off + v)) >= 2)
784 Kokkos::View<const int*, CpMem> eB,
int nE,
int nV,
785 Kokkos::View<const float*, CpMem> invMass) {
788 const int nH = H.
nHubs;
790 Kokkos::View<int*, CpMem> hubOf(
"peclet::dem::lh_hubof", nV);
791 Kokkos::deep_copy(hubOf, -1);
792 Kokkos::parallel_for(
793 "peclet::dem::lh_map", Kokkos::RangePolicy<CpExec>(0, nH),
794 KOKKOS_LAMBDA(
int h) { hubOf(hv(h)) = h; });
795 Kokkos::View<double*, CpMem> msum(
"peclet::dem::lh_msum", nH);
796 Kokkos::View<int*, CpMem> mcnt(
"peclet::dem::lh_mcnt", nH);
797 Kokkos::parallel_for(
798 "peclet::dem::lh_accum", Kokkos::RangePolicy<CpExec>(0, nE), KOKKOS_LAMBDA(
int e) {
799 const int a = eA(e), b = eB(e);
802 const int ends[2][2] = {{a, b}, {b, a}};
803 for (
int j = 0; j < 2; ++j) {
804 const int h = hubOf(ends[j][0]);
805 const float im = invMass(ends[j][1]);
806 if (h >= 0 && im > 0.0f) {
807 Kokkos::atomic_add(&msum(h), 1.0 /
static_cast<double>(im));
808 Kokkos::atomic_add(&mcnt(h), 1);
813 Kokkos::parallel_reduce(
814 "peclet::dem::lh_count", Kokkos::RangePolicy<CpExec>(0, nH),
815 KOKKOS_LAMBDA(
int h,
int& acc) {
816 const float im = invMass(hv(h));
817 if (mcnt(h) == 0 || im <= 0.0f)
819 const double mHub = 1.0 /
static_cast<double>(im);
820 if (mHub < 10.0 * msum(h) /
static_cast<double>(mcnt(h)))
int countLightHubs(const PhaseCopies &H, Kokkos::View< const int *, CpMem > eA, Kokkos::View< const int *, CpMem > eB, int nE, int nV, Kokkos::View< const float *, CpMem > invMass)
Light hubs (split_stats, R-P3): velocity hubs whose mass is below 10x the mean mass of their partners...
void vertexDegree(Kokkos::View< const int *, CpMem > eA, Kokkos::View< const int *, CpMem > eB, int nE, int nV, Kokkos::View< int *, CpMem > deg)
Per-vertex active degree over [0, nV) (§4.4 step 1). Wall edges have one endpoint.
void finishActivity(Kokkos::View< const unsigned char *, CpMem > hit, int nSlots, PhaseCopies &H, Kokkos::View< int *, CpMem > a)
a(q) from the pass (§13.3): hit(q) for a slot outside any group; at a hub base the number of its grou...
void activityHitVelocity(Kokkos::View< const ManifoldC *, CpMem > manifolds, int nm, Kokkos::View< const int *, CpMem > realIdx, Kokkos::View< const int *, CpMem > color, SlotOverride ov, Kokkos::View< unsigned char *, CpMem > hit, int nSlots)
Rank-level activity pass (docs/contact_solve_framework.md §13.3 C4; the distributed step only),...
void markCopySeeds(const PhaseCopies &H, Kokkos::View< float *[3], CpMem > x, Kokkos::View< float *[3], CpMem > w, Kokkos::View< float *, CpMem > orphan, Kokkos::View< float *, CpMem > orphanPeak, bool shareFromBase=false)
Mark the phase seed sigma of every group and re-seed its members from the base (§4....
void positionEdgeEnds(Kokkos::View< const ContactC *, CpMem > contacts, const PosUnits &units, int nu, Kokkos::View< const int *, CpMem > color, Kokkos::View< int *, CpMem > eA, Kokkos::View< int *, CpMem > eB)
Position-phase colouring edges: one per unit, the leader contact's raw (bodyA, bodyB); active = the u...
void velocityEdgeEnds(Kokkos::View< const ManifoldC *, CpMem > manifolds, int nm, Kokkos::View< const int *, CpMem > realIdx, Kokkos::View< const int *, CpMem > color, Kokkos::View< int *, CpMem > eA, Kokkos::View< int *, CpMem > eB)
Velocity-phase colouring edges: the vertices realIdx(bodyA / bodyB) of each manifold (-1: a wall end,...
constexpr int kHubEdgeBudget
Hub edge budget (§4.4): a colouring vertex with more active edges is split into ceil(d / kHubEdgeBudg...
void buildSolveViewsRankK(Particles &P, const PhaseCopies &H, int nSlots, Kokkos::View< const float *, CpMem > invMass, Kokkos::View< const float *[3], CpMem > invInertia, Kokkos::View< const int *, CpMem > kRank)
Solve views under rank-level M (§13.3, §4.5): invMassSolve / invInertiaSolve = k x the body's masses ...
CpExec::memory_space CpMem
void activityHitPosition(Kokkos::View< const ContactC *, CpMem > contacts, const PosUnits &units, int nu, Kokkos::View< const int *, CpMem > color, SlotOverride ov, Kokkos::View< unsigned char *, CpMem > hit, int nSlots)
The same over the position phase's units (raw slots of the leader contact, through the overrides).
void reseedCopies(CpExec space, const PhaseCopies &H, Kokkos::View< float *[3], CpMem > x, Kokkos::View< float *[3], CpMem > w)
Re-seed every member from its base, sigma unchanged (the multilevel pass, after the coarse cycle has ...
void buildHubCopies(Kokkos::View< const int *, CpMem > eA, Kokkos::View< const int *, CpMem > eB, int nE, int nV, int slotBase, Kokkos::View< const int *, CpMem > deg, PhaseCopies &H)
Build one phase's hub copies (§4.4 steps 2, 3 and 5): every vertex with d > kHubEdgeBudget active edg...
void buildInvInertiaCoarse(Kokkos::View< const float *[3], CpMem > invInertia, Kokkos::View< const int *, CpMem > k, Kokkos::View< const int *, CpMem > a, int n, Kokkos::View< float *[3], CpMem > out)
The multilevel coarse vertex's inverse inertia (docs/contact_physics_followups.md §2....
void buildSolveViews(Particles &P, const PhaseCopies &H, int nSlots, Kokkos::View< const float *, CpMem > invMass, Kokkos::View< const float *[3], CpMem > invInertia)
Solve views of a phase (§4.5): invMassSolve / invInertiaSolve = the phase's masses on every slot in [...
void seedCopySlotState(Particles &P, const PhaseCopies &H)
Seed the copy slots' read-only state from their hub vertex (§4.4 step 6): orientation,...
Kokkos::DefaultExecutionSpace CpExec
constexpr float kSplitOmegaVelocity
Split relaxation (§4.5, §13.1): the PGS normal step on an edge touching a mass-split slot is scaled b...
int countSplitBodies(const PhaseCopies &H)
Count the bodies whose group has k > 1 (split_stats).
int countSplitAggregated(Kokkos::View< const int *, CpMem > parent, int off, int nV, int nGroups1, Kokkos::View< const unsigned char *, CpMem > split)
split_stats.mlHubAggregated (§13.2's positive control): the vertices v in [0, nV) with split(v) !...
void growCopyView(V &v, std::size_t n, const char *label)
Grow-only (re)allocation of a copy-machinery view to at least n entries.
void buildCopyGroups(Kokkos::View< const int *, CpMem > realIdx, int span, int numReal, Kokkos::View< const int *, CpMem > deg, Kokkos::View< const float *[3], CpMem > imageShift, PhaseCopies &H, bool identityBodies=false)
Build the fold groups of a phase (§4.4 "local fold", §WO-4 item 2): every body with more than one slo...
void foldCopies(CpExec space, const PhaseCopies &H, Kokkos::View< float *[3], CpMem > x, Kokkos::View< float *[3], CpMem > w, Kokkos::View< float *, CpMem > orphan, Kokkos::View< float *, CpMem > orphanPeak, Kokkos::View< float, CpMem > consensus={})
The local fold (§4.4), once per iteration after the sweep: per group T = sum over the ACTIVE members ...
int countInactiveAggregated(Kokkos::View< const int *, CpMem > parent, int off, int nV, int nGroups1, Kokkos::View< const int *, CpMem > a)
Debug-build check (§13.2, §13.5 WO-5 item 4): the vertices with a = 0 that sit in a level-1 multileve...
void buildInvMassCoarse(Kokkos::View< const float *, CpMem > invMass, Kokkos::View< const int *, CpMem > k, Kokkos::View< const int *, CpMem > a, int n, Kokkos::View< float *, CpMem > out)
The multilevel coarse vertex's inverse mass (§13.2): invMass(q) (k(q) / max(1, a(q))),...
void unfoldOrphan(const PhaseCopies &H, Kokkos::View< float *, CpMem > orphan)
Orphan accounts back from share form (before a rank sync and at the end of the velocity phase): the b...
dem — portable (Kokkos) particle SoA container: the storage the dem flip pivots on.
Portable mirror of ManifoldConstraint.
Kokkos::View< float *[3], CpMem > invInertiaSolve
Kokkos::View< unsigned char *, CpMem > splitSlot
Kokkos::View< float *, CpMem > invMassSolve
Kokkos::View< unsigned char *, CpMem > groundedLevel
One solve phase's body copies (docs/contact_solve_framework.md §4.4, §4.5, §WO-4 item 2): the hub cop...
Kokkos::View< float *[3], CpMem > seedX
Kokkos::View< int *, CpMem > hubS
Kokkos::View< float *[3], CpMem > seedW
Kokkos::View< int *, CpMem > slotB
Kokkos::View< float *[3], CpMem > groupShift
Kokkos::View< int *, CpMem > hubVertex
Kokkos::View< int *, CpMem > copyBase
Kokkos::View< int *, CpMem > slotA
Kokkos::View< int *, CpMem > groupK
Kokkos::View< int *, CpMem > groupStart
Kokkos::View< unsigned char *, CpMem > groupActive
Kokkos::View< int *, CpMem > groupSlot
The position units of a contact list as a CSR (§4.3): unit u owns the contacts list(start(u)) .
Per-edge slot overrides of a phase's hub copies (docs/contact_solve_framework.md §4....
int slotA(int e, int def) const
int slotB(int e, int def) const