Three-Dimensional Simulations of Free Surface Flows Senior Thesis
Author: Mingru Li Research Supervisor: Frederic Gibou Graduate Student Mentor: Raphael Egan
Department of Mechanical Engineering College of Creative Studies University of California Santa Barbara Contents
1 Introduction 3 1.1 WhatAreFreeSurfaceFlow?...... 3 1.2 TheModel ...... 4
2 Computational Techniques 6 2.1 LevelSetMethods ...... 6 2.1.1 IntroductiontoLevelSetMethod...... 6 2.1.2 TheEvolvingLevelSet ...... 8 2.2 Grids&Discretization...... 9 2.2.1 E cientStructuredGrids ...... 9 2.2.2 DealingwithTreeStructure...... 10 2.2.3 TreesinParallelComputing...... 10 2.2.4 Finite Di↵erenceDiscretization ...... 13 2.2.5 ReinitializationSchemes...... 18 2.3 ProjectionMethod ...... 20 2.3.1 WhatisProjectionMethod? ...... 20 2.3.2 MarkerandCell ...... 21 2.3.3 Solving from the past–Semi-Lagrangian Method ...... 22 2.3.4 Finite Volume Method on Voronoi Meshes ...... 23 2.3.5 Discretization of the Projection Step ...... 26
3 Free Surface Flow 30 3.1 TwoModels...... 30 3.1.1 Sinusoidal Wave in 2D ...... 30 3.1.2 OscillatingCylinder/Ball ...... 31 3.2 Boundary Condition Report ...... 32 3.2.1 Boundary Condition: Pressure ...... 32 3.2.2 Boundary Condition: Stress ...... 33 3.3 LiquidVolumeReport ...... 37 3.3.1 LevelofRefinement ...... 38 3.3.2 Frequency...... 38 3.3.3 SurfaceTension...... 39
4 Summary 41
Bibliography 43
1 Acknowledgment
Writing this senior thesis would be impossible without the support from these people. IwanttofirstthankmyresearchadvisorProfessorFredericGibouforintroducingmeto this area. I met him because of a small visualization project, and I’m still so glad that he allows me to further study computational science in his lab. He also supports me with lots of lab resources, which is essential to the research I present in this thesis. I’ll forever remember his insight about this subject, and his email ends with energetic ”Cheers”. Also, I want to thank my graduate student mentor Raphael Egan. He guided me through my learning process. Every time I cannot figure out a concept in the paper or a bug in the code, he kindly gives great illustration, which builds up my ability to a higher level. His familiarity about the computational fluid dynamics always surprises me, along with his lightening fast proofread skill. At last, I really appreciate all the people in the lab for creating a friendly environment to learn and to research. I’m really glad that I got this chance to grow here.
2 Chapter 1
Introduction
1.1 What Are Free Surface Flow?
Free surface flow, also known as open channel flow, is one of the fundamental subjects to various branches in computational fluid dynamics (CFD). It describes a situation where the fluid surface is subject to zero tangential stress. This model can be applied to many fluid- gas interface problems. It can also be extended to approximate a multi-phase system. For example, Zappa’s researches about the microwave breaking process involves studying the sea-air interface[20]. He introduces that the flux of the air into the fluid is a↵ected by the slope of the fluid surface and the di↵erence in concentration between air and the fluid. Also for combustion problem, the formation of the droplets and sprays which subsequently burns originates from the interfacial instability[17]. Or even in simpler cases, the collision between two travelling waves, or two water droplets also have the essence of the free surface flow in them. Because of its wide applications, free surface flow has attracted lots of research e↵ort, both theoretical and computational. For example, Meniko↵developed the theory evolution in 2D with periodic boundary conditions[10]. He analyzed both the stable and unstable modes for a flow containing two kinds of fluid. However, due to the complexity of fluid problem, it’s usually impossible to gain a analytic solution under realistic assumptions. The compu- tational approaches is the mainstream in studying this subject. However, even though the computational technology has been developed for a long time, the fluid simulation is still expensive and delicate, which is embodied by various aspects. First it’s still not realizable to run a complex simulation, like multi-phase systems with distinct properties and dynamics, without the power of clusters. Especially in 3D, the number of nodes and equations increases tremendously compared to 2D simulation, which requires advanced parallel CPU processing and large memory storage. On the other hand, because the governing equation is intrinsi- cally non-linear, for di↵erent scenarios, we need to apply di↵erent methods to let the whole simulation converge. Without the proper treatment even to one small section, the simulation tends to either diverge or give nonphysical results. This still poses various obstacles to our research to this relative simple fluid problem.
3 CHAPTER1.INTRODUCTION 1.2.THEMODEL
Fig. 1.1: Example of tracking the free surface using structured (left) and unstructured (right) grids
1.2 The Model
There are many methods that are applicable in solving the free surface flow and they have their own advantages and disadvantages. In most scenarios, a grid (structured or unstruc- tured) is present (Fig. 1.1), with di↵erent discretization methods to the governing equations. Other methods, like moving particle semi-implicit method[7], does not require a grid in the whole computational domain. The set of governing equations can be usually Navier-Stokes equations solving the velocity of fluid @ (⇢u)+ (⇢u u)= p + + f (1.1) @t r· ⌦ r r· or its equivalent expression about the vorticity of the incompressible fluid. @! +(u ) ! =(! )u + ⌫ 2!. (1.2) @t ·r ·r r Here is the stress tensor corresponding to the fluid, and f is the external body forces. ! = u is the vorticity of the velocity field.⌫ is the kinematic viscosity. Inr⇥ this research, our interest focuses on the water-air interface of water with horizontal periodic boundary condition. We use adaptive Cartesion grids with adaptive time-stepping to simulate the evolution of the free surface.With such characteristic, we can e ciently use the computational power to the region where the details need to be examined more carefully. In such region, we refine the meshes, which means that we reduce the size of the mesh to increase the accuracy of the simulation. Adaptive time step control also has similar advantages. It allows us to gain more details about the evolution from tn to tn+1 if the motion is complicated at tn. Also, the combination of this two features stabilizes the simulation by satisfying criterion like Courant–Friedrichs–Lewy (CFL) condition given by t u C . (1.3) | |max · x max where t and x are the time and spatial separation. C is the Courant number. This condition ensures satisfactory resolution of advection.
4 CHAPTER1.INTRODUCTION 1.2.THEMODEL
We set up the problem using the Navier-Stokes solver built in CASL library, which is developed from P4EST and PETSC. The CASL library is able to setup non-uniform struc- tured grids, called octree (or quatree in 2D). The computational domain is first tessellated with macro-cells called the ”root cells”. Each cell can be divided into 4 (or 8 in 3D) children cells, and the operation can be recursively repeated onto chosen children cells. Illustration are provided in Fig. 1.21 for 2D and 3D cases with one single root cell, minimum level of refinement equal to 1 and maximum level of refinement equal to 4(in 2D) and 3(in 3D). Comparing to uniform grid shown in Fig. 1.1, the number of cells (leaves in the tree) is greatly reduced. Along with the benefits also come the challenges. We need to apply new spatial discretization to solve the governing equations. Also when we march in time, the grid needs to be changed according to the current situation. Therefore, there are a couple key techniques: level set methods, projection methods, etc, which will be introduced in chapter 2. Along with Eq. 1.1 to be solved come boundary conditions. The boundary conditions to be applied onto the irregular free surface determine the quality of the model and its physical relevance. Usually, to maintain the accuracy and stability of the solver, people usually set homogeneous Dirichlet and Neumann boundary conditions for the variables. Specifically, at the free surface ,
+ (p p ) =0, (1.4) |
µ( u nˆ) = 0, (1.5) r · | + where p and p are the pressure above and below the free surface. These two values come from the interpolation given by the data stored at certain location. These two boundary conditions indicate that across the interface, the pressure jump is zero. However, by Young- Laplace law, we know that this shouldn’t be the case due to the surface tension. Similarly, the gradient of velocity field is related to the stress tensor of the fluid, which can be treated in a more physical way. The old version of the free surface solver implements the boundary condition in these two ways. After the modification, I’ll present the di↵erence brought by setting more realistic boundary conditions in Chapter 3.
Fig. 1.2: Example of quadtree(2D) and octree(3D). The dots on the right picture mark some of the cells with di↵erent level of refinement.
1Octree picture is from https://developer.apple.com/documentation/gameplaykit/gkoctree
5 Chapter 2
Computational Techniques
2.1 Level Set Methods
2.1.1 Introduction to Level Set Method Determining how to specify the free surface is the first important aspect of this research. There are a lot of ways to achieve this goal, such as defining a height function h(x, y)oruse front tracking method[4]. Explicit methods are usually more accurate and have some good properties (like volume preserving), but they require the simulation to change the topology when the interface changes, which makes the whole simulation more expensive. In this research, we use level set method introduced by Osher and Sethian[14]. In this framework, irregular interfaces are represented by a chosen iso-contour of a Lipschitz- continuous scalar function (x), hence the name ”level set method”. It is a scalar function, mapping the spatial point to a value. Besides Lipschitz-continuity, the only requirement of the level set function is that on interface , (x) =0. (2.1) | Therefore, the 0-level contour specifies the position of the interface. Because there are infinitely many functions that satisfy this requirement, certainly some of them are more applicable to this problem. A signed-distance function is preferred in the computation. We’ll discuss the advantages later. The computational domain ⌦is split by in three parts
+ + ⌦=⌦ ⌦ ⌦ ⌦ = (2.2) [ \ ; A sign-distance function can be defined as
d x ⌦+, 2 (x)= 0 x , (2.3) 8 2 <> d x ⌦ , 2 where d is the distance from x to the interface:> . In 1D, the level set function can be easily defined and visualized. With only one dimension, the interface is represented by points. We can see from Fig. 2.1 that the signed-distance function is an absolute value function with slope 1, and because of this characteristic, the value of the signed-distance function is equal to± the distance (di↵erence in horizontal
6 CHAPTER2. COMPUTATIONALTECHNIQUES 2.1. LEVELSETMETHODS
Fig. 2.1: Example of a one dimensional signed distance function is an absolute value function. The slope is 1. The two blue dots are the interface. ± coordinates) between the points to the nearest interface (blue dots). Within the interface, denoted by ⌦ ,whichistheregionbetweentwobluedots,thevalueofsigned-distance function is negative. Outside the interface, the value of signed-distance function is positive as desired. One more thing worth noticing is that the absolute value function is not a smooth function. It has a point with discontinuous derivative in the middle between two interface. This property usually preserves in higher dimension, which needs to be dealt carefully during the computation. In 2D, the interface is represented as a closed curve in the plane. It’s a little more sophisticated than one-dimension case, but it still can be visualized for simple interface. The simplest interface we could consider is a circle on the plane. Shown in Fig. 2.2, the signed- distance function corresponding to a circle is a cone. With a multi-interface computational domain, we can have multiple signed-distance function to describe di↵erent interface. We do not have to merge to create a global level set function when the interfaces are separate. However, when di↵erent interfaces merge into each other, as depicted on the right, we have to combine two signed distance function. Similar as one dimensional case, we still have discontinuous gradient for the signed-distance function. One obvious question is why we want to use signed-distance function as our level set function, provided that it almost always has discontinuity in it. The answer is trivial: because the benefits it brought to the simulation outweigh its intrinsic mathematical badness. The first appealing property of such level set function is that (x) =1. (2.4) |r | One thing we should be careful about is that this property is only true for signed-distance function. When we update our level set function in the computation, it evolves to a non- signed-distance function and we do not have such property anymore, which is one of the reasons why reinitialization step is very important, introduced in the later section. The second advantage is that we could easily calculate the normal vector of the interface
7 CHAPTER2. COMPUTATIONALTECHNIQUES 2.1. LEVELSETMETHODS
Fig. 2.2: Examples of two dimensional signed-distance function. For a simple circle as interface, the signed- distance function is a cone-shape function. With more complex interfaces (right), we could approximate it by combining multiple circles. Figure from [3]. by nˆ = r (2.5) |r | and subsequently we can compute the curvature of the interface = nˆ. (2.6) r· This is extremely useful because in many stages of the simulation, such as setting boundary conditions for the interface, the normal vector and curvature are required. In this frame work, we do not need to do extra work to get them.
2.1.2 The Evolving Level Set The first di culty coming from transient simulation is to capture the moving interface. Because we use a level set function to achieve the goal, we also need to advect the level set function in an accurate way to proceed to next time step. Mathematically, this is done by the advection equation under velocity field v =(u, v, w)[12] @ + v =0, where v = v nˆ. (2.7) @t ·r n · Eq. 2.7 is a general advection equation that works for any level set function. The new in- terface is described by the new 0-level contour of the advected level set function. However, when a signed-distance function is advected in this way, it does not retain its signed-distance- function property. To solve this issue, Sussman proposes the following reinitialization equa- tion [18] @ +sgn( 0)( 1) = 0. (2.8) @⌧ |r | This equation can transform a arbitrary level set function 0 into the signed distance function .Thesgn( 0) is a smoothed-out signum function and can be expressed as
8 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION
1,x>0 sgn(x)=8, 0,x=0 (2.9) <>, 1,x<0, and ⌧ represents a fictitious time. We can think of the reinitialization in this way: we let :> the level-set function evolve in an independent time line. This evolution will not change the 0-level set because at those point, @ sgn( 0) =0 |0-level =0 (2.10) |0-level ) @⌧ For other points, the end of deforming happens when the current level set function retain the property =1,showingthatthecurrentlevelsetfunctionisanewsigned-distance function. |r |
2.2 Adaptive Grids and Discretization Schemes
2.2.1 E cient Structured Grids Grids and meshes are essential to computational techniques. It determines the way of dis- cretizing the nonlinear equations. Some computational methods work greatly for some grids but not the others. For example, the finite di↵erence method is simple and e↵ective using structured rectangle grids, but not very useful for unstructured grids. Therefore, choosing the way to split the computational domain determines to the way we implement methods to solve the problem. The advantage of structured grids is that it’s easy to generate. The implementation of discretization methods is relatively obvious. However, it has a huge disadvantage. To get higher resolution of the computation, the number of cells increases exponentially, which means if we cut the cell sizes in half, the number of cells increases by 2d,whered is the dimension of computational domain. In order to alleviate this cost of dimensionality, we choose an alternative approach to obtain necessary fine resolution. We split our computational domain using adaptive quadtree/octree. Then we carry out the computation in parallel[13]. An example of a quadtree is shown in Fig. 2.5. We can see that each cell is still in square shape, but cells are di↵erent in sizes. Specifically, a large square can be divided into 4 smaller squares with equal size. The large square is called the parent of the smaller squares generated inside, who are call the children. Asquarewithoutfurthersplittingiscalledaleaf. By applying this grid structure, we can adjust the resolution to each region. If we want ahigherresolutioninasmallerregion,wecanjustsplitcertainsquaresmultipletimesso that in that region, the cells are small enough to capture all the details we want. For other regions, we can have relatively coarse meshes without losing too much accuracy. In this way, we do not need to have a global refined grids, which greatly reduces the number of cells in the computational domain. It makes the whole simulation much lighter, and requires less computational power and memory storage.
9 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION
(c) Polygonal
(a) Triangular (b) Voronoi
Fig. 2.3: Examples of di↵erent grids used in computational techniques
2.2.2 Dealing with Tree Structure With the basic structure being set, the next problem we need to consider is how to make use of such a structure. The most interesting region we want to focus on is the motion of the interface. Therefore, we need to refine the mesh around the interface. Considering the interface changes with time, throughout the whole simulation, we need to continuously refine and coarsen the grid. Along with the level set function capturing the interface, we could set our first condition of refinemeng[12]. For a specific cell C with the vertices v,if min (v) Lip( ) , diag-size(C)(2.11) v vertices(C)| | · 2 then the cell is refined. Lip( ) denotes the Lipschitz constant. Basically, this condition means that we need to further split the cell if the value of level set function (distance to the interface) on any vertices is smaller than the cell edge length. The solver will keep checking this condition for each cell and refine who satisfies this condition. Obviously, with only this condition, this process is incessant, so there are adjustable predetermined maximum and minimum levels of refinement. Furthermore, we implement another condition for refinement with local vorticity so that we gain high resolution in those highly non-linear regions. A typical result after this refinement process is shown in Fig. 2.4. We can see that far away from the interface, the mesh is coarse to reduce amount of calculation in those area. As approaching the interface represented by the red line, the grid is gradually refined to the highest level to capture more details about the interface. Comparing Fig. 2.4a and 2.4b, we notice this refinement process is executed for each time step to follow the motion of the interface.
2.2.3 Trees in Parallel Computing Solving PDE is a complex process. There are thousands of linearized equations and other op- erations that the computer needs to do. Parallel algorithm makes use of the multi-core (CPUs or GPUs) feature of modern computer or computational clusters to do lots of calculation at the same time. However, the tree structure introduces a new challenge: how to distribute
10 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION
(a)
(b)
Fig. 2.4: 2D computational domain with the refined grid structure. The red line shows the shape of the interface, which is the 0-level contour of level set function. (a) and (b) are from same simulation but di↵erent time steps. We can see the grid changes when the interface changes.
11 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION
Fig. 2.5: Example of a quadtree gird. The domain is split several times. Each time a square is uniformly divided into 4 smaller squares. The largest square is called 0th level or ”the root”. On the right, it shows the parent-children relation between meshes with di↵erent sizes. Smaller cells generated from a larger cell are called the children of the large cell. A cell without any children is called a leaf. A computational domain may contain several root cells and tree structures, which in collection is usually called a forest. the computational cells across the collection of processes to allow for good balancing and fast communication. The z-curve provides an answer to the question. It can be visualized as a line connecting each leaf through the whole forest. Fig. 2.6 gives an example of 2D z-curve traversing the trees T0 and T1[13]. The z-curve will start at the cell whose (x, y, z)coordinateissmallest(the origin). Then it goes inx ˆ direction to search for the next cell with same level of refinement. If inx ˆ direction the cell does not exist, it goes back to the smallest x coordinate and search iny ˆ direction, and so on. If the cell contains children, it connects the children following the same rule. In this way, all the leaves can be labeled with indices. Then the solver can balance the load for each core. In Fig. 2.6, di↵erent colors represent di↵erent cores. We can see that the first two cores (yellow and green) are taking 6 cells each, and the last core (red) is taking 5 cells. Usually the number of cells each core is responsible for is di↵erent, but they do not di↵er by a lot. Inside the region that the core is the owner, the core will perform calculation and modify the data stored in those cells. However, to perform the calculation, the core needs to know information outside its region. For example, to compute the derivatives at a point, the solver needs to know the value of the function at neighboring points, which will be shown in the next section. Then at the boundary of the region, the owner has to access the data from other regions. This creates a ghost layer of the region, Fig. 2.7 shows the cell allocation and the ghost layer. There are 4 cores running and di↵erent area is assigned to each core, depicted by the color di↵erence. We can see a couple characteristics here
12 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION
Fig. 2.6: Example of a 2D Z-curve in a quadtree structure. The left plot shows the Z-curve traverses through the leaves in tree T0 and T1. The right plot is a abstraction of the forest, showing the rule obeyed by the Z curve. The Z curve will always start at the cell at origin (the left corner in this case) and proceed to next cell with same level of refinement. If the next cell contains children, Z-curve connect all children in the same way. The priority direction is usually in orderx ˆ,ˆy,ˆz. Figure from[13].
1. The cells are assigned according to the Z-curve. Basically, it means that the solver cuts the Z-curve in 4 pieces and assign each piece to one core. 2. The 4 plots on the right separately show all the data that’s accessible by each core. We notice that the ghost layer (cells marked by di↵erent color) is around the owner region. 3. The sizes of each region is roughly the same, but due to the vairation in the size of ghost layer, each core can access di↵erent amount of data.
2.2.4 Finite Di↵erence Discretization When solving the di↵erential equation, approximating the derivatives is an essential task to acquire accurate and stable solutions. This process is usually called discretization. The most common used discretization schemes for structured grids is finite di↵erence methods (FDM). It’s inspired by the Taylor expansion. If we consider the Taylor expansion of function f(x) at point x = x0
1 1 2 1 (n) n f(x)=f(x )+f 0(x )(x x )+ f 00(x )(x x ) + = f (x )(x x ) (2.12) 0 0 0 2 0 0 ··· n! 0 0 n=0 X Then we can make use of this series to approximate approximate derivatives. For example, if we know the value of the function f(x)attwopointsf(x0)andf(x0 + x), then we can calculate the derivative by
1 2 f(x + x) f(x ) f(x0)+f 0(x0) x + f 00(x0) x + f(x0) 0 0 = 2 ··· x x (2.13) f 00(x0) x 2 = f 0(x )+ + O( x ) 0 2 In Eq. 2.13, the left hand side (LHS) is the one of the finite di↵erence method called Forward Euler Method. On the right hand side (RHS), the result is the first derivative with 1 acorrectionterm 2 f 00(x0) x.Therefore,knowingthetwovaluesoffunctionf(x), we can
13 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION
Fig. 2.7: This diagram shows the typical allocation of cells to each core. There are four cores running and the region owned by each core is shown in di↵erent color on the left. On the right, the four plots shows the cells owned by each core and the ghost layer around the region. Figure from[13].
approximate the first derivative f 0(x)atpointx = x0 by LHS. Those two points are usually neighbors on the grid and x is the size of the cell. By applying smaller grids, the correction will be smaller and in the limit of infinitely fine grids,
f(x0 + x) f(x0) lim . f 0(x0)(2.14) x 0 ! x ! The idea that reducing the size of cells or increasing the number of samples to increase the accuracy is fundamental to most of successful discretization schemes. In this method, the error reduces with order O( x), which is called a 1st order method. When the size of cell is reduced by 2, the leading error is reduced by 2 as well. Higher order method converges faster. For example, the Central Di↵erence Method is a 2nd order method. If f(x0)and f(x x) are all given, we can calculate the following 0 ± 2 f(x0 + x) f(x0 x) f 000(x0) x 3 = f 0(x ) + O( x ). (2.15) 2 x 0 6 1 2 In this case, RHS is f 0(x0)withasecond-orderleadingcorrection 6 f 000(x0) x ,which means that if the size of cell is reduced by 2, the leading error is decreased by 4. We can also approximate f 00(x0)aswellby
f(x0 + x) 2f(x0)+f(x0 + x) 1 2 = f 00(x ) f 000(x ) x + O( x ). (2.16) x2 0 3 0 For higher order method, such as Runga-Kutta 4th order method, the result will converge even faster. However, when solving the complicated coupled PDE, higher order method requires more information from neighbors, and is usually more unstable than lower order method. Therefore, choosing the discretization schemes is the balance between stability and convergence.
14 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION
Fig. 2.8: Neighboring of T-junction nodes v0.
Non-uniform square grids provide extra challenges to the finite discretization schemes. The main di culty comes from the T-junction as illustrated in Fig. 2.8 where the T-junction node v0 is missing neighbor on its right[12]. From the discussion above, if we want to calculate the second derivative of a function, i.e level set function ,weneedtoknowatleastvaluesfrom both neighbors to perform a 1st order approximation. However, there is no direct neighbor to the right of v0. G Our solution to this situation is to create a ghost node v4.Thenghostvalue (v4)is linearly interpolated from its neighbor v5 and v6 by
G G 5s6 + 6s5 (v4)= 4 = (2.17) s5 + s6 This is a second order method because @ 1 @2 s = s + 4 s + 4 s2 + O( x3 ) 5 6 6 4 @y 5 2 @y2 5 smallest ✓ ◆ @ 1 @2 s = s 4 s + 4 s2 + O( x3 ) 6 5 5 4 @y 6 2 @y2 6 smallest ✓ ◆ 2 5s6 + 6s5 s5s6 @ 4 3 = 4 + 2 + O( xsmallest)(2.18) s5 + s6 2 @y 2 @ 4 For @y2 , @2 4 = (v )+ (v )s + O( x2 ) @y2 yy 0 yyx 0 4 smallest If we plug this approximation in Eq. 2.18, then the yyx term is a third order term which 3 will be put in to O( xsmallest), so we can say