Fluid cost r2: mutant readings and bounds across twelve bucket orders, memory per lane in Fluid_cost_line, docs
Column mean bound 0.0907 (ruling ymir-column-mean-bound-order-noise): Md claims it; Mk is claimed by KERNEL_REACH (table of 512 buckets so a shared bucket cannot hide the miss), Mf by floor penetration and through count, Mo by the overflow asserts; Mx and Mu unclaimed. Fluid_cost_line prints bytes per lane. docs/soa-world.md: two sorts with fluid live, kernel cell, CSR lists under the fluid capacity, fluid-solid contact, cost readings. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e71c731bd5
commit
35b0b6d7f9
3 changed files with 49 additions and 21 deletions
|
|
@ -104,7 +104,7 @@ separate native object (`ymir_box3d_soa.c`, ABI 12) so the Aetheria session's co
|
|||
of `ymir_particles_begin`, `_substep` and `_end`). The particle state is a constraint graph: particles are one lane set with a
|
||||
phase word and every constraint type is a lane set of its own. There is no object above the lanes: a rope, a sheet, a gut or
|
||||
flesh is whatever constraints a caller emitted, and exists only in that caller's builders. A world created with a
|
||||
`ymir_particle_capacities{particles, distances, bends, attachments, tethers, materials}` that is not all zero owns fixed
|
||||
`ymir_particle_capacities{particles, distances, bends, attachments, tethers, materials, fluid}` that is not all zero owns fixed
|
||||
lanes that never move; created with none (`NULL` or all zero) it behaves byte-identically to ABI 8. Nothing writes a
|
||||
particle's position or velocity but the step.
|
||||
- Data model. Particle lanes: `x y z vx vy vz radius inv_mass rest_x rest_y rest_z phase material live generation removed_at
|
||||
|
|
@ -151,7 +151,7 @@ separate native object (`ymir_box3d_soa.c`, ABI 12) so the Aetheria session's co
|
|||
except `removed_at`) reused only once a step has passed, lowest lane first. Stale generations are refused. Counts are high-water
|
||||
marks; a view's counts are read when the view is taken, so take it after the last command.
|
||||
- Solve (inside the fork's substep callback, `h = dt / substeps`, one iteration of each pass per substep: the small step does
|
||||
the converging). Order: predict particles and proxies, hash grid, pair contacts (Jacobi), attachments, distances in
|
||||
the converging). Order: predict particles and proxies, hash grid (the non-fluid lanes), pair contacts (Jacobi), the fluid pass (its own grid; fluid-solid contact), attachments, distances in
|
||||
lane order, bends in lane order, tethers, body contacts last (with contacts first a box pushed into a rope reads 14% of a
|
||||
radius inside). A bend works on the offset of its shared particle b from the centroid of a, b, c (Kelager 2010): a soft XPBD
|
||||
pass toward the rest offset, then a hard unilateral pass at the offset `max_angle` allows (computed from the two rest
|
||||
|
|
@ -176,22 +176,30 @@ separate native object (`ymir_box3d_soa.c`, ABI 12) so the Aetheria session's co
|
|||
`C_i = max(n_i / n0 - 1, 0)`, so there is no artificial-pressure term and an under-dense fluid (a gas of far particles) is not
|
||||
pulled together; `lambda_i = -C_i / (sum_k w_k |grad_k C_i|^2 + eps w_i)` (0 when that is 0; XPBD inverse-mass weighting, Macklin et al. 2016) with the gradients over `n0` in 1/m^2 and `eps = 1e-4` (a sweep of
|
||||
1e-6 to 1e-2 on the column test moved the max density between 1.344 and 1.377 and nothing else: the gradient sum is about 500).
|
||||
Per substep, after contact: pass A gathers `n_i` for each fluid particle over the rings of cells that hold its kernel reach (cell then
|
||||
index order; self and the solids counted, `s = 1` as Flex 7.1) and its `lambda` (a solid's is 0), and writes its neighbour list: every
|
||||
kernel neighbour (fluid, or a solid it would touch by contact) in walk order, up to 96 (about 33 at rest at 4 r reach, about 45 at the
|
||||
column's compression); each one past that adds 1 to `fluid_neighbour_overflow`, the ABI 12 view scalar (last step, summed over its
|
||||
substeps), so `n` and `lambda` stay exact and only the correction and XSPH lose those pairs. Pass B reads the lists: each fluid row in index
|
||||
Per substep, after contact, the fluid pass rebuilds the grid over every live lane at the kernel cell `4 r_fmax` (the same tables, in place; nothing after the
|
||||
pass reads the contact grid) and copies position, inverse mass and phase into sorted order, so a bucket reads contiguously (`sorted[q]` is the lane of sorted index `q`).
|
||||
`fluid_rings = ceil(2 (r_fmax + r_max) / 4 r_fmax)` (1 at equal radii: 27 cells). Pass A takes each fluid row in sorted order: the buckets of its cells, each bucket once (a
|
||||
bucket two offsets hash to is skipped the second time, by a visit stamp; a particle of a cell outside the rings is out of reach, so the distance test needs no cell
|
||||
compare), a branchless compaction of the candidates within `2 (r_i + r_max)` into a stack row buffer of 128 (hits past it add to `fluid_neighbour_overflow`), and over the
|
||||
buffer `n_i` (self and the solids it would touch by contact counted, `s = 1` as Flex 7.1) and `lambda` (a solid's is 0), and the row's neighbour list: every kernel neighbour
|
||||
in walk order, packed (CSR) into an arena of `fluid_capacity * 96` entries (about 33 neighbours at rest at 4 r reach, about 45 at the column's compression); each past the
|
||||
arena adds 1 to `fluid_neighbour_overflow`, the ABI 12 view scalar (last step, summed over its substeps), so `n` and `lambda` stay exact until the row buffer overflows and
|
||||
only the correction and XSPH lose the pairs past the arena. `fluid_capacity` (`ymir_particle_capacities.fluid`, `Box3DSoaParticleCapacities.Fluid`, 0 by default) is the most
|
||||
live fluid particles: `create_particles` refuses a batch past it whole (`FULL`, no lane taken). Pass B reads the lists: each fluid row in index
|
||||
order, each listed neighbour in list order, a fluid neighbour below the row skipped (its own row does the pair), a solid always done from the
|
||||
fluid row; a pair moves by `d = (lambda_i + lambda_j) grad W / n0(h)`, end `i`
|
||||
by `w_i d` and end `j` by `-w_j d`, applied after the pass (equal masses move as before; a static end takes nothing and the fluid its XPBD share, so the energy at 30 : 1 and 100 : 1 does not rise). A pair therefore
|
||||
carries equal and opposite momentum at any mass ratio (a solid end is the reaction: `m_i dx_i = -m_j dx_j`), a zero-mass end
|
||||
takes nothing, and the one pair formula serves fluid with fluid and with solids. The XSPH viscosity of Schechter and Bridson
|
||||
takes nothing, and the one pair formula serves fluid with fluid and with solids. Then the fluid-solid contact (the contact pass never sees a fluid lane: the contact grid holds
|
||||
the other lanes only, at `2 r_max`): two passes over the fluid rows' lists, the first counting the overlaps of each listed solid at `ri + rj`, the second moving both ends as the contact
|
||||
pass does, weight `1 / max(n_i, n_j)` over these pairs only, applied after (Jacobi); PhysX solves fluid-solid in its fluid pass the same way. The XSPH viscosity of Schechter and Bridson
|
||||
runs after the velocity update over the same lists (fluid neighbours above the row), `dv = c (v_j - v_i) W / n0` with `c` the mean of the two
|
||||
materials' `viscosity`, split by inverse mass the same way, and only when some material has a viscosity above 0 (one scan of the material lanes a substep). A pair that
|
||||
entered reach since pass A is missed by XSPH (smoothing, not a constraint). The lists are per-substep scratch, carved once at create (384 bytes a particle lane). The grid cell is `2 r_max` always, solids and fluid alike: the contact
|
||||
pass walks the half of its 27 cells, and the fluid passes walk `ceil(2 (r_fmax + r_max) / 2 r_max)` rings (2 at equal radii: 5^3 cells); a world with no live fluid steps byte-identically to
|
||||
entered reach since pass A is missed by XSPH (smoothing, not a constraint). Lists, copies and the fluid grid are per-substep scratch, carved once at create: 28 bytes a particle lane
|
||||
(`nbr_start`, `nbr_count`, `sx sy sz sw sphase`; h1's per-lane lists were 388) and 384 a unit of fluid capacity. A world with no live fluid steps byte-identically to
|
||||
one before fluid (no pass runs: `live_fluid` counts the live fluid particles, written by create and destroy only). Cost on the 16 x 16 sheet scene at 4 substeps, increment over the same scene without fluid (Release, three runs):
|
||||
512 fluid +3.0 to +3.1 ms a tick at viscosity 0 and +3.2 to +3.4 at 0.01; 2000 fluid +13.1 to +13.5 and +13.6 to +13.9, against a target of 1.0 ms at 512. By phase at 512 (ms a tick): contact pass +0.7 over its no-fluid 1.5, pass A 2.9 (of which the bare walk of 125 cells a row, with no arithmetic, 2.0), pass B 0.11, apply 0.01, XSPH 0.12, grid 0.16. The walk of the rings is the owner of the miss; per-tick lists and cell-sorted copies are the parked levers. The
|
||||
512 fluid +0.76 to +0.84 ms a tick at viscosity 0 and +0.86 to +1.01 at 0.01; 2000 fluid +4.1 to +4.4 at both, against a target of 1.0 ms at 512 (h1: +3.0 to +3.4 and +13.1 to +13.9). The probe behind the design
|
||||
(a standalone replica of the pass) read 7 ns a cell visit in the 125-cell walk: the cost was per cell, not arithmetic, so the cell is now the kernel reach and the copies and the branchless filter keep the 27 buckets cheap. Two counting sorts a substep run with fluid live.
|
||||
sensor lane `particle_density` reads `n_i / n0` (1 at rest, 0 for a solid) in the last substep the particle ran.
|
||||
Fluid holds no constraint: `create_distances` and `attach` refuse a fluid particle, so `create_bends` (over distances) can
|
||||
never name one; a thing that holds liquid is cloth around free fluid (a balloon), as in Flex sec. 8. Every `create_particles`
|
||||
|
|
@ -236,7 +244,7 @@ no allocation across 100 steps with fact reads. `Box3DSoaImpulseTests`: `contact
|
|||
|
||||
## Not done
|
||||
|
||||
`Box3DSoaFluidTests`: the refusals (a distance or attachment naming fluid, a viscosity below 0 or not finite); 64 fluid particles created and destroyed a tick on the 20-pin sheet leaving every tether lane byte-equal; an 8 x 8 x 16 column in a box well (max density, mean density, nothing outside); fluid thrown into a free sheet and rope at fluid : solid mass 64 : 20, 1 : 30, 30 : 1 and 100 : 1 (momentum drift, energy on every row); a 343-particle fluid block dropped 15 cm onto a floor of immovable solid particles at 4 substeps (penetration, nothing through the floor's interior bar the one particle over a lattice hole); probe scene 3, the 343-particle pour on a tilted sheet and a sloped rope at 4 substeps, printed as readings with the same block flagged solid as the control, asserting nothing; fluid pushing a free box with the impulse lane equal to its M dv; a 3 r lattice not clumping; XSPH damping a shear field; the kernel reaching a larger solid beyond two contact radii; the pour's six checkpoint hashes (two runs, a one-ulp nudge, eight concurrent worlds). Each bound states its readings and the mutant it separates from. `Fluid_cost_line` prints 512 and 2000 fluid particles on the sheet scene at viscosity 0 and 0.01. Overflow is asserted 0 in the column, the floor and the pour.
|
||||
`Box3DSoaFluidTests`: the refusals (a distance or attachment naming fluid, a viscosity below 0 or not finite; a batch of fluid past the fluid capacity, refused whole); 64 fluid particles created and destroyed a tick on the 20-pin sheet leaving every tether lane byte-equal; an 8 x 8 x 16 column in a box well (max density, mean density, nothing outside); fluid thrown into a free sheet and rope at fluid : solid mass 64 : 20, 1 : 30, 30 : 1 and 100 : 1 (momentum drift, energy on every row); a 343-particle fluid block dropped 15 cm onto a floor of immovable solid particles at 4 substeps (penetration, nothing through the floor's interior bar the one particle over a lattice hole); probe scene 3, the 343-particle pour on a tilted sheet and a sloped rope at 4 substeps, printed as readings with the same block flagged solid as the control, asserting nothing; fluid pushing a free box with the impulse lane equal to its M dv; a 3 r lattice not clumping; XSPH damping a shear field; the kernel reaching a larger solid beyond two contact radii; the pour's six checkpoint hashes (two runs, a one-ulp nudge, eight concurrent worlds). Each bound states its readings and the mutant it separates from. `Fluid_cost_line` prints 512 and 2000 fluid particles on the sheet scene at viscosity 0 and 0.01. Overflow is asserted 0 in the column, the floor and the pour.
|
||||
|
||||
Body removal with a stable ordering rule, compound bodies
|
||||
and per-shape material, and motor joints with a velocity target or per-joint force readback (the motor joint here is a position spring only; Lodur drives limbs from torque lanes).
|
||||
|
|
|
|||
|
|
@ -415,12 +415,28 @@ public sealed class Box3DSoaCouplingTests
|
|||
return watch.Elapsed.TotalMilliseconds / 240;
|
||||
}
|
||||
|
||||
/// <summary>Private bytes the world takes for <paramref name="particles"/> particle lanes and a fluid capacity, as the process counts them (the native block is one calloc).</summary>
|
||||
private static long WorldBytes(int particles, int fluid)
|
||||
{
|
||||
GC.Collect();
|
||||
var before = System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64;
|
||||
using var world = new Box3DSoaWorld(4, particles: new Box3DSoaParticleCapacities(particles, 0, 0, 0, 0, 1, fluid));
|
||||
GC.Collect();
|
||||
return System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 - before;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(512)]
|
||||
[InlineData(2000)]
|
||||
public void Fluid_cost_line(int fluid)
|
||||
{
|
||||
// Printed, not asserted. Target at 512: an increment of at most 1.0 ms per tick over the same scene without fluid, at XSPH viscosity 0 and 0.01.
|
||||
const int lanes = 200000;
|
||||
var perLane = (double)WorldBytes(lanes, 0) / lanes;
|
||||
var perFluid = (double)(WorldBytes(lanes, lanes) - WorldBytes(lanes, 0)) / lanes;
|
||||
var memory = $"PARTICLE_COST bytes: {perLane:F0} per particle lane at fluid capacity 0 (the whole block; the fluid copies, nbr_start and nbr_count are 7 x 4 = 28 of it, where h1 carved 388 in every world), {perFluid:F0} more per fluid capacity (the neighbour arena, 96 entries)";
|
||||
Console.Error.WriteLine(memory);
|
||||
Reading(memory);
|
||||
var without = PourCost(0);
|
||||
foreach (var viscosity in new[] { 0f, 0.01f })
|
||||
{
|
||||
|
|
|
|||
|
|
@ -242,12 +242,15 @@ public sealed class Box3DSoaFluidTests
|
|||
// ---- behaviour ------------------------------------------------------------------------------------------
|
||||
|
||||
// Bounds follow lodur:ruling:deterministic-bound-margin: the geometric mean of the shipped worst and the least claimed mutant, separation >= 1.2.
|
||||
// |mean - 1| at 3 s: shipped 0.0133, Md (fluid-fluid pairs done from both rows) 0.467, Mr (rings forced to 1) 0.0138. Md is 35 away; the midpoint
|
||||
// sqrt(0.0133 x 0.467) = 0.0788 would rise, so the standing 0.0137 stays (never loosened); shipped is 1.03 under it and Mr, 1.01 over it, is
|
||||
// not separated (unclaimed here: KERNEL_REACH and the floor claim it, a follow-up for this metric). The max density reads 1.3278 shipped,
|
||||
// 1.3331 under Mr and 1.867 under Md: Md is 1.41 away, the midpoint 1.575 would rise, so the sanity ceiling 1.5 stays and also claims Md (the
|
||||
// |mean - 1| at 3 s, by lodur:ruling:ymir-column-mean-bound-order-noise: summation order is not behaviour, so the shipped worst is taken over twelve orders
|
||||
// of the fluid pass's bucket offsets (the six axis permutations, each ascending and descending): 0.0178 worst (0.0027 to 0.0178). Md (fluid-fluid pairs done
|
||||
// from both rows) reads 0.4625 to 0.4865: bound sqrt(0.0178 x 0.4625) = 0.0907, separation 5.1 each side (it was 0.0137 against one order's reading, and one order broke it).
|
||||
// The mean no longer separates the others: Mk (fluid cell 2 rmax, 1 ring) 0.0142 to 0.0182, Mx (fluid pairs also contact; the column sets SELF_COLLIDE) 0.0038 to 0.0154,
|
||||
// Mu (bucket dedupe deleted) 0.0013 to 0.0058, Mf (fluid-solid contact deleted; the column holds no solid particle) unchanged: Mk is claimed by KERNEL_REACH, Mf by the floor
|
||||
// penetration and the through count, Mu and Mx are unclaimed (Mu only moves the FluidHashes pin). The max density reads 1.2992 to 1.3795 shipped over the twelve orders and
|
||||
// 1.7133 to 1.7550 under Md: Md is 1.14 away, the midpoint 1.537 would rise, so the sanity ceiling 1.5 stays and also claims Md (the
|
||||
// column compressing under its weight is the one-pass solver, not a defect: probe pours peaked at 1.07). Mo (capacity 8) overflows the lists
|
||||
// 597364 times in the column against 0 shipped (half a unit by lodur:ruling:deterministic-bound-zero-reading): the overflow assert is exact
|
||||
// 377700 times in the column against 0 shipped (half a unit by lodur:ruling:deterministic-bound-zero-reading): the overflow assert is exact
|
||||
// zero, below the rule's midpoint, because the count is exact and any overflow means pairs were lost.
|
||||
// Unclaimed since the fix cut, readings of its build, a follow-up: Mc1 (lambda halved) max 1.2116, Mc2 (pass A without the self term) max 1.3340.
|
||||
private const float ColumnMax = 1.5f;
|
||||
|
|
@ -303,11 +306,11 @@ public sealed class Box3DSoaFluidTests
|
|||
public void Fluid_density_counts_a_larger_solid_beyond_two_contact_radii()
|
||||
{
|
||||
// The kernel reach of a pair is 2 (ri + rj), so a fluid particle sees a solid of radius 5 cm 12.5 cm away while contact reaches
|
||||
// 6.25 cm: the grid cell is 2 r_max (10 cm) and the fluid pass walks 2 rings of them. Placed two cells apart (10.15 cm), the solid is in
|
||||
// the fluid particle's estimate only if the rings are derived from the kernel reach (Mr forces 1).
|
||||
// 6.25 cm: the fluid grid cell is 4 r_fluid (5 cm) and the fluid pass walks 3 rings of them. Placed three cells apart (10.15 cm), the solid is in
|
||||
// the fluid particle's estimate only if the rings are derived from the kernel reach (Mk forces the cell to 2 r_max and 1 ring: the solid is then two cells away).
|
||||
double Density(bool solid)
|
||||
{
|
||||
using var world = FluidWorld(8, gravityY: 0f);
|
||||
using var world = FluidWorld(256, gravityY: 0f); // a table of 512 buckets: a bucket two cells share could hide the miss
|
||||
world.CreateParticles([Fluid((0.099f, 0f, 0f))]);
|
||||
if (solid) world.CreateParticles([new Box3DSoaParticleDesc((0.2005f, 0f, 0f), 1f, 0.05f, Box3DSoaPhase.Of(1))]);
|
||||
world.Step(1f / 60f, 4);
|
||||
|
|
@ -321,7 +324,7 @@ public sealed class Box3DSoaFluidTests
|
|||
Assert.True(rise >= KernelReachBound, line);
|
||||
}
|
||||
|
||||
// Relative rise of the fluid particle's density: shipped 2.530e-3, Mr (rings forced to 1) 0, which counts one unit (1e-6) by
|
||||
// Relative rise of the fluid particle's density: shipped 2.530e-3, Mk (cell 2 r_max, 1 ring) 0 (a table of 512 buckets, as 16 would hide the miss; Mu, dedupe deleted, 5.06e-2), which counts one unit (1e-6) by
|
||||
// lodur:ruling:deterministic-bound-zero-reading: bound sqrt(2.530e-3 x 1e-6) = 5.0e-5, separation 50.
|
||||
private const double KernelReachBound = 5.0e-5;
|
||||
|
||||
|
|
@ -412,6 +415,7 @@ public sealed class Box3DSoaFluidTests
|
|||
// Md (fluid-fluid pairs done from both rows) 0.401 with 22 through: both fail the bounds. Mo (capacity 8) reads 0.629 and 25823 overflows. Through: shipped 1, Mt1 343, Mt2 1: bound sqrt(1 x 343) = 18, separation 343. The shipped 1 is the
|
||||
// block's centre column, exactly over a hole of the floor lattice: by the lattice symmetry the contacts push it sideways at the hole's plane and the
|
||||
// column's weight takes it through. Nowhere near half a contact distance deep, so not the fluid defect the spec stops on; reported.
|
||||
// At the kernel-cell cut (lodur:cut_spec:cut-ymir-fluid-cost.r2): shipped 0.134 and 0 through; Mk (fluid cell 2 r_max, 1 ring) 0.171 and 0 (unclaimed here, KERNEL_REACH claims it); Md 0.435 and 10 through; Mf (fluid-solid contact deleted) 0.945 and 259 through, claimed by both; Mo (arena 8 a fluid lane) 0.843 and 13650 overflows.
|
||||
private static (float Penetration, int Below, int Overflow) Floor(out string line)
|
||||
{
|
||||
using var world = FluidWorld(640, gravityY: -9.81f);
|
||||
|
|
|
|||
Loading…
Reference in a new issue