1 
\section{Level Set Method} 
2 

3 
The Level Set Method is used for tracking interfaces between two different types of fluids, which may have different physical parameter values for density or viscosity. The interface is represented by a signed distance function, $\phi(x)$, where the isocontour at $\phi(x)=0$ is used to defined the interface. A point in the domain can then be determined on which side of the interface it resides, based on the local sign of $\phi(x)$; for example positive $\phi(x)$ on one side of the interface and negative $\phi(x)$ on the other. Parameters values such as density and viscosity can then be defined for the two different mediums. The Level Set Method consists of two procedures, the advection and reinitialization of the signed distance function, $\phi$. The LevelSet class can be used in conjunction with the StokesProblemCartesian class for solving computational fluid dynamics problems involving the tracking of the interface. The advantage of the Level Set Method is that it can be used to track surfaces that break apart or intersect. Also, the Level Set Method avoids the need for remeshing, which is required by the LagrangianEulerian (ALE) method. 
4 

5 
% An example of using the Level Set Method is described in the tutorial Chapter, Section %\ref{LEVELSET CHAP}. 
6 

7 
\subsection{Solution Method} 
8 

9 
The displacement of the interface at the zero isocontour of $\phi(x)$ is calculated each timestep by using the velocity field. This is achieved my solving the advection equation: 
10 
% 
11 
\begin{equation} 
12 
\frac{\partial \phi}{\partial t} + \vec{v} \cdot \nabla \phi = 0, 
13 
\label{ADVECTION MODELS} 
14 
\end{equation} 
15 
% 
16 
where $\vec{v}$ is the velocity field. The advection equation is solved using a TaylorGalerkin scheme with the presence of diffusion; by expanding $\phi$ into a Taylor series: 
17 
% 
18 
\begin{equation} 
19 
\phi^{+} \simeq \phi^{} + dt\frac{\partial \phi^{}}{\partial t} + \frac{dt^2}{2}\frac{\partial^{2}\phi^{}}{\partial t^{2}}, 
20 
\label{TAYLOR EXPANSION MODELS} 
21 
\end{equation} 
22 
% 
23 
then by inserting 
24 
% 
25 
\begin{equation} 
26 
\frac{\partial \phi^{}}{\partial t} =  \vec{v} \cdot \nabla \phi^{}, 
27 
\label{INSERT ADVECTION MODELS} 
28 
\end{equation} 
29 
% 
30 
and 
31 
% 
32 
\begin{equation} 
33 
\frac{\partial^{2} \phi^{}}{\partial t^{2}} = \frac{\partial}{\partial t}(\vec{v} \cdot \nabla \phi^{}) = \vec{v}\cdot \nabla (\vec{v}\cdot \nabla \phi^{}), 
34 
\label{SECOND ORDER MODELS} 
35 
\end{equation} 
36 
% 
37 
into Equation (\ref{TAYLOR EXPANSION MODELS}), the calculation of the level set function is given by: 
38 
% 
39 
\begin{equation} 
40 
\phi^{+} = \phi^{}  dt\vec{v}\cdot \nabla \phi^{} + \frac{dt^2}{2}\vec{v}\cdot \nabla (\vec{v}\cdot \nabla \phi^{}). 
41 
\label{TAYLOR GALERKIN MODELS} 
42 
\end{equation} 
43 

44 
If $\nabla \cdot \vec{v}=0$ is assumed, then the calculation of the second order derivatives in Equation (\ref{TAYLOR GALERKIN MODELS}) can be avoided. 
45 

46 
As the computation of the distance function progresses, it becomes distorted, and so it needs to be updated in order to stay regular \cite{SUSSMAN1994}. This process is known as the reinitialization procedure. The aim is to iteratively find a solution to the reinitialization equation: 
47 
% 
48 
\begin{equation} 
49 
\frac{\partial \psi}{\partial \tau} + sign(\phi)(1  \nabla \psi) = 0. 
50 
\label{REINITIALISATION MODELS} 
51 
\end{equation} 
52 
% 
53 
where $\psi$ shares the same level set with $\phi$, $\tau$ is pseudo time, and $sign(\phi)$ is the smoothed sign function. This equation is solved to meet the definition of the level set function, $\lvert \nabla \psi \rvert = 1$; the normalization condition. Equation (\ref{REINITIALISATION MODELS}) can be rewritten in a similar form to the advection equation: 
54 
% 
55 
\begin{equation} 
56 
\frac{\partial \psi}{\partial \tau} + \vec{w} \cdot \nabla \psi = sign(\phi), 
57 
\label{REINITIALISATION2 MODELS} 
58 
\end{equation} 
59 
% 
60 
where 
61 
% 
62 
\begin{equation} 
63 
\vec{w} = sign(\phi)\frac{\nabla \psi}{\nabla \psi}. 
64 
\label{REINITIALISATION3 MODELS} 
65 
\end{equation} 
66 
% 
67 
$\vec{w}$ is the characteristic velocity pointing outward from the free surface. Equation (\ref{REINITIALISATION2 MODELS}) can be solved by a similar technique to what was used in the advection step, using the TaylorGalerkin procedure. 
68 
When the distance function, $\phi$, is calculated, the physical parameters, density and viscosity, are updated using the sign of $\phi$. The region along the interface is assumed to be of finite thickness of $\alpha h$, where $h$ is the size of the elements in the computational mesh and $\alpha$ is a smoothing parameter. The parameters are updated by the following expression: 
69 
% 
70 
\begin{equation} 
71 
P = 
72 
\left \{ \begin{array}{l} 
73 
P\hackscore{1} \hspace{5cm} where \ \ \psi <  \alpha h \\ 
74 
P\hackscore{2} \hspace{5cm} where \ \ \psi > \alpha h \\ 
75 
(P\hackscore{2}  P\hackscore{1}) \psi/2\alpha h + (P\hackscore{1} + P\hackscore{2})/2 \ \ \ \ \ \ where \ \ \psi < \alpha h. 
76 
\end{array} 
77 
\right. 
78 
\label{UPDATE PARAMETERS MODELS} 
79 
\end{equation} 
80 
% 
81 
where the subscripts $1$ and $2$ denote the different fluids. 
82 

83 

84 
\subsection{Functions} 
85 

86 
\begin{classdesc}{LevelSet}{domain, func, reinit\_max, reinit\_each, tolerance, smooth} 
87 
opens the LevelSet \index{Level Set} on the \Domain domain. \var{func} defines the initial Level Set function representing the interface between two fluids. \var{reinit\_max} sets the maximum number of iterations to satisfy the normal condition, $\nabla \phi=1$, during the reinitialization of the Level Set function. \var{reinit\_each} sets the frequency of reinitialization for a number of timesteps. \var{tolerance} sets the convergence tolerance to satisfy the normal condition during the reinitialization of the Level Set function. \var{smooth} sets the bandwidth of size 2$\alpha h$ along the interface to smooth the physical parameters of density and viscosity; $h$ is the size of the elements in the mesh and $\alpha$ is the smoothing parameter, usually set to 1. 
88 
\end{classdesc} 
89 

90 
\begin{methoddesc}[LevelSet]{update\_parameter}{par1, par2} 
91 
updates the physical parameters using the sign of $\phi$. \var{par1} and \var{par2} are the physical parameter values for fluid1 and fluid2 respectively. Usually this method is called twice during each timestep to update the density and viscosity of the two fluids. 
92 
\end{methoddesc} 
93 

94 
\begin{methoddesc}[LevelSet]{update\_phi}{vel, dt, t\_step} 
95 
updates the Level Set function. It performs the advection and reinitialization procedures. \var{vel} is the velocity field of the fluid domain, \var{dt} is the timestep size, and \var{t\_step} is the current timestep to determine when to reinitialize. 
96 
\end{methoddesc} 