nx_fluid_seal.nx source
↩ module page · 121 lines · 4776 B
1// nx_fluid_seal.nx -- fluid/seal-integrity kernel (#4 of 4 -- COMPLETES the
2// physics-kernel set). Independent leak detection for plumbing, brake fluid,
3// coolant, hydraulics, refrigerant, tires -- anything that should hold pressure
4// or stay sealed.
5//
6// Two universal independent signals, integer/no-float:
7// - PRESSURE-DECAY TEST: isolate the system, watch pressure over time. A
8// healthy seal holds; a failing seal DECAYS. Decay rate -> severity, on the
9// seepage -> leak -> rapid-loss progression (catch it BEFORE catastrophe).
10// - FLOW-WHILE-ISOLATED: any flow when the system is isolated = a leak path
11// (the hidden slab-leak / continuous-drip a homeowner never sees).
12//
13// THE EXCEED: most fluid systems have NO independent leak detection -- you learn
14// of a leak from water damage / low fluid / brake failure. This quantifies seal
15// integrity early and continuously, vendor-independent.
16//
17// NEVER-BRICK (#26): reads pressure/flow, emits a verdict; writes nothing,
18// actuates no valve. Read-only by construction.
19//
20// genealogy_id: project-maintenance-platform-sclass-2026-06-23 (kernel #4 -- set complete)
21// license_tier: ORIGINAL
22//
23// nx_capability_claims:
24// needs: [pointer_arithmetic]
25// provides: [pressure_decay_leak_test, flow_while_isolated_leak,
26// seal_integrity_verdict, early_progression_detect]
27// safety: [no_floating_point, no_syscall, bounded_iteration,
28// read_only_no_device_write, no_firmware_write_by_construction,
29// sealed_enum_verdict]
30// verdict: [sealed_enum_fluid, no_silent_failure]
31// license: ORIGINAL
32// kind: maintenance_runtime_primitive
33
34const NX_FLUID_INSUFFICIENT_DATA: i64 = 0
35const NX_FLUID_SEALED: i64 = 1 // holds pressure (decay within allowance)
36const NX_FLUID_SEEPAGE: i64 = 2 // small elevated decay -- monitor
37const NX_FLUID_LEAK: i64 = 3 // clear leak (decay over alarm, or flow-while-isolated)
38const NX_FLUID_RAPID_LOSS: i64 = 4 // burst / wide-open -- rapid decay
39const NX_FLUID_NO_PRESSURE: i64 = 5 // never reached test pressure (weak pump / big open leak)
40const NX_FLUID_BAD_ARG: i64 = 6
41const NX_FLUID_N: i64 = 7
42
43func nx_fluid_verdict_is_valid(v: i64) -> i64 {
44 if v < 0 { return 0 }
45 if v >= NX_FLUID_N { return 0 }
46 return 1
47}
48
49// Data-driven spec = the seal's allowed envelope (#11; svc-config in prod).
50struct FluidSpec {
51 test_pressure_min: i64, // min start pressure for a valid test (centi-units)
52 seep_decay_per_min: i64, // decay above this = SEEPAGE
53 leak_decay_per_min: i64, // decay above this = LEAK
54 rapid_decay_per_min: i64, // decay above this = RAPID_LOSS
55}
56
57struct FluidEff {
58 start_pressure: i64,
59 end_pressure: i64,
60 decay_per_min: i64, // can be negative (pressure rose -> sealed)
61 verdict: i64,
62}
63
64// pressure[i] over t_sec[i] = pressure samples in an ISOLATED system.
65// flow_when_isolated = a flow reading taken while isolated (0 = none = good).
66func nx_fluid_analyze(pressure: *i64, t_sec: *i64, n: i64, flow_when_isolated: i64,
67 spec: *FluidSpec, out: *FluidEff) -> i64 {
68 out.start_pressure = 0
69 out.end_pressure = 0
70 out.decay_per_min = 0
71 out.verdict = NX_FLUID_INSUFFICIENT_DATA
72
73 if flow_when_isolated < 0 {
74 out.verdict = NX_FLUID_BAD_ARG
75 return out.verdict
76 }
77 if n < 2 {
78 out.verdict = NX_FLUID_INSUFFICIENT_DATA
79 return out.verdict
80 }
81 let last: i64 = n - 1
82 let total: i64 = t_sec[last] - t_sec[0]
83 if total <= 0 {
84 out.verdict = NX_FLUID_INSUFFICIENT_DATA
85 return out.verdict
86 }
87
88 let start: i64 = pressure[0]
89 let end: i64 = pressure[last]
90 out.start_pressure = start
91 out.end_pressure = end
92
93 // Must build to test pressure for a valid seal test; otherwise the system
94 // is wide open / the pump is weak (a leak of a different kind).
95 if start < spec.test_pressure_min {
96 out.verdict = NX_FLUID_NO_PRESSURE
97 return out.verdict
98 }
99
100 out.decay_per_min = ((start - end) * 60) / total
101
102 // Flow while isolated = a definitive leak path regardless of decay.
103 if flow_when_isolated > 0 {
104 out.verdict = NX_FLUID_LEAK
105 return out.verdict
106 }
107 if out.decay_per_min >= spec.rapid_decay_per_min {
108 out.verdict = NX_FLUID_RAPID_LOSS
109 return out.verdict
110 }
111 if out.decay_per_min >= spec.leak_decay_per_min {
112 out.verdict = NX_FLUID_LEAK
113 return out.verdict
114 }
115 if out.decay_per_min >= spec.seep_decay_per_min {
116 out.verdict = NX_FLUID_SEEPAGE
117 return out.verdict
118 }
119 out.verdict = NX_FLUID_SEALED
120 return out.verdict
121}