Two Phase Level Set COMSOL Tutorial
Two Phase Level Set COMSOL Tutorial
17 January 2007
ii
Preface
This report is written at the Technological University of Denmark. The Department of
Micro and Nanotechnology offers the three week course 33443 Microfluidics Theory and
Simulation, which sorts under the Microfluidics Theory and Simulation (MIFTS) group [4],
headed by Professor Henrik Bruus.
The motivation for the present report is built on a contact from the Swedish company
HemoCue [3], who requests theoretical calculations on their blood analysis products. De-
velopment of the HemoCue products has until now based on a trial and error approach
and further progress now demands a more theoretical and analytical treatment. The main
problem is air bubbles that get stuck in the central analysis chamber, which is filled using
the capillary forces. Optical measurements on the blood are very sensitive to these bubbles
that give rise to incorrect outcomes. It is therefore decided that this report shall act as a
preliminary treatment of the problem.
During the three weeks the authors and their supervisors has visited the R&D depart-
ment of HemoCue in Angelholm, Sweden. It has been an interesting meeting, which first
of all has given an introduction to the company and their visions, but has also clarified
the specific problem of trapped bubbles. This report focuses on following a two phase flow
interface by using a level set method, which can simulate complex flows. It does not give
the specific answer for the HemoCue problem, but provides a tool, which together with
analytical treatments of the problem, can provide HemoCue with the necessary guidelines
when developing new micro cuvettes.
Throughout the report the Einstein summation rule will be used when appropriate.
The reader is assumed to be familiar with this notation. For notational simplicity x will
be used instead of x etc.
We hope the reader will enjoy reading the report.
1 Theory 1
1.1 Capillary Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Analytical analysis of capillary micro pump . . . . . . . . . . . . . . . . . . 3
1.3 A conservative level set method for two phase flow . . . . . . . . . . . . . . 5
2 Numerical implementation 9
2.1 Setting up the model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.1 Domain variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1.2 Boundary variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Results 15
4 Conclusions 19
iii
iv CONTENTS
Chapter 1
Theory
In this chapter the general physics that give rise to capillary effects is presented. Physical
quantities such as surface tension and contact angle are described. The length scale for
which capillary effects are dominant is found. This will explain why capillary rise is not
observed in, e.g. , an ordinary water bottle but is unavoidable in small structures such
as the HemoCue micro cuvettes. Finally, the theory for the level set method is briefly
reviewed. The level set method makes complicated simulations of capillary effects possible
and can be a relevant tool, when designing new products with optimal functionality.
where R1 and R2 are the radii of curvature. An everyday analog of the Young-Laplace
pressure drop is blowing up of a balloon. Here one obviously adds pressure to the internal
volume of the balloon, which gives rise to a surface tension and radii of curvature.
Another important parameter is the contact angle, , which appears at the contact line
between three different phases, which is typically two immisible fluids and a solid wall.
The contact angle is an important parameter, since it is directly related to the radii of
curvature and the surface tensions between the different phases. This is given by Youngs
1
2 CHAPTER 1. THEORY
Figure 1.1: Graphical representation of the contact angle, c . The figure shows a drop
of liquid on a substrate. There are three interfaces all denoted with the corresponding
surface tension, sl , lg and sg . The contact line is the geometrical line where the three
phases meet and the contact angle is measured between the tangents to the solid-liquid
and liquid-gas interfaces at this line. The picture is from WikiPedia.
equation.
sg sl
cos = , (1.2)
lg
where s, g and l refer to the solid, gas and liquid phases, respectively. See Fig. 1.1. This
section is build on [1].
1.2. ANALYTICAL ANALYSIS OF CAPILLARY MICRO PUMP 3
z
p0 p0 p p0
0 h
x
0 L(t)
Figure 1.2: Basic sketch of the capillary micro pump in a channel with open ends at an
arbitrary pressure, p0 . Notice the finite pressure jump, p, across the meniscus that drives
the fluid column into the channel. The hydraulic resistance is proportional to the length,
L(t), of the water column and thus increases, making it more difficult to draw in fluid, as
time goes. The height of the channel is h.
where L is the position of the meniscus, Q is the volume flow rate and A is the cross
sectional area of the rectangular channel. The volume flow rate for a Poiseuille flow in a
an infinite parallel plate channel is calculated by use of the Hagen-Poiseuille law,
p
Q= , (1.6)
Rhyd
where Rhyd is the hydraulic resistance of the channel. The hydraulic resistance of an
infinite parallel plate channel is given by
1
Rhyd = 12 L(t) , (1.7)
h3 w
with being the viscosity of the fluid1 and w being the width of a finite section in the
y-direction. Eq. (1.5) becomes an ordinary first order differential equation for the position
of the meniscus. The solution is stated in [1, Eq. (5.34)] and reproduced below
s
t 3h
L(t) = h , adv . (1.8)
adv cos()
L
L = , (1.9)
h
t
t = . (1.10)
adv
1
Whole blood at 37 C and 1 atm has a viscosity of blood = 3.26 0.43 103 Pa s
(http://www.clinchem.org/cgi/content/abstract/42/8/1189)
1.3. A CONSERVATIVE LEVEL SET METHOD FOR TWO PHASE FLOW 5
The level set function is positive on one side of the interface, (r) > 0, and negative on
the other, (r) < 0. To represent the density and the viscosity in the two phases one has
to use a Heaviside function (
0, < 0,
H() = (1.16)
1, > 0.
In numerical simulations the abrupt jump in the fields due to Eq. (1.16) will cause insta-
bilities in the Finite Element Method. Therefore a smeared out Heaviside function is used
instead e.g.
0,
< ,
1 1
Hsm () = 2 + 2 + 2 sin( ), , (1.17)
1, > ,
2
Note that this is a general introduction to the level set method. The actual level set method used in
this report follows the 21 -level set.
6 CHAPTER 1. THEORY
Figure 1.3: Graphical representation of the level set function. Imagine a forest fire where
the gray areas represents trees and the edge is the burning fire front. Time then propagates
as one moves to the right in the upper part of the figure and the fire front eats into the
trees. This two phase problem (trees/burnt tress) is modeled with a level set function
shown below in the figure. Observe that the propagation of the fire front is given as a
level set of the level set function.
where corresponds to half the thickness of the interface3 . The interface thickness shall
depend on the grid size in the mesh, such that it is sufficiently resolved. One can now
define a new level set function
(r) = Hsm ((r)). (1.18)
The level set function in Eq. (1.18) has the advantage that it is straightforward to represent
the density and viscosity in the two different phases. One simply defines scalar fields that
use the level set function to distinguish between the phases
where the i and i is the density and viscosity of phase i = 1, 2. The interface is in
1
this case given as the -level set of Eq. (1.18). For convenience the tilde is dropped and
2
throughout the rest of this report the level set function is interpreted as given in Eq. (1.18).
When operating with interfaces it is necessary to work with the interface normal vector
3
Note again that the Heaviside function in Eq. (1.17) is different from the one used in this report. It
just serves as an example.
1.3. A CONSERVATIVE LEVEL SET METHOD FOR TWO PHASE FLOW 7
and interface curvature. These two quantities are obtained from the level set function
gradient and the divergence of the gradient
nl = , (1.21a)
||
= nl = , (1.21b)
||
where nl is the normal vector of the level set function and is the curvature. Notice that
these two quantities are defined in all of the domain, , and not just on the interface and
domain boundary, . In order to maintain the thickness of the interface an interme-
diate step has to be performed in the numerical simulation. This step adds an artificial
compression and are implemented by solving the conservation law
+ f () = 0, (1.22)
where is an artificial time and f is the artificial flux. As Eq. (1.22) shall work in the
regions where 0 < < 1 and in the normal direction of the interface, the artificial flux is
chosen to be
f = (1 )nl = (1 ) . (1.23)
||
To avoid discontinuities at the interface, a small amount of viscosity/diffusion is added to
Eq. (1.22)
+ f () = 2 , (1.24)
where is the viscosity. When implementing Eq. (1.13) and Eq. (1.24) in COMSOL it is
possible to combine the equations to one - setting the artificial time equal to the real time
- such that the resulting equation for the level set function becomes
where the time, t, is the real time and the divergence of the artificial flux has been moved
to the right-hand-side. Notice that this equation resembles a continuity equation for .
The term with the Laplacian in Eq. (1.25) can be thought of as a kind of diffusion term,
trying to enlarge the width of the interface. To counteract this diffusion one has the term
with the divergence of the flux. These two terms are in equilibrium when the interface has
a thickness of . Keeping the thickness of the interface constant is achieved. Eq. (1.25)
can be written in conservative form
t + v + (1 ) = 0. (1.26)
||
Eq. (1.26) is on the form that COMSOL uses for the numerical implementation. The
equation is coupled to the Navier-Stokes equation through the level set function and the
velocity field. The Navier-Stokes equation reads
t v + (v )v = + (r rl )nl , (1.27)
8 CHAPTER 1. THEORY
where is the surface tension. The stress tensor, , is for an incompressible fluid given
by
ik = pik + (k vi + i vk ), (1.28)
where index notation has been used. The Kronecker delta, ik , is given by
(
0 if i 6= k
ik = . (1.29)
1 if i = k
Finally, it is possible to express the Dirac delta function as the absolute value of the
||
x x
Figure 1.4: The graph to the left is the level set function, , in two dimensions. Notice the
transition from zero to unity. The absolute value of the gradient of the level set function,
||, is displayed to the right. Observe that this is a good approximation to the Dirac
delta function at the interface.
That Eq. (1.30) is a good approximation is intuitively clear when looking at Eq. (1.17).
The absolute value of the gradient is zero for points away from the interface since the level
set function is constant. As one reaches the interface the absolute value of the gradient
1
increases, has maximum exactly at the -contour of the level set function and falls off
2
again, see Fig. 1.4. This resembles a Dirac delta function.This concludes the introduction
to the level set function. This chapter is based on [5] and [6].
Chapter 2
Numerical implementation
This chapter describes the numerical implementation of the physical equations into COM-
SOL. First the model is set up with the necessary approximations. Then the equations
are rewritten in order to implement them in the correct form. In numerics it is possible
to formulate the equations and boundary conditions in strong or weak form. The strong
form is what one would think of as the normal way to write the equations. The weak form
is a special integral formulation of the equations that in some cases are more suited for
numerical simulations. It provides the user with more possibilities to control and enforce
given constraints. Nevertheless, the weak form is not as accurate as the strong form. Both
forms are used to solve the present problem.
= (x, y, t) (2.1)
vx = vx (x, y, t) (2.2)
vy = vy (x, y, t) (2.3)
p = p(x, y, t) (2.4)
9
10 CHAPTER 2. NUMERICAL IMPLEMENTATION
y
3
y0
4 2
O 1 x0 x
where p is the pressure. Notice that an Eulerian reference frame is used. The velocity
vector field is
v(x, y, t) = (vx (x, y, t), vy (x, y, t)). (2.5)
Each of the four fields has a corresponding governing equation. The level set function
is governed by Eq. (1.26) corresponding to the numerical extension of the convection
equation. The Navier-Stokes equation governs the two components of the velocity field.
Finally the continuity equation for mass conservation governs the pressure field. For
incompressible fluids the continuity equation reads
i vi = 0. (2.6)
This gives a set of four coupled linear/non-linear differential equations. COMSOL uses a
special form when solving differential equations [2]
and nb is the normal vector on the domain boundary. The ui s are Lagrange multipli-
ers. These Lagrange multipliers are only relevant when the Rui s are different from zero
i.e. Rui 6= 0. More generally speaking one can create a Lagrange multiplier for each con-
straint the problem is subjected to. The Rui could e.g. be equal to one of the velocity
components Rui = vx on a specific boundary segment. This means that the x-component
of the velocity must be zero on that domain boundary part. Looking at Eq. (2.8) one
observes that the derivative with respect to x-component of the velocity is different from
zero. It is unity. COMSOL has the freedom to choose the Lagrange multiplier - on this
special part of the boundary - such that Eq. (2.8) is fulfilled for any Gui . The conclusion
is that if a Lagrange multiplier is introduced for a given constraint in the problem then
the Gui is irrelevant and can be left out of the treatment. One has thereby eliminated a
constraint in the expense of another equation for the Lagrange multiplier.
In the Navier-Stokes equation, Eq. (1.27), one can with advantage use the weak formulation
to include the force density from the surface tension. Rewriting the remaining terms yields
For the pressure one has the liberty to choose between two formulations. One where
is non-zero and one where F is non-zero. In this context F is chosen to be non-zero
0 = i vi (2.14)
dp = 0
p = 0 . (2.15)
Fp = i vi
12 CHAPTER 2. NUMERICAL IMPLEMENTATION
For the level set function Eq. (1.26) is on the correct form and it is straightforward to
identify the different variables
i
t + i vi + (1 ) i = 0 (2.16)
||
d = 1
= v + (1 ) || . (2.17)
F = 0
This accounts for all the strong contributions in the numerical implementation concerning
the domain, . The variables are given in the fem.equ.da, fem.equ.ga and fem.equ.f
COMSOL structs and summarized in Table 2.1.
ui vx vy p
d ui 0 1
ui [xx , xy ] [yx , yy ] 0 v + (1 ) ||
Fui (vi i )vx (vi i )vy vi i 0
Table 2.1: The variables for the strong form in the domain implemented in COMSOL.
Weak form
For the domain the only weak contribution comes from the Navier-Stokes equation. There-
fore COMSOL only needs two equations for the velocity components. The weak contribu-
tion stems from the term including the surface tension reads
(r rl )nl . (2.18)
One can multiply Eq. (2.18) with a test/basis function and integrate over the domain.
Using Greens theorem this integral can be divided up into a integral over the domain
and one over the boundary. It is the integral over the domain that defines the weak
contribution. Without going into the details the weak contributions are simply stated
below
(x v x )nl,x + (y v x )nl,y ||nl,x , for x, (2.19)
(x v y )nl,x + (y v y )nl,y ||nl,y , for y. (2.20)
where the v i s are the so-called test/basis functions used by COMSOL. These equations
are given in the fem.equ.weak struct.
which gives a total of 16 variables. One Lagrange multiplier is introduced for 2 in order
to enforce the contact angle condition on this boundary. This results in a weak equation
on this boundary. The integral along the boundary from the transformation of Eq. (2.18)
is also implemented as a weak equation.
Strong form
For the first boundary, 1 , the assumptions are free flow, a pressure of zero and a constant
value of the level set function of one.
For the second boundary, 2 , the component of the velocity normal to the wall, vx ,
has to be zero. The no-slip condition is relaxed such that the component of the velocity
parallel to the wall are free. No conditions are applied to the pressure and the level set
function.
Boundary three, 3 , has free flow like boundary one. Different simulations are pre-
formed - some with zero pressure and some with a back pressure, p. A constant value
of the level set function of zero are assumed.
The last boundary, 4 , is the symmetry boundary. The condition for symmetry is
that the component of the velocity normal to the boundary, vx , is zero.
COMSOL uses the struct fem.bnd.r for the R values. The values are summarized in
Table 2.2. The strong form on the domain boundary is ultimately converted to weak form
Ru ik 1 2 3 4
vx 0 vx 0 vx
vy 0 0 0 0
p p 0 p p 0
1 0 0
Table 2.2: The R variables implemented in COMSOL. The back pressure, p, is the
Young-Laplace pressure for the given cylindrical meniscus such that no capillary rise is
expected.
in COMSOL. Nevertheless, the R variables are given and then by the command flform
converted from fem.bnd.r to fem.bnd.constr. This means that the G variables at the same
time are converted to weak equations. No G variables are therefore given.
Weak form
The general Neumann condition is given in Eq. (2.8). In weak form this corresponds to
Z
u i Gui dr. (2.22)
The weak equation is then the integrand in Eq. (2.22). On boundary segment two, 2 ,
a contact angle of has to be applied. This boundary condition can be expressed by the
dot product between the level set normal vector at the interface and the boundary normal
vector
nl nb = cos(). (2.23)
14 CHAPTER 2. NUMERICAL IMPLEMENTATION
If one finds the Gui that fulfills Eq. (2.8) and then convert the constraint to weak form by
use of Eq. (2.22) the result is
(y cos()), (2.26)
, (2.27)
where and are test/basis functions for the Lagrange multiplier and the level set
function. The weak equations are given in fem.bnd.weak.
Chapter 3
Results
The simulations carried out considers the capillary pump and uses the COMSOL script
shown in the appendix. To verify that the script is able to keep a certain contact angle
at the boundary, the interface is started as a cosine, which is unphysical due to the
equations of the system. See Fig. 3.1. Besides the unperturbed interface a back pressure -
corresponding to the Young-Laplace pressure - is added in order to avoid propagation of the
interface. As time goes the unperturbed interface relaxes through some small oscillations.
It obtains the correct shape with respect to the contact angle. In figure 3.2 is shown the
water-air interface for three different times. The ends in top and bottom are open and
have a zero pressure. It is therefore the pressure difference due to the surface tension,
which causes the dynamics. The interface starts to be linear, but as time goes it finds the
contact angle, , at the wall and an angle of 90 at the center of the channel, and starts to
propagate. The figure considers a very short timescale and thus a Poiseuille flow has not
been fully developed. The capillary propagation length can therefore not be compared to
the analytical solution given in Eq. (1.8). In figure 3.3 is plotted the capillary length, L(t),
as a function of time, t, and for clarity also the analytical capillary length is plotted. In
the time t [0; 0.5] 107 s the water-air interface accelerates to an almost linear velocity
and at the time t = 1 107 s the interface hits the end of the channel and the calculation
is no more valid. It is expected that for further times the capillary length will follow the
analytical solution. It is important to stress that the simulation is not yet verified until a
simulation for longer times has been executed.
15
16 CHAPTER 3. RESULTS
Figure 3.1: Relaxing of a cosine-perturbed water-air interface. The ends in top and bottom
are closed and a back pressure corresponding to the Young-Laplace pressure is added at
the top boundary. The geometry is symmetric and thus the boundary at x = 0 corresponds
to the middle of the channel.
17
Figure 3.2: Capillary propagation of water-air interface. The ends in top and bottom are
open and have a zero pressure. The geometry is symmetric and thus the boundary at
x = 0 corresponds to the middle of the channel.
18 CHAPTER 3. RESULTS
7
x 10
8
5
L(t)
1 numerical
analytical
0
0 0.5 1 1.5 2
7
x 10
t
Figure 3.3: Capillary length, L(t), as a function of time, t. Both the numerical and
analytic results are shown, even though they are not comparable.
Chapter 4
Conclusions
A COMSOL script for simulating a two phase flow interface by using a conservative level
set method has been made. It is not yet verified by comparing to analytical solutions, but
it does act intuitively correct. It succeeds to keep a correct contact angle at the boundaries,
which has been the most difficult part. The report does not contain very many results,
but mainly describes the theory and implementation of the level set method. It has been
far from trivial to implement the method, but the promising strength of the method is
worth the work done.
19
20 CHAPTER 4. CONCLUSIONS
[3] http://www.hemocue.com.
[4] http://www.mic.dtu.dk/Research/BCMS/MIFTS.aspx.
[5] E. Olsson and G. Kreiss. A conservative level set method for two phase flow. Journal
of Computational Physics, 210(1):225246, 2005.
[6] Peter Smereka and J.A. Sethian. Level set methods for fluid interfaces. Annual Review
of Fluid Mechanics, 35:341372, 2003.
23