code wiki / (root) / nx_water_erosion.nx

nx_water_erosion.nx

buildroot/runtime/nx_water_erosion.nx

32053 B781 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic water
docsdependenciesstructsconstsfunctions

about

nx_water_erosion.nx -- full Mei 2007 hydraulic erosion simulation. Mei, Decaudin, Hu 2007: "Fast Hydraulic Erosion Simulation and Visualization on GPU". Full implementation per cardinal `feedback-maximum-capability-no-simplification`: this primitive ships the entire shallow-water + sediment-transport algorithm, not a slope-magnitude approximation. Algorithm (Mei 2007 sections 3.1 - 3.5): STAGE 1 -- WATER INCREMENT (rain) d(t+dt) += dt * r_t where r_t = rain rate per cell STAGE 2 -- FLOW SIMULATION (pipe model) For each cell + each cardinal direction X: f_X(t+dt) = max(0, f_X(t) + dt * A * g * dh_X / L) where dh_X = h(this) + d(this) - h(neighbour_X) - d(neighbour_X), A = pipe cross-section, L = pipe length, g = gravity. Outflow scaling: if total_outflow * dt > available_water * cell_area, scale all 4 outflows by min(1, available_water * cell_area / (total_outflow * dt)). STAGE 3 -- WATER UPDATE (mass conservation) d(t+dt) = d(t) + dt * (total_inflow - total_outflow) / cell_area STAGE 4 -- VELOCITY FIELD delta_W_x = (f_R(left_neighbour) - f_L(this) + f_R(this) - f_L(right_neighbour)) / 2 u = delta_W_x / (cell_size * d_avg) (similar for v, y axis) STAGE 5 -- EROSION + DEPOSITION C = K_c * |sin(local_tilt)| * |velocity| (sediment capacity) if C > s: erode -> h -= K_s * (C - s); s += K_s * (C - s) if C < s: deposit -> h += K_d * (s - C); s -= K_d * (s - C) STAGE 6 -- SEDIMENT TRANSPORT (semi-Lagrangian) s_new(x, y) = s_old(x - u*dt, y - v*dt) -- bilinear interp STAGE 7 -- EVAPORATION d(t+dt) = d(t) * (1 - K_e * dt)

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_water_erosion.nx

imports: nx_syscalls.nxnx_tier.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_water_mode_is_valid nx_water_erosion_delta nx_water_mode_is_valid ↻ sys_mmap nx_water_mode_params sys_mmap ↻ nx_water_erosion_params_de nx_water_erosion_init nx_water_erosion_add_rain nx_water_erosion_compute_f _w_cell_base _w_cell_base ↻ nx_water_erosion_tick nx_water_erosion_add_rain ↻ nx_water_erosion_compute_f ↻ nx_water_erosion_update_wa _w_cell_base ↻ nx_water_erosion_terrain_u _w_cell_base ↻ nx_water_erosion_transport _w_cell_base ↻ nx_water_erosion_evaporate nx_water_erosion_evaporate ↻

structs

none

consts

79const NX_MAGIC_2000: i64 = 2000
82const NX_WATER_Q: nx_int = 16384
86const NX_WATER_STRIDE: nx_int = 9
87const NX_WATER_OFF_H: nx_int = 0 // terrain height (signed metres, Q14)
88const NX_WATER_OFF_D: nx_int = 1 // water depth (metres, Q14)
89const NX_WATER_OFF_S: nx_int = 2 // suspended sediment depth (metres, Q14)
90const NX_WATER_OFF_FL: nx_int = 3 // outflow flux LEFT (m^3/s, Q14)
91const NX_WATER_OFF_FR: nx_int = 4 // outflow flux RIGHT
92const NX_WATER_OFF_FT: nx_int = 5 // outflow flux TOP (lower y)
93const NX_WATER_OFF_FB: nx_int = 6 // outflow flux BOTTOM (higher y)
94const NX_WATER_OFF_U: nx_int = 7 // x-velocity (m/s, Q14)
95const NX_WATER_OFF_V: nx_int = 8 // y-velocity (m/s, Q14)
101const NX_WATER_DEFAULT_GRAVITY: nx_int = 160760 // 9.81 m/s^2
102const NX_WATER_DEFAULT_PIPE_AREA: nx_int = 16384 // 1.0 m^2
103const NX_WATER_DEFAULT_PIPE_LENGTH: nx_int = 16384 // 1.0 m
104const NX_WATER_DEFAULT_DT: nx_int = 1638 // 0.1 seconds per tick
105const NX_WATER_DEFAULT_K_CAPACITY: nx_int = 1638 // 0.1 (Mei's K_c)
106const NX_WATER_DEFAULT_K_SOIL: nx_int = 4915 // 0.3
107const NX_WATER_DEFAULT_K_DEPOSIT: nx_int = 4915 // 0.3
108const NX_WATER_DEFAULT_K_EVAP: nx_int = 164 // 0.01
109const NX_WATER_DEFAULT_CELL_SIZE: nx_int = 16384 // 1.0 m grid cell
112const NX_WATER_PARAM_COUNT: nx_int = 9
113const NX_WATER_PARAM_GRAVITY: nx_int = 0
114const NX_WATER_PARAM_PIPE_AREA: nx_int = 1
115const NX_WATER_PARAM_PIPE_LENGTH: nx_int = 2
116const NX_WATER_PARAM_DT: nx_int = 3
117const NX_WATER_PARAM_K_CAPACITY: nx_int = 4
118const NX_WATER_PARAM_K_SOIL: nx_int = 5
119const NX_WATER_PARAM_K_DEPOSIT: nx_int = 6
120const NX_WATER_PARAM_K_EVAP: nx_int = 7
121const NX_WATER_PARAM_CELL_SIZE: nx_int = 8
124const NX_WATER_MODE_GENTLE_WEATHERING: nx_int = 0
125const NX_WATER_MODE_RIVERINE: nx_int = 1
126const NX_WATER_MODE_FLASH_FLOOD: nx_int = 2
127const NX_WATER_MODE_SUSTAINED: nx_int = 3
129const NX_WATER_MODE_COUNT: nx_int = 4

functions

131func nx_water_mode_is_valid(m: nx_int) -> nx_int
140func nx_water_mode_params(mode: nx_int, out: *i64)
163func nx_water_erosion_params_default(params: *i64)
called by 1: main
176func _w_cell_base(x: nx_int, y: nx_int, width: nx_int) -> nx_int
183func nx_water_erosion_init(state: *i64, width: nx_int, gridh: nx_int)
called by 1: main
202func nx_water_erosion_add_rain(
219func nx_water_erosion_compute_flow(
321func nx_water_erosion_update_water_and_velocity(
called by 1: nx_water_erosion_tick calls 1: _w_cell_base
417func nx_water_erosion_terrain_update(
called by 1: nx_water_erosion_tick calls 1: _w_cell_base
509func nx_water_erosion_transport(
called by 1: nx_water_erosion_tick calls 1: _w_cell_base
573func nx_water_erosion_evaporate(
594func nx_water_erosion_tick(
614func nx_water_erosion_delta(
632func nx_water_slope_at(
called by 1: nx_water_erosion_at
664func nx_water_erosion_at(
677func main() -> i64