Settle pooling: restore the unwind pin, pin the world-position frame math and the tie rule, doc the rule in soa-world.md
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d5f05673ea
commit
44c8463e6f
2 changed files with 57 additions and 1 deletions
|
|
@ -241,7 +241,7 @@ separate native object (`ymir_box3d_soa.c`, ABI 20) so the Aetheria session's co
|
|||
tombstoned and reused as the others). A drop's support is its last step's `support_body` (else `support_particle`); one with neither is refused. A drop's volume is `(2 r)^3`, its patch's radius
|
||||
`sqrt(volume / (pi film))` with `YMIR_WET_FILM` = 1 mm (one constant; a film per liquid is not added). In handle order a drop joins the lowest live patch on the same support and material whose
|
||||
disc holds its contact point (volumes add, the centre is the volume-weighted mean, the radius is recomputed); else it takes the lowest free lane; else it joins the nearest patch of the same support
|
||||
and material; else the batch is refused `FULL`, whole, and every lane is as it was (an undo log sized by `fluid_capacity`). A dead or non-fluid particle, a stale handle, a particle named twice
|
||||
and material; else (no patch on its support) it adds its volume to the nearest live patch of its material in the world, by world distance from the drop to the patch's centre (the patch's body pose applied; ties go to the lowest lane), and that centre stays; else (no live patch of its material at all) the batch is refused `FULL`, whole, and every lane is as it was (an undo log sized by `fluid_capacity`). A dead or non-fluid particle, a stale handle, a particle named twice
|
||||
or one with no support is refused whole too. `wet_volume` per body (the view's `WetVolume`, `body_wet_volume` natively) is the sum of the live patches on the body in wet lane order, written by
|
||||
`rederive_wet` alone, which `settle`, `remove(WET)` and `destroy_particles` (when it kills patches on the solid particles it destroys) call; the step never writes a wet lane or the volume. `remove(WET)` kills patches and ends in `rederive_wet`,
|
||||
never in `rederive_topology`; `destroy_particles` kills the patches on the solid particles it destroys. `settle` and `remove` return the patch handles to read. Material `wet_friction` (>= 0) is stored
|
||||
|
|
|
|||
|
|
@ -319,6 +319,62 @@ public sealed partial class Box3DSoaFluidTests
|
|||
Assert.Equal(2, LivePatches(v));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Settle_refusal_undoes_a_merge_it_made()
|
||||
{
|
||||
// One lane taken by a floor patch. The batch is a floor drop that merges into it, then a drop of material 1 that finds no lane and no live patch of its material anywhere: FULL.
|
||||
// The merge must go back: every lane is as it was.
|
||||
using var world = FluidWorld(16, gravityY: -9.81f, wets: 1);
|
||||
world.AddStaticBox(1, (0f, -0.5f, 0f), (2f, 0.5f, 2f), friction: 0.3f);
|
||||
world.AddStaticBox(2, (0.5f, 0.1f, 0f), (0.1f, 0.1f, 0.1f), friction: 0.3f);
|
||||
world.CreateParticles([Fluid((-0.5f, R, 0f)), Fluid((-0.45f, R, 0f)), Fluid((0.5f, 0.2f + R, 0f), material: 1u)]);
|
||||
for (var tick = 0; tick < 20; tick++) world.Step(1f / 60f, Sub);
|
||||
world.Settle([Handle(world, 0)]);
|
||||
var before = WorldBytes(world.View);
|
||||
Assert.Throws<InvalidOperationException>(() => world.Settle([Handle(world, 1), Handle(world, 2)]));
|
||||
Assert.True(before.AsSpan().SequenceEqual(WorldBytes(world.View)), "a refused batch left a merge behind");
|
||||
Assert.Equal(DropVolume, world.View.WetPatchVolume[0], 1e-9f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_drop_with_no_patch_on_its_support_pools_into_the_patch_nearest_in_world_position()
|
||||
{
|
||||
// Two lanes, both taken: a floor patch A (floor at y -0.5, point 1.7 m left of the drop's body) and a pedestal patch B (body at x -0.4, 0.6 m from the drop). In each body's own frame
|
||||
// A (-1.7, 0.5, 0) is nearer the drop's world point (-1, 0.2, 0) than B (0, 0.1, 0); in the world B is. Only the body's pose puts B first.
|
||||
using var world = FluidWorld(16, gravityY: -9.81f, wets: 2);
|
||||
world.AddStaticBox(1, (0f, -0.5f, 0f), (4f, 0.5f, 2f), friction: 0.3f);
|
||||
world.AddStaticBox(2, (-0.4f, 0.1f, 0f), (0.1f, 0.1f, 0.1f), friction: 0.3f);
|
||||
world.AddStaticBox(3, (-1.0f, 0.1f, 0f), (0.1f, 0.1f, 0.1f), friction: 0.3f);
|
||||
world.CreateParticles([Fluid((-1.7f, R, 0f)), Fluid((-0.4f, 0.2f + R, 0f)), Fluid((-1.0f, 0.2f + R, 0f))]);
|
||||
for (var tick = 0; tick < 20; tick++) world.Step(1f / 60f, Sub);
|
||||
Assert.Equal(2, world.View.SupportBody[2]); // body lanes: floor 0, pedestal 1, the drop's box 2
|
||||
world.Settle([Handle(world, 0), Handle(world, 1)]);
|
||||
Assert.Equal(0, world.FreeWetSlots);
|
||||
Assert.Equal(1, world.View.WetBody[1]);
|
||||
world.Settle([Handle(world, 2)]);
|
||||
Assert.Equal(DropVolume, world.View.WetPatchVolume[0], 1e-9f);
|
||||
Assert.Equal(2f * DropVolume, world.View.WetPatchVolume[1], 1e-9f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_drop_equidistant_from_two_patches_pools_into_the_lower_lane()
|
||||
{
|
||||
// Floor patches A (x -0.5, lane 0) and B (x +0.5, lane 1), no lane free; the drop on a pedestal at x 0 is the same distance from both, and the lowest lane takes it.
|
||||
using var world = FluidWorld(16, gravityY: -9.81f, wets: 2);
|
||||
world.AddStaticBox(1, (0f, -0.5f, 0f), (2f, 0.5f, 2f), friction: 0.3f);
|
||||
world.AddStaticBox(2, (0f, 0.1f, 0f), (0.1f, 0.1f, 0.1f), friction: 0.3f);
|
||||
world.CreateParticles([Fluid((-0.5f, R, 0f)), Fluid((0.5f, R, 0f)), Fluid((0f, 0.2f + R, 0f))]);
|
||||
for (var tick = 0; tick < 20; tick++) world.Step(1f / 60f, Sub);
|
||||
world.Settle([Handle(world, 0), Handle(world, 1)]);
|
||||
var v = world.View;
|
||||
var da = Math.Abs(v.WetX[0]) - Math.Abs(v.WetX[1]);
|
||||
Assert.Equal(0.0, da, 1e-6); // the scene is a tie
|
||||
world.Settle([Handle(world, 2)]);
|
||||
v = world.View;
|
||||
Assert.Equal(2f * DropVolume, v.WetPatchVolume[0], 1e-9f);
|
||||
Assert.Equal(DropVolume, v.WetPatchVolume[1], 1e-9f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Settle_refusal_unwinds_a_patch_it_created()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue