Game Development Reference

In-Depth Information

f
p
=

2
v
is the viscous force. Equa-

tion (6.1) can be applied to these two quantities to interpolate them at any location

in the fluid.

We will first interpolate
f
p
(
x
) in a straightforward manner, as stated by

p
is the pressure force, and
f
v
=
μ

−∇

∇

n

m
j

ρ
j
p
(
x
)

f
p
(
x
)=

−∇

p
(
x
)=

−

∇

W
(
x

−

x
j
,h
)
.

(6.5)

j
=1

To calculate the per-particle force
f
i

,[Muller et al. 03] proposed an adapta-

tion to Equation (6.5) to obtain symmetric pressure forces between any pair of

particles
i
and
j
, by substituting (
p
i
+
p
j
)
/
2 for
p
(
x
). Also, the acceleration of

the fluid, defined as
a
(
x
)=
f
(
x
)
/ρ
(
x
), has to be matched by every fluid parti-

cle. Therefore, the pressure force
f
p
(
x
) at an arbitrary location within the fluid

defined by Equation (6.5) is multiplied by
m
i

ρ
i

to get the pressure force
f
i

acting

on a single particle
i
. The complete definition of
f
i

is given by

n

m
i

ρ
i

m
j

ρ
j

(
p
i
+
p
j
)

2

f
i

−∇

p
i
=

−

∇

W
(
x
i
−

x
j
,h
)
,

=

(6.6)

j
=1

where according to the ideal gas law
p
j
=
kρ
j
, with
k
being a gas constant that

can be used to increase or decrease the compressibility of our simulated fluid. We

do not find it necessary to use a rest density as in [Muller et al. 03]. We choose

the smoothing kernel

W
(
r
,h
)=(45
/πh
4
)(1

/h
)
2

r

r

, which is the gra-

dient of the spiky kernel used for density computations. Note that

∇

−

r

W
(
r
,h
) is

undefined when
r
=
0
. Because a particle never exerts a force on itself, we define

W
(
0
,h
)=0.

Apart from Equation (6.6), there are other ways in which we can use Equa-

tion (6.1) to interpolate a gradient. According to [Colin et al. 06], some of them

yield more-accurate approximations of the gradient of a function. For instance, a

more-accurate approximation would be obtained by using the difference gradient

approximation formula (DGAF), as in [Colin et al. 06]. However, the inaccura-

cies of Equation (6.6) tend to decrease compressibility for areas with similar but

high pressure, while this is not the case for a DGAF approximation. Simulating

water or other incompressible fluids therefore benefits from using Equation (6.6).

The approximation of the viscous force
f
i

∇

=
μ∇

2
v
is similar to the approxi-

mation of
f
i

, as the following demonstrates:

n

2
v
=
μ
m
i

ρ
i

m
j

ρ
j
(
v
j
−

f
i

2
W
(
x
i
−

=
μ

∇

∇

x
j
,h
)
,

v
i
)

(6.7)

j
=1

where
μ
is the viscosity constant, used to increase or decrease the viscosity of the

simulated fluid. Here, we choose the smoothing kernel

2
W
(
r
,h
)=(45
/πh
6
)

∇