peclet-dem 1.1.0
Performance-portable XPBD Discrete Element Method (Kokkos + ArborX)
Loading...
Searching...
No Matches
solver_velocity.hpp File Reference

dem — portable (Kokkos) manifold velocity solve (normal restitution impulse). More...

#include <climits>
#include <Kokkos_Core.hpp>
#include <tuple>
#include <utility>
#include <vector>
#include "contact_preprocessing.hpp"
#include "dem_portable.hpp"
#include "solver_fused.hpp"

Go to the source code of this file.

Classes

struct  peclet::dem::ShockPropagation
 Shock propagation for persistent loaded contacts (see solveVelocity): the persistence flags, predicted positions, gravity direction and grounded levels. More...
struct  peclet::dem::ShockGate
 The geometric and rise gate of shock propagation (see solveVelocity) for one persistent body-body pair with separation dx = x_A - x_B: the LOWER body may be held static (|up| > 0.3 |dx|, so near-horizontal pairs stay symmetric) ONLY when it is not moving UPWARD faster than 4 * restVelThreshold. More...
struct  peclet::dem::ManifoldEdges
 The manifold edge source of colorEdges: vertex realIdx(body) or its hub copy slot through ov, key colorKey(manifold index). More...
struct  peclet::dem::PGSManifoldSweep
 One full colored PGS sweep. More...
struct  peclet::dem::PGSManifoldSweep::PairVelocity
 The endpoints' velocities (B on a wall: the wall's average velocity, zero spin). More...
struct  peclet::dem::PGSManifoldSweep::Row
 One manifold's constraint row as the three impulse channels share it: the manifold, its endpoints' solve slots, mass data and velocities at the start of this manifold's solve, the averaged normal and arm sums, and the substep's sign, effective mass, side gate and restitution. More...
struct  peclet::dem::PGSManifoldSweep::ReleaseBudget
 The Poisson release's budget: the pair's owed impulse, the release speed scale and the endpoints' orphan balances. More...
struct  peclet::dem::VelocitySweepBodies
 The bodies a velocity sweep reads and updates in place: mass data and orientation, the predicted velocities, the canonical velocity slot realIdx and the hub-copy slot overrides (ov, §4.4; empty = realIdx). More...
struct  peclet::dem::PoissonBankViews
 Event-level (Poisson) restitution views, all empty when the model is off. More...
struct  peclet::dem::XGateSpec
 Rank-level X evaluated inline in the one-shot sweep (only for the manifolds of the colour being swept): the same test as computeXGate, without a separate pass over every manifold per iteration. More...
struct  peclet::dem::ColoredManifolds
 The colour classes one coloured sweep visits: manifolds [0, numManifolds), labelled by mColor in [0, numColors). More...

Namespaces

namespace  peclet
namespace  peclet::dem
namespace  peclet::dem::detail

Functions

F3 peclet::dem::detail::ld3 (Kokkos::View< const float *[3], CpMem > v, int i)
float peclet::dem::detail::genInvMass (F3 tau, F3 invIlocal, F4 q)
void peclet::dem::countVelocityJacobi (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, Kokkos::View< const int *, CpMem > realIdx, Kokkos::View< int *, CpMem > counts, bool dedupTwins=true)
 Mass-split Jacobi count pass (docs/contact_solve_framework.md §3.1, D3): per body (REAL index), the number of manifolds the Jacobi velocity solve visits – num_points > 0, one manifold per periodic pair (the solve's realA > realB dedup); a wall side counts nothing.
void peclet::dem::solveVelocity (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, const BodyState &bodies, const BodyPred &pred, Kokkos::View< const int *, CpMem > realIdx, float growthRate, float restitutionNormal, float restVelThreshold, Kokkos::View< float *[3], CpMem > deltaVel, Kokkos::View< float *[3], CpMem > deltaAngVel, Kokkos::View< int *, CpMem > velCounts, Kokkos::View< const int *, CpMem > onlyColor={}, int colorFilter=0, const ShockPropagation &shock={}, bool massSplit=false, bool dedupTwins=true)
 Accumulate normal-restitution velocity deltas for numManifolds manifolds.
template<class V3, class Vi>
void peclet::dem::applyVelocityDeltasAveraged (int n, V3 velPred, V3 angVelPred, V3 deltaVel, V3 deltaAngVel, Vi velCounts, bool averaged=true)
 Apply the accumulated velocity deltas AVERAGED by the per-body manifold count — the velocity- solve twin of the position solve's constraint-count averaging (applyUpdates).
int peclet::dem::colorManifolds (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, Kokkos::View< const int *, CpMem > realIdx, int numReal, Kokkos::View< int *, CpMem > mColor, const ColorScratch &scratch, int &leftover, Kokkos::View< const unsigned char *, CpMem > sleepMask={}, SlotOverride ov={}, bool dedupTwins=true, int vertexSpan=0)
 Greedy graph-colour the manifolds: no two manifolds sharing a real body get the same colour (colorEdges over ManifoldEdges).
int peclet::dem::colorManifoldsIncremental (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, Kokkos::View< const int *, CpMem > realIdx, int numReal, const CarriedColors &carried, Kokkos::View< int *, CpMem > mColor, const ColorScratch &scratch, int &leftover, bool forceFull, Kokkos::View< const unsigned char *, CpMem > sleepMask={}, bool dedupTwins=true)
 Incremental (warm-started) manifold colouring for the single-GPU PGS path.
void peclet::dem::computeVn0 (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, const BodyPred &pred, Kokkos::View< const int *, CpMem > realIdx, float growthRate, Kokkos::View< float *, CpMem > vn0, Kokkos::View< float *[3], CpMem > vt0, bool dedupTwins=true)
 -— Warm-started projected Gauss-Seidel (PGS) velocity solve -— Nonsmooth contact dynamics (Moreau-Jean; Stewart-Trinkle LCP): per manifold an ACCUMULATED push impulse p >= 0 along the manifold normal, updated by colored GS sweeps and projected to p >= 0 (a contact may push, never pull; over-push is retracted in later sweeps).
void peclet::dem::updateRestitutionBank (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, const BodyState &bodies, const BodyPred &pred, Kokkos::View< const int *, CpMem > realIdx, float growthRate, float restitutionNormal, float restVelThreshold, Kokkos::View< const float *, CpMem > vn0, const PairLedger &ledger, Kokkos::View< const float *, CpMem > restRel, bool dedupTwins=true)
 Event-level (Poisson) restitution bookkeeping, once per substep AFTER all velocity phases (restitutionModel == 1 only).
void peclet::dem::decayBodyOrphan (Kokkos::View< float *, CpMem > orphan, Kokkos::View< float *, CpMem > orphanVPeak, int numOwned, float restVelThreshold)
 Orphan-account aging, once per substep over the OWNED bodies: both the balance and the carried event peak decay 1/64 per substep (e-fold ~3 ms at dt = 5e-5 — long enough for the rebound payout, which completes within ~2 ms of turnaround, short enough that a BURIED impactor's slowly re-fed credit cannot keep fluidizing its crater: with the pair-state 1/256 decay the 100k Dosta plateau crept 0.007 deeper), and once the peak ages below the resting threshold the whole account evaporates — stranded credit on a settling body never pops the pile later.
void peclet::dem::scatterOrphanBanks (const PairLedger &prev, Kokkos::View< const unsigned char *, CpMem > matched, int prevCount, Kokkos::View< const float *, CpMem > invMass, Kokkos::View< float *, CpMem > orphan, Kokkos::View< float *, CpMem > orphanVPeak, Kokkos::View< const int *, CpMem > gidSorted={}, Kokkos::View< const int *, CpMem > slotSorted={}, int ownedLimit=-1)
 Orphan transfer: previous-ledger entries NOT matched by any current manifold (their pair died this substep) credit their remaining owed budget to the endpoint BODIES, mass-weighted — the heavier endpoint keeps the larger share (energy of a later release scales J^2/2m, so the light grain is the dangerous store and the heavy impactor is both the safe one and the event's physical carrier); boundary pairs (wall endpoint) credit everything to the particle.
std::tuple< double, float, int > peclet::dem::restBankStats (Kokkos::View< const float *, CpMem > bank, int n)
 Poisson-restitution diagnostics: (sum, max, count>0) over the committed owed-impulse store (namespace scope: nvcc forbids KOKKOS_LAMBDA in member functions).
void peclet::dem::computeSideFlags (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, Kokkos::View< const int *, CpMem > realIdx, const ShockPropagation &shock, Kokkos::View< const float *[3], CpMem > velPred, float riseThr, Kokkos::View< unsigned char *, CpMem > sideFlag, Kokkos::View< const float *, CpMem > vn0, float approachThr, bool dedupTwins=true)
 Decide each persistent contact's treatment ONCE per substep (before any impulse is applied): 0 = symmetric momentum-conserving PGS, 1 = one-sided with B as the held ground side, 2 = A held.
void peclet::dem::warmStartApply (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, const BodyState &bodies, const BodyPred &pred, Kokkos::View< const int *, CpMem > realIdx, Kokkos::View< const float *, CpMem > warmP, Kokkos::View< float *[3], CpMem > warmT, bool dedupTwins=true)
 Apply the warm-start impulses up front (order-independent: fixed impulses, atomic adds).
PGSManifoldSweep peclet::dem::makePGSManifoldSweep (Kokkos::View< const ManifoldC *, CpMem > manifolds, const VelocitySweepBodies &bodies, float growthRate, float restitutionNormal, float restVelThreshold, Kokkos::View< float, CpMem > maxApproach, Kokkos::View< float, CpMem > maxApproachQS, Kokkos::View< float *, CpMem > lambdaAcc, Kokkos::View< const float *, CpMem > vn0, Kokkos::View< const unsigned char *, CpMem > sideFlag, Kokkos::View< float *[3], CpMem > lambdaT, float frictionDynamic, Kokkos::View< const float *[3], CpMem > vt0, float restitutionTangent, Kokkos::View< const float *, CpMem > posImpulse, const PoissonBankViews &bank)
 Build the shared per-manifold sweep functor (the colored launch loop, the fused kernels and the fused multilevel iteration loop all run this one body).
bool peclet::dem::solveVelocityPGS (const PGSManifoldSweep &f, int numManifolds, const ColorSchedule &sched, const FusedLoopSpec *loop=nullptr)
 Returns true when the sweep (or, with loop, the whole iteration loop) was submitted; false ONLY in loop mode when the fused path is unavailable — the caller then runs its own host-side iteration loop (which calls back in per-iteration mode).
void peclet::dem::buildLevelColorBuckets (Kokkos::View< const ManifoldC *, CpMem > manifolds, int numManifolds, Kokkos::View< const int *, CpMem > realIdx, Kokkos::View< const int *, CpMem > mColor, Kokkos::View< const int *, CpMem > heights, Kokkos::View< int *, CpMem > keys, Kokkos::View< int *, CpMem > perm, std::vector< std::pair< int, int > > &buckets)
 Bucket the active coloured manifolds by (support level, colour) for the level-ordered ("multilevel") stabilization sweeps.
void peclet::dem::solveVelocityPGSBuckets (const PGSManifoldSweep &f, Kokkos::View< const int *, CpMem > perm, const std::vector< std::pair< int, int > > &buckets, bool topDown)
 Level-ordered symmetric sweep: launch one PGS kernel per (level, colour) bucket, ascending (bottom-up: a chain's load drains towards the floor in ~one pass) or descending (top-down: the return pass carries rebound waves back up).
int peclet::dem::xPopcount (unsigned long long m)
 Rank-level X (docs/contact_solve_framework.md §1.4): the holder of a body whose velocity activity mask has several bits (ranks) in sync interval t – the colour t mod C if it is in the mask, else the (t mod popcount)-th set bit (lowest = 0th).
int peclet::dem::xHolder (unsigned long long mask, long long t, int numColors)
void peclet::dem::computeXGate (Kokkos::View< const ManifoldC *, CpMem > manifolds, int nm, Kokkos::View< const int *, CpMem > realIdx, Kokkos::View< const unsigned long long *, CpMem > velMask, Kokkos::View< unsigned char *, CpMem > gate, int color, int numColors, long long t)
 The per-manifold fire gate of sync interval t: 1 iff this rank (colour color) holds every endpoint whose mask names two or more ranks.
long long peclet::dem::countUnfired (Kokkos::View< const unsigned char *, CpMem > gate, int nm)
 Diagnostics (iterCounters): the number of gated-off manifolds of one sweep.
F3 peclet::dem::angularDelta (F3 jang, F3 invI, F4 q)
 World-frame angular velocity change of an angular impulse jang on a body with diagonal local inverse inertia invI and orientation q: R (invI_local * (R^T jang)).
void peclet::dem::solveVelocityColoredGS (const ColoredManifolds &colored, const VelocitySweepBodies &bodies, float growthRate, float restitutionNormal, float restVelThreshold, Kokkos::View< float, CpMem > maxApproach, XGateSpec xg={}, const ShockPropagation &shock={})
 Colored Gauss–Seidel normal-restitution solve: sweep the numColors colour classes in order, applying each manifold's impulse directly to velPred/angVelPred (in place).

Detailed Description

dem — portable (Kokkos) manifold velocity solve (normal restitution impulse).

Kokkos port of solve_velocity_jacobi_kernel (solver_velocity.cu): one thread per manifold computes the aggregate normal impulse (with growth-velocity term and restitution) and atomically scatters the linear/angular velocity deltas onto the two bodies' REAL indices. Faithful copy of the CUDA math; runs on the particle SoA expressed as Kokkos Views. Friction is a separate per-contact pass (solver_position) and is not done here, matching the original.

Definition in file solver_velocity.hpp.