Skip to content

Simplify pressure_flow_kernel to discrete slope/chain flow behavior#1

Closed
Copilot wants to merge 3 commits into
trunkfrom
copilot/simplify-pressure-flow-kernel
Closed

Simplify pressure_flow_kernel to discrete slope/chain flow behavior#1
Copilot wants to merge 3 commits into
trunkfrom
copilot/simplify-pressure-flow-kernel

Conversation

Copy link
Copy Markdown

Copilot AI commented May 15, 2026

This PR rewrites pressure_flow_kernel in fluid_simulator.py to a functionally simpler, discrete voxel-flow model. The kernel now emphasizes unit-like pressure differences, local slope detection, and chain-style horizontal redistribution while preserving Warp kernel compatibility.

  • Flow model simplification

    • Replaced phase/tick-driven branching with a direct per-voxel reaction model for active cells.
    • Reduced behavior to two slope checks:
      • voxel has a direct downslope neighbor
      • voxel is near a downslope chain and should participate
  • Lowering/settling first

    • Added a downward-first pass so water walks volume down before lateral balancing.
    • This enables traversal until dispersion and natural pooling behavior.
  • Discrete horizontal slope redistribution

    • Horizontal transfers are computed from local volume differences and split across open neighbors.
    • Redistribution is gated by slope presence to avoid unnecessary lateral churn.
  • Empty-target safety for chain transfers

    • When sloping toward effectively empty air cells, transfer is reduced (half-diff behavior) to avoid full→empty recursive breakage artifacts.
  • State/dirty/momentum integration retained

    • Kept existing state, dirty, and cascade_momentum interactions, with updated reaction-driven momentum updates.
if my_vol > 0.0 and open_h > 0 and slope_near == wp.uint8(1):
    diff = my_vol - neighbor_vol
    share = (diff / wp.float32(open_h)) * wp.float32(viscosity)
    if neighbor_vol <= wp.float32(min_vol):
        share = share * wp.float32(0.5)  # avoid aggressive full->empty recursion
Original prompt

Rewrite pressure_flow_kernel in fluid_simulator.py to make it functionally simple.

Implement the logic based on these rules:

  • The main logic takes increments of 1 (or more) volume in pressure and applies a check to determine valid flows.
  • Make it simple and discrete so each voxel of water is a unit in the calculation with states. The states let us change how the voxel responds to nearby pressure.
  • Each actively simulating voxel checks if it must react in 1 of 2 ways:
    1. Am I flowing toward the nearest "slope"?
    2. Is there a "slope" near me?
  • When any voxel sees an open air slot with any amount greater than 0 volume, it instantly starts transfers of volume over to that voxel and creates a "water chain" where all nearby water starts sloping in equivalence with the "slope volume difference" using division to split the differences across horizontal neighbors.
  • It should also check if the air voxel it's sloping toward is empty and then only transfer half the difference to avoid making broken recursive water that goes from full to empty.
  • Add a lower check that walks voxel volumes down in states so that water can traverse until dispersion or just fall down until hitting a pool.
  • Ensure the resulting code is still a valid Warp kernel (@wp.kernel).

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Hi Copilot, I'd like to work on this self made project and keep progressing.

Today I want to work on the fluid_simulator.py and rewrite the "pressure_flow_kernel()" so that it's as functionally simple as mathematically possible. I have a relative sense on how this can look and I'll try and break it down so we can nail this in cleanly.

The "pressure_flow_kernel":

The main logic is to take increments of 1 (or more) volume in pressure and apply a check to determine valid flows.

To make it simple and discrete so each voxel of water is a unit in the calculation with states, the states let us change how the voxel is responding to nearby pressure from other voxels which are doing the same. When doing state checks we just need each actively simulating voxel to "see if it must react" in 1 of 2 ways:

  1. Am I flowing toward the nearest "slope"?

  2. Is there a "slope" near me?

When any voxel sees an open air slot with any amount greater than 0 volume, the first voxel that detects this, it instantly starts transfers of volume over to that voxel and creates a "water chain" where all nearby water starts sloping in equivalence with the "slope volume difference" using division to split the differences across horizontal neighbors. It should also check if the air voxel it's sloping toward is empty and then only transfer half the difference to avoid making broken recursive water that goes from full to empty like a bug.

Like this it just needs a lower check that walks voxel volumes down in states so that water can traverse until dispersion or just fall down until hitting a pool.

Can you help me rewrite the "pressure_flow_kernel()" with rules like that?

Assistant: I've initiated the process to rewrite the pressure_flow_kernel with your simplified discrete slope and flow logic; please accept the prompt to continue so we can proceed with the changes.

This pull request was created from Copilot chat.

Copilot AI and others added 2 commits May 15, 2026 22:47
Agent-Logs-Url: https://github.com/TavariAgent/TokenTorch/sessions/f52d8b41-c54e-44c5-b8a4-65cb92914f2e

Co-authored-by: TavariAgent <217487387+TavariAgent@users.noreply.github.com>
Agent-Logs-Url: https://github.com/TavariAgent/TokenTorch/sessions/f52d8b41-c54e-44c5-b8a4-65cb92914f2e

Co-authored-by: TavariAgent <217487387+TavariAgent@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor pressure flow kernel for simpler functionality Simplify pressure_flow_kernel to discrete slope/chain flow behavior May 15, 2026
Copilot AI requested a review from TavariAgent May 15, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants