Skip to content

Commit

Permalink
[doc,demos] Update FLIP demos
Browse files Browse the repository at this point in the history
  • Loading branch information
holl- committed Dec 9, 2023
1 parent c6cbe8e commit 74b9238
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions demos/flip_liquid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@


domain = Box(x=64, y=64)
gravity = vec(x=0, y=-9.81)
obstacle = Box(x=(1, 25), y=(30, 33)).rotated(-20)
particles = distribute_points(union(Box(x=(15, 30), y=(50, 60)), Box(x=None, y=(-INF, 5))), x=64, y=64) * (0, 0)


@jit_compile
def step(particles: Field, dt=.2):
def step(particles: Field, pressure=None, dt=.1, gravity=vec(x=0, y=-9.81)):
# --- Grid Operations ---
grid_v = prev_grid_v = field.finite_fill(resample(particles, StaggeredGrid(0, 0, x=64, y=64), scatter=True, outside_handling='clamp'))
grid_v = prev_grid_v = field.finite_fill(particles.at(StaggeredGrid(0, 0, domain, x=64, y=64), scatter=True, outside_handling='clamp'))
occupied = resample(field.mask(particles), CenteredGrid(0, grid_v.extrapolation.spatial_gradient(), grid_v.bounds, grid_v.resolution), scatter=True, outside_handling='clamp')
grid_v, pressure = fluid.make_incompressible(grid_v + gravity * dt, [obstacle], active=occupied)
# --- Particle Operations ---
particles += resample(grid_v - prev_grid_v, to=particles) # FLIP update
# particles = resample(grid_v, particles) # PIC update
particles = advect.points(particles, grid_v * mask(~obstacle), dt, advect.finite_rk4)
particles = advect.points(particles, grid_v * resample(~obstacle, to=grid_v), dt, advect.finite_rk4)
particles = fluid.boundary_push(particles, [obstacle, ~domain], separation=.5)
return particles, pressure

Expand Down
6 changes: 3 additions & 3 deletions docs/FLIP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@
"outputs": [],
"source": [
"@jit_compile\n",
"def step(particles: Field, pressure=None, dt=.2, gravity=vec(x=0, y=-9.81)):\n",
"def step(particles: Field, pressure=None, dt=.1, gravity=vec(x=0, y=-9.81)):\n",
" # --- Grid Operations ---\n",
" grid_v = prev_grid_v = field.finite_fill(resample(particles, StaggeredGrid(0, 0, x=64, y=64), scatter=True, outside_handling='clamp'))\n",
" grid_v = prev_grid_v = field.finite_fill(particles.at(StaggeredGrid(0, ZERO_GRADIENT, domain, x=64, y=64), scatter=True, outside_handling='clamp'))\n",
" occupied = resample(field.mask(particles), CenteredGrid(0, grid_v.extrapolation.spatial_gradient(), grid_v.bounds, grid_v.resolution), scatter=True, outside_handling='clamp')\n",
" grid_v, pressure = fluid.make_incompressible(grid_v + gravity * dt, [ground], active=occupied)\n",
" # --- Particle Operations ---\n",
" particles += resample(grid_v - prev_grid_v, to=particles) # FLIP update\n",
" # particles = resample(grid_v, particles) # PIC update\n",
" particles = advect.points(particles, grid_v * mask(~ground), dt, advect.finite_rk4)\n",
" particles = advect.points(particles, grid_v * resample(~ground, to=grid_v), dt, advect.finite_rk4)\n",
" particles = fluid.boundary_push(particles, [ground, ~domain], separation=.5)\n",
" return particles, pressure"
],
Expand Down

0 comments on commit 74b9238

Please sign in to comment.