diff --git a/docs/soa-world.md b/docs/soa-world.md index 355bfe1..ca19290 100644 --- a/docs/soa-world.md +++ b/docs/soa-world.md @@ -174,22 +174,22 @@ separate native object (`ymir_box3d_soa.c`, ABI 11) so the Aetheria session's co adapted. The rest density `n0(h)` is the Poly6 sum over the simple-cubic lattice of spacing `h / 2` (a constant, computed at create, times `h^-3`), so a particle has volume `(2 r)^3` and there is no rest-density field. The constraint is unilateral, `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 |grad C_i|^2 + eps)` with the gradients over `n0` in 1/m^2 and `eps = 1e-4` (a sweep of + 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` over the full 27 cells in cell then index order (self and the solids counted, `s = 1` as Flex 7.1) and `lambda` of each fluid particle (a solid's is 0); pass B walks the contact pass's half of the neighbourhood and moves a pair with a fluid end and a kernel overlap by `d = (lambda_i + lambda_j) grad W / n0(h)`, end `i` - by `2 w_i / (w_i + w_j) d` and end `j` by the negative of `2 w_j / (w_i + w_j) d`, applied after the walk. A pair therefore + by `w_i d` and end `j` by `-w_j d`, applied after the walk (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 - runs after the velocity update over fluid pairs on the same walk, `dv = c (v_j - v_i) W / n0` with `c` the mean of the two - materials' `viscosity`, split by inverse mass the same way. The grid cell is `2 r_max` as before when no fluid is live and + runs after the velocity update over fluid pairs on the same walk (fluid rows only), `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). The grid cell is `2 r_max` as before when no fluid is live and `2 (r_fmax + r_max)` when one is, so every kernel pair lies in the 27 cells; a world with no live fluid steps byte-identically to one before this change (no pass runs: `live_fluid` counts the live fluid particles, written by create and destroy only). The 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` - and every `destroy_particles` of particles that held no distance or attachment derives only the isolated lanes + and every `destroy_particles` of particles that held no distance derives only the isolated lanes (`rederive_topology` with the ISOLATED mode: `component[i] = i` for created lanes, 0 for destroyed, tethers untouched): emitting and removing 64 fluid particles a tick on the 20-pin 32 x 32 sheet costs 0.3 ms a tick of commands where the full derivation costs 4.2 ms. @@ -230,14 +230,14 @@ 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 and 30 : 1 (momentum drift, energy); probe scene 3, the 343-particle pour on a tilted sheet and a sloped rope (touches, none within half a contact distance); 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. +`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. 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). `Ymir.Core` has no session-level surface over the SoA world yet; consumers use `Ymir.Box3D` directly. Unity consumption is unrun; cross-platform bit-identity is unclaimed. -Particles: no boundary density for rigid bodies (a Box3D body adds nothing to a fluid particle's density estimate, so fluid +Particles: a sheet pinned at few points sieves at 4 substeps (the pour stretches a corner-pinned 16 x 16 sheet 38% and a same-size particle passes it, a same-mass solid block worse; per-substep travel is about 1 cm against a 4 cm contact, so it is the sheet and the contact solver, not the fluid: question ymir-sheet-sieve-at-budget-substeps), no boundary density for rigid bodies (a Box3D body adds nothing to a fluid particle's density estimate, so fluid beside a wall or floor under-reads: a 8 x 8 x 16 column in a box well reads 0.88 mean at zero gravity), no cohesion, adhesion or vorticity, no settle of fluid to rest (the column keeps a velocity noise, 1.25 m/s at its worst at 3 s with the one pass a substep, 0.82 with viscosity 0.1), a column compresses under its own weight (max density 1.34 on 16 layers), no pinning command beyond zero mass and attachments, no sleep, no threads, no particle write lanes. A heavy body cannot be held up by contacts against a floor (the particles are squeezed diff --git a/native/Ymir.Box3D/ymir_particles.c b/native/Ymir.Box3D/ymir_particles.c index 739831b..c45f034 100644 --- a/native/Ymir.Box3D/ymir_particles.c +++ b/native/Ymir.Box3D/ymir_particles.c @@ -786,7 +786,7 @@ int32_t ymir_particles_destroy_particles(ymir_particles* p, int32_t n, const ymi return YMIR_PARTICLES_INVALID_ARGUMENT; } } - int held = 0; // whether a named particle holds a live distance or attachment: then the graph changes + int held = 0; // whether a named particle holds a live distance: then the graph changes (an attachment alone makes no tether lane) for (int32_t k = 0; k < n && !held; ++k) { int32_t i = h[k].lane; @@ -794,10 +794,6 @@ int32_t ymir_particles_destroy_particles(ymir_particles* p, int32_t n, const ymi { held = p->dist_live[e] && (p->dist_a[e] == i || p->dist_b[e] == i); } - for (int32_t a = 0; a < p->attachment_count && !held; ++a) - { - held = p->att_kind[a] != YMIR_ATTACH_REMOVED && p->att_particle[a] == i; - } } int32_t killed = 0; for (int32_t k = 0; k < n; ++k) @@ -1259,7 +1255,7 @@ static int touching(const ymir_particles* p, int32_t i, int32_t j, v3 xi, v3* d, typedef void (*pair_fn)(ymir_particles* p, void* ctx, int32_t i, int32_t j); -// Rows are the walked particles; `rows` is a phase bit every walked row must carry (0 walks all of them). +// Rows are the walked particles; `rows` is a phase bit every walked row must hold (0 walks all of them). YMIR_INLINE void walk_half(ymir_particles* p, pair_fn fn, void* ctx, uint32_t rows) { for (int32_t i = 0; i < p->particle_count; ++i) diff --git a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaFluidTests.cs b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaFluidTests.cs index 6b1b974..dd12473 100644 --- a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaFluidTests.cs +++ b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaFluidTests.cs @@ -127,6 +127,23 @@ public sealed class Box3DSoaFluidTests Readings.Add(line); } + [Fact] + public void Destroying_a_lone_attached_particle_leaves_the_tether_lanes_as_before_the_attach() + { + // A particle with a tether attachment and no distance: does it make a tether lane, and does destroying it leave one behind? + using var world = Box3DSoaParticleTests.World(particles: 16, distances: 16, bends: 16, attachments: 4, tethers: 64); + var ps = new Box3DSoaParticleHandle[2]; + world.CreateParticles([new((0f, 0f, 0f), 0.02f, 0.0125f), new((1f, 0f, 0f), 0.02f, 0.0125f)], ps); + var before = Snapshot(world.View); + world.Attach(Box3DSoaAttachKind.Static, ps[0], point: (0f, 0f, 0f), tether: true); + var held = world.View.TetherCount; + world.DestroyParticles([ps[0]]); + var line = $"HELD_ATTACHMENT tether lanes {before.Count} before the attach, {held} with a lone tethered particle, {world.View.TetherCount} after destroying it"; + Readings.Add(line); + Console.Error.WriteLine(line); + SameTethers(before, Snapshot(world.View)); + } + // ---- scenes --------------------------------------------------------------------------------------------- private static float Sq(float x) => x * x; @@ -209,7 +226,7 @@ public sealed class Box3DSoaFluidTests // 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.0124, M2 (cell stays 2 r_max) 0.0152, M7 (fluid pairs also contact) 0.0206: bound sqrt(0.0124 x 0.0152) = 0.0137, // separation 1.23. The max density reads 1.3440 shipped, 1.3576 under M2 and 1.2653 under M7: no mutant is 1.2 away, so the max has no - // claim; 1.5 is a sanity ceiling (the column compressing under its weight is the one-pass solver, not a defect: probe pours peaked at 1.07). + // claim (Mc1, lambda halved, reads 1.2116, 1.11 under shipped; Mc2, pass A without the self term, 1.3340, 1.01: unclaimed, a follow-up); 1.5 is a sanity ceiling (the column compressing under its weight is the one-pass solver, not a defect: probe pours peaked at 1.07). private const float ColumnMax = 1.5f; private const float ColumnMean = 0.0137f; private const float FloorPenetration = 0.233f; diff --git a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaParticleTests.cs b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaParticleTests.cs index 9846529..922d458 100644 --- a/tests/Ymir.Box3D.Soa.Tests/Box3DSoaParticleTests.cs +++ b/tests/Ymir.Box3D.Soa.Tests/Box3DSoaParticleTests.cs @@ -1090,6 +1090,13 @@ public sealed class Box3DSoaParticleSourceTests Assert.Contains("rederive_topology(p, ", Body(c, $"int32_t ymir_particles_{command}(")); foreach (var command in new[] { "create_distances", "create_bends", "attach", "remove" }) Assert.DoesNotContain("TOPO_ISOLATED", Body(c, $"int32_t ymir_particles_{command}(")); + // emission derives the isolated lanes only (a new particle holds no constraint); destroy names both, the graph changing when a victim held one + var created = Body(c, "int32_t ymir_particles_create_particles("); + Assert.Contains("TOPO_ISOLATED", created); + Assert.DoesNotContain("TOPO_FULL", created); + var destroyed = Body(c, "int32_t ymir_particles_destroy_particles("); + Assert.Contains("TOPO_ISOLATED", destroyed); + Assert.Contains("TOPO_FULL", destroyed); Assert.Equal(0, Count(c + h, @"PxReal|physx")); // the retired owners stay gone var retired = string.Join("|", "create_" + "chain", "split_" + "chain", "destroy_" + "chain", "chain_" + "first", "chain_" + "size", "chain_stable_" + "id", @@ -1102,7 +1109,7 @@ public sealed class Box3DSoaParticleSourceTests // no fluid path runs in a world with no live fluid: both passes sit behind the counter var substep = StripComments(Body(c, "void ymir_particles_substep(")); Assert.Equal(1, Count(substep, @"if \(p->live_fluid > 0\)\s*\{\s*fluid_density\(p\);")); - Assert.Equal(1, Count(substep, @"if \(p->live_fluid > 0\)\s*\{\s*fluid_viscosity\(p\);")); + Assert.Equal(1, Count(substep, @"if \(p->live_fluid > 0 && viscous_material\(p\)\)\s*\{\s*fluid_viscosity\(p\);")); // fluid has one writer of live_fluid pair: the two commands Assert.Equal(0, Count(StripComments(c.Replace(Body(c, "int32_t ymir_particles_create_particles("), "").Replace(Body(c, "int32_t ymir_particles_destroy_particles("), "")), @"live_fluid\s*(\+\+|--|[-+]?=[^=])")); }