Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# v0.9.0
- Add an implicit grid solver, selected per simulation with `MpmData::integrator =
MpmIntegrator::Implicit(ImplicitSolverParams { .. })` on a pipeline built with
`MpmPipelineKernels { implicit: true, .. }` (off by default). It replaces the explicit
momentum-to-velocity update by backward Euler solved with Newton's method on the incremental
potential, entirely on the GPU: each Newton iteration evaluates the trial state of every particle
(deformation gradient projected for plastic models, stress, energy), solves for the direction with
a matrix-free, mass-preconditioned conjugate gradient on the definiteness-fixed Hessian, and picks
the step with a backtracking line search (on the incremental potential, or on the residual norm
for models without an energy). This lifts the sound-speed bound on the substep length: stiff
elastics run with a handful of substeps per frame. `ImplicitSolverParams::semi_implicit()` gives
the one-linearization variant. Grid-level stick/slip conditions and fixed particles are Dirichlet
conditions inside the solve; separating contacts stay explicit corrections.
- Constitutive models take part in the implicit solve through the new `IImplicitParticleModel`
slang interface (`slosh/models/implicit_interfaces.slang`): a trial-state evaluation and a stress
differential. The default models implement it, and `LinearElasticModel` / `NeoHookeanModel`
gained an `energy_density`. A custom model specialization must export an
`ImplicitParticleModel` alongside `ParticleModel` to compile the implicit kernels.
- The particle update reads a new `IntegratorFlags` uniform (`GpuSimulationParams::integrator_flags`)
and leaves the stress out of the APIC affine matrix when the implicit solver is active. A `run_g2p`
hook that fuses the particle update must do the same.
- The testbeds compile the implicit kernels and expose the integrator and its parameters in the
settings window, with the last solve's Newton and CG statistics.
- The testbed settings window exposes the substep count: a fixed number, or the adaptive
`[min, max]` range (scenes still set their defaults on restart).

# v0.8.0
- Add the `GpuBoundaryCondition::non_reflecting` (absorbing) boundary condition, based on
Lysmer-Kuhlemeyer viscous dashpots. It lets outgoing elastic waves leave the domain instead of
Expand Down
2 changes: 1 addition & 1 deletion crates/slosh2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "slosh2d"
authors = ["Sébastien Crozet <sebcrozet@dimforge.com>"]
description = "Cross-platform GPU 2D Material Point Method implementation."
repository = "https://github.com/dimforge/slosh"
version = "0.8.0"
version = "0.9.0"
edition = "2024"
license = "Apache-2.0"

Expand Down
2 changes: 1 addition & 1 deletion crates/slosh3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "slosh3d"
authors = ["Sébastien Crozet <sebcrozet@dimforge.com>"]
description = "Cross-platform GPU 3D Material Point Method implementation."
repository = "https://github.com/dimforge/slosh"
version = "0.8.0"
version = "0.9.0"
edition = "2024"
license = "Apache-2.0"

Expand Down
4 changes: 2 additions & 2 deletions crates/slosh_testbed2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "slosh_testbed2d"
authors = ["Sébastien Crozet <sebcrozet@dimforge.com>"]
description = "Testbed for the slosh GPU-based MPM physics simulation library (2D version)."
version = "0.8.0"
version = "0.9.0"
license = "Apache-2.0"
edition = "2021"

Expand Down Expand Up @@ -38,7 +38,7 @@ futures-test = "0.3"
serial_test = "3"
approx = "0.5"
async-std = { version = "1", features = ["attributes"] }
slosh2d = { version = "0.8", path = "../slosh2d" }
slosh2d = { version = "0.9", path = "../slosh2d" }
regex = "1"
web-time = "1"

Expand Down
4 changes: 2 additions & 2 deletions crates/slosh_testbed3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "slosh_testbed3d"
authors = ["Sébastien Crozet <sebcrozet@dimforge.com>"]
description = "Testbed for the slosh GPU-based MPM physics simulation library (3D version)."
version = "0.8.0"
version = "0.9.0"
license = "Apache-2.0"
edition = "2021"

Expand Down Expand Up @@ -38,7 +38,7 @@ futures-test = "0.3"
serial_test = "3"
approx = "0.5"
async-std = { version = "1", features = ["attributes"] }
slosh3d = { version = "0.8", path = "../slosh3d" }
slosh3d = { version = "0.9", path = "../slosh3d" }
regex = "1"
web-time = "1"

Expand Down
11 changes: 6 additions & 5 deletions shaders/slosh/grid/grid.slang
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,20 @@ public func find_block_header_id(
key: BlockVirtualId
) -> BlockHeaderId {
let packed_key = pack_key(key);
var slot = hash(packed_key) & (grid[0].hmap_capacity - 1);
let capacity = grid[0].hmap_capacity;
var slot = hash(packed_key) & (capacity - 1);

while (true) {
// Bounded by the capacity: a full hashmap without the key must not loop forever (that hangs
// the GPU when diverging particles scatter over more blocks than the hashmap holds).
for (var k = 0u; k < capacity; k++) {
let state = hmap_entries[slot].state;
if (state == packed_key) {
return hmap_entries[slot].value;
} else if (state == NONE) {
// Using break here instead of `return BlockHeaderId(NONE);` otherwise slang optimizes-out the
// final return and naga complains about a missing return after the infinite loop.
break;
}

slot = (slot + 1) & (grid[0].hmap_capacity - 1);
slot = (slot + 1) & (capacity - 1);
}

return BlockHeaderId(NONE);
Expand Down
135 changes: 134 additions & 1 deletion shaders/slosh/models/default.slang
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module default_model;
#include "slosh/features.h"

import slosh.models.interfaces;
import slosh.models.implicit_interfaces;
import slosh.models.linear_elasticity;
import slosh.models.neo_hookean_elasticity;
import slosh.models.drucker_prager;
Expand Down Expand Up @@ -50,7 +51,7 @@ public static const uint DEFAULT_MODEL_BYTES_STRIDE = 52;
// NOTE: the BYTES_STRIDE parameter exists so that third-party models extending this default model
// can specify their own stride if it differ from the default one (i.e. if the extended union
// type is bigger than the default union type).
public struct DefaultParticleModel<let BYTES_STRIDE: uint = DEFAULT_MODEL_BYTES_STRIDE>: IParticleModel {
public struct DefaultParticleModel<let BYTES_STRIDE: uint = DEFAULT_MODEL_BYTES_STRIDE>: IParticleModel, IImplicitParticleModel {
uint dummy; // Dummy field because naga doesn’t accept empty structs.

public __init() {
Expand Down Expand Up @@ -125,6 +126,138 @@ public struct DefaultParticleModel<let BYTES_STRIDE: uint = DEFAULT_MODEL_BYTES_
}
}

/// Trial-state evaluation for the implicit solver: stress and incremental energy at a trial
/// deformation gradient, without storing any state. Plastic models project the trial gradient
/// and evaluate their elastic backbone there; the return mapping itself stays with the regular
/// particle update.
public func trial_state(
models: RWByteAddressBuffer,
data: ParticleUpdateData,
inout def_grad: Mat<float>,
) -> TrialState {
let tag_offset = data.particle_id * BYTES_STRIDE;
let model_offset = tag_offset + 4;
let model_tag = models.Load(tag_offset);

switch (DefaultParticleModelType(model_tag)) {
case DefaultParticleModelType::ElasticLinear: {
let model = models.Load<LinearElasticModel>(model_offset);
var stress = model.kirchoff_stress(def_grad);
var energy = model.energy_density(def_grad);
#if SLOSH_PML
stress += viscous_stress(model.lambda, model.mu, data.velocity_gradient, data.stiffness_damping);
energy += viscous_dissipation(model.lambda, model.mu, data.velocity_gradient, data.stiffness_damping, data.dt);
#endif
return TrialState(stress, energy);
}
case DefaultParticleModelType::ElasticNeoHookean: {
let model = models.Load<NeoHookeanModel>(model_offset);
var stress = model.kirchoff_stress(def_grad);
var energy = model.energy_density(def_grad);
#if SLOSH_PML
stress += viscous_stress(model.lambda, model.mu, data.velocity_gradient, data.stiffness_damping);
energy += viscous_dissipation(model.lambda, model.mu, data.velocity_gradient, data.stiffness_damping, data.dt);
#endif
return TrialState(stress, energy);
}
case DefaultParticleModelType::SandLinear: {
let model = models.Load<SandModel<LinearElasticModel>>(model_offset);
let projection = model.plastic.project(model.plastic_state, def_grad);
def_grad = projection.deformation_gradient;
var stress = model.elastic.kirchoff_stress(def_grad);
var energy = model.elastic.energy_density(def_grad);
#if SLOSH_PML
stress += viscous_stress(model.elastic.lambda, model.elastic.mu, data.velocity_gradient, data.stiffness_damping);
energy += viscous_dissipation(model.elastic.lambda, model.elastic.mu, data.velocity_gradient, data.stiffness_damping, data.dt);
#endif
return TrialState(stress, energy);
}
case DefaultParticleModelType::SandNeoHookean: {
let model = models.Load<SandModel<NeoHookeanModel>>(model_offset);
let projection = model.plastic.project(model.plastic_state, def_grad);
def_grad = projection.deformation_gradient;
var stress = model.elastic.kirchoff_stress(def_grad);
var energy = model.elastic.energy_density(def_grad);
#if SLOSH_PML
stress += viscous_stress(model.elastic.lambda, model.elastic.mu, data.velocity_gradient, data.stiffness_damping);
energy += viscous_dissipation(model.elastic.lambda, model.elastic.mu, data.velocity_gradient, data.stiffness_damping, data.dt);
#endif
return TrialState(stress, energy);
}
#if SLOSH_PML
case DefaultParticleModelType::AbsorbingPml: {
// The layer is treated through its elastic backbone: its own stretched operator
// has no potential the line search could use.
let model = models.Load<PmlModel>(model_offset);
let stress = model.kirchoff_stress(def_grad)
+ model.viscous_stress(data.velocity_gradient, data.stiffness_damping);
return TrialState(stress, model.elastic.energy_density(def_grad));
}
#endif
default:
return TrialState(Mat<float>(0.0), 0.0);
}
}

/// Stress differential for the implicit solver (see `IImplicitParticleModel`). Elastic
/// models see `dF = dt F dC` in the stored layout; the stiffness-proportional damping, linear
/// in the velocity gradient, enters exactly.
public func stress_differential(
models: RWByteAddressBuffer,
data: ParticleUpdateData,
def_grad: Mat<float>,
d_vel_grad: Mat<float>,
) -> Mat<float> {
let tag_offset = data.particle_id * BYTES_STRIDE;
let model_offset = tag_offset + 4;
let model_tag = models.Load(tag_offset);
let d_def_grad = mul(def_grad, d_vel_grad) * data.dt;

switch (DefaultParticleModelType(model_tag)) {
case DefaultParticleModelType::ElasticLinear: {
let model = models.Load<LinearElasticModel>(model_offset);
var dtau = model.stress_differential(def_grad, d_def_grad);
#if SLOSH_PML
dtau += viscous_stress(model.lambda, model.mu, d_vel_grad, data.stiffness_damping);
#endif
return dtau;
}
case DefaultParticleModelType::ElasticNeoHookean: {
let model = models.Load<NeoHookeanModel>(model_offset);
var dtau = model.stress_differential(def_grad, d_def_grad);
#if SLOSH_PML
dtau += viscous_stress(model.lambda, model.mu, d_vel_grad, data.stiffness_damping);
#endif
return dtau;
}
case DefaultParticleModelType::SandLinear: {
let model = models.Load<SandModel<LinearElasticModel>>(model_offset);
var dtau = model.elastic.stress_differential(def_grad, d_def_grad);
#if SLOSH_PML
dtau += viscous_stress(model.elastic.lambda, model.elastic.mu, d_vel_grad, data.stiffness_damping);
#endif
return dtau;
}
case DefaultParticleModelType::SandNeoHookean: {
let model = models.Load<SandModel<NeoHookeanModel>>(model_offset);
var dtau = model.elastic.stress_differential(def_grad, d_def_grad);
#if SLOSH_PML
dtau += viscous_stress(model.elastic.lambda, model.elastic.mu, d_vel_grad, data.stiffness_damping);
#endif
return dtau;
}
#if SLOSH_PML
case DefaultParticleModelType::AbsorbingPml: {
let model = models.Load<PmlModel>(model_offset);
return model.elastic.stress_differential(def_grad, d_def_grad)
+ model.viscous_stress(d_vel_grad, data.stiffness_damping);
}
#endif
default:
return Mat<float>(0.0);
}
}

public func timestep_bound(
models: ByteAddressBuffer,
particle_id: uint,
Expand Down
Loading
Loading