nx_fluid.nx
buildroot/runtime/nx_fluid.nx
about
nx_fluid.nx -- ★R6 of the Infinigen ladder: FLUID SIMULATION (their FLIP-fluids axis). A height-field WAVE
simulation (the shallow-water / wave-equation grid -- the standard real-time water technique; FLIP is the
particle variant). Real physics, all integer: a height grid h + velocity grid v integrated by the discrete
wave equation v += c^2*dt * laplacian(h) ; v *= damp ; h += v , with REFLECTING boundaries so VOLUME is
exactly conserved (sum(laplacian)=0 => sum(v) stays 0 => sum(h) constant). Disturbances propagate outward at
finite speed, reflect off shores, and damp -- not a flat plane. license_tier: ORIGINAL
dependencies 2 imports · 1 importers
imports: nx_syscalls.nxnx_itrig.nx
imported by: nx_fluid_gate.nx
structs
| none |
consts
| 9 | const FL_MAGIC_1024: i64 = 1024 |
| 10 | const FL_MAGIC_1048576: i64 = 1048576 |
| 11 | const FL_MAGIC_9973: i64 = 9973 |
| 12 | const FL_MAGIC_4096: i64 = 4096 |
| 13 | const FL_MAGIC_65536: i64 = 65536 |
| 15 | const FL_N: i64 = 168 // grid cells per axis |
| 16 | const FL_K: i64 = 100 // c^2*dt (fx1024) -- CFL-stable (4*K/1024 = 0.39, well under the 2D limit) |
| 17 | const FL_DAMP: i64 = 1013 // velocity damping per step (~0.989) -- removes energy, keeps sum(v)=0 |
functions
| 22 | func fl_isqrt(x: i64) -> i64 { if x<=0 {return 0} var a: i64=x; var b: i64=(a+1)/2; while b<a {a=b; b=(a+x/a)/2} return a } |
| 23 | func fl_iabs(v: i64) -> i64 { if v<0 {return 0-v} return v } |
| 24 | func fl_clampi(v: i64, lo: i64, hi: i64) -> i64 { if v<lo {return lo} if v>hi {return hi} return v } called by 1: fl_render |
| 26 | func fl_init() -> i64 |
| 38 | func fl_drop(cx: i64, cy: i64, r: i64, amp: i64) -> i64 called by 1: main |
| 60 | func fl_step() -> i64 called by 1: main |
| 117 | func fl_h(x: i64, y: i64) -> i64 { let h: *i64 = FL_H as *i64; return h[y*FL_N+x] } called by 1: main |
| 118 | func fl_n() -> i64 { return FL_N } called by 1: main |
| 120 | func fl_volume() -> i64 { let h: *i64 = FL_H as *i64; var s: i64=0; var i: i64=0; while i<FL_N*FL_N { s=s+h[i]; i=i+1 } return s } called by 1: main |
| 121 | func fl_energy() -> i64 { let h: *i64 = FL_H as *i64; var s: i64=0; var i: i64=0; while i<FL_N*FL_N { s=s+fl_iabs(h[i]); i=i+1 } return s } calls 1: fl_iabs |
| 124 | func fl_maxabs() -> i64 { let h: *i64 = FL_H as *i64; var m: i64=0; var i: i64=0; while i<FL_N*FL_N { let a: i64=fl_iabs(h[i]); if a>m {m=a} i=i+1 } return m } |
| 126 | func fl_front(cx: i64, cy: i64, thr: i64) -> i64 |
| 146 | func fl_render(fb: *i64, W: i64, H: i64, sunx: i64, suny: i64, sunz: i64) -> i64 |