Skip to content

WIP: Avalanche Simulation with MPM - #258

Closed
Emanum wants to merge 107 commits into
AlpineMapsOrg:mainfrom
Emanum:upstream-candidate
Closed

Emanum wants to merge 107 commits into
AlpineMapsOrg:mainfrom
Emanum:upstream-candidate

Conversation

@Emanum

@Emanum Emanum commented Nov 10, 2026

Copy link
Copy Markdown

WIP so far. I want to keep the changes to existing files as little as possible.

Emanum and others added 30 commits November 10, 2026 18:45
Step 1 - dispatcher refactor, no physics change:
- Move the Stomakhin 2013 model out of mpm_common.wgsl into
  mpm_material_stomakhin.wgsl behind a runtime dispatcher
  (mpm_material.wgsl, switch on settings.constitutive_model).
- Split terrain contact into mpm_friction.wgsl behind its own dispatcher
  (switch on settings.basal_friction_model). Internal friction (material
  law) and basal friction (boundary condition) are now selected
  independently, as proposal v3.0 requires.
- Add material_initial_state() to the model interface: the initial plastic
  state is model-dependent (Jp = 1 for Stomakhin, 0 for CCC/DP).
- Rename Particle.jp -> plastic_state; its meaning is now per model.
- C++: ConstitutiveModel / BasalFrictionModel enums, uniform 144 -> 160 B,
  serialised, combos in sidebar and node editor.
- Proven behaviour-preserving by diffing the resolved WGSL against HEAD
  (scripts/check_refactor_preserving.py): every retained function body
  identical modulo renames.

Step 2 - basal friction:
- mu default 0.4 -> 0.47 (Li et al. 2021, real terrain); preset updated.
- Voellmy: Coulomb plus turbulent drag g|v|^2/(xi h), h = slab_thickness
  so xi keeps com1DFA units (default 4000). Applied at the grid level only
  via an apply_basal_drag flag - the drag depends on |v_t|^2, not vn, so
  the existing grid+particle double call would count it twice per
  substep. Coulomb ignores the flag and is unchanged.
- scripts/test_friction.py: verbatim port on an inclined plane. Voellmy
  reaches the analytic terminal velocity to 0.085 %; Coulomb slope
  acceleration exact to 3 dp; both stick below atan(mu).

Docs: mpm-mls-doc/07-constitutive-models.md (v3.0 gap analysis and plan),
updates across 01-06, README, refs; claude_log.md session entries.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Second constitutive model behind the dispatcher, chosen before Cam-Clay
because its return mapping is a closed-form projection and it introduces
the Hencky elasticity CCC will reuse.

- mpm_material_drucker_prager.wgsl: Hencky log-strain elasticity in the
  principal frame, tau = 2 mu eps + lambda tr(eps); friction cone
  |dev tau| + alpha tr tau <= 0; Klar section 5.3 Case I/II/III projection.
  plastic_state accumulates delta_gamma; hardening of phi left out.
  Cohesionless - cold-dense regime only.
- ConstitutiveModel::DRUCKER_PRAGER = 1, dp_friction_angle setting
  (default 30 deg), alpha precomputed CPU-side into the last pad slot.
  Uniform unchanged at 160 B. Combos + slider in both panels.
- E/nu are shared across models rather than duplicated per model; presets
  will carry per-model recommended values.

Bug caught by the test before shipping: the Case II guard
"|dev eps| = 0 OR tr > 0" sent pure hydrostatic compression to the cone
apex. That state sits on the cone axis, inside the surface, and must stay
elastic; the condition is tr > 0 alone.

Verification: scripts/test_material_dp.py checks every Case III
projection lands on the cone (|y| < 1.5e-10 over 500 random gradients).
test_mpm.py now takes MPM_MODEL=drucker_prager; on the same drop test the
cohesionless material keeps spreading (mean z 3.65 falling, |v| 2.7 m/s)
where Stomakhin piles and stops (4.00 stable, 0.06 m/s). Stomakhin
regression unchanged. 8/8 tint, 8 pipelines on Metal.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The snow-science model the proposal's paper survey recommends. All three
constitutive models named in proposal v3.0 are now implemented and
switchable at runtime.

- mpm_material_ccc.wgsl: Hencky elasticity (shared with Drucker-Prager),
  Gaume's ellipse (1+2b)q^2 + M^2(p+b p0)(p-p0) <= 0 with p = -K tr(eps),
  q = sqrt(3/2) 2mu |dev eps|; hardening p0 = K sinh(xi max(-alpha, 0)).
  plastic_state is alpha, initialised to -asinh(p0_ini/K)/xi so that
  p0(alpha0) == p0_ini.
- Return mapping is the three-case projection of Wolper et al. 2019
  (NACC), the same group's implementation of this surface: compressive
  cap -> (p0, 0) with hardening; tensile tip -> (-beta p0, 0) with
  softening; shear -> q onto the ellipse at fixed p. Gaume describes an
  associative rule; this is the non-associated variant, documented as
  such and confined to ccc_plasticity().
- ConstitutiveModel::COHESIVE_CAM_CLAY = 2; ccc_m / ccc_beta / ccc_xi /
  ccc_p0_initial settings, defaults Li et al. 2021 Case V. Uniform
  160 -> 176 B. Combos + sliders in both panels.

Verification: scripts/test_material_ccc.py, 12 checks - alpha0
round-trips exactly; Case 3 lands on the ellipse at the same p; Case 1
hardens, Case 2 softens; 500 random gradients never leave the surface;
repeated tension softens monotonically to p0 = 0; all five Li 2021
Table 1 cases produce finite initial states at E = 3 MPa. test_mpm.py
with MPM_MODEL=ccc: weak Case V (3 kPa) flattens on impact, strong
Case III (42 kPa) piles alongside Stomakhin - the parameter-to-regime
link works. 8/8 tint, 8 pipelines on Metal.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Presets: seven entries in the sidebar - Stomakhin 2013, Li et al. 2021
Cases I-IV (cold dense, warm shear, sliding slab, warm plug) and Case V
(Vallee de la Sionne 2003), plus a Drucker-Prager cold-dense fallback
with phi derived from M = 0.5. A preset writes the ordinary settings
(model, E, nu, rho, mu, model parameters) and nothing else, so there is
one source of truth. Applying one forces a reseed and pulls dt under
the CFL bound of the new stiffness - Li's 3 MPa is ~6x the wave speed
of Stomakhin's 0.14 MPa. Hand edits drop the combo to "(custom)".

Bug fixed: switching the material model did not reseed. plastic_state
is model-specific (Jp / plastic strain / alpha); Stomakhin's Jp = 1 read
by Cam-Clay is alpha = 1, a fully softened material with p0 = 0. Both
panels now force reset_on_next_run on any model change.

Diagnostics: SimState gains plastic_particles (24 B), counted once per
run in mpm_splat as particles whose state has left
material_initial_state(). The state buffer is allocated once in the
constructor - it is fixed-size, and an async readback in flight across
an ensure_resources() reallocation would be a use-after-free. Per-run
counters are zeroed by a 2-slot write before non-reset runs.
read_back_state() fires from the work-done callback into last_state();
the sidebar shows particle count, plastic ratio, max speed and terrain
range, and warns when nothing seeded.

Verified end to end on real terrain by temporarily auto-running the
graph: 131072 active, 968 plastic (0.7 %), max 1.57 m/s (~ g sin(theta) t),
terrain 1303-2060 m. 8/8 tint, build clean, temporaries reverted.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Along the centre-of-mass path the energy height z + v^2/2g drops by exactly mu
per horizontal metre under Coulomb friction, so the fitted slope is the
effective friction and its excess over the basal mu is internal dissipation.

- mpm_splat sums position and |v|^2 over active particles into SimState as
  64-bit lo/hi u32 pairs (carry detected from atomicAdd's return value);
  SimState 24 -> 56 bytes. A first version that summed value/N quantised
  every particle below 3.6 m/s to zero.
- MpmSolverNode keeps an EnergySample per run and fits energy_line_friction()
  over the sliding regime; AvalanchePanel shows mu_eff, the set mu, their
  difference and a sparkline.
- test_mpm.py terrain generalised to an inclined plane; test_energy_line.py
  recovers the basal mu to under 1 % (0.3024 vs 0.3) with ~0 internal
  dissipation on a frictionless plane.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…down

P2G truncated every grid contribution to 1e-4 and kept the node mass in one
i32 at the same quantum. Truncation takes relatively more off a small mass
contribution than off its momentum, so momentum/mass came out too large at
every low-weight node - and a 1.5 m slab in a 12.5 m cell hands its third z
layer such weights for every particle. APIC's C carried the excess back into
the particles each step: model-, dt- and particle-count-independent energy
creation, tangential only, ending at 17 000 m/s.

- Round instead of truncate; mass gets its own 2^-20 quantum in a 64-bit u32
  lo/hi pair (add_node_mass / node_mass, carry via atomicAdd's return);
  momentum stays i32 at 1e-4 with its range limit now documented.
  GridNode 16 -> 20 bytes.
- test_sheet_fixed_point.py: the slab test at device scale with both
  schemes emulated - old scheme +336 % vs the rigid block in 20 s, new
  scheme -0.1 %.
- On device: max speed 21-26 m/s for the whole run, mu_eff 0.58 -> 0.49
  against a basal 0.47, flow stops after 340-380 m (Stomakhin and CCC).
- Docs: 03, 04 (why round, why the mass is 64-bit), 05, 06 (4h, bug 8 with
  the ruled-out detours), 07; claude_log entry 8.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Standalone write-up of the 2026-09-13 blow-up: symptoms, what was
established and ruled out on the device, the device-scale offline
reproduction, the truncation-bias mechanism, the fix and its
verification, and the lessons for the final report.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The grid stores 16 node layers per (x, y) column above a per-column floor
written by mpm_prepare, instead of a dense res^3 box that was 98 % air.
Memory and grid work now scale with the footprint, so the domain grows from
1.6 km to 4 km at the same dx = 12.5 m and runs faster (100 vs 116 ms per
run). Region extent 8000 m. Verified against the dense grid offline and on
device (06-verification.md 4i); options and measured cost in
08-domain-size-options.md.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
WebGPU has one queue, so a run submitted as a single ~100 ms command buffer
parked the next frame's render behind it and the view dropped to ~25 fps
while playing. MpmSolverNode::submit_chunk() now submits substeps_per_submit
substeps per command buffer, re-armed from the queue's work-done callback
with two chunks in flight (one alone leaves the queue idle every other frame).
Overlay and readback still update once per run.

Measured on an M5 at vsync 60: one submit 25 fps / 2.0x real time; chunks of
2 (default) 60 fps / 1.65x; 4 -> 53 fps / 1.8x. Setting exposed in both
panels and the graph preset.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
… default

AvalanchePanel::ready() runs after NodeGraphPanel has loaded the default
graph and, when asked, swaps in the MLS-MPM preset, applies the remembered
material preset and scenario (which runs the graph: terrain fetch + seed)
and optionally starts playing once the solver has valid inputs.

- Native: "Load this simulation at launch" / "and play" checkboxes, stored
  per user with QSettings("weBIGeo", "avalanche"); the location and
  material combos remember their choice. Nothing is written into the graph
  preset.
- Web build: no settings store, so it loads by default (temporary for the
  release); ?avalanche=0 skips it, ?avalanche=play also starts playing.
- The panel no longer hides when the active graph has no MPM node; it
  offers a "Load the MLS-MPM simulation" button instead.
- NodeGraphPanel::load_preset() made public (the one upstream line).
- misc/scripts/serve_wasm.py: COOP/COEP static server for testing the wasm
  build locally (SharedArrayBuffer needs cross-origin isolation).
- First-run notice of the MPM graph now points at the sidebar.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`aqt list-qt linux android --spec 6.11.1` started failing on 2026-09-14 with
"No latest version available": the linux index lists nothing past 6.7.3,
while Qt >= 6.8 ships its Android packages host-independently under all_os,
where 6.11.1 and both arches are present. Deploy's build-android jobs failed
on that step and the Pages deploy was skipped although every wasm build
passed. Same fix in the Play Store workflow.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Cross-section figure (dense box vs per-column band, terrain, snow layers,
column_floor, a particle's 3x3 stencil) as mpm-mls-doc/terrain-following-grid.svg,
embedded and walked through in 04-data-layout.md; 08 points to it. Log entry
for the 15.9. meeting notes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Runs the real WGSL kernels on an analytic slope with the node's bindings, uniform
layout and dispatch sequence; per-stage GPU times from timestamp queries, exact
solver memory, and a centre-of-mass trace as physics fingerprint. A headless
driver (Playwright, SwiftShader or --gpu) can A/B against the shaders of any git
revision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvhQvDz3HXRPPGxgNK6cDV
…ubstep

Kernels:
- P2G flags the 8x8-column tiles its stencil touches; the grid update runs one
  workgroup per tile and returns at once for unflagged ones. It is the last
  reader of the fixed-point accumulators, so it zeroes them and writes the
  node velocity as floats to a separate buffer - no full-grid clear pass.
- The return mapping in G2P also returns tau = P F^T, computed from the SVD it
  has just done; the particle stores it in its padding and P2G no longer runs
  an SVD. The per-particle volume slot goes (it was the same for all particles).

Node:
- Diagnostics are copied into a persistent MapRead buffer inside the last
  chunk instead of RawBuffer::read_back_async, which allocated a staging buffer
  and leaked a command buffer and a queue reference per run.
- Async callbacks carry a liveness token instead of a raw this, so replacing
  the graph mid-run no longer calls into a destroyed node.
- One pipeline factory per resource registry instead of one [this] factory per
  node instance, which dangled after every graph reload and ran on F5.
- Bind group cached; energy line bounded to 2048 samples; buffer sizes clamped
  to the device's storage binding limit; GPU time per substep measured with
  timestamp writes on the solver's pass; solver GPU memory reported.
- Default detail lowered to 65536 particles and 12 grid layers.

validate_wgsl.py falls back to naga when tint has not been built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvhQvDz3HXRPPGxgNK6cDV
Pacing gives the simulation a GPU budget per frame (Smooth 6 ms, Balanced
14 ms, Fast 30 ms) and derives the substeps per frame from the solver's
measured GPU time per substep; Manual keeps the old fixed setting. Detail
presets set particle count and grid layers (Low 32k/10, Medium 64k/12, High
128k/16). The panel shows simulated seconds per wall second, GPU ms per
substep and the solver's GPU memory. The graph preset now starts at Medium.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvhQvDz3HXRPPGxgNK6cDV
In the automatic pacing modes substeps_per_run follows the chunk size
(at least two chunks per run, never under 24 substeps): a one-chunk run
left the GPU idle until the next frame started the next run, and the
run length no longer only ever grows. Both fields are read-only unless
Pacing is Manual.

The graph preset's dt goes from 0.01 to 0.02 s: on the benchmark slope
Stomakhin at 0.02 and 0.03 tracks 0.01 to within 0.6 and 1.2 % of the
centre-of-mass travel after 7 s, still 3x under the panel's CFL bound.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvhQvDz3HXRPPGxgNK6cDV
09-performance-analysis.md: why the demo felt slow (map-scale physics,
frame-rate-bound pacing, GPU cost), where the GPU time goes, defaults,
VRAM and device limits, the leaks and lifetime bugs found and fixed,
main-loop and threading options, the benchmark protocol, the literature
on real-time MPM, measurements of this round and a ranked list of next
steps. Chapters 01-05, 07 and the README follow the new kernel schedule
and particle layout.

bench/results: SwiftShader A/B of the old and new kernels for all three
material models, the new default detail, and a dt stability sweep.
scripts/syntax_check.sh type-checks the extension's C++ without a build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvhQvDz3HXRPPGxgNK6cDV
ResolveQuerySet's destination offset must be a multiple of 256
(QUERY_RESOLVE_BUFFER_ALIGNMENT), but the two timestamp slots were packed
at their natural 16-byte stride, so slot 1 resolved at offset 16. Dawn
rejected the whole command buffer, not just the resolve - so every second
chunk's P2G/grid/G2P dispatches never ran: half speed, no GPU timing, and
the adaptive pacing with nothing to pace on.

Each slot now gets a 256-byte stride in the resolve buffer. Verified on
device: no validation errors over a 60 s run, timestamps arriving,
gpu_ms_per_substep 0.55 -> 1.7 ms as the flow spreads.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Kernel benchmark at Medium (per stage and per pass) and High detail, plus
the in-app speed readout on Breite Ries for the web and native builds.
Medium: 0.58 ms GPU per substep, 15.5x real-time ceiling, P2G 74 %;
High: 1.15 ms, 8.3x. Documented in 09 §8.5, together with the upstream
lifetime crashes (F5 after a graph reload, reload mid-run) confirmed on
the device and fixed in a separate PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ay High

Cam Clay costs +9 % per substep over Stomakhin (0.64 vs 0.58 ms), so the
material model is not a performance factor. Documented in 09 §8.5.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Emanum and others added 29 commits November 10, 2026 18:45
The map graph gets an "AvaFrame Release" node between the region and the
solver. The five AvaFrame map scenarios know their dataset and the release
scenario the comparison used; applying one points the node at the dataset
when it is downloaded, else at nothing, and the solver releases the disc as
before. The panel shows which ("Release: AvaFrame avaKot / relKot, 21664 m3 on
1.5 ha" or "a disc of the same area") and, for avaGar, a picker for its three
release scenarios.

The node logs the release centroid; the solver warns when a release reaches
outside its domain (those cells are not seeded).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New mpm-mls-doc/14-avaframe-release-on-map.md: pipeline, the coordinate chain
and what is approximate, measurements on the five scenarios, a figure of the
release areas against the old discs (made by
avaframe/tools/map_release_figure.py). Files/API, verification, README and the
claude_log updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OverlayRenderNode linked its overlay to the source node's texture by raw
pointer, set when the overlay node ran. The graph runs its nodes in one chain
in topological order, so in the sandbox graph (sandbox -> solver -> map
overlay) the sandbox node replaced its map texture on a dataset switch, and
the overlay node relinked only after the solver's run had finished, frames
later. Every frame painted in between drew through the freed texture:
EXC_BAD_ACCESS in TextureOverlay::draw (map mode, then the sandbox, then a
dataset switch).

- TextureOverlay::link_texture_source(): the overlay asks a callback for the
  texture every frame; OverlayRenderNode passes one that reads its input
  socket, so it always gets the producer's current texture.
- Overlay::can_draw(): an overlay without a texture (an unlinked one left
  behind by a replaced graph, or a source that has none this frame) is left
  out of the ping-pong chain like a hidden one, instead of asserting or
  reading a null texture.

Reproduced with a temporary harness (map, sandbox, three dataset switches):
crashed on the first switch before, survives all three now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the sky under the cursor the position readback returns the camera
position as the operation centre, and the zoom normalised a zero vector:
the camera position became NaN, a black view no input could recover.
Zooming in could also step through the terrain with the fixed minimum step.

- No terrain under the cursor: zoom along the view ray towards a point as
  far away as the last terrain hit.
- move_towards_centre() keeps the distance to the centre within 10 near
  planes (50 world units) and 500,000 world units (half the far clipping
  distance); a camera already outside may only move back. Wheel, drag,
  pinch and tap-tap-move all use it.
- Tests in unittests/nucleus/Camera.cpp: zoom in, zoom out, sky.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- mpm-mls-doc/12-rendering-plan.md becomes 12-rendering.md: what is
  implemented and where (files, frame order, data path, flow surface,
  track, snow cover, powder, panel controls, limits), without the
  dated status history. Links updated.
- docs/time_stepped_simulations.md: how to add a simulation that is not
  MPM specific (the TimeSteppedSimulation contract, a sketch of a node,
  wiring, interpolation, pitfalls, testing); linked from
  webgpu_app_dev.md and 13-simulation-driver.md.
- Design history written solution-first (12-rendering.md).
- Web build tested in the browser: AvaFrame release areas on the map,
  rendering and real-time interpolation work (06, 12, 13, 14, README).
- claude_log entries for 25 Oct.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The dataset preparation (prepare_dataset.py and its C++ port in the
  app's download) rasterises the ENT shapefile like a release scenario:
  entrainment.asc (slope-normal thickness, 0.3 m where a feature has
  none, as com1DFA) and an "entrainment" entry in dataset.json with
  volume, area and mean slope. C++ and Python output are byte-identical.
- load_sandbox_terrain() turns it into vertical depth and removes the
  cells under the chosen release, as com1DFA crops the overlap per run.
  AvaFrameSandboxNode uploads it as a texture.
- AvaFrameReleaseNode resamples it onto the map region with the release
  (resample_depth()), so ReleaseArea carries the cover too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cover is a field per grid column (column_stats.cover), set at the
reset from AvaFrame's entrainment areas (sandbox, AvaFrame scenarios on
the map) or one slope-normal thickness up to a slope (generic map
scenarios), without the release. The grid update erodes it where the
flow passes, in com1DFA's two modes:
- plowing: the front takes the whole cover of a column once the flow is
  plowing_depth deep;
- erosion (com1DFA's default): tau_b |u| / e_b per area and second, with
  tau_b from the solver's friction law.
Eroded snow becomes particles from a pool after the release particles,
each with a release particle's mass, at rest; G2P lets them join and the
next P2G adds their mass without momentum, so the flow slows by exactly
the momentum the snow takes up.

Readback and export carry the cover, the entrained mass and volume (as
cover, comparable with com1DFA) and pool overflow. The Avalanche panel
gets entrainment controls; the mode is kept per context (map: erosion,
sandbox: off, so the null-test comparison stays as it was).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- run_com1dfa.py: com1DFA 2.1 on the five avalanches without entrainment,
  with erosion and with plowing, using the null benchmarks' settings.
- compare_aimec.py --reference null|erosion|plowing|auto rates an MPM
  run against those runs; batch_entrainment.json is the MPM side.
- Results: entrainment off reproduces the 11 Oct runouts exactly; erosion
  entrains 80-83 % of com1DFA's volume (Madlein 55 %); com1DFA's plowing
  takes more than the cover holds (its own TODO); mean runout error to
  com1DFA 149 m without entrainment, 119 m with erosion.
- mpm-mls-doc/15-entrainment.md (what is implemented and where, results),
  updates to 02-07, README, avaframe/README, claude_log.
- bench/mpm_bench.js follows the new uniform (240 B), state and cover
  binding, and still runs older revisions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…igure

run_com1dfa.py --modes coulomb runs com1DFA with the MPM's basal law
(Coulomb, mu 0.47), to separate the friction law from the numerics;
compare_aimec.py --reference coulomb rates against it. AIMEC's runout
statistics figure raised on one pair; it is only a picture, so it is
now skipped with a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The solver keeps the entrainment cover as one number per grid column and
fills pool particles at rest under the flow, so nothing showed what the
flow would pick up. The flow surface now reads the solver's column stats
and draws the remaining cover as a layer of fresh, slightly blue snow
("Entrainable snow", on); flow over track over cover, so it ends where
the flow has eroded it.

- Particle, powder and splat shaders draw a slot that was empty in the
  previous chunk at its current position instead of blending from the
  domain origin.
- The surface's terrain lookup is Catmull-Rom: on bilinear terrain the
  thin cover was lit in blocks of the height texels.

Checked on Madlein (avaMal) at 25 s: cover on, off, speed colours.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every MPM shader lists its papers in the header comment and cites section,
equation and PDF page where the code implements them. The numbers were
checked against the PDFs. Comments only; tint validates all kernels.

Docs: Wolper's q is sqrt((6-d)/2)|s|, the same as Gaume's sqrt(3/2)|s| in
3D, so no M rescaling is needed (01-theory, refs, correction notes in both
audits). Hu 2018 is Article 146; its force term is sec. 3.4, eq. 15-18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_MpmGolden.cpp runs the real WGSL functions on the GPU (headless
Dawn) and compares them with the Python ports: svd3, the three return
mappings with their stress, Coulomb and Voellmy friction, and the B-spline
weights. make_golden.py writes inputs and expected outputs from the ports.
MpmSolverSettingsUniform is public so the test fills the real uniform.

GPU and ports agree to 1e-7 to 4e-6, with the same branch in every case.
Local only, not on CI (CI runs no WebGPU tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
p0 = K sinh(xi |alpha|) and the initial alpha = -asinh(p0_ini / K) / xi
were written with exp / log, which cancel for a small argument. For Li
2021 case V at E = 3 MPa (p0 / K = 1.2e-3), p0 was 8.1e-5 off, alpha_0
2.2e-5. ccc_sinh and ccc_asinh use the Taylor series below 0.1; the
golden tests now compare p0(alpha) directly, with sinh arguments from
0.05 to 3, and see 5e-7 at most.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What each script checks or produces, which venv it needs, measured run
times, and how to run it: shader validation, the Python ports, the GPU
golden tests, the AvaFrame comparison and the benchmark tables. Linked
from the docs index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A counting sort of the particle indices by 4x4-column tile, once per chunk
(mpm_sort_count / _scan / _scatter), lets each P2G workgroup sum its home
tile's 6x6x16-node window in workgroup memory and write each node to the
grid once instead of once per particle. The particle buffer keeps its
order (the renderer pairs particles by index); the sort data follows the
tile flags in binding 10, so the solver stays at eight storage buffers.

Apple M5, Chrome 158, against main: 1.73-2.16x less GPU time per run for
all three materials and 65k-1M particles, P2G about 3x faster. The grid
sums are integers, and the benchmark's centre-of-mass trace is
bit-identical to main in every configuration (09-performance-analysis.md
section 8.6, bench/results/m5-chrome158-sorted-p2g-vs-main-*.json).

The benchmark mirrors the new schedule; run_headless.mjs gains --chrome,
because Playwright's headless shell has no GPU on macOS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bench/check_substep.mjs runs the real kernels with their bindings from a
known state of 300 particles on a planar slope and compares every field
of struct Particle with a float64 reference (scripts/make_golden_substep.py)
that mirrors the shaders, including the fixed-point rounding. Two
scenarios: free (1 and 3 substeps) and contact (1 substep; a particle that
has touched the surface hovers within float32 noise of it, so its contact
decision in later substeps is not reproducible). The generator rejects
inputs with a particle within 4e-4 m of the surface at the end of a
substep.

Apple M5: velocity within 3.3e-4 m/s, F within 1.6e-6, for all three
materials; identical to the digit with the shaders from before the sort.
Eight mutations of the shaders are detected. Also runs on SwiftShader.

MpmBench gains setParticles, readParticles, prepareTerrain and a terrain
function; headless_common.mjs holds what run_headless.mjs and the new
checker share. Documented in 06-verification.md section 4p.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… folder

The README now opens with what the project adds to weBIGeo (solver, simulation
driver, 3D rendering, switchable overlays, AvaFrame integration, panel and
scenarios, tooling), an AI-assistance note and a "Current state" section. The
three issue #3 audit reports move to mpm-mls-doc/audit-report/ and are listed at
the end. Stale content is updated across the living docs: current performance
figures, sorted P2G in the deviations table and the file list, entrainment
status, and the non-reproducibility of entrainment runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
09-performance-analysis describes the solver as it is now: current GPU times
by particle count and material, the kernel design behind them, memory from the
current buffer sizes, playback, resource lifetime, the benchmark method and the
next improvements. The history is reduced to a pointer to the dated results.
README and 05 now name the real graph preset (65 536 particles, 320² × 12).
07 lists what is actually not implemented instead of a struck-through to-do
list, and drops the build order. Links into 09's sections are updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
History-first passages ("until 2026-xx it was X", "used to", "the old ...")
in 01, 03, 04, 05, 07, 13 and 14 now state what the code does and then why.
08 is rewritten from a September decision record into a description of the
terrain-following grid, its limits, why not a dense grid (with the
measurements) and the alternatives not chosen. 05's renderer plan becomes a
pointer to 12-rendering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"For the report" asides become plain statements, private claude.ai and
Notion pointers that outside readers cannot open are removed, and wording
addressed to the author is rephrased. Dated reports and audits unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The avalanche models can hand a flow field (a vector and attributes per cell
of a regular 2D grid) to whatever draws or exports it, in one neutral format:
VectorField, FieldBuilder and VectorFieldSource, with the 32-byte FieldRecord
in vector_field.wgsl. MpmSolverNode implements VectorFieldSource and exposes an
MpmRawView; MpmBaselineFieldBuilder averages the grid velocity over depth,
weighted by node mass, in its own pass and bind group.

For the grid to be readable as a whole, the grid update writes the node mass
into grid_velocity.w, tiles the flow has left are cleared once (a second
tile-flag bit), and a reset clears grid_velocity. The physics is unchanged: the
whole-kernel substep test has the same errors, and the benchmark trace is
identical. The substep test now also checks the node mass and the clearing.

test_VectorField.cpp checks the builder against a float64 reference and its
update protocol. The benchmark can time the builder (vectorField=1). Documented
in mpm-mls-doc/16-vector-field.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…d builder

The streamline project builds its own field from the solver's raw data, so the
neutral VectorField format, the baseline builder, its shaders and its test are
removed again. What stays is what makes the raw grid readable as a whole:
MpmSolverNode::raw_view() (MpmRawView: grid velocity, column floors, grid
resolution, mass-to-kg factor, counters, a layout version), the node mass in
grid_velocity.w, the second tile-flag bit that clears tiles the flow has left,
and the reset clearing grid_velocity. The substep test still checks the mass
and the clearing.

mpm-mls-doc/16-vector-field.md becomes 16-raw-grid-view.md: what is handed out,
the grid layout, what the solver guarantees and what to watch when reading it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e time

MPM_LAYOUT_VERSION (MpmSolverNode.h) versions what code outside the solver
reads from its buffers: struct Particle, struct ColumnStats, grid_velocity and
column_floor. MpmParticleView and MpmRawView carry it as layout_version.

The avalanche renderer's shaders copy that layout. AvalancheRenderer records
the version they were written for (SOLVER_LAYOUT_VERSION) and
ParticleRenderNode.cpp static_asserts it against the solver's, so a layout
change fails the build there until the shaders are updated. The procedure is in
mpm-mls-doc/04-data-layout.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Removed from this branch only (main keeps them):
- claude_log.md, AVALANCHE_SIM_PLAN.md, CMAKE_FOR_WEBDEVS.md,
  WEBGPU_OVERVIEW.md, imgui.ini, docs/webgpu_app_ios.md
- docs/webgpu_app.md, docs/webgpu_app_dev.md reset to upstream
  (camera_controls.md and time_stepped_simulations.md stay)
- .github/workflows/ reset to upstream

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… KTX target

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Emanum Emanum closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants