EUROGRAPHICS 2015 / O. SorkineHornung and M. Wimmer(This is an author copy, the deﬁnite version is available at http://digilib.eg.org andhttp://onlinelibrary.wiley.com)
Volume 34
(
2015
),
Number 2
A CutCell Geometric Multigrid Poisson Solver for FluidSimulation
Daniel Weber
1
, Johannes MuellerRoemer
†
1
, André Stork
1
and Dieter Fellner
1
,
2
1
TU Darmstadt & Fraunhofer IGD, Germany
2
Institut für ComputerGraphik & WissensVisualisierung, TU Graz, Austria
Figure 1: Three frames from a simulation of smoke ﬂowing past a sphere on a 256
×
512
×
256 grid.
Abstract
We present a novel multigrid scheme based on a cutcell formulation on regular staggered grids which generatescompatible systems of linear equations on all levels of the multigrid hierarchy. This geometrically motivated formulation is derived from a ﬁnite volume approach and exhibits an improved rate of convergence compared to previous methods. Existing ﬂuid solvers with voxelized domains can directly beneﬁt from this approach by onlymodifying the representation of the nonﬂuid domain. The necessary building blocks are fully parallelizable and can therefore beneﬁt from multi and manycore architectures.
Categories and Subject Descriptors
(according to ACMCCS)
: I.3.5 [Computer Graphics]: Computational Geometry and Object Modeling—Physically based modeling I.3.7[Computer Graphics]: ThreeDimensional Graphics and Realism —Animation
1. Introduction
Efﬁcient simulation of ﬂuids remains a challenging problem in the ﬁeld of computer graphics. In order to reproduce small and large scale phenomena, a large number of degrees of freedom is required. We target applications that
†
the two primary authors contributed equally to this work
use structured, orthogonal and equidistant staggered grids,ﬁrst introduced to the computer graphics community by Foster and Metaxas [FM96], with semiLangrangian advection(see [Sta99]). At the core of this wellknown and widespreadmethod the pressure projection step requires the solutionof a large system of linear equations. This is computationally intensive and typically takes most of each simulation step’s duration. Many authors (see, e.g., [Bri08]) usean incomplete Cholesky preconditioned conjugate gradient(ICCG) method, which is illsuited for parallel implementations as back substitution is difﬁcult to parallelize. Morerecent works use multigrid methods for pressure projectionas a preconditioner [MST10], using a variational discretization [CM11a, CM11b] or using an adaptive ﬁnite element
submitted to EUROGRAPHICS 2015.
2
D. Weber et al. / A CutCell Geometric Multigrid Poisson Solver for Fluid Simulation
discretization for very large simulations [FWD14].We construct a geometric multigrid scheme based onthe cutcell method proposed by Ng et al. [NMG09] thatproduces consistent mesh hierarchies, simple coarseningschemes and symmetric matrices on every level. This in turnleads to improved convergence for Neumann boundary conditions. Additionally, we address how to handle Dirichletboundary conditions in a cutcell ﬁnite volume approach,which are only ﬁrst order accurate but maintain symmetry intheresultinglinearsystem.Cellsoncoarserlevelsarenotduplicated to maintain memory alignment especially for GPUimplementations. Our method can either be used as a standalone multigrid solver or embedded in a conjugate gradientalgorithm as a preconditioner.Existing ﬂuid solvers based on voxelized regular grids candirectly beneﬁt by slightly modifying the solidﬂuid boundary representation. In comparison to stateoftheart algorithms, our method results in a speedup of up to 3
×
fora 256
3
grid. In addition, we show a GPU implementation of our multigrid solver which allows for ﬂuid simulations up tofour million degrees of freedom at interactive rates, i.e., withsimulation times below 100 ms on current hardware.
2. Related WorkFluid simulation
In the last years a vast number of papersin the area of ﬂuid simulation for computer graphics havebeen published. Our focus lies on Eulerian, gridbased approaches that use semiLangrangian advection which wasintroduced in the pioneering work of Stam [Sta99]. In general, the challenges using a gridbased approach are numerical viscosity due to semiLangrangian advection and highcomputational effort for computing the pressure correctionwhen using large grids. Furthermore, large time steps potentially smear out small scale vortices and resolving nonaligned solid geometry on a regular grid is difﬁcult.
Multigrid approaches
The solution of the linear systemsfor enforcing incompressibility remains the main bottleneckin ﬂuid simulation, especially for highly detailed simulations on large grids. Multigrid methods theoretically providethe best performance for a large number of degrees of freedom (see [TS01]). However, the construction of highly efﬁcient multigrid schemes is challenging and optimal convergence rates are difﬁcult to achieve. Various methods havebeen proposed. Aftosmis et al. [ABA00] presented a multilevel method for embedded boundaries. If a cell is separated by the embedding geometry it is duplicated to maintainthe topological connectivity. In the work of Johansen andColella [JC98] and Schwartz et al [SBCL06] a ﬁnite volume
discretization to solve embedded Dirichlet boundary conditions on two and threedimensional, regular grids has beenproposed. They solve the corresponding linear system witha multigrid approach. However the proposed discretizationgenerates nonsymmetric systems, which are more difﬁcultto solve. A similar method has been developed by Wan andLiu [WdL04], who proposed numerical multigrid scheme tosolve irregular boundary conditions represented by a levelset. However, they only handle Dirichlet boundary conditions. Hellrung et al. [HJWST12] addressed the problemof nonsymmetric matrices by proposing an alternative discretization and obtain a symmetric system instead. They furthermore extended the approach to three dimensions, additionally handle Neumann boundary conditions and solve thelinear system with a multigrid approach. However, the existence of embedded Neumann boundary conditions results ina more complex stencil requiring special handling, explicitmatrix storage and specialized restriction and prolongationoperators. Our discretization and multigrid approach is morespecialized to easily handle and efﬁciently compute scenarios with Neumann boundaries. We are also able to handleDirichlet conditions and the resulting matrices can be storedimplicitly by ﬂuid faces resulting in a reduced memory consumption.Furthermore,thecoarsematricesdonotneedtobestored explicitly and the computation of their representationas well as the restriction and prolongation operators is fastand easy to implement. This allows for an efﬁcient updateof the matrix hierarchies, which is needed for free surfacesimulation, where the system matrix changes in every timestep.In the context of ﬂuid simulation for computer graphicsMcAdams et al. [MST10] presented a multigrid method embedded in a CG solver for solving Poisson equations forthe pressure correction. They use a single multigrid Vcyclefor preconditioning, as their multigrid method does not converge on its own. Chentanez and Müller [CM11a] analyzedMcAdams’ approach and stated that the divergence is due tonot using a solid fraction method, as it leads to incompatible discretizations at different levels of the mesh hierarchy.They extend the approach and propose a multigrid solver forcollocated discretizations (i.e., pressure and velocity samples are stored at cell centers) based on the variational approach described by Batty et al. [BBB07]. In Chentanez andMüller [CM11b] they propose a similar multigrid methodbut on a variational staggered grid discretization.Ferstl. et al. [FWD14] introduced a method for liquid simulation using a ﬁnite element discretization on adpative regular grids. They use an octree to discretize the space accurately at liquidair boundaries and provide coarse grid cellsin regions, which are covered entirely by ﬂuid. To resolvethe liquidair boundary a specialized marching cubes algorithm is applied to create tetrahedral elements for partiallyﬁlled cells. On coarser levels cells and vertices are locallyduplicated for topologically separated domains to improveconvergence. Setaluri et al. [SABS14] present a specializedsparse grid data structure by means of pyramids of uniformgrids, where cells are marked as active or inactive for adaptive reﬁnement. A multigrid preconditioned conjugate gradient algorithm is used to solve the linear equations for thepressure correction.
submitted to EUROGRAPHICS 2015.
D. Weber et al. / A CutCell Geometric Multigrid Poisson Solver for Fluid Simulation
3
Modeling irregular boundaries
Many authors address theissue of solid geometry that is not aligned with cell borders, i.e., irregular boundaries. To model subcell featuresadaptive grids such as octrees (see Losasso et al. [LGF04])or adaptive conforming tetrahedral meshes near the boundary (see Feldmann et al. [FOK05]) were proposed. In thework of Chentanez et al. [CFL
∗
07] a tetrahedral mesh deﬁned on a lattice was used. Near solid walls the elementsare transformed to better conform with the boundary. Battyet al. [BXH10] built upon this approach but use ﬁxed tetrahedral meshes near the boundaries and propose tetrahedralcutcells to more accurately resolve the ﬂuid. Lentine etal. [LZF10] used a coarse grid projection to accelerate thepressure correction by solving smaller linear systems whileretaining a high resolution grid for advection.A variational approach for handling irregular boundarieshas been presented by Batty et al. [BBB07]. In that approachvolume fractions between adjacent cells are computed torepresent a fractional coverage of solid and ﬂuid to improvethe voxelized pressure solve. Ng et al. [NMG09] have shownthat this type of discretization induces signiﬁcant errors inthe
L
1
and
L
∞
norms of the resulting divergencefree ﬁeldof velocity near the boundaries. They propose an alternativerepresentation that uses the fractional coverage of solid andﬂuid at cell interfaces to cope with irregular domains. Thisdiscretization serves as a basis of our multigrid approach.For ﬂuid simulation with irregular boundaries there is aneed to recompute the border between ﬂuid and air. Therefore, several sub grid modeling approaches were designed.Gibou et al. [GFCK02] presented a discretization of irregular domains based on ﬁnite differences to obtain symmetric matrices. Enright et al. [ENGF03] introduced the ghostﬂuid method based on a ﬁnite difference scheme, proposingto model Dirichlet boundary conditions at the ﬂuid interfaceby modifying the right hand side virtually moving degrees of freedom torwards the interface. In the case of ﬁnite volumesa similar approach results in nonsymmetric matrices.
Alternative approaches
Instead of using very large grids toreproduce small scale phenomena, alternative methods suchas vorticity conﬁnement (see Fedkiw et al. [FSJ01]) or vortex particles (see Selle et al. [SRF05]) have been presented.Pfaff et al. [PTSG09] proposed to inject the precomputedeffects of artiﬁcial boundary layers into the simulation toachieve subgrid motion. Later they used triangular meshesto model the interface between distinct phases [PTG12]. Onthis representation turbulent behavior is directly synthesizedby applying vortex sheet dynamics. Zhu et al. [ZLC
∗
13] introduced a new grid structure with bigger cells that surrounda ﬁne uniform grid to create larger farﬁelds.For liquid simulation Wojtan et al. [WTGT09] introducedmeshbased surface tracking for a more detailed representation of the interface. Da et al. [DBG14] employ meshbasedsurface tracking for multiple materials. They present operations to obtain watertight and intersectionfree meshes whenmaterial interfaces collide, which is important to accuratelyrepresent and simulate the interfaces. Edwards and and Bridson [EB14] combine the discontinous Galerkin method andsurface meshes for ﬂuid simulation. With a high polynomialdegree they can use a very low number of cellsMany of the aforementioned approaches make use of aregular grid discretization. The popular staggered grid discretization was introduced by Harlow and Welch [HW65]and is numerically advantageous compared to a collocateddiscretization. In collocated discretizations both the velocityand pressure samples are stored in the cell center, whereasin staggered grids the normal components of the velocity arestored at cell faces.
3. Discretization
To simulate incompressible ﬂuids with constant density
ρ
it is necessary to compute a divergencefree velocity ﬁeld
u
. The incompressibility constraint can be enforced with apressure projection step by determining a pressure ﬁeld
p
which satisﬁes the Poisson equation
∇·∇
p
=
ρ∆
t
∇·
u
,
(1)on a domain
Ω
subject to boundary conditions on
∂Ω
,where
∆
t
is the time step. We discretize the boundaryvalue problem on a structured, orthogonal and equidistant staggered MAC grid (as introduced by Harlow andWelch [HW65] and popularized in computer animation byFoster and Metaxas [FM96]), where the pressure variablesare located at the cell centers and the normal components of the velocities are located at the interfaces between adjacentcells. This setting is depicted in Fig. 2 and is described indetail in the textbook of Bridson [Bri08].For irregular domains a simple approach is to use a voxelized domain, i.e., to mark each cell either as interior, solidor air to model the ﬂuid, walls or free surfaces. A ﬁnite difference discretization of Eq. (1) then yields a system of linear equations
Lx
=
b
, where the sparse matrix
L
consistsof seven entries per row due to the regular mesh topology(ﬁve per row in 2D). The entries in this matrix depend onthe state of the adjacent cells. A matrixfree approach can beused (see, e.g., [MST10]), as the sparse matrixvector multiplication and other operations can be deduced from the localconﬁguration (the state of the neighboring cells).We use an alternative discretization of the Poisson equation by applying a ﬁnite volume scheme similar to Ng etal. [NMG09]. We transform Eq. (1) into the weak form by
integrating both sides and applying the divergence theorem.For the left hand side
˚
C
ijk
∩
Ω
∇·∇
p
d
V
=
‹
∂
(
C
ijk
∩
Ω
)
n
·∇
p
d
A
(2)is obtained, where
C
ijk
is a voxel grid cell. d
V
and d
A
areinﬁnitesimal volume and area elements, respectively. Simi
submitted to EUROGRAPHICS 2015.
4
D. Weber et al. / A CutCell Geometric Multigrid Poisson Solver for Fluid Simulation
larly,
ρ∆
t
˚
C
ijk
∩
Ω
∇·
u
d
V
=
ρ∆
t
‹
∂
(
C
ijk
∩
Ω
)
n
·
u
d
A
(3)is obtained for the right hand side.By introducing cell and face averages (denoted by anoverline) Eqns. (2) and (3) can be written as discrete sums
V
ijk
∇·∇
p
=
∑
f
A
f
n
f
·∇
p
(4)and
ρ∆
t V
ijk
∇·
u
=
ρ∆
t
∑
f
A
f
n
f
·
u
,
(5)where
f
are the faces,
V
ijk
is the volume of cell
C
ijk
and
A
f
is the area of face
f
.For regular faces which are part of the cell surface
∂
C
ijk
but not part of the domain boundary
∂Ω
(
∂Ω
includes freesurfaces) the gradient term
n
f
·∇
p
can be approximated bya ﬁnite difference
n
f
·∇
p
≈
p
F
−
p
ijk
∆
x
,
(6)as the cell centers are on a regular, orthogonal grid andaligned with the face normals.
∆
x
is the cell spacing and
p
F
is the pressure value of the cell on the opposing side of
f
.The
n
f
·
u
term in Eq. (5) corresponds to the velocity value
±
u
f
stored on the cell face (the sign depends on the reference normal and the face normal).For a regular cell lying completely inside the domain thisresults in the volumescaled discretization of Eq. (1)
∆
x
. . .
−
p
i
−
1
jk
+
6
p
ijk
−
p
i
+
1
jk
. . .
=
−
ρ∆
t
∆
x
2
u
i
+
12
jk
−
u
i
−
12
jk
+
. . .
,
(7)as all face areas
A
f
equal
∆
x
2
(both sides are negated to create a positive deﬁnite system of linear equations). For suchcells the discretization differs from the commonly used ﬁnitedifference discretization only by a scale factor of
V
ijk
=
∆
x
3
.For cell faces partially cut by the irregular domain boundary
A
f
varies between 0 and
∆
x
2
. As the main diagonal equalsthe negated sum of the offdiagonal elements and the faceareas are equal for all adjacent cells, the resulting matrix remains positive deﬁnite and diagonally dominant in all cases.For Neumann boundary conditions (e.g., walls, ﬁxed velocity inlets) the pressure gradient along the face normal isdeﬁned as
∂
p
∂
n
f
=
a
.
(8)Therefore, the corresponding term
A
f
n
f
·∇
p
=
A
f
a
(9)can be moved to the right hand side and does not affect theresulting matrix.Unlike McAdams et al. [MST10] who use the commonapproach where Dirichtlet boundaries (e.g., free surfaces,ﬁxed pressure inlets) are enforced at ghost cells which liebeyond the actual boundary instead of at the boundary andNg et al. [NMG09] who do not consider free surfaces at all,we apply Dirichlet boundary conditions at the corresponding geometric boundary. Chentanez and Mueller [CM11b]achieve this using the ghost cell method by extrapolating anegative pressure outside of the domain, ensuring that
p
=
0at the boundary. We use a ﬁnite difference approximation
A
f
n
f
·∇
p
≈
2
A
f
b
−
p
ijk
∆
x
(10)for gridaligned boundaries, where
b
is the boundary pressure, as the distance to the cell boundary is
∆
x
2
, which isequivalent to applying the ghost ﬂuid method proposed byEnright et al. [ENGF03]. The known component 2
A
f b
∆
x
ismoved to the right hand side and 2
A
f
1
∆
x
is added to the maindiagonal of the discretized matrix.For nonaligned Dirichlet boundaries
∇
p
is approximatedas
∇
p
≈
sgn
(
n
)
2
b
−
p
ijk
∆
x
,
(11)where
n
isthenormaloftheboundarywhere
∇
p
isevaluatedand sgn is the componentwise sign function, i.e., the gridaligned value with the same sign of the normal as the currentcomponent is used. Then
‹
∂
(
C
ijk
∩
Ω
)
n
·∇
p
d
A
≈
2
b
−
p
ijk
∆
x
∑
k
∈
x
,
y
,
z
‹
∂
(
C
ijk
∩
Ω
)

n
k

d
A
=
2
b
−
p
ijk
∆
x
∑
k
∈
x
,
y
,
z
‹
∂
(
C
ijk
∩
Ω
)

cos
β
k

d
A
=
2
A
projd
b
−
p
ijk
∆
x
,
(12)where
β
k
is the angle between the normal and the unit vector
e
k
along axis
k
and
A
projd
is the unsigned, projected areaof the Dirichlet boundary within the cell. This discretization is consistent with the restriction and prolongation operatorschoseninthemultigridalgorithmandyieldsbetterconvergence than always moving the Dirichlet boundary to theclosest cell boundary on all levels. Effectively, nonalignedboundariesareapproximatedasalignedboundarieswithpartial coverage of cells faces.
submitted to EUROGRAPHICS 2015.
D. Weber et al. / A CutCell Geometric Multigrid Poisson Solver for Fluid Simulation
5
p
ij
u
i
−
12
j
u
i
+
12
j
u
ij
−
12
u
ij
+
12
A
projd
,
ij
A
i
−
12
j
A
i
+
12
j
A
ij
−
12
A
ij
+
12
Figure 2: Twodimensional staggered grid and storage locations of discretized areas. The dashed lines represent areasinside obstacles and the green line corresponds to the domain boundary
∂Ω
.Combining all of the above, the matrix is constructed as
L
r
ijk
,
r
i
±
1
jk
=
−
A
i
±
12
jk
∆
x
L
r
ijk
,
r
ij
±
1
k
=
−
A
ij
±
12
k
∆
x
L
r
ijk
,
r
ijk
±
1
=
−
A
ijk
±
12
∆
x
L
r
ijk
,
r
ijk
=
∑
o
∈±
12
A
i
+
ojk
∆
x
+
∑
o
∈±
12
A
ij
+
ok
∆
x
+
∑
o
∈±
12
A
ijk
+
o
∆
x
+
2
A
projd
∆
x
(13)and the right hand side as
b
r
ijk
=
−
ρ∆
t
A
i
+
12
jk
u
i
+
12
jk
−
A
i
−
12
jk
u
i
−
12
jk
+
A
ij
+
12
k
u
ij
+
12
k
−
A
ij
−
12
k
u
ij
−
12
k
+
A
ijk
+
12
u
ijk
+
12
−
A
ijk
−
12
u
ijk
−
12
+
A
d
n
d
·
u
d
+
A
n
a
+
2
A
projd b
∆
x
,
(14)where
r
ijk
is the row or column corresponding to
C
ijk
and
A
n
is the total Neumann surface area. The Dirichlet divergenceterm
A
d
n
d
·
u
d
is either approximated using an extrapolatedvelocity or computed in the same fashion as the other divergence terms for gridaligned boundaries.This alternative discretization can be interpreted as follows: The areas
A
f
between the faces implicitly model theboundaries of the ﬂuid. The values
A
f
∈
[
0
,
∆
x
2
]
representthe fraction of area over which ﬂuid can be exchanged between adjacent cells (see Fig. 2 for a twodimensional example). The resulting discretization yields cut cells, wherethe ﬁnite volume approach takes care of the irregular cells atboundaries. This allows us to resolve the boundary of the geometry more accurately, especially when multiple grid resolutions are used to represent the same simulation domain. Inthat case, a better match of the corresponding geometry representations on each level is achieved than with the standardapproach, where the domain boundary must align with thecell boundaries. Especially on coarse levels, this cutcell dis
def
mgvcycle
(
x
0
,
b
0
)
:
for
l
in
[
0
. . .
L
)
:
x
l
:
=
smooth
(
L
l
,
x
l
,
b
l
)
r
l
:
=
b
l
−
L
l
x
l
b
l
+
1
:
=
I
l
+
1
l
r
l
;
x
l
+
1
:
=
0x
L
:
=
L
−
1
L
b
L
for
l
in
(
L
. . .
0
]
:
x
l
:
=
x
l
+
I
ll
+
1
x
l
+
1
x
l
:
=
smooth
(
L
l
,
x
l
,
b
l
)
return x
0
Listing 1: Multigrid Vcyclecretization is essential for obtaining the high rate of convergence of our multigrid solver, as it makes the discretizationequivalentto deriving itfromthe usedrestrictionandprolongationoperatorsviathe Galerkincoarsegridmethod[TS01].However, additional expensive sparse matrixmatrix products are not required with our approach.This makes it easier to update the discretization if, for example, obstacle geometry changes. Note that Eqns. (13) and(14) can be used both with cut cells or a voxelized domain(with
A
f
∈{
0
,
∆
x
2
}
) on the ﬁne simulation grid. The restriction operators presented in Section 4 automatically converta voxelized domain into a cut cell representation on coarserlevels.
4. Multigrid solver
The nonrecursive multigrid Vcycle given in Listing 1 consists of ﬁve basic operations: restriction (
I
H h
), prolongation(
I
h H
), sparse matrixvector multiplication (
L
l
x
l
), smoothingand the exact solution on the lowest level (
L
−
1
L
x
L
). Wechoose level 0 to be the ﬁne grid and
L
to be the coarsestgrid.The natural restriction operator
I
H h
resulting from the ﬁnite volume discretization
x
H IJK
=
∑
i
∈
[
2
I
,
2
I
+
1
]
j
∈
[
2
J
,
2
J
+
1
]
k
∈
[
2
K
,
2
K
+
1
]
x
hijk
(15)is a simple sum over 4 or 8 cells in 2D and 3D, respectively,asshowninFig.3,sincethesummationovermultiplecellsisthe discrete equivalent to an integral over multiple cells. Theprolongation operator
I
h H
is chosen to be the transpose of therestriction operator in matrix representation
I
h H
= (
I
H h
)
T
, i.e.,the coarse grid result is simply repeated for the corresponding ﬁne grid cells.In fact, these restriction and prolongation operators arenot only simpler to implement than the cellcentered trilinear interpolation used by McAdams et al. [MST10], but also
submitted to EUROGRAPHICS 2015.