Diff of /trunk/doc/user/levelset.tex

revision 2120 by lgraham, Tue Dec 2 06:21:49 2008 UTC revision 2881 by jfenwick, Thu Jan 28 02:03:15 2010 UTC
# Line 1  Line 1
1
2  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3  %  %
4  % Copyright (c) 2003-2008 by University of Queensland  % Copyright (c) 2003-2010 by University of Queensland
5  % Earth Systems Science Computational Center (ESSCC)  % Earth Systems Science Computational Center (ESSCC)
6  % http://www.uq.edu.au/esscc  % http://www.uq.edu.au/esscc
7  %  %
# Line 15  Line 15
15  \section{Rayleigh-Taylor Instability}  \section{Rayleigh-Taylor Instability}
16  \label{LEVELSET CHAP}  \label{LEVELSET CHAP}
17
18  In this chapter we will implement the Level Set Method in Escript for tracking the interface between two fluids for Computational Fluid Dynamics (CFD). The method is tested with a Rayleigh-Taylor Instability problem, which is an instability of the interface between two fluids with differing densities. \\  In this section we will implement the Level Set Method in Escript for tracking the interface between two fluids for Computational Fluid Dynamics (CFD). The method is tested with a Rayleigh-Taylor Instability problem, which is an instability of the interface between two fluids with differing densities. \\
19  Normally in Earth science problems two or more fluids in a system with different properties are of interest. For example, lava dome growth in volcanology, with the contrast of the two mediums as being lava and air. The interface between the two mediums is often referred to as a free surface (free boundary value problem); the problem arises due to the large differences in densities between the lava and air, with their ratio being around 2000, and so the interface between the two fluids move with respect to each other.    Normally in Earth science problems two or more fluids in a system with different properties are of interest. For example, lava dome growth in volcanology, with the contrast of the two mediums as being lava and air. The interface between the two mediums is often referred to as a free surface (free boundary value problem); the problem arises due to the large differences in densities between the lava and air, with their ratio being around 2000, and so the interface between the two fluids move with respect to each other.
20  %and so the lava with the much higher density is able to move independently with respect to the air, and the interface between the two fluids is not constrained.  %and so the lava with the much higher density is able to move independently with respect to the air, and the interface between the two fluids is not constrained.
21  There are a number of numerical techniques to define and track the free surfaces. One of these methods, which is conceptually the simplest, is to construct a Lagrangian grid which moves with the fluid, and so it tracks the free surface. The limitation of this method is that it cannot track surfaces that break apart or intersect. Another limitation is that the elements in the grid can become severely distorted, resulting in numerical instability. The Arbitrary Lagrangian-Eulerian (ALE) method for CFD in moving domains is used to overcome this problem by remeshing, but there is an overhead in computational time, and it results in a loss of accuracy due to the process of mapping the state variables every remesh by interpolation.  There are a number of numerical techniques to define and track the free surfaces. One of these methods, which is conceptually the simplest, is to construct a Lagrangian grid which moves with the fluid, and so it tracks the free surface. The limitation of this method is that it cannot track surfaces that break apart or intersect. Another limitation is that the elements in the grid can become severely distorted, resulting in numerical instability. The Arbitrary Lagrangian-Eulerian (ALE) method for CFD in moving domains is used to overcome this problem by remeshing, but there is an overhead in computational time, and it results in a loss of accuracy due to the process of mapping the state variables every remesh by interpolation.
# Line 24  There is a technique to overcome these l Line 24  There is a technique to overcome these l
24  %  %
25  \begin{figure}  \begin{figure}
26  \center  \center
27  \scalebox{0.7}{\includegraphics{figures/unitcircle.eps}}  \scalebox{0.8}{\includegraphics{figures/unitcircle}}
28  \caption{Implicit representation of the curve $x^2 + y^2 = 1$.}  \caption{Implicit representation of the curve $x^2 + y^2 = 1$.}
29  \label{UNITCIRCLE}  \label{UNITCIRCLE}
30  \end{figure}  \end{figure}
# Line 86  into Equation (\ref{TAYLOR EXPANSION}) Line 86  into Equation (\ref{TAYLOR EXPANSION})
86
87
88
89  \subsection{Governing Equations for Fluid Flow}  %\subsection{Governing Equations for Fluid Flow}
90
91  The fluid dynamics is governed by the Stokes equations. In geophysical problems the velocity of fluids are low; that is, the inertial forces are small compared with the viscous forces, therefore the inertial terms in the Navier-Stokes equations can be ignored. For a body force $f$ the governing equations are given by:  %The fluid dynamics is governed by the Stokes equations. In geophysical problems the velocity of fluids are low; that is, the inertial forces are small compared with the viscous forces, therefore the inertial terms in the Navier-Stokes equations can be ignored. For a body force $f$ the governing equations are given by:
92  %  %
93    %
94  \nabla \cdot (\eta(\nabla \vec{v} + \nabla^{T} \vec{v})) - \nabla p = -f,  %\nabla \cdot (\eta(\nabla \vec{v} + \nabla^{T} \vec{v})) - \nabla p = -f,
95  \label{GENERAL NAVIER STOKES}  %\label{GENERAL NAVIER STOKES}
96    %
97  %  %
98  with the incompressibility condition  %with the incompressibility condition
99  %  %
100    %
101  \nabla \cdot \vec{v} = 0.  %\nabla \cdot \vec{v} = 0.
102  \label{INCOMPRESSIBILITY}  %\label{INCOMPRESSIBILITY}
103    %
104  %  %
105  where $p$, $\eta$ and $f$ are the pressure, viscosity and body forces, respectively.  %where $p$, $\eta$ and $f$ are the pressure, viscosity and body forces, respectively.
106  Alternatively, the Stokes equations can be represented in Einstein summation tensor notation (compact notation):  %Alternatively, the Stokes equations can be represented in Einstein summation tensor notation (compact notation):
107  %  %
108    %
109  -(\eta(v\hackscore{i,j} + v\hackscore{j,i})),\hackscore{j} - p,\hackscore{i} = f\hackscore{i},  %-(\eta(v\hackscore{i,j} + v\hackscore{j,i})),\hackscore{j} - p,\hackscore{i} = f\hackscore{i},
110  \label{GENERAL NAVIER STOKES COM}  %\label{GENERAL NAVIER STOKES COM}
111    %
112  %  %
113  with the incompressibility condition  %with the incompressibility condition
114  %  %
115    %
116  -v\hackscore{i,i} = 0.  %-v\hackscore{i,i} = 0.
117  \label{INCOMPRESSIBILITY COM}  %\label{INCOMPRESSIBILITY COM}
118    %
119  %  %
120  The subscript comma $i$ denotes the derivative of the function with respect to $x\hackscore{i}$. A linear relationship between the deviatoric stress $\sigma^{'}\hackscore{ij}$ and the stretching $D\hackscore{ij} = \frac{1}{2}(v\hackscore{i,j} + v\hackscore{j,i})$ is defined as \cite{GROSS2006}:  %The subscript comma $i$ denotes the derivative of the function with respect to $x\hackscore{i}$. A linear relationship between the deviatoric stress $\sigma^{'}\hackscore{ij}$ and the stretching $D\hackscore{ij} = \frac{1}{2}(v\hackscore{i,j} + v\hackscore{j,i})$ is defined as \cite{GROSS2006}:
121  %  %
122    %
123  \sigma^{'}\hackscore{ij} = 2\eta D^{'}\hackscore{ij},  %\sigma^{'}\hackscore{ij} = 2\eta D^{'}\hackscore{ij},
124  \label{STRESS}  %\label{STRESS}
125    %
126  %  %
127  where the deviatoric stretching $D^{'}\hackscore{ij}$ is defined as  %where the deviatoric stretching $D^{'}\hackscore{ij}$ is defined as
128  %  %
129    %
130  D^{'}\hackscore{ij} = D^{'}\hackscore{ij} - \frac{1}{3}D\hackscore{kk}\delta\hackscore{ij}.  %D^{'}\hackscore{ij} = D^{'}\hackscore{ij} - \frac{1}{3}D\hackscore{kk}\delta\hackscore{ij}.
131  \label{DEVIATORIC STRETCHING}  %\label{DEVIATORIC STRETCHING}
132    %
133  %  %
134  where $\delta\hackscore{ij}$ is the Kronecker $\delta$-symbol, which is a matrix with ones for its diagonal entries ($i = j$) and zeros for the remaining entries ($i \neq j$). The body force $f$ in Equation (\ref{GENERAL NAVIER STOKES COM}) is the gravity acting in the $x\hackscore{3}$ direction and is given as $f = -g \rho \delta\hackscore{i3}$.  %where $\delta\hackscore{ij}$ is the Kronecker $\delta$-symbol, which is a matrix with ones for its diagonal entries ($i = j$) and zeros for the remaining entries ($i \neq j$). The body force $f$ in Equation (\ref{GENERAL NAVIER STOKES COM}) is the gravity acting in the $x\hackscore{3}$ direction and is given as $f = -g \rho \delta\hackscore{i3}$.
135  The Stokes equations is a saddle point problem, and can be solved using a Uzawa scheme. A class called StokesProblemCartesian in Escript can be used to solve for velocity and pressure.  %The Stokes equations is a saddle point problem, and can be solved using a Uzawa scheme. A class called StokesProblemCartesian in Escript can be used to solve for velocity and pressure.
136  In order to keep numerical stability, the time-step size needs to be below a certain value, known as the Courant number. The Courant number is defined as:  %In order to keep numerical stability, the time-step size needs to be below a certain value, known as the Courant number. The Courant number is defined as:
137  %  %
138    %
139  C = \frac{v \delta t}{h}.  %C = \frac{v \delta t}{h}.
140  \label{COURANT}  %\label{COURANT}
141    %
142  %  %
143  where $\delta t$, $v$, and $h$ are the time-step, velocity, and the width of an element in the mesh, respectively. The velocity $v$ may be chosen as the maximum velocity in the domain. In this problem the Courant number is taken to be 0.4 \cite{BOURGOUIN2006}.  %where $\delta t$, $v$, and $h$ are the time-step, velocity, and the width of an element in the mesh, respectively. The velocity $v$ may be chosen as the maximum velocity in the domain. In this problem the Courant number is taken to be 0.4 \cite{BOURGOUIN2006}.
144
145
146  \subsection{Reinitialization of Interface}  \subsection{Reinitialization of Interface}
# Line 199  $\vec{w}$ is the characteristic velocity Line 199  $\vec{w}$ is the characteristic velocity
199  \label{REINITIAL CONVERGE}  \label{REINITIAL CONVERGE}
200
201  %  %
202  where $\epsilon$ is the convergence tolerance. Normally, the reinitialization procedure is performed every third time-step of solving the Stokes equation.  where $\epsilon \hackscore{\psi}$ is the convergence tolerance. Normally, the reinitialization procedure is performed every third time-step of solving the Stokes equation.
203
204  The mid-point technique works provided that the left-hand side of Equations (\ref{REINITIAL MIDPOINT2}) and (\ref{REINITIAL MIDPOINT3}) is a lumped mass matrix. Alternatively, for a one-step procedure, the reinitialization equation can be given by:  The mid-point technique works provided that the left-hand side of Equations (\ref{REINITIAL MIDPOINT2}) and (\ref{REINITIAL MIDPOINT3}) is a lumped mass matrix. Alternatively, for a one-step procedure, the reinitialization equation can be given by:
205  %  %
# Line 212  The accuracy of $\phi$ is only needed wi Line 212  The accuracy of $\phi$ is only needed wi
212  %  %
213  \begin{figure}  \begin{figure}
214  \center  \center
215  \scalebox{0.45}{\includegraphics{figures/LevelSetFlowChart.eps}}  \scalebox{0.5}{\includegraphics{figures/LevelSetFlowChart}}
216  \caption{Flow chart of level set procedure \cite{LIN2005}.}  \caption{Flow chart of Level Set Method procedure \cite{LIN2005}.}
217  \label{LEVELSET FLOWCHART}  \label{LEVELSET FLOWCHART}
218  \end{figure}  \end{figure}
219  %  %
# Line 235  Further work is needed in the reinitiali Line 235  Further work is needed in the reinitiali
235
236  \subsection{Benchmark Problem}  \subsection{Benchmark Problem}
237
238  The Rayleigh-Taylor instability problem is used as a benchmark to validate CFD implementations \cite{VANKEKEN1997}. Figure \ref{RT2DSETUP} shows the setup of the problem. A rectangular domain with two different fluids is considered, with the greater density fluid on the top and the lighter density fluid on the bottom. The viscosities of the two fluids are equal (isoviscous). An initial perturbation is given to the interface of $\phi=0.02cos(\frac{\pi x}{\lambda}) + 0.2$. The aspect ratio $\lambda = L/H = 0.9142$ is chosen such that it gives the greatest disturbance of the fluids.  The Rayleigh-Taylor instability problem is used as a benchmark to validate CFD implementations \cite{VANKEKEN1997}. Figure \ref{RT2DSETUP} shows the setup of the problem. A rectangular domain with two different fluids is considered, with the greater density fluid on the top and the lighter density fluid on the bottom. The viscosities of the two fluids are equal (isoviscous). An initial perturbation is given to the interface of $\phi=0.02cos(\frac{\pi x}{\lambda}) + 0.2$. The aspect ratio $\lambda = L/H = 0.9142$ is chosen such that it gives the greatest disturbance of the fluids. The fluid properties is chosen such that the compositional Rayleigh number is equal to one:
239    %
240
241    R\hackscore{b} = \frac{\Delta \rho H^{3}}{\kappa \eta} = 1.
242    \label{RAYLEIGH NUMBER}
243
244    %
245    where $\Delta \rho$ is the difference in density between the two fluids, $\eta$ is the viscosity and $\kappa$ is the thermal diffusivity; arbitrarily taken equal to 1 for a non thermal'' case.
246    %
247  %  %
248  \begin{figure}  \begin{figure}
249  \center  \center
250  \scalebox{0.7}{\includegraphics{figures/RT2Dsetup.eps}}  \scalebox{0.7}{\includegraphics{figures/RT2Dsetup}}
251  \caption{Parameters, initial interface and boundary conditions for the Rayleigh-Taylor instability problem. The interface is defined as $\phi=0.02cos(\frac{\pi x}{\lambda}) + 0.2$. The fluids have been assigned different densities and equal viscosity (isoviscous) \cite{BOURGOUIN2006}.}  \caption{Parameters, initial interface and boundary conditions for the Rayleigh-Taylor instability problem. The interface is defined as $\phi=0.02cos(\frac{\pi x}{\lambda}) + 0.2$. The fluids have been assigned different densities and equal viscosity (isoviscous) \cite{BOURGOUIN2006}.}
252  \label{RT2DSETUP}  \label{RT2DSETUP}
253  \end{figure}  \end{figure}
254    %
255    %
256    The following PYTHON code is for the Rayleigh-Taylor instability problem, which is available in the example directory as 'RT2D.py'. This script uses the 'StokesProblemCartesian' class for solving the Stokes equation, along with the incompressibility condition. A class called 'LevelSet' is also used, which performs the advection and reinitialization procedures to track the movement of the interface of the fluids. The details and use of these classes are described in Chapter \ref{MODELS CHAPTER} (Models Chapter).
257
258  %The Level Set Method can be applied to many areas of science, for example simulating subduction zones in geophysics, motion of bubbles, and flame propagation. Its also used in image processing. However, the Level Set Method does have limitations. The level set function can still become irregular after reinitialisation, leading to artifacts in the simulations, requiring more thought into the implementation of the reinitialisation step.  The script starts off by importing the necessary classes. The physical properties of the two fluids are defined, such as density and viscosity.
259    Acceleration due to gravity is taken as 10.0 $ms^{-2}$.
260    Solver settings are set for solving the Stokes problem, with the number of time-steps, solver tolerance, maximum solver iterations,
261    and the option to use the Uzawa scheme or not; the default solver is the PCG solver. A regular mesh is defined with 200$\times$200 elements.
262    Level set parameters are set for the reinitialization procedure, such as the convergence tolerance, number of
263    reinitialization steps, the frequency of the reinitialization, for example, every third time-step, and the smoothing
264     parameter to smooth the physical properties across the interface.
265     A no-slip boundary condition is set for the top and bottom of the domain, while on the left and right-hand sides
266     there is a slip condition.
267    The initial interface between the two fluids is defined as in Figure \ref{RT2DSETUP}. Instances of the StokesProblemCartesian and LevelSet class are created.
268    The iteration throughout the time-steps involves the update of the physical parameters of the fluids; the initialization of
269    the boundary conditions, viscosity, and body forces; the solving of the Stokes problem for velocity and pressure; then the
270    level set procedure.
271    The output of the level set function, velocity and pressure is saved to file.
272    The time-step size is selected based on the Courant condition.
273    Due to the number of elements in the computational mesh, the simulation may take a long time to complete on a desktop computer,
274    so it is preferable to run it on the super computer.
275    At present, the fine mesh is required to capture the details of the fluid motion and for numerical stability.
276    %
277  \begin{python}  \begin{python}
278
279  from esys.escript import *  from esys.escript import *
280  import esys.finley  import esys.finley
281  from esys.escript.models import StokesProblemCartesian  from esys.escript.models import StokesProblemCartesian
282  from esys.finley import finley  from esys.finley import finley
283    from esys.finley import Rectangle
284  from LevelSet import *  from LevelSet import *
285
286  #physical properties  #physical properties
# Line 259  rho1 = 1000        #fluid density on bottom Line 288  rho1 = 1000        #fluid density on bottom
288  rho2 = 1010     #fluid density on top  rho2 = 1010     #fluid density on top
289  eta1 = 100.0        #fluid viscosity on bottom  eta1 = 100.0        #fluid viscosity on bottom
290  eta2 = 100.0        #fluid viscosity on top  eta2 = 100.0        #fluid viscosity on top
penalty = 100.0
291  g=10.0  g=10.0
292
293  #solver settings  #solver settings
# Line 274  useUzawa=True Line 302  useUzawa=True
302  #define mesh  #define mesh
303  l0=0.9142  l0=0.9142
304  l1=1.0  l1=1.0
305  n0=100        n0=200
306  n1=100  n1=200
307
308  mesh=esys.finley.Rectangle(l0=l0, l1=l1, order=2, n0=n0, n1=n1)  mesh=Rectangle(l0=l0, l1=l1, order=2, n0=n0, n1=n1)
309  #get mesh dimensions  #get mesh dimensions
310  numDim = mesh.getDim()  numDim = mesh.getDim()
311  #get element size  #get element size
312  h = Lsup(mesh.getSize())  h = Lsup(mesh.getSize())
print "element size",h
313
314  #level set parameters  #level set parameters
315  tolerance = 1.0e-6  tolerance = 1.0e-6
# Line 294  smooth = alpha*h Line 321  smooth = alpha*h
321  #boundary conditions  #boundary conditions
322  x = mesh.getX()  x = mesh.getX()
323  #left + bottom + right + top  #left + bottom + right + top
324  b_c = whereZero(x[0])*[1.0,0.0] + whereZero(x[1])*[1.0,1.0] + whereZero(x[0]-l0)*[1.0,0.0] + whereZero(x[1]-l1)*[1.0,1.0]  b_c = whereZero(x[0])*[1.0,0.0] + whereZero(x[1])*[1.0,1.0] + whereZero(x[0]-l0)*[1.0,0.0] \
325          + whereZero(x[1]-l1)*[1.0,1.0]
326
327  velocity = Vector(0.0, ContinuousFunction(mesh))  velocity = Vector(0.0, ContinuousFunction(mesh))
328  pressure = Scalar(0.0, ContinuousFunction(mesh))  pressure = Scalar(0.0, ContinuousFunction(mesh))
# Line 309  h_interface = h_interface + (0.02*cos(ma Line 337  h_interface = h_interface + (0.02*cos(ma
337  func = yy - h_interface  func = yy - h_interface
338  func_new = func.interpolate(ReducedSolution(mesh))  func_new = func.interpolate(ReducedSolution(mesh))
339
340  #Stokes cartesian  #Stokes Cartesian
341  solution=StokesProblemCartesian(mesh,debug=True)  solution=StokesProblemCartesian(mesh,debug=True)
342  solution.setTolerance(TOL)  solution.setTolerance(TOL)
343  solution.setSubProblemTolerance(TOL**2)  solution.setSubProblemTolerance(TOL**2)
# Line 322  while t_step <= t_step_end: Line 350  while t_step <= t_step_end:
350    rho = levelset.update_parameter(rho1, rho2)    rho = levelset.update_parameter(rho1, rho2)
351    eta = levelset.update_parameter(eta1, eta2)    eta = levelset.update_parameter(eta1, eta2)
352
353    #get velocity and pressue of fluid    #get velocity and pressure of fluid
354    Y[1] = -rho*g    Y[1] = -rho*g
356    velocity,pressure=solution.solve(velocity,pressure,max_iter=max_iter,verbose=verbose,useUzawa=useUzawa)    velocity,pressure=solution.solve(velocity,pressure,max_iter=max_iter,verbose=verbose, \
357      useUzawa=useUzawa)
358
359    #update the interface    #update the interface
360    func = levelset.update_phi(velocity, dt, t_step)      func = levelset.update_phi(velocity, dt, t_step)
# Line 337  while t_step <= t_step_end: Line 366  while t_step <= t_step_end:
366
367    #save interface, velocity and pressure    #save interface, velocity and pressure
368    saveVTK("phi2D.%2.4i.vtu"%t_step,interface=func,velocity=velocity,pressure=pressure)    saveVTK("phi2D.%2.4i.vtu"%t_step,interface=func,velocity=velocity,pressure=pressure)
369    #courant condition    #Courant condition
370    dt = 0.4*Lsup(mesh.getSize())/Lsup(velocity)    dt = 0.4*Lsup(mesh.getSize())/Lsup(velocity)
371    t_step += 1    t_step += 1
372
373  \end{python}  \end{python}
374    %
375    %
376    The results from the simulation can be viewed by visualization software such as \textit{visIt}. If the software is installed, it can be opened by simply executing the following command:
377    %
378    \begin{python}
379    visit
380    \end{python}
381    %
382    In the visIt main window, vtk/vtu files can be opened from the File menu; contours and vectors can then be displayed by selecting them from the Plots menu and pressing the Draw button. A movie of the simulation can be watched by pressing the Play button. The graphics are displayed in the Vis window. For more information on \textit{visIt} see the website \cite{VisIt}.
383
384    The simulation output is shown in Figures \ref{RT2D OUTPUT1} and \ref{RT2D OUTPUT1} showing the progression of the interface of the two fluids. A diapir can be seen rising on the left-hand side of the domain, and then later on, a second one rises on the right-hand side.
385    \begin{figure}
386    \center
387    \subfigure[t=300]{\label{RT OUTPUT300}\includegraphics[scale=0.252]{figures/RT2D200by200t300}}
388    \subfigure[t=600]{\label{RT OUTPUT600}\includegraphics[scale=0.252]{figures/RT2D200by200t600}}
389    \subfigure[t=900]{\label{RT OUTPUT900}\includegraphics[scale=0.252]{figures/RT2D200by200t900}}
390    \subfigure[t=1200]{\label{RT OUTPUT1200}\includegraphics[scale=0.252]{figures/RT2D200by200t1200}}
391    \caption{Simulation output of Rayleigh-Taylor instability, showing the movement of the interface of the fluids. The contour line represents the interface between the two fluids; the zero contour of the Level Set function. Velocity vectors are displayed showing the flow field. Computational mesh used was 200$\times$200 elements.}
392    \label{RT2D OUTPUT1}
393    \end{figure}
394    %
395    \begin{figure}
396    \center
397    \subfigure[t=1500]{\label{RT OUTPUT1500}\includegraphics[scale=0.252]{figures/RT2D200by200t1500}}
398    \subfigure[t=1800]{\label{RT OUTPUT1800}\includegraphics[scale=0.252]{figures/RT2D200by200t1800}}
399    \caption{Simulation output of Rayleigh-Taylor instability.}
400    \label{RT2D OUTPUT2}
401    \end{figure}
402    %
403    %
404    %The Level Set Method can be applied to many areas of science, for example simulating subduction zones in geophysics, motion of bubbles, and flame propagation. Its also used in image processing. However, the Level Set Method does have limitations. The level set function can still become irregular after reinitialisation, leading to artifacts in the simulations, requiring more thought into the implementation of the reinitialisation step.
405    %

Legend:
 Removed from v.2120 changed lines Added in v.2881