diff --git a/src/BadDay.Ymir/Blood.cs b/src/BadDay.Ymir/Blood.cs
index df387aa..0f245e2 100644
--- a/src/BadDay.Ymir/Blood.cs
+++ b/src/BadDay.Ymir/Blood.cs
@@ -20,6 +20,10 @@ public sealed record BloodParameters
public double Density { get; init; } = 1060.0;
/// m/s along the wound's normal, over the part's own velocity.
public float ExitSpeed { get; init; } = 0.5f;
+ /// m/s along an airway opening's outward normal: a cough's drops leave the mouth or nose at this speed (a balance knob).
+ public float CoughSpeed { get; init; } = 3.0f;
+ /// m/s along an airway opening's outward normal: what drains by gravity leaves at this speed (a balance knob).
+ public float DrainSpeed { get; init; } = 0.2f;
/// m/s: a supported drop slower than this is calm.
public float SettleSpeed { get; init; } = 0.05f;
/// Consecutive calm ticks before a drop settles into a wet patch.
@@ -54,6 +58,12 @@ public sealed record BloodParameters
/// they stay under . A lane Settle frees cannot be taken before the next Step, so a cap-bound run sheds fewer drops
/// than it could (measured 50% of 8 a tick at saturation, 19268 of 38400 drops over 4800 ticks at SettleTicks 30; the rest waits as backlog, none is lost); a lethal bleed (2.5 drops a tick) never reaches it. Ymir never settles by itself; this is the policy.
/// Allocation-free once the wound points are open.
+///
+/// The airway trades liquid with the world through this too ( owns the ledger): destroys the live drops a breath drew in at an
+/// opening, and gathers what the body coughed and drained at the lowest opening as world volume, never scaled by the gain. Each opening carries two expulsion points
+/// (cough at , drain at ) just outside its sensor sphere, so a drop is not read back the tick it is born; they shed
+/// through the same loop as the wounds' points (speed per point, shared, volume waiting as ).
+///
///
public sealed class Blood
{
@@ -61,7 +71,9 @@ public sealed class Blood
{
public int Part;
public float Px, Py, Pz, Nx, Ny, Nz; // the part's frame
- public double Volume; // visible m^3 gathered and not yet shed
+ public double Volume; // m^3 gathered and not yet shed: visible (the gain applied) at a wound, world volume at an expulsion point
+ public float Speed; // m/s along the normal over the part's own velocity
+ public bool Expel; // an airway expulsion point: gathers only through Expel, never a part's bleed or the gain
}
private const int SpiralSpots = 40;
@@ -82,6 +94,8 @@ public sealed class Blood
private readonly Box3DSoaParticleDesc[] _descs;
private readonly Box3DSoaParticleHandle[] _created;
private readonly Box3DSoaParticleHandle[] _settling;
+ private readonly Box3DSoaParticleHandle[] _doomed;
+ private readonly int[] _expelPoint; // per airway opening: the index of its cough point, the drain point next to it
internal Blood(Box3DSoaWorld world, Ragdoll ragdoll, BloodParameters parameters)
{
@@ -99,13 +113,44 @@ public sealed class Blood
_descs = new Box3DSoaParticleDesc[parameters.MaxDropsPerTick];
_created = new Box3DSoaParticleHandle[parameters.MaxDropsPerTick];
_settling = new Box3DSoaParticleHandle[parameters.LiveCap];
+ _doomed = new Box3DSoaParticleHandle[parameters.LiveCap];
+ var openings = ragdoll.Plan.AirwayOpenings;
+ _expelPoint = new int[openings.Count];
+ for (int k = 0; k < openings.Count; k++)
+ {
+ var (ox, oy, oz) = openings[k].Offset;
+ float length = MathF.Sqrt(ox * ox + oy * oy + oz * oz);
+ if (!(length > 0f)) throw new ArgumentException($"Airway opening {openings[k].Label} sits at its part's origin: it has no outward normal.");
+ float outward = 1f + (openings[k].Radius + parameters.DropRadius) / length;
+ _expelPoint[k] = _pointCount;
+ for (int kind = 0; kind < 2; kind++)
+ {
+ AddPoint(new WoundPoint
+ {
+ Part = openings[k].Part, Px = ox * outward, Py = oy * outward, Pz = oz * outward, Nx = ox / length, Ny = oy / length, Nz = oz / length,
+ Speed = kind == 0 ? parameters.CoughSpeed : parameters.DrainSpeed, Expel = true,
+ });
+ }
+ }
+ }
+
+ private void AddPoint(in WoundPoint point)
+ {
+ if (_pointCount == _points.Length) Array.Resize(ref _points, _points.Length * 2);
+ _points[_pointCount++] = point;
}
/// Visible volume (m^3) shed as drops so far, settled or live.
public double Emitted { get; private set; }
+ /// Visible volume (m^3) shed as drops by the expulsion points (what the body coughed and drained): part of , display only.
+ public double Expelled { get; private set; }
+
/// Visible volume (m^3) gathered at the wounds and not yet shed.
- public double Backlog { get { double b = 0.0; for (int i = 0; i < _pointCount; i++) b += _points[i].Volume; return b; } }
+ public double Backlog { get { double b = 0.0; for (int i = 0; i < _pointCount; i++) if (!_points[i].Expel) b += _points[i].Volume; return b; } }
+
+ /// World volume (m^3) coughed or drained and not yet shed as drops: display only.
+ public double ExpelBacklog { get { double b = 0.0; for (int i = 0; i < _pointCount; i++) if (_points[i].Expel) b += _points[i].Volume; return b; } }
/// Drops in the air or resting, not yet settled.
public int Live => _liveCount;
@@ -114,11 +159,61 @@ public sealed class Blood
internal void Open(int part, float px, float py, float pz, float nx, float ny, float nz)
{
if ((uint)part >= (uint)_pointsOnPart.Length) throw new ArgumentOutOfRangeException(nameof(part));
- if (_pointCount == _points.Length) Array.Resize(ref _points, _points.Length * 2);
- _points[_pointCount++] = new WoundPoint { Part = part, Px = px, Py = py, Pz = pz, Nx = nx, Ny = ny, Nz = nz };
+ AddPoint(new WoundPoint { Part = part, Px = px, Py = py, Pz = pz, Nx = nx, Ny = ny, Nz = nz, Speed = _p.ExitSpeed });
_pointsOnPart[part]++;
}
+ /// Gathers a tick's cough and drain (world m^3, the gain not applied) at 's expulsion points; they shed at the next .
+ internal void Expel(int opening, double cough, double drain)
+ {
+ if ((uint)opening >= (uint)_expelPoint.Length) throw new ArgumentOutOfRangeException(nameof(opening));
+ if (!(cough >= 0.0 && drain >= 0.0) || double.IsInfinity(cough + drain)) throw new ArgumentOutOfRangeException(nameof(cough), "A cough and a drain are finite volumes of 0 or more.");
+ _points[_expelPoint[opening]].Volume += cough;
+ _points[_expelPoint[opening] + 1].Volume += drain;
+ }
+
+ ///
+ /// Destroys, oldest first, whole live drops whose centre lies inside an airway opening's sphere (the opening's Offset in its part's pose, its Radius: the sensor's own test) while
+ /// is at least half a drop, so the volume the airway owes the world stays within half a drop of 0; returns the volume destroyed (m^3). Nothing is destroyed for an owed below half a drop.
+ ///
+ internal double TakeLive(double owed)
+ {
+ double half = 0.5 * _dropVolume;
+ if (owed < half || _liveCount == 0) return 0.0;
+ var v = _world.View;
+ var openings = _ragdoll.Plan.AirwayOpenings;
+ int doomed = 0, kept = 0;
+ for (int i = 0; i < _liveCount; i++)
+ {
+ bool take = false;
+ if (owed >= half)
+ {
+ int lane = _live[i].Lane;
+ for (int k = 0; k < openings.Count && !take; k++)
+ {
+ var o = openings[k];
+ int body = _ragdoll.BodyLane(o.Part);
+ new Quat(v.RotationX[body], v.RotationY[body], v.RotationZ[body], v.RotationW[body]).Rotate(o.Offset.X, o.Offset.Y, o.Offset.Z, out var cx, out var cy, out var cz);
+ float dx = v.ParticleX[lane] - (v.PositionX[body] + cx), dy = v.ParticleY[lane] - (v.PositionY[body] + cy), dz = v.ParticleZ[lane] - (v.PositionZ[body] + cz);
+ take = dx * dx + dy * dy + dz * dz <= o.Radius * o.Radius;
+ }
+ }
+ if (take)
+ {
+ _doomed[doomed++] = _live[i];
+ owed -= _dropVolume;
+ continue;
+ }
+ _live[kept] = _live[i];
+ _calm[kept] = _calm[i];
+ kept++;
+ }
+ if (doomed == 0) return 0.0;
+ _world.DestroyParticles(_doomed.AsSpan(0, doomed));
+ _liveCount = kept;
+ return doomed * _dropVolume;
+ }
+
/// Gathers this tick's volume from (real m^3/s per part, empty for none) and sheds what whole drops it makes, before the step.
internal void BeforeStep(ReadOnlySpan bleedPerPart, double dt)
{
@@ -126,7 +221,7 @@ public sealed class Blood
for (int i = 0; i < _pointCount; i++)
{
ref var w = ref _points[i];
- if ((uint)w.Part < (uint)bleedPerPart.Length) w.Volume += _p.Gain * bleedPerPart[w.Part] / _pointsOnPart[w.Part] * dt;
+ if (!w.Expel && (uint)w.Part < (uint)bleedPerPart.Length) w.Volume += _p.Gain * bleedPerPart[w.Part] / _pointsOnPart[w.Part] * dt;
}
// A lane Settle freed is reusable only after the next Step, so the room is what the world says, not the cap alone.
@@ -177,8 +272,9 @@ public sealed class Blood
}
if (!clear) continue;
w.Volume -= _dropVolume;
+ if (w.Expel) Expelled += _dropVolume;
any = true;
- var velocity = (v.VelocityX[lane] + nx * _p.ExitSpeed, v.VelocityY[lane] + ny * _p.ExitSpeed, v.VelocityZ[lane] + nz * _p.ExitSpeed);
+ var velocity = (v.VelocityX[lane] + nx * w.Speed, v.VelocityY[lane] + ny * w.Speed, v.VelocityZ[lane] + nz * w.Speed);
_descs[n++] = new Box3DSoaParticleDesc(at, _mass, r, _phase, (uint)_p.Material, velocity: velocity);
}
}
diff --git a/src/BadDay.Ymir/OfficeBodySession.cs b/src/BadDay.Ymir/OfficeBodySession.cs
index 21bcec5..2b1d538 100644
--- a/src/BadDay.Ymir/OfficeBodySession.cs
+++ b/src/BadDay.Ymir/OfficeBodySession.cs
@@ -84,6 +84,12 @@ public sealed class OfficeBodySession : IBodyRun
public double BloodEmitted { get { Live(); return _body.BloodEmitted; } }
public double BloodBacklog { get { Live(); return _body.BloodBacklog; } }
public int LiveDrops { get { Live(); return _body.LiveDrops; } }
+ /// The blood bled into the airway (real m^3/s) and the live liquid drawn from it (world m^3) in the latest step, then what the airway owes the world (m^3, signed), the part of that was cough and drain, and the cough and drain still waiting to be shed: the body's, display only.
+ public double AirwayBleed { get { Live(); return _physiology.AirwayBleed; } }
+ public double AirwayDrawnLive { get { Live(); return _physiology.DrawnLive; } }
+ public double AirwayOwed { get { Live(); return _body.Owed; } }
+ public double BloodExpelled { get { Live(); return _body.BloodExpelled; } }
+ public double ExpelBacklog { get { Live(); return _body.ExpelBacklog; } }
public DeathCause DeathCause { get { Live(); return _physiology.Cause; } }
public OfficeGoal Goal { get { Live(); return OfficeBrain.GoalAt(_session.Actor.GoalIndex); } }
@@ -112,6 +118,7 @@ public sealed class OfficeBodySession : IBodyRun
double lossBefore = _physiology.BloodLoss;
var events = _session.Tick(_body.X, _body.Y, _body.Z, _body.Strengths, _body.Targets, airway);
if (events != TickEvents.None) _body.Enqueue(tick, events);
+ _body.Exchange(_physiology.DrawnLive, _physiology.DrawnPooled, _physiology.Coughed, _physiology.Drained); // the dying step's flows are real; they read 0 after
if (_physiology.Dead)
{
// Bleed() reads 0 once dead, but the dying step still spilled what it took from the blood: that volume, shared as the step before shared its bleed.
diff --git a/src/BadDay.Ymir/SeatedBody.cs b/src/BadDay.Ymir/SeatedBody.cs
index 0a0d5cb..12bb800 100644
--- a/src/BadDay.Ymir/SeatedBody.cs
+++ b/src/BadDay.Ymir/SeatedBody.cs
@@ -44,6 +44,7 @@ public sealed class SeatedBody : IDisposable
private readonly Blood _blood;
private readonly float[] _airLive, _airPooled, _airDrop;
private readonly Queue _events = new();
+ private double _owed;
private bool _disposed;
public SeatedBody(BloodParameters? blood = null)
@@ -121,6 +122,27 @@ public sealed class SeatedBody : IDisposable
return AirwaySample.Of(_airLive, _airPooled, _airDrop);
}
+ ///
+ /// What the airway owes the world, m^3 signed: the liquid it holds that the world has not given up. Display only; is the one writer. Live drops at the openings are destroyed against it, so with them it stays within half a drop below 0 and half a drop plus a tick's draw above; it is carried across ticks,
+ /// never netted against a cough and never returned with an overdraw.
+
+ public double Owed { get { Live(); return _owed; } }
+
+ ///
+ /// The airway's trade with the world for one tick, called once after the physiology stepped with its flows for that step (world m^3: Physiology owns how much is drawn, coughed and drained, this only
+ /// decides where the liquid goes). A breath's pooled draw leaves the wet patches at the openings (); what the world did not give up, and the live draw, is added to , the
+ /// ledger books the volume the take returned, not the ask; live drops at the openings are destroyed against it; the cough and the drain come out of the lowest opening () as drops,
+ /// at 1x. The invariant: the world's liquid, the airway's, the expulsion backlog, less Owed, less the drops the wounds shed and the blood bled into the airway, is constant.
+ ///
+ public void Exchange(double drawnLive, double drawnPooled, double coughed, double drained)
+ {
+ Live();
+ double taken = _ragdoll.TakeDrawn(drawnPooled);
+ _owed += drawnLive + drawnPooled - taken;
+ _owed -= _blood.TakeLive(_owed);
+ if (coughed + drained > 0.0) _blood.Expel(_ragdoll.LowestOpening(_world.Gravity), coughed, drained);
+ }
+
/// The part of the body a ray from along meets first, with the point and surface normal; null for a miss or when the first thing met is not a part of the body.
public PartHit? Pick(BodyPoint origin, BodyPoint translation)
{
@@ -164,6 +186,9 @@ public sealed class SeatedBody : IDisposable
/// Visible blood volume (m^3) shed so far and still gathered at the wounds, and the drops not yet settled.
public double BloodEmitted { get { Live(); return _blood.Emitted; } }
public double BloodBacklog { get { Live(); return _blood.Backlog; } }
+ /// The part of that was the body's own cough and drain (visible m^3), and what is still waiting to be shed of it: display only.
+ public double BloodExpelled { get { Live(); return _blood.Expelled; } }
+ public double ExpelBacklog { get { Live(); return _blood.ExpelBacklog; } }
public int LiveDrops { get { Live(); return _blood.Live; } }
public void Enqueue(long tick, TickEvents events)
diff --git a/tests/BadDay.Tests/Program.cs b/tests/BadDay.Tests/Program.cs
index d249296..fd6f8c1 100644
--- a/tests/BadDay.Tests/Program.cs
+++ b/tests/BadDay.Tests/Program.cs
@@ -1476,6 +1476,81 @@ public static class Program
Check(s.Dead && s.DeathCause == Lodur.DeathCause.BloodLoss, $"cause {s.DeathCause}");
}),
+ ("a cut throat conserves liquid over the whole cycle: every tick the world's liquid, the airway's and the expulsion backlog, less what the airway owes, the drops the wounds shed and the blood bled into the airway, is what it started as (2e-5 of the world's liquid), and more than a litre is coughed and drained", () =>
+ {
+ var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
+ using var s = new OfficeBodySession(p, 1);
+ var head = SeatedPuppet.Plan.PartIndex("Head", Lodur.Side.Center);
+ Check(s.Wound(HitAt(s, head, (0f, -0.0778f, 0.0778f)), WoundTool.Knife), "the knife was refused at the throat");
+ double c0 = WorldLiquid(s) + s.AirwayLiquid, bledIn = 0.0, worst = 0.0, worstBound = 0.0;
+ long worstTick = 0;
+ int settling = 0; // the 600 ticks after Finished: in-flight drops settle and the backlog sheds
+ for (int t = 0; settling < 600 && t < 20 * 60 * Hz; t++)
+ {
+ bool running = !s.Finished;
+ s.Step();
+ if (running) bledIn += OfficeBody.TickSeconds * s.AirwayBleed;
+ if (s.Finished) settling++;
+ double w = WorldLiquid(s);
+ double residual = w + s.AirwayLiquid + s.ExpelBacklog - s.AirwayOwed - (s.BloodEmitted - s.BloodExpelled) - bledIn - c0;
+ double bound = 2e-5 * w + 1e-9;
+ if (Math.Abs(residual) > worst) { worst = Math.Abs(residual); worstBound = bound; worstTick = s.TickIndex; }
+ Check(Math.Abs(residual) <= bound, $"tick {s.TickIndex}: residual {residual * 1e6:F4} mL against a bound of {bound * 1e6:F4} mL (world {w * 1e6:F1} mL, airway {s.AirwayLiquid * 1e6:F1}, backlog {s.ExpelBacklog * 1e6:F1}, owed {s.AirwayOwed * 1e6:F2})");
+ }
+ Check(s.Finished, "the run did not finish");
+ Check(s.BloodExpelled > 1e-3, $"only {s.BloodExpelled * 1e6:F0} mL was coughed and drained as drops");
+ Console.WriteLine($" throat: coughed and drained {s.BloodExpelled * 1e6:F0} mL as drops, {s.ExpelBacklog * 1e6:F0} mL waiting, owed {s.AirwayOwed * 1e6:F3} mL, worst residual {worst * 1e6:F4} mL (bound {worstBound * 1e6:F4}) at tick {worstTick}");
+ }),
+
+ ("what he breathes at the lips leaves the world and comes back as cough: Wound(MouthHit(s), Knife) for 100 s takes at least one live drop, keeps the airway's debt within half a drop of 0 plus that tick's draw on every tick, and coughs", () =>
+ {
+ var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
+ using var s = new OfficeBodySession(p, 1);
+ Check(s.Wound(MouthHit(s), WoundTool.Knife), "the knife was refused at the mouth");
+ double half = 0.5 * new BloodParameters().DropVolume, lowest = 0.0, highest = 0.0, drawn = 0.0;
+ for (int t = 0; t < 100 * Hz && !s.Finished; t++)
+ {
+ s.Step();
+ lowest = Math.Min(lowest, s.AirwayOwed);
+ highest = Math.Max(highest, s.AirwayOwed);
+ drawn += s.AirwayDrawnLive;
+ Check(Math.Abs(s.AirwayOwed) <= half + s.AirwayDrawnLive + 1e-12, $"tick {s.TickIndex}: the airway owes {s.AirwayOwed * 1e6:F3} mL (half a drop {half * 1e6:F3}, draw {s.AirwayDrawnLive * 1e6:F3})");
+ }
+ Check(drawn > 0.0, "nothing was drawn from the lips");
+ Check(lowest < -1e-9, $"the debt never went below 0 (lowest {lowest * 1e6:F3} mL): no drop was ever taken against it");
+ Check(s.BloodExpelled > 0.0, "nothing was coughed or drained");
+ Console.WriteLine($" lips: drew {drawn * 1e6:F2} mL, owed within [{lowest * 1e6:F2}, {highest * 1e6:F2}] mL, coughed and drained {s.BloodExpelled * 1e6:F1} mL as drops");
+ }),
+
+ ("an expelled drop is born outside the openings: the first drop a drain sheds is, after its step, farther than the opening's radius from every opening's centre and not thrown", () =>
+ {
+ var plan = SeatedPuppet.Plan;
+ var parameters = new BloodParameters();
+ foreach (var (cough, drain) in new[] { (0.0, parameters.DropVolume), (parameters.DropVolume, 0.0) })
+ {
+ using var body = new SeatedBody(parameters);
+ body.Exchange(0.0, 0.0, cough, drain);
+ Check(body.ExpelBacklog > 0.0 && body.BloodExpelled == 0.0, "the volume was shed before the step");
+ body.DriveAndStep(OfficeBody.TickSeconds);
+ Check(body.BloodExpelled > 0.0 && body.LiveDrops == 1, $"{body.LiveDrops} drops after the first step of an expulsion");
+ var v = body.View;
+ int lane = 0;
+ while (v.ParticleLive[lane] == 0u) lane++;
+ double nearest = double.MaxValue;
+ foreach (var o in plan.AirwayOpenings)
+ {
+ int b = body.BodyLane(o.Part);
+ new Quat(v.RotationX[b], v.RotationY[b], v.RotationZ[b], v.RotationW[b]).Rotate(o.Offset.X, o.Offset.Y, o.Offset.Z, out var cx, out var cy, out var cz);
+ double d = Math.Sqrt(Math.Pow(v.ParticleX[lane] - (v.PositionX[b] + cx), 2) + Math.Pow(v.ParticleY[lane] - (v.PositionY[b] + cy), 2) + Math.Pow(v.ParticleZ[lane] - (v.PositionZ[b] + cz), 2));
+ Check(d > o.Radius, $"{(cough > 0.0 ? "cough" : "drain")} drop born {d * 1000.0:F1} mm from the {o.Label}'s centre, inside its {o.Radius * 1000.0:F1} mm sphere");
+ nearest = Math.Min(nearest, d - o.Radius);
+ }
+ // Born a radius and a lift outside the point (2 r + 2 mm, Blood's own clearance), then a step at its exit speed; 5 mm is slack.
+ double reach = 2.0 * parameters.DropRadius + 0.002 + (cough > 0.0 ? parameters.CoughSpeed : parameters.DrainSpeed) * OfficeBody.TickSeconds + 0.005;
+ Check(nearest < reach, $"the drop is {nearest * 1000.0:F1} mm outside the nearest opening (at most {reach * 1000.0:F1}): it was thrown");
+ }
+ }),
+
("seated frame on a turned head: ToPart returns the point's part-frame coordinates and an opened wound sheds along the normal in that frame, with the neck driven so the head is 0.2+ rad off identity", () =>
{
var plan = SeatedPuppet.Plan;
@@ -1736,6 +1811,38 @@ public static class Program
Console.WriteLine($" airway: pooled peak {pooled * 1e6:F1} mL");
}),
+ ("a take on the seated body: what Exchange asks of the pool leaves the patches the openings read, the ledger books the volume taken (a breath's share at 1/120 of the pool within 5e-8 of the pool, five times the pool takes the pool and owes the rest)", () =>
+ {
+ var plan = SeatedPuppet.Plan;
+ var mouth = plan.AirwayOpenings.First(a => a.Label == "Mouth");
+ var c = plan.Parts[mouth.Part].Position;
+ using var body = new SeatedBody(new BloodParameters { SettleSpeed = 100f, SettleTicks = 1 });
+ var hit = body.Pick(new BodyPoint(c.X, c.Y + mouth.Offset.Y + 0.04f, c.Z + 1f), new BodyPoint(0f, 0f, -1.5f));
+ Check(hit is { } h && h.Part == mouth.Part, "no hit on the face above the mouth");
+ body.OpenWound(hit!.Value.Part, hit.Value.Point, hit.Value.Normal);
+ var bleeds = new double[plan.Parts.Count];
+ bleeds[hit.Value.Part] = 0.0003;
+ for (int t = 0; t < 300; t++) body.DriveAndStep(1.0 / Hz, bleeds);
+ for (int t = 0; t < 120 && body.LiveDrops > 0; t++) body.DriveAndStep(1.0 / Hz); // the bleed stops and what is in the air settles, so no live drop is at an opening
+ Check(body.LiveDrops == 0, $"{body.LiveDrops} drops still live");
+ double pool = body.ReadAirway().Pooled;
+ Check(pool > 1e-5, $"the pool at the openings read {pool} m^3");
+
+ double ask = pool / 120.0;
+ body.Exchange(0.0, ask, 0.0, 0.0);
+ double owed = body.Owed;
+ Check(Math.Abs(owed) <= 5e-8 * pool, $"a take of {ask * 1e6:F3} mL from {pool * 1e6:F1} mL left {owed * 1e6:F6} mL owed (the budget is {5e-8 * pool * 1e6:F6})");
+ body.DriveAndStep(1.0 / Hz);
+ double after = body.ReadAirway().Pooled;
+ Check(Math.Abs((pool - after) - (ask - owed)) <= 1e-6 * pool, $"the pool fell {(pool - after) * 1e6:F4} mL for a take of {(ask - owed) * 1e6:F4} mL");
+
+ body.Exchange(0.0, 5.0 * after, 0.0, 0.0);
+ Check(Math.Abs(body.Owed - (owed + 4.0 * after)) <= 1e-6 * pool, $"taking five times the pool left {body.Owed * 1e6:F4} mL owed, expected {(owed + 4.0 * after) * 1e6:F4}");
+ body.DriveAndStep(1.0 / Hz);
+ Check(body.ReadAirway().Pooled <= 1e-6 * pool, $"{body.ReadAirway().Pooled * 1e6:F4} mL still pooled after the pool was taken");
+ Console.WriteLine($" take: pool {pool * 1e6:F1} mL, a 1/120 take owed {owed * 1e6:E2} mL");
+ }),
+
("seated world identity: a SeatedBody (a particle system, no wound) steps to the same positions and rotations as the same world with no particle system, 1200 driven ticks", () =>
{
using var body = new SeatedBody();
@@ -1830,6 +1937,16 @@ public static class Program
}
/// A hit on the head at the plan's Mouth opening: a ray from 1 m in front of it, straight back and on through it.
+ /// The volume of liquid in the world: the live fluid particles' (2 r)^3 and the live wet patches', m^3.
+ private static double WorldLiquid(OfficeBodySession s)
+ {
+ var v = s.View;
+ double w = 0.0;
+ for (int i = 0; i < v.ParticleCount; i++) if (v.ParticleLive[i] != 0u) w += Math.Pow(2.0 * v.ParticleRadius[i], 3.0);
+ for (int i = 0; i < v.WetCount; i++) if (v.WetLive[i] != 0u) w += v.WetPatchVolume[i];
+ return w;
+ }
+
private static PartHit MouthHit(OfficeBodySession s)
{
var plan = SeatedPuppet.Plan;