Lecture 13 18.086 Multi-phase flow

Lattice-Boltzmann simulation of two-phase flow

https://www.youtube.com/watch?v=1tasbL39xds A. I. Kupershtokh, 2013 Modeling of moving Evolving Curves and Surfacesinterfaces

• Propagate curve according• Will talk to speedabout Levelsetv = andF n Fast marching method

• F depends on space,• Based time, and on the notes curve of itself Per-Olof Persson (see download link on course website)

• Surfaces in three dimensions • Problem statement: Moving interfaces Evolving Curves and Surfaces F • Propagate curve according to speed function v = F n

• F depends on space, time, and the curve itself

• Surfaces in three dimensions

F Two differentGeometry Representations approaches

Explicit Geometry Implicit Geometry

• Parameterized boundaries • Boundaries given by zero level set

φ(x, y)=0

φ(x, y) < 0

(x, y)=(x(s),y(s)) φ(x, y) > 0 Explicit geometry modeling Explicit Techniques Explicit• Simple approach: Techniques Model geometry explicitly by parametrized curves c(s) or surfaces Ω(s1,s2) (i) x(i) • Simple• Simple approach: approach: Represent• Discretized Represent curve as explicitly curvea set of explicitly nodes by nodes x , byconnectedx nodes(i) and by lines edgesand (in lines 3D: “triangulated ”) • Propagate curve by solving ODEs • Propagate curve by solving• Move ODEs nodes according to ODEs: (i) x(i) dx (i) d (i)v x(i) (i) x(i) (i) x = v(x= ,t(), x,t),(0) = x(0), = 0 , dt dt 0 • Geometric properties (normal vector, curvature etc.) obtained by finite • Normal• Normal vector, vector, curvature, curvature,differences, etc by differenceetc e.g. by difference approximations, approximations, e.g.: e.g.: − dx(i) dxx(i)(i+1) x−(ix+1)(i−−1) x(i 1) ≈ ≈ ds ds 2∆s 2∆s • MATLAB• MATLAB Demo Demo DisadvantagesExplicit Techniques - Drawbacksof explicit • Node redistributiongeometry required, introduces modeling errors • •NoShape entropy deformation solution, sharp leads corners to distortion handled => incorrectly need to redistribute nodes to accurately represent geometry! • Need special treatment for topology changes • Incorrect behavior at corners • Stability constraints for curvature dependent speed functions • Difficult to deal with topology changes!

Node distribution Sharp corners Topology changes Implicit geometry modeling

• Sethian & Osher (1988)

• Represent curve by the zero level set of a function, ɸ(x)=ɸ(x,y,…)=0

• Level set of a function f(x): Values x along which f has constant value

Circle of radius r is in the level Topological changes easy to 2 2 set of the function f(x)=x +y model! ImplicitDiscretized geometry Implicit Geometries modeling

Discretize implicit function on background grid • •Discretization (idea): Discretizeφ implicit function ɸ(x) on background grid • Obtain φ(x) for general x by interpolation • To find curve of zero level set ɸ(x)=0, interpolate for general x.

Cartesian Quadtree/Octree Implicit Geometries

•ImplicitRepresent curve bygeometry zero level set of a function, modelingφ(x)=0

•• ASpecial special but case: verySigned important choice for function ɸ(x) is the: signed distance function. Then: – |∇φ| =1 – |φ(x)| gives (shortest) distance from x to curve

φ>0

φ<0 Geometric Variables

n • Normal vector (withoutImplicit assumingGeometric geometry distance Variables function): modeling Geometric Variables • When the curven is evolving,∇φ it’s often necessary to know its geometric • Normal vectorproperties.n (without For instance, assuming= a distanceforest fire function): only moves normal to its current front • Normal vector n (without assuming distance function):|∇φ| • Normal vector n (for general ∇�)φ • Curvature (in two dimensions): ∇φ n = n = |∇φ| |∇φ| 2 2 • Curvature (in∇ twoφ dimensions):φxxφy − 2φyφxφxy + φyyφx • Curvature (for 2D curve): • Curvature (in two dimensions):κ = ∇ · = 2 2 3/2 . |∇φ| (φx2 + φy) 2 ∇φ φxxφy − 2φyφxφxy + φyyφx κ = ∇2 · = 2 . ∇φ φxxφy − 2φyφxφxy + φyyφx2 2 3/2 |∇φ| (φx + φy) • Writeκ = material∇ · parameters,= etc,2 in terms2 3/2 of φ: . |∇φ| • Material parameters(φx + φy )(e.g. density inside vs. outside):

• Write materialx parameters, etc, in terms of φ: x • Write material parameters, etc, ρ in( terms)= ofρ1φ+(: ρ2 − ρ1)θ(φ( ))

ρ(x)=ρ1 +(ρ2 − ρ1)θ(φ(x)) x where θ is the Heavisidex step function (smoothened in the discretized Smooth Heavisideρ( )=ρ functioncase)1 +(ρ2 θ−overρ1)θ( aφ few( )) grid cells. Smooth Heaviside function θ over a few grid cells. Smooth Heaviside function θ over a few grid cells. The Level Set Equation The LevelLevel Set Equation set equation • Solve convection equation to propagate φ =0by velocities v The Level Set Equation v • Solve convection equation• Propagate to propagate � (not onlyφ =0its zeroby level velocities set!) by solving the advection equation v • TheSolve Level convection Set equation Equation to propagateφt +φ =0v ·by∇ velocitiesφ =0. φt + v · ∇φ =0. • Since only normalv part F=v ·n of velocity changes shape of curve, we can • Solve convection equation to propagateφ =0by velocitiesφt + v · ∇φ =0. simply assume v=Fn. Then, we obtain, using 2 For v• Fornv, use= nF n, use n =and∇φ/|∇φ| and ∇φ2·to∇ obtainφ = the|∇φ| to obtain the • = F φt +=v ·∇∇φφ=0/|∇. φ| ∇φ · ∇φ = |∇φ| • For v = F n, use n = ∇φ/|∇φ| and ∇φ · ∇φ = |∇φ|2 to obtain the Level SetLevel Equation Set Equation • For v = Fn, useLeveln = Set∇φ/ Equation|∇φ| and ∇φ · ∇φ = |∇φ|2 to obtain the Level Set Equation φ + Fφ|∇+φF||∇=0φ| =0. . level set equation t t φt + F |∇φ| =0. φt + F|∇φ| =0.

• Nonlinear, hyperbolic• Since equation F can depend (Hamilton-Jacobi). on shape of curve, this is a nonlinear (hyperbolic) equation. •• Nonlinear,Nonlinear, hyperbolic hyperbolic equation (Hamilton-Jacobi). equation (Hamilton-Jacobi). • Nonlinear, hyperbolic• Shape of equation curve is obtained (Hamilton-Jacobi). by finding the zero level set Discretization

• Discretize � using upwind finite differences (schemes from conservation laws!)

• See online notes for details of discretization (change upwind direction depending on sign of F).

• Matlab demo The Level Set Equation

• Solve convection equation to propagate φ =0by velocities v

φt + v · ∇φ =0.

v n n 2 • For Reinitialization=ReinitializationF , use = ∇φ/|∇φ| and ∇φ · ∇φ = |∇φ| to obtain the Level Set Equation • Large variations in ∇φ for general speed functions F • Consider the level set equation φ t + F | ∇ φ | =0 . • Poor accuracy and performance, need smaller timesteps for stab ility • After few timesteps, ∇� varies from point to point. • Reinitialize by• finding=>• Nonlinear,requires new φ smallwith hyperbolic same timestep zero equation levelfor stable set but (Hamilton-Jacobi). time|∇ integration!φ| =1

• => Re-initialize by finding a new with the same zero level set, but with | ∇ |=1 • Different approaches: � � • Two different approaches: 1. Integrate the reinitialization equation for a few time steps • Stop advection, instead integrate the reinitialization equation for a few timesteps:

φt + sign(φ)(|∇φ| − 1) = 0

2. Compute • Find a completely from φ =0 new �explicitly with | ∇�|=1 for : Signed nodes distance close function! to boundary, => Need to find signed distance of each mesh point from current curve, i.e. from �=0 (e.g. use Fast Marchingusing the Method fast marching for remaining method) nodes Implicit Geometries

• Represent curve by zero level set of a function, φ(x)=0

• Special case: Signed distance function: – |∇φ| =1 – |φ(x)| gives (shortest) distance from x to curve Fast marching φ>0 method φ<0 • Problem statement: Find distance of grid points from curve �=0. • Equivalent problem: Let the curve propagate in normal direction with uniform speed F>0 (outward), or F<0 (inward), and find the arrival time of the front for each grid Firstpoint. arrivals and shortest geodesic paths • Arrival time calculation is a very generic problem:

Visibility around obstacles The Boundary Value Formulation

• For F>0, formulate evolution by an arrival function T • T (x) gives time toFast reach x from initial marchingΓ method • time * rate = distance gives the Eikonal equation: • Problem statement: Find| ∇distanceT |F =1 of,T grid points=0on fromΓ. curve �=0 <=> arrival time T(x) for front propagating with speed F>0 • Special case: F =1gives distance functions • T(x) is the time needed to reach x from initial curve �

T(x,y) The Boundary Value Formulation T(x,y) for � a circle

• For F>0, formulate evolution by an arrival functionT

• T(x) gives time to reach x from initial Γ x y • time * rate = distance gives the Eikonal equation: • Note: Since time * velocity = distance, we obtain the Eikonal equation |∇T|F =1,T=0on Γ. This is now an boundary value problem, not an initial value problem! In other words, the• fastSpecial marching case: methodF =1 actuallygives distancesolves an functionsEikonal equation… • To obtain the distance function, we are interested in constant F=1

T(x,y)

x y The Fast Marching algorithm Fast marching method ! Loop { • Rough sketch of method: First, identify curve and fixed values. Mark nearest neighbors1. asLet candidates Trial be and the everything point else in Theas Narrow far-distance. Boundary band Then: Valuewith smallest Formulation u 2.1. MoveLet Trial beTrial the candidatefrom Narrow point with smallest band T. to Alive • For F>0, formulate evolution by an arrival function T 3.2. MoveMark Trial all as aneighbors fixed value (meaning of Trial T is known)to Narrow band • T (x) gives time to reach x from initial Γ 4.3. RecomputeMove all far-distanceu forneighbors all neighbors of Trial as Candidates of Trial • time * rate = distancethis gives is done the byEikonal solving equation the Eikonal: 4. Compute T for all neighbors of Trial } equation using a FD scheme 5. Repeat 1-4 until all grid points are fixed |∇T |F =1,T=0on Γ.

•AlivefixedSpecial case: F =1gives distance functions Narrowcandidates band Farfar-distance points T(x,y)

x y First arrivals and shortest geodesic paths

Applications of Fast

MarchingVisibility Method around obstacles Visibility of obstacles • Travel time (modified fast marching) Examples (in combination with levelsets) Examples

https://www.youtube.com/watch?v=J0hYFvkSfJk Matrices in FD and Matlab

• In discretized problems, we often end up solving Ku=f

• Need fast algorithms to invert K

• Require some knowledge about K (symmetry, Eigenvalues, etc.) Gauss elimination

• Consider Ax=b (with A invertible). Rewrite as

• Bring A of Ax=b into upper triangular form by adding/subtracting multiples of lines with each other:

This is an upper triangular matrix U. One can write A=LU with L a lower triangular matrix: LU decomposition • Solution is Pivots

• Pivots of Gauss elimination: diagonal elements of U.

• Note that very small Pivots are potentially dangerous:

• Cases:

• A=LU (without permutations) and all pivots non-zero: A is invertible

• PA=LU (with permutation matrix P), and all pivots non-zero: A invertible

• There is always one or more zero Pivots: A not invertible Symmetric A, Cholesky factorization

• What if A is symmetric?

• What if A is symmetric and positive definite? Performance

• If A is tridiagonal n x n matrix, U and L are bi-diagonal and LU-factorization requires O(n) operations

• If A is a full matrix:

• A symmetric: O(1/3 n3) operations

• general A: O(2/3 n3) operations

• Band matrices: A has bandwidth w if it’s “farthest” nonzero diagonal has offset w from the diagonal.

• Takes O(w2n) operations