Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions genesis/engine/solvers/sf_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ def reset_swap(self):
@ti.kernel
def pressure_jacobi(self, pf: ti.template(), new_pf: ti.template()):
for I in ti.grouped(ti.ndrange(*self.res)):
pl = pf[self.compute_location(*I, -1, 0, 0)]
pr = pf[self.compute_location(*I, 1, 0, 0)]
pb = pf[self.compute_location(*I, 0, -1, 0)]
pt = pf[self.compute_location(*I, 0, 1, 0)]
pp = pf[self.compute_location(*I, 0, 0, -1)]
pq = pf[self.compute_location(*I, 0, 0, 1)]
u, v, w = I
pl = pf[self.compute_location(u, v, w, -1, 0, 0)]
pr = pf[self.compute_location(u, v, w, 1, 0, 0)]
pb = pf[self.compute_location(u, v, w, 0, -1, 0)]
pt = pf[self.compute_location(u, v, w, 0, 1, 0)]
pp = pf[self.compute_location(u, v, w, 0, 0, -1)]
pq = pf[self.compute_location(u, v, w, 0, 0, 1)]

new_pf[I] = (pl + pr + pb + pt + pp + pq - self.grid[I].div) / 6.0

Expand Down Expand Up @@ -132,25 +133,26 @@ def advect_and_impulse(self, f: ti.i32, t: ti.f32):
@ti.kernel
def divergence(self):
for I in ti.grouped(ti.ndrange(*self.res)):
vl = self.grid.v_tmp[self.compute_location(*I, -1, 0, 0)]
vr = self.grid.v_tmp[self.compute_location(*I, 1, 0, 0)]
vb = self.grid.v_tmp[self.compute_location(*I, 0, -1, 0)]
vt = self.grid.v_tmp[self.compute_location(*I, 0, 1, 0)]
vp = self.grid.v_tmp[self.compute_location(*I, 0, 0, -1)]
vq = self.grid.v_tmp[self.compute_location(*I, 0, 0, 1)]
vc = self.grid.v_tmp[self.compute_location(*I, 0, 0, 0)]

if not self.is_free(*I, -1, 0, 0):
u, v, w = I
vl = self.grid.v_tmp[self.compute_location(u, v, w, -1, 0, 0)]
vr = self.grid.v_tmp[self.compute_location(u, v, w, 1, 0, 0)]
vb = self.grid.v_tmp[self.compute_location(u, v, w, 0, -1, 0)]
vt = self.grid.v_tmp[self.compute_location(u, v, w, 0, 1, 0)]
vp = self.grid.v_tmp[self.compute_location(u, v, w, 0, 0, -1)]
vq = self.grid.v_tmp[self.compute_location(u, v, w, 0, 0, 1)]
vc = self.grid.v_tmp[self.compute_location(u, v, w, 0, 0, 0)]

if not self.is_free(u, v, w, -1, 0, 0):
vl.x = -vc.x
if not self.is_free(*I, 1, 0, 0):
if not self.is_free(u, v, w, 1, 0, 0):
vr.x = -vc.x
if not self.is_free(*I, 0, -1, 0):
if not self.is_free(u, v, w, 0, -1, 0):
vb.y = -vc.y
if not self.is_free(*I, 0, 1, 0):
if not self.is_free(u, v, w, 0, 1, 0):
vt.y = -vc.y
if not self.is_free(*I, 0, 0, -1):
if not self.is_free(u, v, w, 0, 0, -1):
vp.z = -vc.z
if not self.is_free(*I, 0, 0, 1):
if not self.is_free(u, v, w, 0, 0, 1):
vq.z = -vc.z

self.grid.div[I] = 0.5 * (vr.x - vl.x + vt.y - vb.y + vq.z - vp.z)
Expand All @@ -168,12 +170,13 @@ def pressure_from_swap(self):
@ti.kernel
def subtract_gradient(self):
for I in ti.grouped(ti.ndrange(*self.res)):
pl = self.grid.p[self.compute_location(*I, -1, 0, 0)]
pr = self.grid.p[self.compute_location(*I, 1, 0, 0)]
pb = self.grid.p[self.compute_location(*I, 0, -1, 0)]
pt = self.grid.p[self.compute_location(*I, 0, 1, 0)]
pp = self.grid.p[self.compute_location(*I, 0, 0, -1)]
pq = self.grid.p[self.compute_location(*I, 0, 0, 1)]
u, v, w = I
pl = self.grid.p[self.compute_location(u, v, w, -1, 0, 0)]
pr = self.grid.p[self.compute_location(u, v, w, 1, 0, 0)]
pb = self.grid.p[self.compute_location(u, v, w, 0, -1, 0)]
pt = self.grid.p[self.compute_location(u, v, w, 0, 1, 0)]
pp = self.grid.p[self.compute_location(u, v, w, 0, 0, -1)]
pq = self.grid.p[self.compute_location(u, v, w, 0, 0, 1)]

self.grid.v[I] = self.grid.v_tmp[I] - 0.5 * ti.Vector([pr - pl, pt - pb, pq - pp], dt=gs.ti_float)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "README.md"
requires-python = ">=3.10,<3.14"
dependencies = [
"psutil",
"gstaichi==4.5.0",
"gstaichi==4.6.0b4",
"pydantic>=2.11.0",
"numpy>=1.26.4",
"trimesh",
Expand Down
Loading