Graphics Reference
In-Depth Information
scale =1/dx;
loop over i,j,k where cell(i,j,k)==FLUID:
rhs(i,j,k) = -scale * (u(i+1,j,k)-u(i,j,k)
+v(i,j+1,k)-v(i,j,k)
+w(i,j,k+1)-w(i,j,k));
Figure 4.2. Calculating the negative divergence, which will become the right-hand
side of the linear system for pressure.
condition with finite differences and require that the divergence estimated
at each fluid grid cell be zero for u n +1 .
Remember the divergence in two dimensions is
u = ∂u
∂x + ∂v
∇·
∂y
and in three dimensions is
∂u
∂x + ∂v
∂y + ∂w
∇·u =
∂z .
Using the obvious central differences (take a look at the MAC grid again),
we approximate the two-dimensional divergence in fluid grid cell ( i, j )as
u i +1 / 2 ,j
u i 1 / 2 ,j
Δ x
+ v i,j +1 / 2
v i,j 1 / 2
Δ x
(
∇·
u ) i,j
(4.7)
and in three dimensions, for fluid grid cell ( i, j, k )as
u i +1 / 2 ,j,k
u i 1 / 2 ,j,k
Δ x
+ v i,j +1 / 2 ,k
v i,j 1 / 2 ,k
Δ x
(
∇·
u ) i,j,k
+ w i,j,k +1 / 2
w i,j,k 1 / 2
Δ x
.
(4.8)
In terms of the storage convention used earlier, with divergence stored in
the same way as pressure, this can be implemented as in the pseudocode
of Figure 4.2. It turns out (see below) that we actually are more interested
in the negative of divergence, so we store that in a vector we will call rhs
(standing for the right-hand side of a linear system).
Note that we are only ever going to evaluate divergence for a grid cell
that is marked as fluid. For example, our fluid simulation is not concerned
with whether solids are changing volume or not.
Search WWH ::




Custom Search