<<

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 EcientStructuredGrids ...... 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 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- 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 , 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 . 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 eciently 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 . 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 diculty 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 Ecient 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) 2x 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 diculty 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

5s6 + 6s5 s5s6 3 = 4 + yy(v0)+O(xsmallest)(2.19) s5 + s6 2

Then we could use standard first order approximate to yy(v0)tomakethelinearinter- polation third order accurate. s + s s s G(v )=G = 5 6 6 5 5 6 2 0 + 3 0 (2.20) 4 4 s + s s + s s s 5 6 2 3 ✓ 2 3 ◆

15 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION

In three dimension, we have the similar cases. In Fig. 2.9, v0 is the ”T-junction” node. It misses two neighbors: one in the xˆ direction; one in yˆ direction. Min discusses situation and states that this pattern is a general configuration of neighboring nodes in octree[12]. We set up two ghost nodes v4 and v5 representing two kinds of missed node. If the missing node lies on the side like v4, we can use similar linear interpolation as the 2D case shown previously.

G s78 + s87 4 = (2.21) s7 + s8

If the missing node is on a face as v5, we could use bilinear interpolation using the four corner nodes of the face.

G s11s1211 + s11s912 + s10s129 + s10s910 5 = (2.22) (s10 + s11)(s9 + s12) These two methods are also both second order accurate. We can boost them into a third order method by subtracting the second derivatives.

s + s s s G = 7 8 8 7 7 8 3 0 + 6 0 4 s + s s + s s s 7 8 3 6 ✓ 3 6 ◆ s s + s s + s s + s s s s G = 11 12 11 11 9 12 10 12 9 10 9 10 10 11 3 0 + 6 0 (2.23) 5 (s + s )(s + s ) s + s s s 10 11 9 12 3 6 ✓ 3 6 ◆ s s G 9 12 1 0 + 4 0 s + s s s 1 4 ✓ 1 4 ◆ The benefit of computing ghost nodes in this complicated way is that we can then treat the T-junction node as a normal node with up to third order accuracy. Then we can proceed to finite di↵erence discretization on the quadtree/octree. For central di↵erence method (marked by D0, we need to slightly modify the formula, referring to Fig. 2.10. s s D0 = 2 0 1 + 0 1 2 x 0 s · s + s s · s + s 2 1 2 1 1 2 (2.24) 0 2 0 2 0 1 2 Dxx0 = s2 · s1 + s2 s1 · s1 + s2 + Sometimes, we also have to use first order forward (D )andbackward(D)Eulermethod, and they are given by

+ 2 0 0 1 D 0 = D0 = (2.25) s2 s1 The reason we want both method is because sometimes the type of PDE requires us to choose one of them, e.g. upwind method to solve hyperbolic PDE. Also, we may have a second order accurate approximation of the first derivatives.

16 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION

Fig. 2.9: Neighboring vertices of a vertex in three dimension. Figure from[12].

Fig. 2.10: One dimensional non-uniform grid

s D+ = 2 0 2 minmod(D0 ,D0 ) 0 s 2 xx 0 xx 2 2 (2.26) 0 1 s1 0 0 D0 = + minmod(Dxx0,Dxx1) s1 2 The minmod function is a slope limiter. It is defined as

min(x ,x ,...,x ) x > 0, 1 2 n 8 i minmod(x1,x2,...,xn)= max(x ,x ,...,x ) x < 0, (2.27) 8 1 2 n 8 i <>0otherwise.

This function has good properties when:> dealing with the sudden change of function be- tween nodes. Considering the case in Fig. 2.11, between nodes v0 and v2,thefunction changes suddenly. If we keep using the first order forward Euler method, we would get the black dotted line as our estimation of the slope at v0,whichisnotquiteidea.Ifwefurther 0 0 calculate minmod(Dxx0,Dxx2), we would find that in this example, both second derivatives are negative, and we can pick the larger one and modify the first order result according to Eq. 2.27, which increases the value of the slope approximation at v0 shown by the red dotted line. Therefore, minmod function can allow the solver to further approximate the local first derivative of the function.

17 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION

Fig. 2.11: An example of smooth kinks between nodes v0 and v2. The dotted black line shows the result from the first order forward Euler method. The red line intends to show the correction made by applying minmod function.

2.2.5 Reinitialization Schemes Reinitialization process, as introduced in Section 1.1.2, allows the level set function to stay as a signed-distance function. Eq. 2.8 specifies the method to evolve the level set function in continuous case. The standard discretization of this equation is given by[18]:

@ + + +sgn( ) H (D ,D,D ,D) 1 =0 (2.28) @⌧ 0 G x x y y ⇥ ⇤ The newly introduced HG is the Godunov Hamiltonian, which is defined as:

max( a+ 2, b 2)+max(c+ 2, d 2)ifsgn(0) 0, H (a, b, c, d)= | | | | | | | |  (2.29) G max( a 2, b+ 2)+max(c 2, d+ 2)ifsgn(0) > 0, (p | | | | | | | | + p where a =max(a, 0) and a =min(a, 0). If we plug in the first order derivatives in HG, it produces a gradient-like object. This complicated definition has its own purpose. Notice that we can rewrite Eq. 2.8 into @ +sgn( ) r ·r 1 =0. (2.30) @⌧ 0 ✓ |r | ◆ If we compare this equation to normal advection of a scaler field under velocity field u @ + u =0, (2.31) @t ·r We can see that two equation have similar form if we make substitution u sgn( ) r . ) 0 |r |

18 CHAPTER2. COMPUTATIONALTECHNIQUES 2.2. GRIDS&DISCRETIZATION

To solve the advection equation, the upwind method is usually applied. Upwind dis- cretization scheme checked the local velocity field and change discretization scheme when the direction of local velocity field. In one dimension specifically,

@ Dxux > 0, = + (2.32) @x (Dx ux < 0. The reason for this is to respect the flow of information. When the local velocity is to the right, the information for next time step comes from the left, which means the solver should use backward Euler method to gather information from the left, and vice versa. Similarly in the reinitialization equation, Godunov Hamiltonian is responsible to choose the correct Euler method to discretize the equation. The exact procedure to reinitialize the level function begins with solving the equation twice from time step tn with n.

n+1 n 0 + n n + n n +sgn( ) H (D ,D ,D ,D ) 1 =0 ⌧ G x x y y e ⇥ ⇤ n+2 n+1 0 + n+1 n+1 + n+1 n+1 +sgn( ) H (D ,D ,D ,D ) 1 =0 ⌧ G x x y y e e n+1 h i Then we could compute by e e e e n + n+2 n+1 = 2 The region near the interface needs special attention.e When the reinitialization evolves the level set function, it should preserve the volume/area. This feature means that the zero level contour should stay at the original position during reinitialization. Russo and Smereka solved this problem by including the location of the interface in the Euler method[15]. Considering asimplesituationthat2 0 < 0 shown in Fig. 2.10, it shows that part of the interface is between these two points. Then· to find out the location of the interface, we can use quadratic interpolation.

1 0 0 0 0 c2 = 2 minmod[Dxx0,Dxx2] 0 0 0 2 2 0 (x)=c2x + c1x + c0, with c1 = (2.33) 8 s2 0 0 2 <>c = 2+0 c2(s2) 0 2 4 Then the location of the interface sI is the:> root of the quadratic interpolation, which is given by:

c /c if c <✏ s 0 1 | 2| s = 2 + ( c + (c )2 4c c /(2c ) if c ✏ and 0 < 0 I 2 8 1 1 2 0 2 2 0 2 | | 0 <>( c1 (c1) 4c2c0/(2c2) if c2 ✏ and 0 p | | 0 After solving s ,weinsteadusethev and interface to solve for the first derivative by I :> p 0 n + n 0 0 sI 0 n 0 n Dx 0 = minmod(Dxx0 ,DxxI )(2.34) sI 2

19 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

Min found that this method proposed by Russo and Smereka leads to unstable result when 0 n 0 n the interface is close to the node[12], so we usually substitute DxxI by Dxx2 .

2.3 Solving the un-solvable–Projection Method

2.3.1 What is Projection Method? The Navier-Stokes equations have been famous for a long time. Tons of researches have been done based on the equations, either studying the fluid mechanics or purely mathematical aspects. In this research, we consider the Navier-Stokes equation for incompressible flow.

@u ⇢ + u u = p + µu + f in ⌦, @t ·r r (2.35) ✓ ◆ u =0 in⌦ r· where ⇢ is the density of the fluid; u =(u, v, w)isthevelocityfield;p is the pressure field; µ is the viscosity; f is the external volumetric force per volume, which is usually the gravity. Before Chorin published his astounding work, solving this set of equations are quite dicult due to the role of pressure field. We notice that velocity field u has its explicit evolving equation, but the pressure field p does not. The pressure field is acting like a Lagrangian multiplier to the velocity field so that u is divergence free. This feature means that if we evolve the Navier-Stokes in the regular way, we cannot guarantee that incompressible condition is met. To solve this problem, Chorin proposed a multi-step method, which was later called pro- jection method[2]. The first step is to calculate an intermediate velocity field u⇤ using the Navier-Stokes equation. There are di↵erent ways to proceed, and we choose to completely igonore the pressure field p in this step. We discretize the the temporal derivative using forward Euler method

n u⇤ u n n ⇢ + u u = µu⇤ + f. (2.36) t ·r ✓ ◆ In this way, the intermediate velocity field u⇤ is not divergence free. The second step is based on Helmholtz-Hodge decomposition. This theorem states that any twice continuously di↵erentiable vector field can be decomposed to a divergence free vector field and the gradient of a scalar field. Therefore, u⇤ can be written as:

n+1 u⇤ = u + (2.37) r where is the Hodge variable. It’s related to the pressure field, which will be shown in Sec.2.3.3. If we apply the divergence operator to both sides of Eq. 2.37, we obtain

= u⇤. (2.38) r·r r· This means that we need to solve a Poisson equation to get Hodge variable, which leads to the true velocity field un+1.

20 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

Fig. 2.12: Marker and cell data layout in quadtree. Figure from [5].

2.3.2 Marker and Cell In Section 2.2, we talked about the quadtree/octree structure used to discretize the com- putational domain. However, in this structure, where should we store the data? There are many reasonable location, such as nodes, cell centers, sides/faces. Our data layout, shown in Fig. 2.12, is called marker and cell, which is the standard approach for solving Navier Stokes equation[6]. As shown in the figure, di↵erent variable are stored at di↵erent location. It makes use of the structure of the equation. For example, the value of level set function is stored on the nodes so that we could use the T-junction discretization scheme. Similarly, the ux = u is stored on the vertical surfaces and Hodge is stored on at the center, because when we consider Eq. 2.37, inx ˆi direction,

n+1 @ ui⇤ = ui + @xi we notice that the velocity field corresponds to the gradient of the Hodge variable. Then defining the Hodge variable at the center allows the solver easily to calculate the gradient of atthefaceinanydirection,e.g( )x at vertical faces. For sure this method has its ownr limitation. When we need to gather information of u and atotherpoints,itisadiculttasktointerpolateu on arbitrary points. We apply weighted quadratic least squares interpolation. The process requires the information of neighboring points and the inversion of a 6 by 6 system in 2D, and a 10 by 10 system in 3D. We use the Cholesky decomposition for this purpose. The weight is given by 1 wi = (x x )2 +(y y )2 i i where (x, y)arecoordinatesofthepointtobeinterpolated,and(p xi,yi)arecoordinatesof neighboring points constructing the least square linear system.

21 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

2.3.3 Solving from the past–Semi-Lagrangian Method In fluid dynamics, there are two kinds of description to the fluid. One is called Lagrangian description, and another one is Eulerian description. Lagrangian description treats the fluid motion as particle motion. At the beginning, every points is given a marker and we track the motion of each point. Eulerian description treats the fluid motion as time-dependent fields, such as velocity, pressure, and density. Due to this di↵erence, same equation has di↵erent forms under the two descriptions. The Navier-Stokes equation people refer to is usually in Eulerian form. However, for the discretization of advection term, it’s shown that Lagrangian description provides a more ecient and stable solution[19]. We combine the Semi-Lagrangian approach and a second-order backward finite di↵erence method with adaptive time step to discretize the advection term[11]: @u + v u @t ·r where v is the current velocity field. Then we can discretize u at time tn+1 by interpolating u along the characteristic curve of the equation through un+1. To find the characteristic curve, n n+1 we tried to find the departure point xd and xd t xˆ = xn+1 n vn(xn+1), 2

n n+1 n+ 1 x = x t v 2 (ˆx), d n and x¯ = xn+1 t vn(xn+1), n n 1 n+1 n xd = x (tn +tn 1)v (x¯). With adaptive time step, tn and tn 1 are usually di↵erent. The basic idea of such interpolation is that we first find the intermediate pointx ˆ andx ¯,thenwecaninterpolate backward with intermediate velocity. Here, the intermediate velocity field is interpolated as:

n+ 1 2tn 1 +tn n tn n 1 v 2 (xˆ)= v (xˆ) v (xˆ) 2tn 1 2tn 1 This hard work of interpolation gives a simple discretization scheme. Along the charac- teristic curve, the advection term becomes @u du + v u = (2.39) @t ·r ds where the characteristic curve is parametrized by (x(s),t(s)). In first order approximation, Eq. 2.39 has a familiar form

@un+1 un+1 un d , @s ⇡ tn but we want to use a second order scheme using

n+1 n+1 n n 1 @u u u u u ↵ d + d d . (2.40) @s ⇡ tn tn 1

22 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

This is a general strategy to obtain higher order discretization using existing information. n 1 n Then we just need to solve for ↵ and .Todothis,wecanexpandud and ud using Taylor series along the characteristic line:

2 n 1 n+1 n+1 (tn +tn 1) 2 n+1 ud = u (tn +tn 1)@su + @s u 2 t2 un = un+1 t @ un+1 + n @2un+1 d n s 2 s Then we can plug them into Eq. 2.40

2 n+1 tn 2 n+1 n+1 tn 1 2 n+1 ↵ @su @s u + tn 1@su tn 1tn + @s u 2 tn 1 2 ✓ ◆ ✓ ✓ ◆ ◆

n+1 tn tn 1 2 n+1 n+1 (↵ + )@ u ↵ + t + @ u = @ u s 2 n 2 s s ✓ ◆ Attempting to achieve second order discretization, we match the coecient that the second order derivative vanishes.

↵ + =1 tn tn 1 (↵ 2 + tn + 2 =0

2tn+tn 1 ↵ = tn+tn 1 ) = tn ( tn+tn 1 With this scheme, Eq. 2.36 becomes

n n n 1 u⇤ ud ud ud ⇢ ↵ + = µu⇤ + f (2.41) tn tn 1 ✓ ◆ From this discretization and the Hodge decomposition, we can recover the pressure by ⇢ p = ↵ µ (2.42) tn

2.3.4 Finite Volume Method on Voronoi Meshes

The remaining work of solving Eq. 2.36 is to find a way to discretize the RHS, which is u⇤. In this research, the fluid has uniform viscosity, which decouples the di↵erent components of the velocity field. Instead of finite di↵erence method, we use finite volume method on Voronoi girds as introduced in Hermeline’s paper (citation, 30 in stable projection). The finite volume method is another approach to turn a PDE to a set of discrete equations. As its name shows, the method uses a small volume around a node. Then, for the PDE that contains divergence of a vector field, we apply volume integral on all terms and use divergence theorem to transform the volume integral of the divergence to a surface integral. For the Navier-Stokes equation, the result is

23 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

Fig. 2.13: Example of a Voronoi cell generated by face u0 and its neighboring nodes, who are also x component of velocity stored at vertical sides. Figure from[5].

@u ⇢ + u u dV = µudV (2.43) @t ·r ZC ✓ ◆ ZC @u ⇢Vol(C) + u u = µ u nˆ (2.44) @t ·r r · ✓ ◆ Z@C where C is the Voronoi cell around the node v0.Vol(C)isthevolumeofthecell. @C is the contour. Here we applied the finite volume method on the RHS and transform it to the surface integral. For the LHS, we simply replace the integral with volume times the discretization of the advection term. Given a set of points P i =0, 1,...,theVoronoicellC associated with the point P is { i} k k the set of points that are close to Pk than any other point int the set. Mathematically, given distance function d,

C = x d(x,P ) d(x,P ) j = k k { | k  k 8 6 } The following procedure can be applied to produce a Voronoi Cell, shown in Fig. 2.14.

1. Locate one of the nodes as the center of the Voronoi cell. 2. For each neighboring nodes, draw a line connecting the center to the node 3. For each connection, find the bisector. 4. The smallest region enclosed by all bisectors is the Voronoi cell. One last subtlety when we build the Voronoi cell is when the interface is in between the center nodes and the neighbor nodes, we cut the Voronoi cell so that the edge follows the interface. This feature helps with setting the Neumann boundary condition on the interface

24 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

Fig. 2.14: Procedure to make a Voronoi cell. The red node is the center node. The final orange region is the Voronoi cell

Fig. 2.15: An example of Voronoi representation close to the interface. The green dashed line shows the Voronoi cell around v0, and the red line is the interface. We can see that line l4l2 is the cut edge of the regular Voronoi cell, which should be a square in this case. Figure from[5].

25 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

Fig. 2.16: This transformation uses the x-velocity stored at the vertical sides of quadtree grids (left). The Voronoi diagram is on the right. Notice on the edge of the computational domain, the Voronoi cells are missing. This is because we force Dirichlet boundary conditions on the edge (such as no-slip b.c), so they do not need to be computed. Figure from[5].

by integrating u nˆ b.c on the edges (or faces) of the Voronoi cell. This feature is shown in Fig. 2.15. r · | For coding part, we build the Voronoi cells using our geometric algorithm developed in 2D, and software Voro++ in 3D[16]. With all the features described above, the transformation from a quadtree grid to Voronoi diagram is shown in Fig. 2.16 The Voronoi spatial separation is extremely useful for the second order discretization. Remember here the surface integral done on the @C in Eq. 2.44, we can easily discretize the surface integral:

@u ui u0 ⇢Vol(C) + u u = si (2.45) @t ·r di ✓ ◆ i Voro(u0) 2 X where Voro(u0)referstotheneighborsofu0 involved in its Voronoi cell; di is the distance between the two data points u0 and ui,andsi is the length of the edge (or the area of the face in 3D).

2.3.5 Discretization of the Projection Step Referring back to Eq. 2.38, the projection step is

= u⇤ r·r r· This step is a Poisson equation solving the value of Hodge variable at the center of the cells. We apply finite volume approach to this equation to get

nˆ = u⇤ nˆ r · · I@c I where @c is the contour of the cell.

26 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

Fig. 2.17: Nomenclature used in the discretization of the projection step. Figure from[5].

Both first order[9] and second order[8] discretization scheme for Poisson equation have been introduced. The following section shows how the second order discretization scheme is applied in the projection step.

We are using notations labeled in Fig. 2.17. ci is the leaf containing ci . NgbL(ci)/NgbR(ci) refers to indices of all the cell connecting to the left/right of ci. For example, NgbR(c2)= Ngb (c )= 1, 2, 3 . s is the length of the side connecting c and c . is the signed L 0 { } ci 0 i fci distance between center of ci and face f where f nˆf is being discretized, andn ˆ is the outer normal of the face. For the signed distance,r | ·

> 0iff is to the left of ci fci (< 0iff is to the right of ci

Because we are using finite volume method on Cartesian grid, on a vertical face, only @x needs to be discretized. First we define the average distance

sci sci f = (fc0 fci )= i sc0 sc0 i Ngb (c0) i Ngb (c0) 2 XL 2 XL Then the discretization scheme is

sci c0 ci f nˆf =(@x)c0,L = (2.46) r | · sc0 f i NgbL(c0) ✓ ◆ 2 X Notice that the discretization is symmetric so that the flux of gradient of Hodge variable is conserved: s (@ ) = s (@ ) . ci x ci c0 x c0,L i Ngb (c0),R 2 XL Now we can show that this discretization scheme is second order accurate at the center of the face f of cell ck. ⌘ik is the signed distance between the center of ci and the center of ck.

27 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

1 sci (@x)ck,R = (c0 ci ) f sc i Ngb (c ) 0 2 XR k 1 sci = ( f + fc0 @x f ⌘k0@y f f fci @x f ⌘ki@y f + o(fci ,⌘ki)) f sc | | | | | | i Ngb (c ) 0 2 XR k 1 sci = (i@ f + ⌘i0@y f + o(fci ,⌘ki)) f sc | | i Ngb (c ) 0 2 XR k @y f = @x f + | sci ⌘i0 + o(fci ,⌘ki)(2.47) | sc f 0 i Ngb (c ) 2 XR k If we use yi,thecoordinateofthecenterofcellci,and↵i,thecoordinateofthecenterof the edges of the cells to rewrite the summation in the second term, we could obtain

s ⌘ = s (y y ) ci i0 ci 0 i i Ngb (c ) i Ngb (c ) 2 XR k 2 XR k n 1 = s y (↵ ↵i)(↵ + ↵ ) c0 0 2 i+1 i+1 i i=0 X 1 n = s y (↵2 ↵2) c0 0 2 i+1 i i=0 1 X = s y (↵2 ↵2) c0 0 2 n 0 1 = s y (↵ ↵ )(↵ + ↵ ) c0 0 2 n 0 n 0 = s y s y c0 0 c0 0 =0. Therefore, the second term in Eq. 2.47 is zero, which shows that the discretization scheme is second order accurate. For the u⇤,it’saeasycaseafterweapplythedivergencetheorem. For uniform grid, the result is r·

⇤ ⇤ ⇤ u dV = u nˆ ufi nˆfi sfi c0 r· @c0 · ⇡ · f @c0 Z I iX2 fi refers to the sides/faces around the cell c0. Notice that in quadtree, this method has one problem. Referring to Fig. 2.17, the u⇤ on the left side of cell c0 is not well defined because each smaller cell (c1, c2,andc3)hasau⇤ defined on their right sides. In this case, we uniquely define the value of un⇤ on the ”problematic” side, which means when the finite volume method is applied, both the smaller cells ci and the larger cell c0 will use the same un⇤ on the ”problematic” side. The value will be the weighted average of the previously defined value:

sc1 (uc⇤1 )n + sc2 (uc⇤2 )n + sc3 (uc⇤3 )n (uL⇤ (c0))n = (uR⇤ (ci))n = sc0

28 CHAPTER 2. COMPUTATIONAL TECHNIQUES 2.3. PROJECTION METHOD

Up to this point, we obtain our scheme to discretize the two steps for solving the incom- pressible Navier-Stokes equations.

29 Chapter 3

Free Surface Flow

In this section, we present the various boundary conditions that have been developed to simulate the free surface flow. While the physical boundary conditions are straightforward to determine from the continuum mechanics, they are not straightforward to enforce and other numerically stable choices have been preferred. In this section, we intend to present and analyze possible improvement.

3.1 Two Models

3.1.1 Sinusoidal Wave in 2D The first scenario we want to examine is the natural evolution of the free surface in 2D. It’s asimplecasewheretheReynoldsnumberisrelativelylowsothatwedonotneedextremely refined mesh to capture all the details. The exact situation is shown in Fig. 3.1. The computational domain is a 1 1 square box. The shape of the free surface at the beginning is given by ⇥

y = h + asin(2⇡kx),x [0, 1] 2 In most cases, h =0.5, a =0.04, k =1.Weenforceaperiodicboundaryconditioninˆx direction for simplicity. Then we need to define the Reynolds number for this case like other fluid dynamic studies. Usually the Reynolds number is defined as ⇢vL Re = (3.1) µ where ⇢ is the density of the fluid, v is the characteristic velocity, L is the characteristic length scale, and mu is the viscosity. Here we define the characteristic parameters as 1 v = pg a, L = · k In this way, we include the parameters to specify the system. In practice, we know that when the dimensionless parameters does not change, the governing equation produces same dimensionless result. Therefore, we adjust gravitational constant g to force v =1.Meanwhile, we set ⇢ =1andforceµ =1/(Re k)toeasilysettheReynoldsnumber. ·

30 CHAPTER3.FREESURFACEFLOW 3.1.TWOMODELS

Fig. 3.1: The initial shape of the free surface.

3.1.2 Oscillating Cylinder/Ball The second situation we used to examine the solver is an oscillating cylinder in 2D or a circularly moving ball in 3D in a tank. The are a couple of significant di↵erences with this case: 1. there is an active energy source. 2. a new level set function is needed to describe the cylinder/ball. The motion of the energy source is defined by a equation of motion about its center. In 2D, L x = + Acos(!t) y = constant (3.2) 2 and in 3D, L L x = + Acos(!t) y = + Asin(!t) z = constant (3.3) 2 2 L is the side length of the computational domain. Usually our computational domain is 1 1( 1). Then we can define the Reynolds number and Weber number as ⇥ ⇥ ⇢U L ⇢U 2 L Re = ball We = ball µ

Here Uball means the maximum speed of the energy source. Typically, if we set the fluid to be water, the Reynolds number is of order 105 106,forwhichoursolvercannotreally capture all the details. Therefore, we usually set⇠ unrealistic parameters to test with our solver in this case.

31 CHAPTER3. FREESURFACEFLOW 3.2. BOUNDARYCONDITIONREPORT

(b) 3D ball moving in a circle.

(a) 2D oscillating cylinder.

Fig. 3.2: Example of oscillating cylinder in 2D and 3D circular motion of a ball. On the left, relevant parameters are marked on the plot.

3.2 Boundary Condition Report

3.2.1 Boundary Condition: Pressure In the original version of the solver, a homogeneous Dirichlet boundary condition on pressure field on the free surface was enforced,

p =0. | This would make the calculation less expensive and stable, but it certainly does not describe the physical situation. The improvement is to include the surface tension e↵ect in to this term. By Young-Laplace equation, the pressure field should have a jump across the free surface given by

u + uT p =  + µnˆ r r nˆ | · · 2 · ✓ ◆ where is the surface tension coecient, and  is the local mean curvature. To implement this feature, a brief procedure is introduced in Algorithm 1.

32 CHAPTER3. FREESURFACEFLOW 3.2. BOUNDARYCONDITIONREPORT

Algorithm 1: Calculate the local pressure jump Data: Result: Store pressure jump on nodes, and ready for interpolation

1 Grab level set function ,andcreateavectortostore@xi

2 Compute the @xi in ghost layer. 3 Start communication between di↵erent processes.

4 Compute the @xi in local layer. 5 End communication between di↵erent processes. 6 Create a vector to store curvature .

7  =computemean curvature(,@xi ,) 8 Scale  by surface coecient . 9 Send  to interpolator. Similar to Reynolds number, Weber number is usually used to describe the surface tension e↵ect. It’s given by

⇢v2L ⇢ag We = = . k

Example 1. First we can compare the result of the new implementation. Specifically, the initial free surface is defined by y =0.5+0.08sin(2⇡x),x,y [0, 1] 2 Parameter is adjusted such that Re = 200 and We = 500, 7520 .Thereisnospecificreason why we choose these two numbers, but just to compare{ results} with vastly di↵erent Weber number. The result is shown in Fig. 3.3. The level of refinement is (5, 7), which means that the computational domain is refined 5 times at the beginning, and then refine according to the criterion introduced in Sec. 2.2.2 up to a maximum of 7 times. In the diagram, we can see the e↵ect of surface tension. The snapshot is taken when the left peak is falling down. Here we can see that with smaller Weber number (cyan line), which means greater surface tension coecient, the free surface falls faster and is more rounded. This result meets our physical intuition because the surface tension tends to flatten out the free surface in this case.

3.2.2 Boundary Condition: Stress The second boundary condition we want to modify is the stress tensor boundary condition on the interface. For Newtonian fluid, we can express the stress tensor (viscous force) as @u @u ⌧ = p + µ i + j ij ij @x @x ✓ j i ◆ The first term is the normal stress and the second term is the shear stress. Before the mod- ification, a homogeneous Neumann boundary condition was enforced, which can be expressed as (ˆn u) = 0. ·r |

33 CHAPTER3. FREESURFACEFLOW 3.2. BOUNDARYCONDITIONREPORT

Fig. 3.3: Result from two simulation with di↵erent Weber number. Each colored line represents the free surface. Cyan line refers to We = 500 and orange line refers to We = 7520. The grid is shown in the background. The level of refinement is (lmin, lmax) = (5, 7).

We want to implement a more realistic boundary condition for the stress, which sets the tangential stress to be zero on the interface, given by (ˆn u) = nˆ uT . ·r | ·r | However, in the solver, boundary condition is applied when solving for the intermediate velocity field u⇤. Notice that u = u⇤ , where is the Hodge variable, we can apply boundary condition r T (ˆn u⇤) = nˆ u +(ˆn ) (3.4) ·r | ·r | ·rr | Or in index notation, @u @u @ @ n i⇤ = n j + n i @x i @x i @x @x j i j i Usually, the second term of RHS of Eq. 3.4 is ignored because the Hodge variable is only known to second order accurate. Then taking second gradients of the Hodge variable will be not accurate at all, which means that it will destabilize the boundary condition. During our research, we found out that this is very dicult to be implemented. We didn’t get a satisfying modification working, but we study several influences brought by this physical boundary condition. Algorithm 2 shows the steps to implement this feature.

34 CHAPTER3. FREESURFACEFLOW 3.2. BOUNDARYCONDITIONREPORT

Algorithm 2: Force the boundary condition of stress tensor.

Data: ,@xi , u Result: Store the value of RHS of Eq. 3.4 on nodes for later interpolation. 1 Initialize several vectors to store the data. 2 Grab , u on nodes. r 3 Calculate normal vector on ghost nodesn ˆ =computenormal(,@xi , nˆ) 4 Calculate @jui and @j@ionnodesusingcentraldi↵erencemethod. 5 Start communication between di↵erent processes. 6 Do the same calculation for local nodes. 7 End communication between di↵erent processes. 8 Assemble boundary condition according to Eq. 3.4 on ghost nodes. 9 Start communication between di↵erent processes. 10 Assemble Eq. 3.4 on local nodes. 11 End communication between di↵erent processes. 12 Set input to the interpolator for calculating the boundary condition on the free surface.

Example 2. The first diculty we encountered is that this boundary condition does not actually make the stress tensor vanish at the free surface. We figure this out by explicitly calculating the boundary values of the stress tensor after the subloop, which means we check after each time step is solved. We calculate ⌧ /µ = nˆ ( u + uT ) .Theresultisshownin Fig. 3.4. The reasonable expectation should| be| that| the· r boundaryr | value converges to zero. In the diagram, with the free surface colored by the boundary value, the legend shows that the boundary values has same order of magnitude with velocity field, which is typically of 1 0 order 10 10 . Also, when the grid is refined, the boundary values is not reduced but sometimes increased.⇠ Meanwhile, we tried to find the tangential components of the stress using projection operator given by ⌧ =(I nˆ nˆ) [( u + uT ) nˆ] tan ⌦ · r r · The tangential component does not converge neither. These outcomes let us draw the conclusion that this method of setting the boundary condition of the stress tensor is not accurate.

Secondly, we notice that this boundary condition tends to make the simulation unstable. For each time step, the solver will iterate a couple times (subloop) to solve for convergence of Hodge variable and velocity field, where the new boundary condition is applied. The exit condition for this subloop is either max <✏or (ui)max <✏. Themeans the di↵erence (error) of a variable at a location between two subloop iterations. In the original version, if we do not set the exit condition, the di↵erences goes down monotonously to machine precision, which is the sign of convergence. However, when we apply the new boundary condition, the di↵erences first decrease and then climbs up, which gives divergent result.

35 CHAPTER3. FREESURFACEFLOW 3.2. BOUNDARYCONDITIONREPORT

Fig. 3.4: This diagram shows two simulation of sinusoidal wave described in Example 1. The boundary condition of stress tensor is turned on. On the left is the simulation with level of refinement (4,6). On the right is the simulation with level of refinement (5,7). The free surface is colored according to the boundary values.

Example 3. We use the oscillating cylinder model to present this result. The computational domain is still (x, y) [0, 1]. The free surface starts flat with height y =0.7. The cylinder has radius r =1.5 and2 its position and velocity is given by, x =0.5+0.1cos(!t) y =0.3 v = 0.1!sin(!t) v =0 x y ! =0.1⇡f, f (0, 40] is the angular frequency which we change to see di↵erent results. We exclude f 2=0casebecauseofwaterlosse↵ect(willbeintroducedinnextsection), and the simulation diverges after the free surface reaches the oscillating cylinder. To better understand the instability, we checked the lower bound of the error respect to time. It means that for each time step, we let the subloop run until the error is not decreased anymore. We also check the dependency of the lower bound respect to the oscillating frequency of the cylinder. The plots of lower bounds are in Fig. 3.6. We can see two characteristics right from the plots: 1. The lower bound that the error of velocity can reach tends to grow over time. 2. The lower bound tends to be larger for higher frequencies. The first characteristic implies that if we set the tolerance to a certain value, then there will be a moment when the error cannot be reduced to the tolerance because it’s increasing

36 CHAPTER 3. FREE SURFACE FLOW 3.3. VOLUME REPORT

(a) subloop iteration #0 (b) subloop iteration #6 (c) subloop iteration #12

Fig. 3.5: The change of velocity field during subloop at the time step when the simulation diverges. The computational domain is colored according to the magnitude of the velocity. over time. The second feature is reasonable because with fast oscillation, the system has high Reynolds number, which requires finer mesh to capture all the details. In addition to checking the lower bound of the error, we also examine the evolution of the velocity field in the subloop to seek for the reason why the simulation diverges. In Fig. 3.5, we can see that at the beginning of the subloop, the velocity field looks normal. After 6 iterations, there are some areas above the free surface growing abnormally. Then the region around those areas are a↵ected and further increases the instability, which fails the whole simulation. This issue can only be alleviated by changing the order of extrapolation. The specific scheme used to do the extrapolation is described in[1]. We usually ignore the computational domain above the free surface because we treat the system as single phase. However, when we need to calculate the derivative of a variable such as velocity field near the free surface, we need the information from neighbors. Therefore, extrapolation scheme is used to produce a reasonable guess for the pseudo field above the free surface, which allows us to do appropriate derivatives. When we solve the projection method in two steps, we apply 2nd order extrapolation across the free surface, which is identified as the primary source of instability after we apply the stress boundary condition. After changed to 0th order extrapolation, a number of cases run through for the two scenarios we consider here. However, one disadvantage of the 0th order extrapolation is that it adds a small amount of energy into the system. That means for the cases as sinusoidal wave who have no other energy source, the energy of the system is not preserved. Currently we haven’t found a better way to deal with this boundary condition, but if future research will carry out a more stable and accurate method to correctly force this boundary condition, it would definitely help with subsequent fluid simulation such as multi-phase flow.

3.3 Liquid Volume Report

There are always some quantities that should be preserved during the simulation, such as energy, , and mass. In this section, we examine the most obvious quantity that should be preserved in our simulation–the volume of the liquid, which is equivalent to mass conservation due to incompressible condition.

37 CHAPTER 3. FREE SURFACE FLOW 3.3. LIQUID VOLUME REPORT

(a) (b)

Fig. 3.6: Two sets of result from lower bound test with various oscillating frequency. The simulation is taken with level of refinement (4, 6).

In all cases, we use the oscillate cylinder model and we adjust the parameters so that there’s no fluid spilled out of the tank. However, the level set method we used to track the free surface does not preserve the volume (area in 2D) of the computational domain ⌦ theoretically. We expect that the change should be negligible if we have a well refined mesh. The way we compute the volume using the member function integrate over negative domain(p4est t, p4est nodes, ,f).Inthefollowingsimulation,weusetheoriginalversionofthesimulation, which imposes the homogeneous boundary condition on velocity field.

3.3.1 Level of Refinement It’s expected the change of water volume should be reduced if we elevate the level of refine- ment. We run the simulation with di↵erent combinations of (lmin, lmax) shown in the Fig. 3.7. we can see that clearly di↵erent levels of refinement have di↵erent rate of volume change. The five cases separated in two branches. The top two are cases that have lmax = 7, and the bottom three lmax = 6. we may deduce from this that the coarseness does not a↵ect this volume change much. It’s because the free surface, which determines the water volume, is captured with the finest grid. Therefore, the coarse cells are far from the finest cells, which have little e↵ect on the evolution of the free surface. In Fig. 3.7(b), we get the same conclusion for uniform grids. It’s worth noticing that when the level of refinement is too low, like 4–4 and 5–5, the simulation cannot appropriately capture the free surface, which introduces the huge fluctuation on the water volume. As shown in Fig. 3.4, the dynamic of the free surface flow is a↵ected by the level of refinement, which could be partly due to this volume change e↵ect.

3.3.2 Frequency Interestingly, frequency also contributes to the change of water volume. Although the reason is still unknown, it’s still helpful to gather some empirical conclusions for future simulation.

38 CHAPTER 3. FREE SURFACE FLOW 3.3. LIQUID VOLUME REPORT

(a) (b)

Fig. 3.7: Water volume respect to time in di↵erent cases. (a) are using adaptive grids, except 6–6, and (b) are using uniform grids.

We still use f (0, 40] as in Example 3 for setting frequencies. The results2 are shown in Fig. 3.8. We see that when we increase the oscillating frequency, the slope is increased as well. For low frequencies, water is lost, but for high frequencies, the water loss e↵ect is suppressed. Illustrated in Fig. 3.8(a), when the frequency increases, the loss e↵ect is reduced fast. The theoretical reason for the frequency dependency is still unknown, but this result prompts us about the range of frequency we should choose for this test.

(a) (b)

Fig. 3.8: Water volume respect to time with various oscillating frequencies. In these cases, level of refinement is (5,8).

3.3.3 Surface Tension The last variable we investigated is the newly implemented surface tension coecient. We also take oscillating cylinder/ball as our test case. We notice that for water, the surface

39 CHAPTER 3. FREE SURFACE FLOW 3.3. LIQUID VOLUME REPORT tension e↵ect is almost negligible in simulation. Therefore, we test this e↵ect by unrealistic 1 surface tension coecient = 0, 5, 10 Nm { }

Fig. 3.9: This plot shows how the surface tension coecient a↵ect the rate of volume change. The level of refinement is (4,6)

In Fig. 3.9, we can tell with di↵erent , the volume of water changes di↵erently. With higher ,watervolumedecreasesfaster.Deducedfromthepreviousinvestigationaboutthe frequency dependency, we may guess the flatter free surface (low frequency or high )leads to higher loss, but currently there’s no mathematical support to this assumption. Notice that for all cases, the slop increases at later stage of simulation, which is another interesting aspect to further study.

40 Chapter 4

Summary

In this thesis, we introduces our research about the free surface flow. Undoubtedly, free surface flow is a basic but fundamental fluid dynamic problem that can be expanded into various deeper researches, such as multi-phase flow and super-hydrophobic flow. However, this basic subject also contains some of the most common diculties we would encounter when conducting computational fluid dynamic researches. The obstacles are not limited to splitting the computational domain, solving highly nonlinear di↵erential equations and repre- sentation of the geometry. Therefore, we start with the introduction of several computational techniques. The level set method aims to provide a simple way to describe the geometry in the com- putational domain. In our cases, the level set method can capture the free surface and the oscillating cylinder/ball. The idea is to use a continuous function defined at each point of the computational domain, whose 0 level set = x (x)=0 represents the target geom- etry. We choose a particular type of level set function–signed-distance{ | } function–to simplify our implementation. The diculties of this method includes the evolution of the level set function, and the reinitialization process, which can turn any level set function into a signed- distance function. We apply a particular set of discretization techniques, e.g. Godunov Hamiltonian and minmod() slope limiter. Splitting the computational domain is also essential to the simulation. There are various methods to generate meshes. In general, there are three categories: uniform grid, non- uniform grid, and grid-free separation. Each of them has its own power and weakness. We use the adaptive grids called quadtree/octree. The computational domain consists of several square/cube tree structure, which means that the space is split into four squares or eight cubes with equal size when refinement happens. This adaptivity allows the solver to focus on the region of interest, which is the free surface in our research. Based on this structure, we give a set of discretization methods such as second order finite di↵erence method, which is important particularly for T-junction nodes. As for solving the Navier-Stokes equation. We make use of the well-known projection method. As introduced in Chapter 2, before the method was developed, incompressible Navier-Stokes equation is nearly not solvable due to the lack of equation for pressure field. Projection method first ignores the pressure field to obtain an intermediate velocity field, which subsequently will solve a Poisson equation of the Hodge variable to get the new pressure field. To implement this process, we incorporated Voronoi cells and finite volume schemes, along with the Poisson equation solver based on finite di↵erence method.

41 CHAPTER 4. SUMMARY

A general goal of this research is to improve the solver such that the simulation better approaches the real situation. To achieve this goal, we try to modify two boundary conditions on the free surface. First one is to include the surface tension e↵ect of the fluid. We take the Young-Laplace equation to compute the surface tension using built in member function. It turns out by a straight forward calculation, the surface tension e↵ect can be included into the solver with physical correction to the result. The second one is the stress tensor (or velocity field) boundary condition. We intend to set the stress on the free surface to be zero because of the property of fluid. However, our method does not lead to a convergent outcome and would potentially destabilize the simulation. Therefore, further exploration is still necessary. A bonus examination of this research is studying the conservation of the volume of the computational domain. We perform inspection on three parameters: level of refinement, frequency of oscillating cylinder, and surface tension coecient. The reason of di↵erent rate of volume change is still unknown, which is another interesting future direction.

42 Bibliography

[1] Tariq D Aslam. A partial di↵erential equation approach to multidimensional extrapola- tion. Journal of Computational ,193(1):349–355,2004. [2] Alexandre Joel Chorin. A numerical method for solving incompressible viscous flow problems. Journal of computational physics,2(1):12–26,1967. [3] Frederic Gibou, Ronald Fedkiw, and Stanley Osher. A review of level-set methods and some recent applications. Journal of Computational Physics,353:82–109,2018. [4] James Glimm, John W Grove, XL Li, and N Zhao. Simple front tracking. Contemporary Mathematics,238(2):133–149,1999. [5] Arthur Guittet, Maxime Theillard, and Fr´ed´eric Gibou. A stable projection method for the incompressible navier–stokes equations on arbitrary geometries and adaptive quad/octrees. Journal of Computational Physics,292:215–238,2015. [6] Francis H Harlow and J Eddie Welch. Numerical calculation of time-dependent viscous incompressible flow of fluid with free surface. The physics of fluids,8(12):2182–2189, 1965. [7] Seiichi Koshizuka and Yoshiaki Oka. Moving-particle semi-implicit method for fragmen- tation of incompressible fluid. Nuclear science and engineering,123(3):421–434,1996. [8] Frank Losasso, Ronald Fedkiw, and Stanley Osher. Spatially adaptive techniques for level set methods and incompressible flow. Computers & ,35(10):995–1010,2006. [9] Frank Losasso, Fr´ed´eric Gibou, and Ron Fedkiw. Simulating water and smoke with an octree data structure. ACM transactions on graphics (TOG),23(3):457–462,2004. [10] R Meniko↵, RC Mjolsness, DH Sharp, and C Zemach. Unstable normal mode for rayleigh–taylor instability in viscous fluids. The Physics of Fluids,20(12):2000–2004, 1977. [11] Chohong Min and Fr´ed´eric Gibou. A second order accurate projection method for the incompressible navier–stokes equations on non-graded adaptive grids. Journal of Computational Physics,219(2):912–929,2006. [12] Chohong Min and Fr´ed´eric Gibou. A second order accurate level set method on non- graded adaptive cartesian grids. Journal of Computational Physics,225(1):300–321, 2007.

43 BIBLIOGRAPHY BIBLIOGRAPHY

[13] Mohammad Mirzadeh, Arthur Guittet, Carsten Burstedde, and Frederic Gibou. Paral- lel level-set methods on adaptive tree-based grids. Journal of Computational Physics, 322:345–364, 2016. [14] Stanley Osher and James A Sethian. Fronts propagating with curvature-dependent speed: algorithms based on hamilton-jacobi formulations. Journal of computational physics,79(1):12–49,1988. [15] Giovanni Russo and Peter Smereka. A remark on computing distance functions. Journal of Computational Physics,163(1):51–67,2000. [16] Chris Rycroft. Voro++: A three-dimensional voronoi cell library in c++. Technical report, Lawrence Berkeley National Lab.(LBNL), Berkeley, CA (United States), 2009. [17] Ruben Scardovelli and St´ephane Zaleski. Direct numerical simulation of free-surface and interfacial flow. Annual review of fluid mechanics,31(1):567–603,1999. [18] Mark Sussman, Emad Fatemi, Peter Smereka, and Stanley Osher. An improved level set method for incompressible two-phase flows. Computers & Fluids,27(5-6):663–680, 1998. [19] Dongbin Xiu and George Em Karniadakis. A semi-lagrangian high-order method for navier–stokes equations. Journal of computational physics,172(2):658–684,2001. [20] Christopher J Zappa, WE Asher, and AT Jessup. Microscale wave breaking and air-water gas transfer. Journal of Geophysical Research: Oceans,106(C5):9385–9391,2001.

Supervisor Signature:

44