lecture 12 - mathematicsmath.mit.edu/~stoopn/18.086/lecture12.pdflecture 12 18.086 navier-stokes /...

24
Lecture 12 18.086

Upload: others

Post on 20-May-2020

14 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Lecture 1218.086

Page 2: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Navier-Stokes / Flow problems

• Tricky equation, tricky numerics…

• Incompressible Navier-Stokes equation:

6.7 Fluid Flow and Navier-Stokes 533

6.7 FLUID FLOW AND NAVIER-STOKES

The velocity of a viscous incompressible fluid is governed by the Navier-Stokes equa- tions. The dimensionless form brings out the importance of the Reynolds number Re. The velocity is a divergence-free vector u and the pressure is a scalar p:

du Navier-Stokes 1 - + ( u - V ) u = - V p + - n u + f dt Re (1) Continuity equation d i v u = V = u = O (2)

Equation (1) is Newton's Law for the momentum with mass density normalized to 1. The external force f is often absent. Four terms deserve immediate comments:

1. The Laplacian A u applies to each component of u . Viscosity produces dissipation.

2. The constraint div u = 0 (no time derivative in this equation) comes from incompressibility and conservation of mass : const ant density.

3. The pressure p(x, y, t ) is the Lagrange multiplier for that constraint V u = 0. The pressure gradient -Vp drives the flow in equation (I) .

4. The nonlinear term (u V ) u comes from the movement of the fluid. Newton's Law is applied to moving particles, and as they move we have to follow them. The transport rule (28) will be the key. In 2D the velocity u has components u(x, y, t) and v(x, y, t) , and (u V ) u also has two components:

uu, + vuy Components of (u V ) u (3)

The first term is neater if uu, is written as ;(u2),. That looks hard to do for vuy. The product rule for ( U V ) ~ will give an extra term uvy. But zero divergence saves us with u, = -vy. Subtracting the unwanted uvy is the same as adding another uuZ:

Simplify uux + vuy = uux + ( U V ) ~ + UU, = (u2), + ( U V ) ~ . (4)

The same device works for uv, + vvy. (It also extends to 3D.) I will write both components of the 2D momentum equation (1) in a form ready for finite differences:

x direction ~t + PX = (UXX + uyy)/Re - (u2)X - ( 2 1 ~ ) ~ + fi y direction vt + Py = (VXX + vyy)/Re - (uv), - (v2)Y + f2 (5)

The derivation of these Navier-Stokes equations is based on conservation of mass and momentum. This will be quite standard (the choice between Euler and Lagrange is important in equation (26) for mass conservation). To progress directly toward a numerical solution we must know some of the possible boundary conditions.

momentum balancecontinuity/incompr.

equation• In this dimensionless form, the only physical parameter is the Reynolds

number Re

• Pressure p is a Lagrange multiplier, adjusted such that the incompressibility condition is fulfilled.

534 Chapter 6 Initial Value Problems

Boundary Conditions in 2D Flow

Suppose that the physical boundaries are in the coordinate directions, horizontal and vertical. The velocity vector u is still (u, v). At a vertical boundary, u is the normal component of velocity and v is the tangential component. We may have an inflow condition at the left end and an outflow condition (no stress) at the right end:

Inflow across a vertical boundary u = uo and v = vo are prescribed (6) 1 du av Outflow across a vertical boundary - - - p = O and - = 0 Re dx ax

In a channel flow, no fluid crosses the upper and lower horizontal boundaries. The no-slip condition further requires that the fluid is at rest:

No-slip along a u = 0 (from viscosity) and v = 0 (no crossing) (8) horizontal boundary

Along a sloping boundary, the velocity vector is separated into normal and tangen- tial components. The inflow and no-slip conditions st ill prescribe both components, and d/dx in (7) changes to d ldn for outflow (like a free end). Our examples will show other possibilities, staying with horizontal and vertical boundaries.

If we prescribe the outward flow u-n on the whole boundary, then div u = 0 would require u = n ds = 0. Please note the difference between u n and duldn = Vu n, a normal component and a normal derivative.

The Reynolds Number

To reach the Reynolds number Re, the Navier-Stokes equations have been made dimensionless. Physical conservation laws have dimensions. The key to the physics is the relative importance of inertial forces and viscous forces.

inertial forces (a velocity U ) (a length L) Reynoldsnumber R e = % - viscous forces (kinematic viscosity v) (9)

Example 1 Flow in a long channel Here L would be the width of the channel, and U could be the inflow velocity. The number v is a ratio p l p of the material constant p (the dynamic viscosity) to the density p.

Experience is needed to identify an appropriate length scale L and velocity U , characteristic of the flow. Here is a light-hearted scale of Re for some familiar motions:

Reynolds lo-3 += lo0 + lo3 + lo6 -+ lo9 number Re bacteria blood baseball ship

It is natural to compare Re with the Pkclet number Pe = convection/diffusion in Section 6.5. When a flow is driven by gravity, the F'roude number Fr = U / f i

Page 3: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Example: 2D flow in a lid-driven cavity

• Consider 2D box, with no-slip boundary conditions at three boundaries:

536 Chapter 6 Initial Value Problems

leads to Poisson's equation for the pressure. This splitting method first creates a velocity vector U* from Un at the start of the step. Then Un+' comes from U*:

Explicit convection U* - un 1 n u * At + (Un v)Un = -vpn + - + f n (10) Implicit diffusion Re

2 Un+' is the divergence-free part of U*. The pressure pn+' accounts for div U*:

Poisson for p U* = u"+' + grad(pn+' - pn) yields Apn+' = div U* + Apn (11)

Poisson is the equation we know best (also the most expensive). It separates U* into a divergence-free part Un+' and a curl-free field grad (pn+l - pn). Those subspaces are orthogonal complements, with correct boundary conditions. The computation of p on a finite difference grid is usually called Chorin's projection method.

selected streamlines

Figure 6.20: Lid-driven cavity flow u = (u, v) in 2D. A triple p, U, V grid in a cell.

Very Staggered Grids

Those steps need to be executed on an actual grid. Normally U, V, and p are defined at different points, as in Figure 6.20. The pressure p, is located at the center of the i, j cell. The horizontal velocity U is level with that point, but on the edges of the cell (p and U are staggered on row 2). The vertical velocity V is above and below the center (again on the cell edges so V and p are staggered up each column). The three grids for p, U, V bring many conveniences and some unavoidable problems.

A first question is notation for the grid values of U and V. I shall venture a small proposal. The discrete values on the edges would naturally be Uz+;,, and V,,,,;, to the right of i, j and above. The inconvenient "+in is just removed in [66] to leave Ui4 and Kjj. But this can be confusing, since 2, j refers to three different points.

I suggest simply deleting the "4" while leaving the + sign as in U,+, and V, + . Similarly Uz-, and V,- can be values on the left edge and lower edge: see Figure 6.20.

This triple grid avoids a checkerboard oscillation from centered differences p, andp,:

Checkerboard pressure p* on white squares and p* * on black squares. (12)

on a rectangular domain ⌦ = [0, l

x

]⇥[0, l

y

]. The four domain boundaries are denoted North,South, West, and East. The domain is fixed in time, and we consider no-slip boundaryconditions on each wall, i.e.

u(x, l

y

) = u

N

(x) v(x, l

y

) = 0 (4)u(x, 0) = u

S

(x) v(x, 0) = 0 (5)u(0, y) = 0 v(0, y) = v

W

(y) (6)u(l

x

, y) = 0 v(lx

, y) = v

E

(y) (7)

A derivation of the Navier-Stokes equations can be found in [2]. The momentum equations(1) and (2) describe the time evolution of the velocity field (u, v) under inertial and viscousforces. The pressure p is a Lagrange multiplier to satisfy the incompressibility condition(3). Note that the momentum equations are already put into a numerics-friendly form. Thenonlinear terms on the right hand side equal

(u2)x

+ (uv)y

= uu

x

+ vu

y

(8)

(uv)x

+ (v2)y

= uv

x

+ vv

y

(9)

which follows by the chain rule and equation (3). The above right hand side is often writtenin vector form as (u ·r)u. We choose to numerically discretize the form on the left handside, because it is closer to a conservation form.

The incompressibility condition is not a time evolution equation, but an algebraic condi-tion. We incorporate this condition by using a projection approach [1]: Evolve the momen-tum equations neglecting the pressure, then project onto the subspace of divergence-freevelocity fields.

3 Visualization

Every fixed number of time steps the current pressure and velocity field are visualized.The pressure field is shown as a color plot with some contour lines. On top of this, thenormalized velocity field is shown as a quiver plot, i.e. little arrows indicate the direction ofthe flow. Since in a lid driven cavity the flow rate varies significantly over di↵erent areas,outputting the normalized velocity field is a common procedure. Additionally, stream linesare shown. Those are paths particles would take in the flow if the velocity field was frozenat the current instant in time. Since the velocity field is divergence-free, the streamlines areclosed. The stream lines are contour lines of the stream function q. It is a function whoseorthogonal gradient is the velocity field

(rq)? = u () �q

y

= u and q

x

= v (10)

Applying the 2d-curl to this equation yields

��q = r⇥ (rq)? = r⇥ u () ��q = �q

yy

� q

xx

= u

y

� v

x

(11)

The stream function exists since the compatibility condition r ·u = u

x

+v

y

= 0 is satisfied.

3

on a rectangular domain ⌦ = [0, l

x

]⇥[0, l

y

]. The four domain boundaries are denoted North,South, West, and East. The domain is fixed in time, and we consider no-slip boundaryconditions on each wall, i.e.

u(x, l

y

) = u

N

(x) v(x, l

y

) = 0 (4)u(x, 0) = u

S

(x) v(x, 0) = 0 (5)u(0, y) = 0 v(0, y) = v

W

(y) (6)u(l

x

, y) = 0 v(lx

, y) = v

E

(y) (7)

A derivation of the Navier-Stokes equations can be found in [2]. The momentum equations(1) and (2) describe the time evolution of the velocity field (u, v) under inertial and viscousforces. The pressure p is a Lagrange multiplier to satisfy the incompressibility condition(3). Note that the momentum equations are already put into a numerics-friendly form. Thenonlinear terms on the right hand side equal

(u2)x

+ (uv)y

= uu

x

+ vu

y

(8)

(uv)x

+ (v2)y

= uv

x

+ vv

y

(9)

which follows by the chain rule and equation (3). The above right hand side is often writtenin vector form as (u ·r)u. We choose to numerically discretize the form on the left handside, because it is closer to a conservation form.

The incompressibility condition is not a time evolution equation, but an algebraic condi-tion. We incorporate this condition by using a projection approach [1]: Evolve the momen-tum equations neglecting the pressure, then project onto the subspace of divergence-freevelocity fields.

3 Visualization

Every fixed number of time steps the current pressure and velocity field are visualized.The pressure field is shown as a color plot with some contour lines. On top of this, thenormalized velocity field is shown as a quiver plot, i.e. little arrows indicate the direction ofthe flow. Since in a lid driven cavity the flow rate varies significantly over di↵erent areas,outputting the normalized velocity field is a common procedure. Additionally, stream linesare shown. Those are paths particles would take in the flow if the velocity field was frozenat the current instant in time. Since the velocity field is divergence-free, the streamlines areclosed. The stream lines are contour lines of the stream function q. It is a function whoseorthogonal gradient is the velocity field

(rq)? = u () �q

y

= u and q

x

= v (10)

Applying the 2d-curl to this equation yields

��q = r⇥ (rq)? = r⇥ u () ��q = �q

yy

� q

xx

= u

y

� v

x

(11)

The stream function exists since the compatibility condition r ·u = u

x

+v

y

= 0 is satisfied.

3

• In 2D, we can write the NS equations in component form as

• visualization of pressure field, velocity field and streamlines

• automatic transition from central to donor-cell discretization for the nonlinear advec-tion part

• fast computation of the time-dependent solution for small to moderate mesh sizes

The code does not provide:

• 3d

• unstructured meshes or complex geometries

• time-dependent geometries

• adaptivity, such as local mesh refinement, time step control, etc.

• non-constant viscosity or density

• higher order time stepping

• turbulence models

• time and memory e�ciency for large computations

The code qualifies as a basis for modifications and extensions. The following extensionshave already been applied to the code by MIT students and other users:

• external forces

• inflow and outflow boundaries

• addition of a drag region

• geometry change to a backwards facing step

• time dependent geometries

• coupling with an advection-di↵usion equation

2 Incompressible Navier-Stokes Equations

We consider the incompressible Navier-Stokes equations in two space dimensions

u

t

+ p

x

= �(u2)x

� (uv)y

+1

Re

(uxx

+ u

yy

) (1)

v

t

+ p

y

= �(uv)x

� (v2)y

+1

Re

(vxx

+ v

yy

) (2)

u

x

+ v

y

= 0 (3)

2• The boundary conditions will be

on a rectangular domain ⌦ = [0, l

x

]⇥[0, l

y

]. The four domain boundaries are denoted North,South, West, and East. The domain is fixed in time, and we consider no-slip boundaryconditions on each wall, i.e.

u(x, l

y

) = u

N

(x) v(x, l

y

) = 0 (4)u(x, 0) = u

S

(x) v(x, 0) = 0 (5)u(0, y) = 0 v(0, y) = v

W

(y) (6)u(l

x

, y) = 0 v(lx

, y) = v

E

(y) (7)

A derivation of the Navier-Stokes equations can be found in [2]. The momentum equations(1) and (2) describe the time evolution of the velocity field (u, v) under inertial and viscousforces. The pressure p is a Lagrange multiplier to satisfy the incompressibility condition(3). Note that the momentum equations are already put into a numerics-friendly form. Thenonlinear terms on the right hand side equal

(u2)x

+ (uv)y

= uu

x

+ vu

y

(8)

(uv)x

+ (v2)y

= uv

x

+ vv

y

(9)

which follows by the chain rule and equation (3). The above right hand side is often writtenin vector form as (u ·r)u. We choose to numerically discretize the form on the left handside, because it is closer to a conservation form.

The incompressibility condition is not a time evolution equation, but an algebraic condi-tion. We incorporate this condition by using a projection approach [1]: Evolve the momen-tum equations neglecting the pressure, then project onto the subspace of divergence-freevelocity fields.

3 Visualization

Every fixed number of time steps the current pressure and velocity field are visualized.The pressure field is shown as a color plot with some contour lines. On top of this, thenormalized velocity field is shown as a quiver plot, i.e. little arrows indicate the direction ofthe flow. Since in a lid driven cavity the flow rate varies significantly over di↵erent areas,outputting the normalized velocity field is a common procedure. Additionally, stream linesare shown. Those are paths particles would take in the flow if the velocity field was frozenat the current instant in time. Since the velocity field is divergence-free, the streamlines areclosed. The stream lines are contour lines of the stream function q. It is a function whoseorthogonal gradient is the velocity field

(rq)? = u () �q

y

= u and q

x

= v (10)

Applying the 2d-curl to this equation yields

��q = r⇥ (rq)? = r⇥ u () ��q = �q

yy

� q

xx

= u

y

� v

x

(11)

The stream function exists since the compatibility condition r ·u = u

x

+v

y

= 0 is satisfied.

3

Lecture

Page 4: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Easiest numerical scheme: FD with projection

• The incompressibility equation is not time-dependent, but needs to be satisfied at every point in time. => Cannot simply integrate NS equation in time…

• Also, we have advective and diffusive terms (i.e. time step problems!) e.g.:

• visualization of pressure field, velocity field and streamlines

• automatic transition from central to donor-cell discretization for the nonlinear advec-tion part

• fast computation of the time-dependent solution for small to moderate mesh sizes

The code does not provide:

• 3d

• unstructured meshes or complex geometries

• time-dependent geometries

• adaptivity, such as local mesh refinement, time step control, etc.

• non-constant viscosity or density

• higher order time stepping

• turbulence models

• time and memory e�ciency for large computations

The code qualifies as a basis for modifications and extensions. The following extensionshave already been applied to the code by MIT students and other users:

• external forces

• inflow and outflow boundaries

• addition of a drag region

• geometry change to a backwards facing step

• time dependent geometries

• coupling with an advection-di↵usion equation

2 Incompressible Navier-Stokes Equations

We consider the incompressible Navier-Stokes equations in two space dimensions

u

t

+ p

x

= �(u2)x

� (uv)y

+1

Re

(uxx

+ u

yy

) (1)

v

t

+ p

y

= �(uv)x

� (v2)y

+1

Re

(vxx

+ v

yy

) (2)

u

x

+ v

y

= 0 (3)

2

• Numerical approach:

• Treat nonlinear terms (advection) explicitly in time first

• Add linear diffusive terms using an implicit scheme

• Correct the pressure to satisfy incompressibility, update velocities to be divergence-free

Page 5: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Nonlinear and diffusive terms

• Nonlinear advection is solved explicitly in time (Euler) to obtain estimate U* and V*:

• visualization of pressure field, velocity field and streamlines

• automatic transition from central to donor-cell discretization for the nonlinear advec-tion part

• fast computation of the time-dependent solution for small to moderate mesh sizes

The code does not provide:

• 3d

• unstructured meshes or complex geometries

• time-dependent geometries

• adaptivity, such as local mesh refinement, time step control, etc.

• non-constant viscosity or density

• higher order time stepping

• turbulence models

• time and memory e�ciency for large computations

The code qualifies as a basis for modifications and extensions. The following extensionshave already been applied to the code by MIT students and other users:

• external forces

• inflow and outflow boundaries

• addition of a drag region

• geometry change to a backwards facing step

• time dependent geometries

• coupling with an advection-di↵usion equation

2 Incompressible Navier-Stokes Equations

We consider the incompressible Navier-Stokes equations in two space dimensions

u

t

+ p

x

= �(u2)x

� (uv)y

+1

Re

(uxx

+ u

yy

) (1)

v

t

+ p

y

= �(uv)x

� (v2)y

+1

Re

(vxx

+ v

yy

) (2)

u

x

+ v

y

= 0 (3)

2

4 Numerical Solution Approach

The general approach of the code is described in Section 6.7 in the book Computational

Science and Engineering [4].While u, v, p and q are the solutions to the Navier-Stokes equations, we denote the

numerical approximations by capital letters. Assume we have the velocity field U

n and V

n

at the n

th time step (time t), and condition (3) is satisfied. We find the solution at the(n + 1)st time step (time t + �t) by the following three step approach:

1. Treat nonlinear terms

The nonlinear terms are treated explicitly. This circumvents the solution of a nonlinearsystem, but introduces a CFL condition which limits the time step by a constant timesthe spacial resolution.

U

⇤ � U

n

�t

= �((Un)2)x

� (Un

V

n)y

(12)

V

⇤ � V

n

�t

= �(Un

V

n)x

� ((V n)2)y

(13)

In Section 5 we will detail how to discretize the nonlinear terms.

2. Implicit viscosity

The viscosity terms are treated implicitly. If they were treated explicitly, we wouldhave a time step restriction proportional to the spacial discretization squared. Wehave no such limitation for the implicit treatment. The price to pay is two linearsystems to be solved in each time step.

U

⇤⇤ � U

�t

=1

Re

(U⇤⇤xx

+ U

⇤⇤yy

) (14)

V

⇤⇤ � V

�t

=1

Re

(V ⇤⇤xx

+ V

⇤⇤yy

) (15)

3. Pressure correction

We correct the intermediate velocity field (U⇤⇤, V

⇤⇤) by the gradient of a pressureP

n+1 to enforce incompressibility.

U

n+1 � U

⇤⇤

�t

= �(Pn+1)x

(16)

V

n+1 � V

⇤⇤

�t

= �(Pn+1)y

(17)

The pressure is denoted P

n+1, since it is only given implicitly. It is obtained by solvinga linear system. In vector notation the correction equations read as

1�t

U

n+1 � 1�t

U

n = �rP

n+1 (18)

Applying the divergence to both sides yields the linear system

��P

n+1 = � 1�t

r · Un (19)

Hence, the pressure correction step is

4

and

4 Numerical Solution Approach

The general approach of the code is described in Section 6.7 in the book Computational

Science and Engineering [4].While u, v, p and q are the solutions to the Navier-Stokes equations, we denote the

numerical approximations by capital letters. Assume we have the velocity field U

n and V

n

at the n

th time step (time t), and condition (3) is satisfied. We find the solution at the(n + 1)st time step (time t + �t) by the following three step approach:

1. Treat nonlinear terms

The nonlinear terms are treated explicitly. This circumvents the solution of a nonlinearsystem, but introduces a CFL condition which limits the time step by a constant timesthe spacial resolution.

U

⇤ � U

n

�t

= �((Un)2)x

� (Un

V

n)y

(12)

V

⇤ � V

n

�t

= �(Un

V

n)x

� ((V n)2)y

(13)

In Section 5 we will detail how to discretize the nonlinear terms.

2. Implicit viscosity

The viscosity terms are treated implicitly. If they were treated explicitly, we wouldhave a time step restriction proportional to the spacial discretization squared. Wehave no such limitation for the implicit treatment. The price to pay is two linearsystems to be solved in each time step.

U

⇤⇤ � U

�t

=1

Re

(U⇤⇤xx

+ U

⇤⇤yy

) (14)

V

⇤⇤ � V

�t

=1

Re

(V ⇤⇤xx

+ V

⇤⇤yy

) (15)

3. Pressure correction

We correct the intermediate velocity field (U⇤⇤, V

⇤⇤) by the gradient of a pressureP

n+1 to enforce incompressibility.

U

n+1 � U

⇤⇤

�t

= �(Pn+1)x

(16)

V

n+1 � V

⇤⇤

�t

= �(Pn+1)y

(17)

The pressure is denoted P

n+1, since it is only given implicitly. It is obtained by solvinga linear system. In vector notation the correction equations read as

1�t

U

n+1 � 1�t

U

n = �rP

n+1 (18)

Applying the divergence to both sides yields the linear system

��P

n+1 = � 1�t

r · Un (19)

Hence, the pressure correction step is

4

• Implicit diffusion is is added to obtain estimate U** and V**:

4 Numerical Solution Approach

The general approach of the code is described in Section 6.7 in the book Computational

Science and Engineering [4].While u, v, p and q are the solutions to the Navier-Stokes equations, we denote the

numerical approximations by capital letters. Assume we have the velocity field U

n and V

n

at the n

th time step (time t), and condition (3) is satisfied. We find the solution at the(n + 1)st time step (time t + �t) by the following three step approach:

1. Treat nonlinear terms

The nonlinear terms are treated explicitly. This circumvents the solution of a nonlinearsystem, but introduces a CFL condition which limits the time step by a constant timesthe spacial resolution.

U

⇤ � U

n

�t

= �((Un)2)x

� (Un

V

n)y

(12)

V

⇤ � V

n

�t

= �(Un

V

n)x

� ((V n)2)y

(13)

In Section 5 we will detail how to discretize the nonlinear terms.

2. Implicit viscosity

The viscosity terms are treated implicitly. If they were treated explicitly, we wouldhave a time step restriction proportional to the spacial discretization squared. Wehave no such limitation for the implicit treatment. The price to pay is two linearsystems to be solved in each time step.

U

⇤⇤ � U

�t

=1

Re

(U⇤⇤xx

+ U

⇤⇤yy

) (14)

V

⇤⇤ � V

�t

=1

Re

(V ⇤⇤xx

+ V

⇤⇤yy

) (15)

3. Pressure correction

We correct the intermediate velocity field (U⇤⇤, V

⇤⇤) by the gradient of a pressureP

n+1 to enforce incompressibility.

U

n+1 � U

⇤⇤

�t

= �(Pn+1)x

(16)

V

n+1 � V

⇤⇤

�t

= �(Pn+1)y

(17)

The pressure is denoted P

n+1, since it is only given implicitly. It is obtained by solvinga linear system. In vector notation the correction equations read as

1�t

U

n+1 � 1�t

U

n = �rP

n+1 (18)

Applying the divergence to both sides yields the linear system

��P

n+1 = � 1�t

r · Un (19)

Hence, the pressure correction step is

4

4 Numerical Solution Approach

The general approach of the code is described in Section 6.7 in the book Computational

Science and Engineering [4].While u, v, p and q are the solutions to the Navier-Stokes equations, we denote the

numerical approximations by capital letters. Assume we have the velocity field U

n and V

n

at the n

th time step (time t), and condition (3) is satisfied. We find the solution at the(n + 1)st time step (time t + �t) by the following three step approach:

1. Treat nonlinear terms

The nonlinear terms are treated explicitly. This circumvents the solution of a nonlinearsystem, but introduces a CFL condition which limits the time step by a constant timesthe spacial resolution.

U

⇤ � U

n

�t

= �((Un)2)x

� (Un

V

n)y

(12)

V

⇤ � V

n

�t

= �(Un

V

n)x

� ((V n)2)y

(13)

In Section 5 we will detail how to discretize the nonlinear terms.

2. Implicit viscosity

The viscosity terms are treated implicitly. If they were treated explicitly, we wouldhave a time step restriction proportional to the spacial discretization squared. Wehave no such limitation for the implicit treatment. The price to pay is two linearsystems to be solved in each time step.

U

⇤⇤ � U

�t

=1

Re

(U⇤⇤xx

+ U

⇤⇤yy

) (14)

V

⇤⇤ � V

�t

=1

Re

(V ⇤⇤xx

+ V

⇤⇤yy

) (15)

3. Pressure correction

We correct the intermediate velocity field (U⇤⇤, V

⇤⇤) by the gradient of a pressureP

n+1 to enforce incompressibility.

U

n+1 � U

⇤⇤

�t

= �(Pn+1)x

(16)

V

n+1 � V

⇤⇤

�t

= �(Pn+1)y

(17)

The pressure is denoted P

n+1, since it is only given implicitly. It is obtained by solvinga linear system. In vector notation the correction equations read as

1�t

U

n+1 � 1�t

U

n = �rP

n+1 (18)

Applying the divergence to both sides yields the linear system

��P

n+1 = � 1�t

r · Un (19)

Hence, the pressure correction step is

4

and

• The current estimate U** and V** does not yet satisfy incompressibility, which is corrected in the last step

Page 6: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Projection step

• In the last step, U** and V** are corrected by a pressure gradient term:

4 Numerical Solution Approach

The general approach of the code is described in Section 6.7 in the book Computational

Science and Engineering [4].While u, v, p and q are the solutions to the Navier-Stokes equations, we denote the

numerical approximations by capital letters. Assume we have the velocity field U

n and V

n

at the n

th time step (time t), and condition (3) is satisfied. We find the solution at the(n + 1)st time step (time t + �t) by the following three step approach:

1. Treat nonlinear terms

The nonlinear terms are treated explicitly. This circumvents the solution of a nonlinearsystem, but introduces a CFL condition which limits the time step by a constant timesthe spacial resolution.

U

⇤ � U

n

�t

= �((Un)2)x

� (Un

V

n)y

(12)

V

⇤ � V

n

�t

= �(Un

V

n)x

� ((V n)2)y

(13)

In Section 5 we will detail how to discretize the nonlinear terms.

2. Implicit viscosity

The viscosity terms are treated implicitly. If they were treated explicitly, we wouldhave a time step restriction proportional to the spacial discretization squared. Wehave no such limitation for the implicit treatment. The price to pay is two linearsystems to be solved in each time step.

U

⇤⇤ � U

�t

=1

Re

(U⇤⇤xx

+ U

⇤⇤yy

) (14)

V

⇤⇤ � V

�t

=1

Re

(V ⇤⇤xx

+ V

⇤⇤yy

) (15)

3. Pressure correction

We correct the intermediate velocity field (U⇤⇤, V

⇤⇤) by the gradient of a pressureP

n+1 to enforce incompressibility.

U

n+1 � U

⇤⇤

�t

= �(Pn+1)x

(16)

V

n+1 � V

⇤⇤

�t

= �(Pn+1)y

(17)

The pressure is denoted P

n+1, since it is only given implicitly. It is obtained by solvinga linear system. In vector notation the correction equations read as

1�t

U

n+1 � 1�t

U

n = �rP

n+1 (18)

Applying the divergence to both sides yields the linear system

��P

n+1 = � 1�t

r · Un (19)

Hence, the pressure correction step is

4

4 Numerical Solution Approach

The general approach of the code is described in Section 6.7 in the book Computational

Science and Engineering [4].While u, v, p and q are the solutions to the Navier-Stokes equations, we denote the

numerical approximations by capital letters. Assume we have the velocity field U

n and V

n

at the n

th time step (time t), and condition (3) is satisfied. We find the solution at the(n + 1)st time step (time t + �t) by the following three step approach:

1. Treat nonlinear terms

The nonlinear terms are treated explicitly. This circumvents the solution of a nonlinearsystem, but introduces a CFL condition which limits the time step by a constant timesthe spacial resolution.

U

⇤ � U

n

�t

= �((Un)2)x

� (Un

V

n)y

(12)

V

⇤ � V

n

�t

= �(Un

V

n)x

� ((V n)2)y

(13)

In Section 5 we will detail how to discretize the nonlinear terms.

2. Implicit viscosity

The viscosity terms are treated implicitly. If they were treated explicitly, we wouldhave a time step restriction proportional to the spacial discretization squared. Wehave no such limitation for the implicit treatment. The price to pay is two linearsystems to be solved in each time step.

U

⇤⇤ � U

�t

=1

Re

(U⇤⇤xx

+ U

⇤⇤yy

) (14)

V

⇤⇤ � V

�t

=1

Re

(V ⇤⇤xx

+ V

⇤⇤yy

) (15)

3. Pressure correction

We correct the intermediate velocity field (U⇤⇤, V

⇤⇤) by the gradient of a pressureP

n+1 to enforce incompressibility.

U

n+1 � U

⇤⇤

�t

= �(Pn+1)x

(16)

V

n+1 � V

⇤⇤

�t

= �(Pn+1)y

(17)

The pressure is denoted P

n+1, since it is only given implicitly. It is obtained by solvinga linear system. In vector notation the correction equations read as

1�t

U

n+1 � 1�t

U

n = �rP

n+1 (18)

Applying the divergence to both sides yields the linear system

��P

n+1 = � 1�t

r · Un (19)

Hence, the pressure correction step is

4

and

• Pn+1 is the pressure needed to make Un+1 divergence-free.

• The correction in vector notation is~Un+1 � ~U⇤⇤

�t= �rPn+1

• Applying the divergence, we obtain an equation for Pn+1:

�4Pn+1 = � 1

�tr · ~U⇤⇤

• This means we need to solve a Poisson-problem!

• visualization of pressure field, velocity field and streamlines

• automatic transition from central to donor-cell discretization for the nonlinear advec-tion part

• fast computation of the time-dependent solution for small to moderate mesh sizes

The code does not provide:

• 3d

• unstructured meshes or complex geometries

• time-dependent geometries

• adaptivity, such as local mesh refinement, time step control, etc.

• non-constant viscosity or density

• higher order time stepping

• turbulence models

• time and memory e�ciency for large computations

The code qualifies as a basis for modifications and extensions. The following extensionshave already been applied to the code by MIT students and other users:

• external forces

• inflow and outflow boundaries

• addition of a drag region

• geometry change to a backwards facing step

• time dependent geometries

• coupling with an advection-di↵usion equation

2 Incompressible Navier-Stokes Equations

We consider the incompressible Navier-Stokes equations in two space dimensions

u

t

+ p

x

= �(u2)x

� (uv)y

+1

Re

(uxx

+ u

yy

) (1)

v

t

+ p

y

= �(uv)x

� (v2)y

+1

Re

(vxx

+ v

yy

) (2)

u

x

+ v

y

= 0 (3)

2

Page 7: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Poisson problem• Pressure correction steps:

(a) Compute F

n = r · Un

(b) Solve Poisson equation ��P

n+1 = � 1�t

F

n

(c) Compute G

n+1 = rP

n+1

(d) Update velocity field U

n+1 = U

n ��tG

n+1

The question, which boundary conditions are appropriate for the Poisson equationfor the pressure P , is complicated. A standard approach is to prescribe homoge-neous Neumann boundary conditions for P wherever no-slip boundary conditions areprescribed for the velocity field. For the lid driven cavity problem this means thathomogeneous Neumann boundary conditions are prescribed everywhere. This impliesin particular that the pressure P is only defined up to a constant, which is fine, sinceonly the gradient of P enters the momentum equation.

In addition to the solution steps, we have the visualization step, in which the stream functionQ

n is computed. Similarly to the pressure is is obtained by the following steps

1. Compute F

n = (V n)x

� (Un)y

2. Solve Poisson equation ��Q

n = �F

n

We prescribe homogeneous Dirichlet boundary conditions.

5 Spacial Discretization

The spacial discretization is performed on a staggered grid with the pressure P in the cellmidpoints, the velocities U placed on the vertical cell interfaces, and the velocities V placedon the horizontal cell interfaces. The stream function Q is defined on the cell corners.

Consider to have n

x

⇥n

y

cells. Figure 1 shows a staggered grid with n

x

= 5 and n

y

= 3.When speaking of the fields P , U and V (and Q), care has to be taken about interior andboundary points. Any point truly inside the domain is an interior point, while points on oroutside boundaries are boundary points. Dark markers in Figure 1 stand for interior points,while light markers represent boundary points. The fields have the following sizes:

field quantity interior resolution resolution with boundary pointspressure P n

x

⇥ n

y

(nx

+ 2)⇥ (ny

+ 2)velocity component U (n

x

� 1)⇥ n

y

(nx

+ 1)⇥ (ny

+ 2)velocity component V n

x

⇥ (ny

� 1) (nx

+ 2)⇥ (ny

+ 1)stream function Q (n

x

� 1)⇥ (ny

� 1) (nx

+ 1)⇥ (ny

+ 1)

The values at boundary points are no unknown variables. For Dirichlet boundary conditionsthey are prescribed, and for Neumann boundry conditions they can be expressed in termof interior points. However, boundary points of U and V are used for the finite di↵erenceapproximation of the nonlinear advection terms. Note that the boundary points in the fourcorner are never used.

5

(b): Pij is a matrix with nx∙ny components (nx, ny : number of spatial cells (resolution)

ΔP can now be expressed using finite differences, resulting in a matrix L. We then need to solve

�LPn+1 = � 1

�tFn

F can also be written as a matrix with nx∙ny components

=> Invert L matrix! Need a way to invert large matrices (see later)

Un+1 = U⇤⇤ ��tGn+1

r ·U⇤⇤

Page 8: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

UVP

Figure 1: Staggered grid with boundary cells

5.1 Approximating derivatives

• Second derivatives

Finite di↵erences can approximate second derivatives in a grid point by a centeredstencil. At an interior point U

i,j

we approximate the Laplace operator by

�U

i,j

= (Uxx

)i,j

+ (Uyy

)i,j

⇡ U

i�1,j

� 2U

i,j

+ U

i+1,j

h

2x

+U

i,j�1 � 2U

i,j

+ U

i,j+1

h

2y

(20)

Here one or two of the neighboring points might be boundary points. The sameformula holds for the component V , and for the Laplacian of the pressure P andthe stream function Q. If the unknown quantity is stored in a large column vector,then the above approximation can be represented as a large sparse block matrix beingapplied from the left. Thus, solving the Poisson equations for P and Q, as well assolving implicitly for the viscosity terms in U and V , yields sparse linear systems tobe solved, as detailed in Section 7.

• First derivatives

A first derivative in a grid point can be approximated by a centered stencil.

(Ux

)i,j

⇡ U

i+1,j

� U

i�1,j

2h

x

(21)

6

Spatial discretization

ij

(a) Compute F

n = r · Un

(b) Solve Poisson equation ��P

n+1 = � 1�t

F

n

(c) Compute G

n+1 = rP

n+1

(d) Update velocity field U

n+1 = U

n ��tG

n+1

The question, which boundary conditions are appropriate for the Poisson equationfor the pressure P , is complicated. A standard approach is to prescribe homoge-neous Neumann boundary conditions for P wherever no-slip boundary conditions areprescribed for the velocity field. For the lid driven cavity problem this means thathomogeneous Neumann boundary conditions are prescribed everywhere. This impliesin particular that the pressure P is only defined up to a constant, which is fine, sinceonly the gradient of P enters the momentum equation.

In addition to the solution steps, we have the visualization step, in which the stream functionQ

n is computed. Similarly to the pressure is is obtained by the following steps

1. Compute F

n = (V n)x

� (Un)y

2. Solve Poisson equation ��Q

n = �F

n

We prescribe homogeneous Dirichlet boundary conditions.

5 Spacial Discretization

The spacial discretization is performed on a staggered grid with the pressure P in the cellmidpoints, the velocities U placed on the vertical cell interfaces, and the velocities V placedon the horizontal cell interfaces. The stream function Q is defined on the cell corners.

Consider to have n

x

⇥n

y

cells. Figure 1 shows a staggered grid with n

x

= 5 and n

y

= 3.When speaking of the fields P , U and V (and Q), care has to be taken about interior andboundary points. Any point truly inside the domain is an interior point, while points on oroutside boundaries are boundary points. Dark markers in Figure 1 stand for interior points,while light markers represent boundary points. The fields have the following sizes:

field quantity interior resolution resolution with boundary pointspressure P n

x

⇥ n

y

(nx

+ 2)⇥ (ny

+ 2)velocity component U (n

x

� 1)⇥ n

y

(nx

+ 1)⇥ (ny

+ 2)velocity component V n

x

⇥ (ny

� 1) (nx

+ 2)⇥ (ny

+ 1)stream function Q (n

x

� 1)⇥ (ny

� 1) (nx

+ 1)⇥ (ny

+ 1)

The values at boundary points are no unknown variables. For Dirichlet boundary conditionsthey are prescribed, and for Neumann boundry conditions they can be expressed in termof interior points. However, boundary points of U and V are used for the finite di↵erenceapproximation of the nonlinear advection terms. Note that the boundary points in the fourcorner are never used.

5

nx,ny: Number of cellsStaggered grid

interior U boundary U interior V boundary V pressurex

Uij

Vij

Pij

Page 9: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Why staggered grid?UVP

Figure 1: Staggered grid with boundary cells

5.1 Approximating derivatives

• Second derivatives

Finite di↵erences can approximate second derivatives in a grid point by a centeredstencil. At an interior point U

i,j

we approximate the Laplace operator by

�U

i,j

= (Uxx

)i,j

+ (Uyy

)i,j

⇡ U

i�1,j

� 2U

i,j

+ U

i+1,j

h

2x

+U

i,j�1 � 2U

i,j

+ U

i,j+1

h

2y

(20)

Here one or two of the neighboring points might be boundary points. The sameformula holds for the component V , and for the Laplacian of the pressure P andthe stream function Q. If the unknown quantity is stored in a large column vector,then the above approximation can be represented as a large sparse block matrix beingapplied from the left. Thus, solving the Poisson equations for P and Q, as well assolving implicitly for the viscosity terms in U and V , yields sparse linear systems tobe solved, as detailed in Section 7.

• First derivatives

A first derivative in a grid point can be approximated by a centered stencil.

(Ux

)i,j

⇡ U

i+1,j

� U

i�1,j

2h

x

(21)

6

• Second derivatives: Centered differences as usual. => Consistent with staggered grid

• First derivatives: “Centered” differences around half-grid points (good accuracy, avoids numerical instabilities):

This, however, can yield instabilities, as shown in many textbooks on numerical anal-ysis. Here the staggered grid comes into play. Assume, we are not interested in thevalue of U

x

in the position of U

i,j

, but instead we want the value in the middle betweenthe points U

i+1,j

and U

i,j

. Then the approximation

(Ux

)i+ 1

2 ,j

⇡ U

i+1,j

� U

i,j

h

x

(22)

is a stable centered approximation to U

x

in the middle between the two points. Inthe staggered grid this position happens to be the position of P

i,j

.

– Pressure correction

In the pressure correction, the approximation of first derivatives on a staggeredgrid works out perfectly:1. The divergence of the velocity field F = r · U computes U

x

and V

y

. Bothvalues then live in the cell centers, i.e. they can be added directly.

2. For the pressure Poisson equation ��P = � 1�t

F , both sides are defined inthe cell centers, and ��P can be approximated as described above.

3. The gradient of the pressure G = rP requires the computation of P

x

andP

y

. Again, a look at Figure 1 indicates that the former then live at theposition of U , while the latter live at the positions of V . Exactly where bothare needed to update the velocity field.

– Stream function

Similarly, the staggered grid works fine for the stream function. Both V

x

and U

y

live on the cell corners, so the Poisson right hand side F = V

x

�U

y

and thus thestream function Q lives at the cell corners.

– Nonlinear terms (central di↵erencing)

The nonlinear terms are the only place where the discretization on the staggeredgrid does not work directly. For instance, the product UV is not directly defined,since U and V live in di↵erent positions. The solution is to take the argumentsbackwards: For updating U , we need (U2)

x

and (UV )y

. If the flow in each timestep is comparably slow, we wish to use the same centered staggered derivativesas before. This requires U

2 to be defined in the cell centers, and UV to the definedin the cell corners. We obtain these quantities by interpolating two neighboringvalues.

(U2)i+ 1

2 ,j

=✓

U

i,j

+ U

i+1,j

2

◆2

(23)

U

i,j+ 12

=U

i,j

+ U

i,j+1

2(24)

V

i+ 12 ,j

=V

i,j

+ V

i+1,j

2(25)

Analogously for the component V . The index notation lets this idea look morecomplicated than it is. All we do is create new data between two points by av-eraging. Using an overbar with superscript h to indicate a horizontally averaged

7

• First derivatives “live” at center of cells => ideal choice for the pressure correction (which lives at cell centers as well):

�4Pn+1 = � 1

�tr · ~U⇤⇤

• Only problem: Nonlinear terms in live at cell center, but are needed at edges!

• visualization of pressure field, velocity field and streamlines

• automatic transition from central to donor-cell discretization for the nonlinear advec-tion part

• fast computation of the time-dependent solution for small to moderate mesh sizes

The code does not provide:

• 3d

• unstructured meshes or complex geometries

• time-dependent geometries

• adaptivity, such as local mesh refinement, time step control, etc.

• non-constant viscosity or density

• higher order time stepping

• turbulence models

• time and memory e�ciency for large computations

The code qualifies as a basis for modifications and extensions. The following extensionshave already been applied to the code by MIT students and other users:

• external forces

• inflow and outflow boundaries

• addition of a drag region

• geometry change to a backwards facing step

• time dependent geometries

• coupling with an advection-di↵usion equation

2 Incompressible Navier-Stokes Equations

We consider the incompressible Navier-Stokes equations in two space dimensions

u

t

+ p

x

= �(u2)x

� (uv)y

+1

Re

(uxx

+ u

yy

) (1)

v

t

+ p

y

= �(uv)x

� (v2)y

+1

Re

(vxx

+ v

yy

) (2)

u

x

+ v

y

= 0 (3)

2

This, however, can yield instabilities, as shown in many textbooks on numerical anal-ysis. Here the staggered grid comes into play. Assume, we are not interested in thevalue of U

x

in the position of U

i,j

, but instead we want the value in the middle betweenthe points U

i+1,j

and U

i,j

. Then the approximation

(Ux

)i+ 1

2 ,j

⇡ U

i+1,j

� U

i,j

h

x

(22)

is a stable centered approximation to U

x

in the middle between the two points. Inthe staggered grid this position happens to be the position of P

i,j

.

– Pressure correction

In the pressure correction, the approximation of first derivatives on a staggeredgrid works out perfectly:1. The divergence of the velocity field F = r · U computes U

x

and V

y

. Bothvalues then live in the cell centers, i.e. they can be added directly.

2. For the pressure Poisson equation ��P = � 1�t

F , both sides are defined inthe cell centers, and ��P can be approximated as described above.

3. The gradient of the pressure G = rP requires the computation of P

x

andP

y

. Again, a look at Figure 1 indicates that the former then live at theposition of U , while the latter live at the positions of V . Exactly where bothare needed to update the velocity field.

– Stream function

Similarly, the staggered grid works fine for the stream function. Both V

x

and U

y

live on the cell corners, so the Poisson right hand side F = V

x

�U

y

and thus thestream function Q lives at the cell corners.

– Nonlinear terms (central di↵erencing)

The nonlinear terms are the only place where the discretization on the staggeredgrid does not work directly. For instance, the product UV is not directly defined,since U and V live in di↵erent positions. The solution is to take the argumentsbackwards: For updating U , we need (U2)

x

and (UV )y

. If the flow in each timestep is comparably slow, we wish to use the same centered staggered derivativesas before. This requires U

2 to be defined in the cell centers, and UV to the definedin the cell corners. We obtain these quantities by interpolating two neighboringvalues.

(U2)i+ 1

2 ,j

=✓

U

i,j

+ U

i+1,j

2

◆2

(23)

U

i,j+ 12

=U

i,j

+ U

i,j+1

2(24)

V

i+ 12 ,j

=V

i,j

+ V

i+1,j

2(25)

Analogously for the component V . The index notation lets this idea look morecomplicated than it is. All we do is create new data between two points by av-eraging. Using an overbar with superscript h to indicate a horizontally averaged

7

=> Interpolate, e.g. and

This, however, can yield instabilities, as shown in many textbooks on numerical anal-ysis. Here the staggered grid comes into play. Assume, we are not interested in thevalue of U

x

in the position of U

i,j

, but instead we want the value in the middle betweenthe points U

i+1,j

and U

i,j

. Then the approximation

(Ux

)i+ 1

2 ,j

⇡ U

i+1,j

� U

i,j

h

x

(22)

is a stable centered approximation to U

x

in the middle between the two points. Inthe staggered grid this position happens to be the position of P

i,j

.

– Pressure correction

In the pressure correction, the approximation of first derivatives on a staggeredgrid works out perfectly:1. The divergence of the velocity field F = r · U computes U

x

and V

y

. Bothvalues then live in the cell centers, i.e. they can be added directly.

2. For the pressure Poisson equation ��P = � 1�t

F , both sides are defined inthe cell centers, and ��P can be approximated as described above.

3. The gradient of the pressure G = rP requires the computation of P

x

andP

y

. Again, a look at Figure 1 indicates that the former then live at theposition of U , while the latter live at the positions of V . Exactly where bothare needed to update the velocity field.

– Stream function

Similarly, the staggered grid works fine for the stream function. Both V

x

and U

y

live on the cell corners, so the Poisson right hand side F = V

x

�U

y

and thus thestream function Q lives at the cell corners.

– Nonlinear terms (central di↵erencing)

The nonlinear terms are the only place where the discretization on the staggeredgrid does not work directly. For instance, the product UV is not directly defined,since U and V live in di↵erent positions. The solution is to take the argumentsbackwards: For updating U , we need (U2)

x

and (UV )y

. If the flow in each timestep is comparably slow, we wish to use the same centered staggered derivativesas before. This requires U

2 to be defined in the cell centers, and UV to the definedin the cell corners. We obtain these quantities by interpolating two neighboringvalues.

(U2)i+ 1

2 ,j

=✓

U

i,j

+ U

i+1,j

2

◆2

(23)

U

i,j+ 12

=U

i,j

+ U

i,j+1

2(24)

V

i+ 12 ,j

=V

i,j

+ V

i+1,j

2(25)

Analogously for the component V . The index notation lets this idea look morecomplicated than it is. All we do is create new data between two points by av-eraging. Using an overbar with superscript h to indicate a horizontally averaged

7

4P

ij

= P

xx,ij

+ P

yy,ij

⇡ P

i�1,j � 2Pi,j

+ P

i+1,j

�x

2+

P

i,j�1 � 2Pi,j

+ P

i,j+1

�x

2

Page 10: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Some notes• Centered differences can be “upwinded” for better accuracy (see code

documentation)• Boundary conditions: Need a bit of care due to the staggered grid…• Boundary conditions for pressure??? This is a delicate issue. Normally, for no-

slip velocity BC, one employs Neumann BCs for pressure, i.e.@P

@~n

����@⌦

= 0 thus, e.g. at the top boundary:

5.2 Boundary conditions

In the lid driven cavity problem we provide Dirichlet boundary conditions for U and V , andNeumann boundary conditions for P . Applying the correct boundary conditions requirescare, since for the staggered grid some points lie on a boundary while others have a boundarybetween them. At the points that lie on the boundary the value is directly prescribed, suchas U at the west and east boundary, and V at the north and south boundary. For U at thenorth and south boundary and for V at west and east boundary, one has to define a valuebetween two data points. The idea is the same as above: average the values of two points.For instance, the north boundary lies between points with velocity U . Let the two pointsbelow respectively above the boundary be U

i,j

and U

i,j+1, and let the prescribed boundaryvalue be U

N

. Then the boundary condition is

U

i,j

+ U

i,j+1

2= U

N

() U

i,j

+ U

i,j+1 = 2U

N

(35)

Analogously at the south boundary, and for V at the west and east boundary.The normal derivative @P

@n at the boundary is defined using two points which have theboundary in their middle. For instance, at the north boundary, prescribing homogeneousNeumann boundary conditions yields

P

i,j+1 � P

i,j

h

y

= 0 () P

i,j+1 = P

i,j

(36)

The stream function is defined on cell boundary points. Thus all its boundary points lieon the domain boundary. We prescibe homogeneous Dirichlet boundary conditions, whichcan be prescribed directly.

6 Solving the Linear Systems

The pressure correction and the implicit discretization of the viscosity terms requires linearsystems to be solved in every time step. Additionally, the computation of the streamfunction requires another system to be solved whenever the data is plotted. Since neithergeometry nor discretization change with time, the corresponding system matrices remain thesame in every step. This means that all matrices can be constructed in an initialization step.Of course, one would would even wish to compute the inverse matrices in an initializationstep, but even for medium grid resolutions these could not be saved, since they are fullmatrices. Of the many possible approaches to do at least some work in the initialization,we propose the following three:

• Use Fourier methods based on the fast Fourier transform in the solution step. Initializememory and constants in the setup phase.

• Compute good preconditioners in the setup phase. Candidates are ILU or multigrid.Save the preconditioners as sparse matrices and use them in the solution phase.

• Use elimination with reordering to compute the inverse matrices exactly, but in acomparably sparse format.

9

=> “Mirror” pressure value in boundary cells

UVP

Figure 1: Staggered grid with boundary cells

5.1 Approximating derivatives

• Second derivatives

Finite di↵erences can approximate second derivatives in a grid point by a centeredstencil. At an interior point U

i,j

we approximate the Laplace operator by

�U

i,j

= (Uxx

)i,j

+ (Uyy

)i,j

⇡ U

i�1,j

� 2U

i,j

+ U

i+1,j

h

2x

+U

i,j�1 � 2U

i,j

+ U

i,j+1

h

2y

(20)

Here one or two of the neighboring points might be boundary points. The sameformula holds for the component V , and for the Laplacian of the pressure P andthe stream function Q. If the unknown quantity is stored in a large column vector,then the above approximation can be represented as a large sparse block matrix beingapplied from the left. Thus, solving the Poisson equations for P and Q, as well assolving implicitly for the viscosity terms in U and V , yields sparse linear systems tobe solved, as detailed in Section 7.

• First derivatives

A first derivative in a grid point can be approximated by a centered stencil.

(Ux

)i,j

⇡ U

i+1,j

� U

i�1,j

2h

x

(21)

6

Page 11: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Demo• CSE website has a demo implementation (and documentation)!• Have a look at the code (you won’t yet understand how the Poisson problem is solved)

Page 12: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Lattice-Boltzmann method• Poisson problem for FD (or, for that matter, finite volume etc.) discretization:

Matrix inversion=>very costly in 3D, not easy to parallelize (non-local)

• An alternative that is much easier to implement numerically is the Lattice-Boltzmann method (LBM)

• Starting point of LBM is kinetic gas theory:

Boltzmann’s equation (one for each fluid):

• f is the Probability Distribution Function of the particles in (x,v,t) space • 7 dimensional space (3 space, 3 velocity, 1 time)!! Can handle, if clever! • F: forces between fluids over the interfaces

• Collision term: This is where VISCOSITY originates

• In an equilibrium: f is the isotropic Maxwell-Boltzmann distribution (a symmetric Gaussian type of PDF)

probability distribution function for particle at position x with speed v

dN = f(x,v, t)dxdv number density of molecules inside “volume” (x,x+dx) and (v,v+dv) at time t

⇢(x, t) =

Z

velocity

f(x,v, t)dv density

mean velocity at (x,t)~u(~x, t)⇢(~x, t) =

Z

velocity

~vf(x,v, t)dv

etc. for other macroscopic fluid quantities

Page 13: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Probability function (1D)Phase space (v,x) for 1 space dimension X PDF shown as contours:

X

V

Integration over V gives hydrodynamic quantities at chosen X

Question: How does the probability in a “volume” change over time? => Since its a probability: We expect a conservation law for f!!!

3 possibilities to change f(x,v,t) inside a small volume:

• Particle can move: x => x+v dt (v: current particle speed)

• Particle can accelerate from v => v+F/m dt (F: external force, m: particle mass)

• Particles can collide: (x1,v1,x2,v2) => (x’1,v’1,x’2,v’2)

We can express this (in 3D) as:

@f

@t

+ ~v · @f@~x

+ ~

F · @f@~v

�✓@f

@t

coll.

= 0 Boltzmann equation

t

t+Δt

By Taylor-expansion of the LHS, one can derive the famous Boltzmann equation:

f(~x+ ~v�t,~v +

~

F/m�t, t+�t)d

3xd

3v = f(~x,~v, t)d

3xd

3v +Collisions

Page 14: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

From Boltzmann to Navier-Stokes

• It can be shown: Boltzmann equation => Navier Stokes equation

• => instead of solving Navier-Stokes (a PDE for average molecule velocities), we could solve the Boltzmann equation (a PDE for probabilities f(x,v,t)), and then obtain the average velocities by integrating f(x,v,t), e.g.

~u(~x, t)⇢(~x, t) =

Z

velocity

~vf(x,v, t)dv

• Lattice-Boltzmann method: Discretize f(x,v,t), then numerically integrate Boltzmann equation!

Page 15: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Lattice Boltzmann method• Let’s consider the previous equation for the prob. density function f(x,v,t), in absence of a force F:

• At each lattice site i, we have a value per discrete velocity j. We write

• Discretize position (xi) and velocities vj on a lattice

0

D2Q9

latticeunit (lu)

8

4

1

5

2

6

3

7

Figure 2: Discrete lattice velocities for the D2Q9 model

The macroscopic variables are defined as functions of the particle distribution functions

(hereafter DFs) according to:

⇢ =

��1X

i=0

f

i

(macroscopic fluid density) (4)

and

~u =

1

��1X

i=0

f

i

~e

i

(macroscopic velocity). (5)

The DFs at each lattice point are updated using the equation:

f

i

(~x + ~e

i

�t, t + �t) = f

i

(~x, t)| {z }Streaming

�[f

i

(~x, t) � f

eq

i

(~x, t)]

⌧| {z }Collision

, (6)

where i 2 [0, � � 1] is an index spanning the (discretized) momentum space and ⌧ is a

relaxation parameter, which is related to the fluid viscosity (more details about this will follow

in this section).

This equation holds for lattice points within the fluid domain, but not for the domain bound-

aries, where boundary conditions compensate for the insufficient number of DFs (it does not

6

f(~x+ ~v�t,~v, t+�t)d

3xd

3v = f(~x,~v, t)d

3xd

3v +Collisions

• One can show: Only very few discrete velocities are necessary! Simplest scheme (D2Q9): 9 velocities are sufficient:

latticespacing

v0 = |~v0| =0

v1..4 =1

v5..8 =p2

~vj=5

fj(~xi, t) = f(~xi,~vj , t)

fj(~xi, t) = f(~xi,~vj , t)

Page 16: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Lattice Boltzmann method• Macroscopic quantities: Integrals => sums:

⇢(x, t) =

Z

velocity

f(x,v, t)dv

~u(~x, t)⇢(~x, t) =

Z

velocity

~vf(x,v, t)dv

0

D2Q9

latticeunit (lu)

8

4

1

5

2

6

3

7

Figure 2: Discrete lattice velocities for the D2Q9 model

The macroscopic variables are defined as functions of the particle distribution functions

(hereafter DFs) according to:

⇢ =

��1X

i=0

f

i

(macroscopic fluid density) (4)

and

~u =

1

��1X

i=0

f

i

~e

i

(macroscopic velocity). (5)

The DFs at each lattice point are updated using the equation:

f

i

(~x + ~e

i

�t, t + �t) = f

i

(~x, t)| {z }Streaming

�[f

i

(~x, t) � f

eq

i

(~x, t)]

⌧| {z }Collision

, (6)

where i 2 [0, � � 1] is an index spanning the (discretized) momentum space and ⌧ is a

relaxation parameter, which is related to the fluid viscosity (more details about this will follow

in this section).

This equation holds for lattice points within the fluid domain, but not for the domain bound-

aries, where boundary conditions compensate for the insufficient number of DFs (it does not

6

~vj=5

• LBM algorithm: Velocities “stream” f from site i to neighboring sites and collide:

make sense to stream DFs from walls towards the fluid). For this reason, the two steps (stream-

ing & collision) are usually treated separately in actual numerical implementations.

The streaming step, where the DFs are translated to the neighbouring sites according to

the respective discrete velocity direction, is illustrated in Fig. (3), in the D2Q9 model for

simplicity. The collision step (illustrated in Fig. [4]) consists of a re-distribution of the DFs

towards the local discretized Maxwellian equilibrium DFs, but in such a way that local mass

and momentum are invariant5.

streaming

Figure 3: Illustration of the streaming process on a D2Q9 lattice. Note that the magnitude of

the DFs remain unchanged, but they move to a neighbouring node according to their direction.

The equilibrium DFs can be obtained from the local Maxwell-Boltzmann SPDF (see for

example [He and Luo, 1997]); they are

f

eq

i

(~x) = w

i

⇢(~x)

1 + 3

~e

i

· ~u

c

2+

9

2

(~e

i

· ~u)

2

c

4�

3

2

~u

2

c

2

�, (7)

where for the D2Q9 model the weights are8>>><

>>>:

w

i=0 =

49

w

i={1..4} =

19

w

i={5..8} =

136

(8)

and c is the propagation speed on the lattice (1lattice spacing/time step), taken as c = 1 in

most cases.5As the method is mostly used in the incompressible limit, energy conservation is equivalent to momentum

conservation

7

streaming

length of arrow: value of fj

~u⇢ =8X

j=0

fj(~xi, t)~vj

⇢ =9X

j=1

fj(~xi, t)

f(~x+ ~v�t,~v, t+�t)d

3xd

3v = f(~x,~v, t)d

3xd

3v +Collisions

LBM

continuum

fj(~xi + ~vj�t, t+�t) = fj(~xi, t) + Coll(fj(~xi, t))

Page 17: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Collision term• Bhatnagar, Gross and Krook showed: Collision term can be approximated by the

relaxation ansatz (BGK approximation):

• Equilibrium distribution for f: wj=0 =4

9

wj=1..4 =1

9

wj=5..8 =1

36

with weights

• Side node: This equilibrium distribution is related to a series expansion of the Maxwell-Boltzmann velocity distribution for small velocities

• 𝜏 is the relaxation time scale• c is the lattice speed of sound

Coll(fj(~xi, t)) = �fj(~xi, t)� f

eqj (~xi, t)

⇢,~v

collision

⇢,~v

Figure 4: Illustration of the collision process on a D2Q9 lattice. Note that the local den-

sity ⇢ and velocity ~v are conserved, but the DFs change according to the relaxation-to-local-

Maxwellian rule.

Under the afore-mentioned assumption of a low Mach number, and further taking Kn

6, �

t

7, �

x

8 !0, this model recovers the incompressible Navier-Stokes equations:

r · ~u = 0 , (9)

⇢@

t

~u + ⇢~ur · ~u = �rP + ⇢⌫r2~u (10)

with an isothermal equation of state:

P = c

2s

⇢ , (11)

where P is the pressure.

The viscosity of the fluid is related to the relaxation parameter ⌧ by the equation

⌫ = c

2s

(⌧ � 1/2) ) ⌧ =

c

2s

+

1

2

���������!c

2s

|D2Q9=1/3

D2Q9 = 3⌫ +

1

2

(12)

The proof of these results follows from the Chapman-Enskog analysis. The speed of sound

c

s

is a lattice-dependent quantity, which takes the value

c

s

=

1

p3

6The assumption of Kn ⌘ �

L

! 0 is a requirement for continuum models to apply, hence it is not specific

to LBM.7Physical time unit, not the computational time unit �t, which is usually taken as 1.8Physical space unit 6= �x, which is usually taken as 1.

8

f

eqj (~xi, t) = wj⇢

1 +

~vj · ~uc

2+

(~u · ~vj)2

2c4� ~u

2

2c2

Page 18: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Notes

• The collision relaxation time is related to the viscosity of the fluid. For 2D9Q model:

• Note: It can be shown that the continuum limit of the 2D9Q model is the Navier-Stokes equation

⇢,~v

collision

⇢,~v

Figure 4: Illustration of the collision process on a D2Q9 lattice. Note that the local den-

sity ⇢ and velocity ~v are conserved, but the DFs change according to the relaxation-to-local-

Maxwellian rule.

Under the afore-mentioned assumption of a low Mach number, and further taking Kn

6, �

t

7, �

x

8 !0, this model recovers the incompressible Navier-Stokes equations:

r · ~u = 0 , (9)

⇢@

t

~u + ⇢~ur · ~u = �rP + ⇢⌫r2~u (10)

with an isothermal equation of state:

P = c

2s

⇢ , (11)

where P is the pressure.

The viscosity of the fluid is related to the relaxation parameter ⌧ by the equation

⌫ = c

2s

(⌧ � 1/2) ) ⌧ =

c

2s

+

1

2

���������!c

2s

|D2Q9=1/3

D2Q9 = 3⌫ +

1

2

(12)

The proof of these results follows from the Chapman-Enskog analysis. The speed of sound

c

s

is a lattice-dependent quantity, which takes the value

c

s

=

1

p3

6The assumption of Kn ⌘ �

L

! 0 is a requirement for continuum models to apply, hence it is not specific

to LBM.7Physical time unit, not the computational time unit �t, which is usually taken as 1.8Physical space unit 6= �x, which is usually taken as 1.

8

• In other words: Viscosity in NS has its origin in collisions in the Boltzmann-picture

c2 =8X

j=0

wj~v2j =

1

3• The speed of sound is (speed by which inform. can be

transported)

⌫ = c2✓⌧ � �t

2

◆(typically one chooses Δt=1; it’s an “artificial” time scale anyway)

• For a given viscosity, the relaxation time is thus fixed: (for 2D9Q scheme, c2=1/3)

⌧ = 3⌫ +�t/2

Page 19: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Boundary conditions

• No-slip boundary conditions: Add a layer of “ghost” sites.

• Possible boundary conditions: • No slip • Periodic (straight forward) • Inlet/outlet velocities (prescribe normal velocities to boundary) • Pressure difference (a bit more complex)

has been proven to be only first-order accurate in time and space [Pan et al., 2006]. A straight-

forward improvement is to consider the wall-fluid interface to be situated halfway between the

wall and fluid lattice nodes [Ziegler, 1993]. This simple translation (which is actually nothing

more than a slightly different post-processing procedure), commonly referred to as half-way

bounce-back in the literature, is illustrated in Fig. (5).

Fluid

Solid

Fluid

Solid

after stream

Fluid

Solid

Fluid

Solid

before stream (t + �t)

after bounce-back

before stream (t)

Figure 5: Illustration of the half-way bounce-back algorithm for the D2Q9 model (adapted

after [Sukop and Thorne, 2006]).

11

has been proven to be only first-order accurate in time and space [Pan et al., 2006]. A straight-

forward improvement is to consider the wall-fluid interface to be situated halfway between the

wall and fluid lattice nodes [Ziegler, 1993]. This simple translation (which is actually nothing

more than a slightly different post-processing procedure), commonly referred to as half-way

bounce-back in the literature, is illustrated in Fig. (5).

Fluid

Solid

Fluid

Solid

after stream

Fluid

Solid

Fluid

Solid

before stream (t + �t)

after bounce-back

before stream (t)

Figure 5: Illustration of the half-way bounce-back algorithm for the D2Q9 model (adapted

after [Sukop and Thorne, 2006]).

11

has been proven to be only first-order accurate in time and space [Pan et al., 2006]. A straight-

forward improvement is to consider the wall-fluid interface to be situated halfway between the

wall and fluid lattice nodes [Ziegler, 1993]. This simple translation (which is actually nothing

more than a slightly different post-processing procedure), commonly referred to as half-way

bounce-back in the literature, is illustrated in Fig. (5).

Fluid

Solid

Fluid

Solid

after stream

Fluid

Solid

Fluid

Solid

before stream (t + �t)

after bounce-back

before stream (t)

Figure 5: Illustration of the half-way bounce-back algorithm for the D2Q9 model (adapted

after [Sukop and Thorne, 2006]).

11

has been proven to be only first-order accurate in time and space [Pan et al., 2006]. A straight-

forward improvement is to consider the wall-fluid interface to be situated halfway between the

wall and fluid lattice nodes [Ziegler, 1993]. This simple translation (which is actually nothing

more than a slightly different post-processing procedure), commonly referred to as half-way

bounce-back in the literature, is illustrated in Fig. (5).

Fluid

Solid

Fluid

Solid

after stream

Fluid

Solid

Fluid

Solid

before stream (t + �t)

after bounce-back

before stream (t)

Figure 5: Illustration of the half-way bounce-back algorithm for the D2Q9 model (adapted

after [Sukop and Thorne, 2006]).

11

before “stream” at time t after “stream” at time t: stream to ghosts

collide in bulk,reverse values at

ghosts sites

bounce back, resulting in the state at time t+Δt

Page 20: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

DEMODemo shows flow through a 2D porous medium, inlet: left, outlet: right, top/bottom: no-slip BC

Page 21: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Parallelization• Parallelization is simple: Domain-decomposition

In each iteration - On each processor:

Stream and collide - Exchange values at domain

boundaries - Next iteration

• Today’s (gaming) graphics cards often have >256 single cores!

Page 22: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Cheap parallelization using GPUs (real time!)

sailfish.us.edu.pl

Page 23: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

LBM: Easy to model multiphase-flow

• Multiphase flow (water & oil, e.g.) is easily incorporated: Use two different prop. densities f (one per phase)

https://www.youtube.com/watch?v=1tasbL39xds A. I. Kupershtokh, 2013https://www.youtube.com/watch?v=ucqgRo6Fd_c

B. Ahrenholz

Page 24: Lecture 12 - Mathematicsmath.mit.edu/~stoopn/18.086/Lecture12.pdfLecture 12 18.086 Navier-Stokes / Flow problems • Tricky equation, tricky numerics… • Incompressible Navier-Stokes

Disadvantages of LBM• Only working for small Knudsen numbers Kn<<1. Kn =

L

r⇡m

2kBT

• L: char. length scale (i.e domain size), kB: Boltzmann constant, T: temperature

cs ⇠r

kBT

m• Kinetic gas theory: Speed of sound of a medium is:

• Taking the problem domain, with N lattice sites spaced by 1 length unit as characteristic length, and c (lattice speed of sound) as maximal sound speed, we find

Kn ⇠ ⌫

cN

• Other problems:

• No consistent thermo-hydrodynamic scheme

• Similar to Kn condition: Problems for high Mach numbers