Introduction to the Numerical Solution of the Navier ...

29
ENGINYERIA AEROESPACIAL Apunts Introduction to the Numerical Solution of the Navier-Stokes equations. Module 9: Time marching algorithm and the incompressibility constraint. Pressure-velocity coupling Manel Soria Assignatura: Aerodinàmica, Mecànica Orbital I Mecànica de Vol Titulació: Master d’Enginyeria Aeronàutica Curs: 1r Escola Superior d’Enginyeries Industrial, Aeroespacial i Audiovisual de Terrassa (ESEIAAT) Idioma: Anglès Novembre 2021

Transcript of Introduction to the Numerical Solution of the Navier ...

Page 1: Introduction to the Numerical Solution of the Navier ...

ENGINYERIA AEROESPACIAL

Apunts

Introduction to the Numerical Solution of the Navier-Stokes equations.

Module 9: Time marching algorithm and the incompressibility constraint. Pressure-velocity coupling Manel Soria Assignatura: Aerodinàmica, Mecànica Orbital I Mecànica de Vol Titulació: Master d’Enginyeria Aeronàutica Curs: 1r Escola Superior d’Enginyeries Industrial, Aeroespacial i Audiovisual de Terrassa (ESEIAAT) Idioma: Anglès Novembre 2021

Page 2: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

Module 9. Time marching algorithm and the incompressibility constraint. Pressure-velocity coupling.

Manel Soria – [email protected]

MÀSTER UNIVERSITARI EN ENGINYERIA AERONÀUTICAESEIAAT

Page 3: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

Module 9. Time marching algorithm and the incompressibility constraint. Pressure-

velocity coupling.

Page 4: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.1 An equation for the pressure. Ladyzhenskaya theorem 3

If we begin from known initial conditions, from momentum equations we can obtain the evolution of velocities. To do so, we need the pressure field.But where is the equation for the pressure ?In compressible equations, mass conservation reads:

Since for a gas density is a function of pressure and temperature, we should be able to obtain an expression for pressure from mass conservation. However, in incompressible flows where 𝜌 is assumed constant, we have removed this possibility.

In next slides, we will describe the projection method that allows us to perform time integration and obtain the pressure.

𝜕𝑢!𝜕𝑡

+ 𝑢"𝜕𝑢!𝜕𝑥"

= −1𝜌𝜕𝑝𝜕𝑥!

+ 𝜈𝜕#𝑢!𝜕𝑥"𝜕𝑥"

𝜕𝑢!𝜕𝑥!

= 0

Review for a moment the incompressible Navier-Stokes equations:

𝜕𝜌𝜕𝑡

+ 𝛻 ⋅ (𝜌𝒖) = 0

Page 5: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

A given vector field 𝒘, defined in a bounded domain Ω with smooth boundary ∂Ω, is uniquely decomposed in a pure gradient field and a divergence-free vector parallel to ∂Ω

9.1 An equation for the pressure. Ladyzhenskaya theorem* 4

O.A. Ladyzhenskaya (1922-2004) **

* Also known as Helmholtz–Hodge Decomposition Hodge decomposition** You can read about Ladyzhenskaya life and work here https://en.wikipedia.org/wiki/Olga_Ladyzhenskaya

𝒘 = 𝒂 + 𝛻𝜙

𝛻 ⋅ 𝒂 = 0 𝒂 ∈ Ω

𝒂 ⋅ 𝒏 = 0 𝒂 ∈ 𝜕Ω

Page 6: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.1 An equation for the pressure 5

In our case we will use theorem as follows,

2𝑝 is a pseudo-pressure field, that as we will see can be used to easily obtain the pressure.

𝒖$ (the arbitrary vector w in Ladyzhenskaya theorem) is known as the predictor velocity. It will be calculated from NS equations, but omitting the pressure gradient term. For now, assume that 𝒖! is just an arbitrary vector field (with both components, 𝑢% and 𝑢#).

𝒖&'% will be the next time step velocity, with all the terms, including the pressure gradient. It will be divergence free, 𝛻 ⋅ 𝒖&'%= 0.

(9.1)

𝒂 = 𝒘 − 𝛻𝜙

𝒖!"# = 𝒖$ − 𝛻 (𝑝

Page 7: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.1 An equation for the pressure 6

𝒖!"# = 𝒖$ −𝛻 %𝑝

𝛻 ⋅ 𝒖!"# = 𝛻 ⋅ 𝒖$ −𝛻 ⋅ 𝛻 %𝑝 = 0

𝛻 ⋅ 𝒖!"# = 𝛻 ⋅ 𝒖$ −𝛻% %𝑝 = 0

𝛻% %𝑝 = 𝛻 ⋅ 𝒖$

We take the divergence at both sides, and impose it to be zero:

Now, we just substitute the divergence of the gradient by the Laplacian:

And we obtain the equation for the pressure (pseudo-pressure actually). This is known as Poisson equation. It is an elliptic equation.

Lets see how we can obtain the scalar field 2𝑝 needed to make 𝒖&'% divergence-free

As seen in the previous slide, the next time step velocity will be evaluated as:

Note: the Laplacian operator can also be expressed as Δ

(9.2)

(9.1)

Page 8: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.1 An equation for the pressure 7

So, our sequence of operations will be:• Find the divergence of the predictor velocity, 𝛻 ⋅ 𝒖$

• Use it as right-hand side to solve the Poisson equation for pseudo-pressure, 𝛻# 2𝑝 = 𝛻 ⋅ 𝒖$For this step, we have to find a field #𝑝 with a given Laplacian. To do so, we will have to solve an equation.

• Subtract the pseudo-pressure gradient to the predictor velocity to obtain the next time velocity, 𝒖&'% = 𝒖$ − 𝛻4𝑝

With these operations, we can transform an arbitrary vector field 𝒖$ into a divergence-free vector 𝒖&'% subtracting the unique gradient of a scalar field 2𝑝.As we will see in Section 9.4, this will be the key to solve the pressure-velocity coupling.

We have introduced three new operators: gradient, divergence and their composition, the divergence of the gradient (Laplacian). In next slides, we will see how can we obtain their discrete expressions.

Page 9: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.2 Discrete divergence, gradient and Laplacian. Divergence 8

Following our finite control volume approach, the divergence will be discretized with an integral over the centered mesh. We will use a uniform mesh as an example. For clarity, the super index and the tilde will be dropped from 𝒖$ and 2𝑝 in next slides.

The divergence of a vector, with both components staggered in their respective directions, is a centered scalar field:

5(𝛻 ⋅ 𝒖 𝑑𝑉 = 5

)𝒖 ⋅ 𝐧 𝑑𝑆 =

∫&𝑣&𝑑𝑆 + ∫*𝑢*𝑑𝑆 − ∫)𝑣)𝑑𝑆 − ∫+𝑢+𝑑𝑆 ≈

≈ Δ 𝑣!," + 𝑢!," − 𝑣!,"-% − 𝑢!-%,"

p(i,j) u(i,j)

v(i,j)

p(i+1,j)u(i-1,j)

p(i,j-1)

p(i,j+1)

v(i,j-1)

Note that our staggered mesh is very helpful in this case, as the velocities needed are available without interpolations

Page 10: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.2 Discrete divergence, gradient and Laplacian. Gradient 9

The discrete gradient is an operator that, applied to a centered scalar field yields a vector with both components staggered. If the scalar field is denoted by 𝑝 and its gradient components by 𝑔𝑥 and 𝑔𝑦, they can be easily approximated by finite differences as:

p(i,j) gx(i,j)

gy(i,j)

p(i+1,j)gx(i-1,j)

p(i,j-1)

p(i,j+1)

gy(i,j-1)

𝑔𝑥(𝑖, 𝑗) =𝑝!'%," − 𝑝!,"

Δ

𝑔𝑦(𝑖, 𝑗) =𝑝!,"'% − 𝑝!,"

Δ

Again, our staggered mesh is very helpful in this case

Page 11: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.2 Discrete divergence, gradient and Laplacian. Laplacian 10

The Laplacian operator will be applied to a scalar field and will return another scalar field, both centered.However, unlike all our previous operators, it will be formulated as an equation to be solved to obtain the pseudo-pressure 2𝑝.

𝛻%�̃� = 𝛻 ⋅ 𝒖$ As aforementioned, to simplify the notation, here we drop the tilde in #𝑝 and the super index in 𝒖!

∫(𝛻#𝑝 𝑑𝑉 = ∫(𝛻 ⋅ 𝒖 𝑑𝑉

∫.𝛻𝑝 ⋅ 𝐧 𝑑𝑆 = Δ 𝑣!," + 𝑢!," − 𝑣!,"-% − 𝑢!-%,"

Δ𝑝",$%& − 𝑝",$

Δ + Δ𝑝"%&,$ − 𝑝",$

Δ − Δ𝑝",$ − 𝑝",$'&

Δ − Δ𝑝",$ − 𝑝"'&,$

Δ = Δ 𝑣",$ +𝑢",$ − 𝑣",$'& −𝑢"'&,$

𝑝!,"'% + 𝑝!'%," + 𝑝!,"-% + 𝑝!-%," − 4𝑝!," = Δ 𝑣!," + 𝑢!," − 𝑣!,"-% − 𝑢!-%,"

Again, for a uniform mesh:

p(i,j) u(i,j)

v(i,j)

p(i+1,j)u(i-1,j)

p(i,j-1)

p(i,j+1)

v(i,j-1)

And our equation reads:

Page 12: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.3 The discrete Poisson equation. Stencil notation 11

In the last slide, we obtained our equation for the pseudo-pressure at node i,j:

𝑝!,"'% + 𝑝!'%," + 𝑝!,"-% + 𝑝!-%," − 4𝑝!," = Δ 𝑣!," + 𝑢!," − 𝑣!,"-% − 𝑢!-%,"

If this is repeated for all the control volumes, we obtain an equation system. Two notations can be used to represent it, the stencil notation and the matrix notation.

In the stencil notation, we only deal express the coefficient that couples each node with its neighbours at East, West, North and South :

𝑎$𝑝$ + 𝑎*𝑝* + 𝑎&𝑝& + 𝑎+𝑝+ + 𝑎)𝑝) = 𝑏$Following the previous example, the coefficient values would be:

𝑎! = −4𝑎* = 𝑎& = 𝑎) = 𝑎+ = 1

This notation is very straightforward but does not reveal the matrix structure and their properties. Also, it is not practical if we want to use a standard linear equation system algorithm to solve it.

If you check the bibliography, you will find that some authors that use this notation (e.g., Patankar) transfer the 𝑎!𝑝! term to the other side of the equation so that the coefficient multiplying 𝑝! is also positive.

Note:𝑎!𝑝! = 𝑎"𝑝" + 𝑎#𝑝# + 𝑎$𝑝$ + 𝑎%𝑝% + 𝑏

𝑎! = 4𝑎" = 𝑎# = 𝑎% = 𝑎$ = 1

Where:

Page 13: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.3 The discrete Poisson equation. Matrix notation 12

This equation for a generic node will now be expressed with matrix notation as:

𝑎$𝑝$ + 𝑎*𝑝* + 𝑎&𝑝& + 𝑎+𝑝+ + 𝑎)𝑝) = 𝑏$Recall our previous stencil equation:

p(1,1)

u(1,1)

v(1,1)

p(2,2)

p(3,3)

p(4,4)

p(5,5)

p(5,4)

p(5,1)

1 2 3

4 5 6

7 8 9While in our halo-augmented domain we have 25 pressure values, actually only 9 of them are unknowns.

The rest can be obtained with a halo update operation (16 pressure values).

We will number the nodes from bottom left to top right, but this is arbitrary.

𝑎* = 𝑎& = 𝑎) = 𝑎+ = 1𝑎$ = −4

In next slide, we will see where they have to be placed in the full matrix

𝐴𝑥 = 𝑏

As an example, we consider the case for N=3 (with 9 unknowns), and periodic boundaries

Where 𝑥 is the unknown, the pseudo-pressure in this case and 𝑏 the right-hand-side, the divergence of the predictor velocity

Recall that with our uniform mesh, the coefficient values are:

Page 14: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.3 The discrete Poisson equation. Matrix notation 13

p(5,5)

p(5,4)

p(5,1)

p(2,2)

p(4,4)

1 2 3

4 5 6

7 8 9

p(3,3)

p(1,1)

u(1,1)

v(1,1)

A =-4 1 1 1 0 0 1 0 01 -4 1 0 1 0 0 1 01 1 -4 0 0 1 0 0 11 0 0 -4 1 1 1 0 00 1 0 1 -4 1 0 1 00 0 1 1 1 -4 0 0 11 0 0 1 0 0 -4 1 10 1 0 0 1 0 1 -4 10 0 1 0 0 1 1 1 -4

Consider p(4,3) , that is in the 6th position of the vector, with East neighbour in position 4, p(2,3) (as the domain is periodic)North neighbour in position 9, p(4,4)South neighbour in position 3, p(4,2)West neighbour in position 5, p(3,3)

Try to follow the equation for each node.

p(4,3)p(2,3)

Page 15: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.3 The discrete Poisson equation. Properties 14

A =-4 1 1 1 0 0 1 0 01 -4 1 0 1 0 0 1 01 1 -4 0 0 1 0 0 11 0 0 -4 1 1 1 0 00 1 0 1 -4 1 0 1 00 0 1 1 1 -4 0 0 11 0 0 1 0 0 -4 1 10 1 0 0 1 0 1 -4 10 0 1 0 0 1 1 1 -4

Now that we have obtained the left-hand-side of Poisson equation in matrix form, we have to study several of its properties that will have an important effect in incompressible CFD solvers.

• The sum of each row of matrix A is zero. • A is symmetric (and this is important for certain algorithms such as

Conjugate Gradient).• Thus, the sum of its columns is zero. • Therefore, A is a singular matrix.• As the sum of all the equations (columns) is zero, the same has to hold

for the sum of b vector*.

In next slide, we will study if the sum of 𝑏 is actually zero and why* For the last statement, you may want to review from your Algebra course the Rouché-Capelli theorem (or Rouché-Frobenius): the rank of the matrix 𝐴 has to be equal to the rank of the augmented matrix 𝐴|𝑏 .

Page 16: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.3 The discrete Poisson equation. About Σ𝑏 and the global mass balance 15

As an example, consider a vector field 𝒖! that is zero everywhere, except for a single location where the horizontal 𝑢(𝑖, 𝑗) velocity is 1.Assume also a uniform mesh with Δ = 1, just for simplicity

So 𝑏 = 0 for all the nodes except for two, (i,j) and (i+1,j) where it is respectively 1 and -1. The green control volume has a deficit of mass and the red one an excess, by exactly the same amount. Thus, their sum will cancel out. The same holds for any other non-null velocity component or mesh size.

𝑏(𝑖, 𝑗) = 𝑣!," + 𝑢!," − 𝑣!,"-% − 𝑢!-%,"

Under the previous considerations (as Δ = 1),

Actually, as 𝑏!," = ∫!,"𝛻 ⋅ 𝒖 𝑑𝑉 is the divergence integral over one control volume, Σ𝑏is the integral over all the domain. The individual contributions to the sum cancel in all the inner domain nodes. In a periodic problem such as ours, Σ𝑏 has to be zero.

This is not necessarily the case, as we will see, for domains with inlets and outlets. If the overall mass conservation equation is not satisfied for 𝒖!, the Poisson equation is incompatible and thus it can not be solved.

p(i,j) u(i,j)

v(i,j)

p(i+1,j)u(i-1,j)

p(i,j-1)

v(i,j-1)

p(i-1,j) b(i,j)=1b(i,j)=-1

Page 17: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.3 The discrete Poisson equation. Singularity of the Poisson equation 16

• As we have seen, Σ𝑏 = 0 is a necessary condition for the Poisson equation to be compatible.• But even in this case, it will be underdetermined, with one degree of freedom. • From a physical point of view, this makes perfect sense. Note that in the incompressible Navier-Stokes the

pressure is underdetermined. As only its gradient is present in the equations, if an arbitrary constant is added to a valid pressure field, it continues to be a valid solution.

• Note that Ladyzhenskaya theorem states that the gradient 𝛻𝜙 is unique, but not 𝜙 itself.• Depending on the method used to solve the matrix equation, the constant obtained can be different. For

instance, negative values of the pseudo-pressure could be obtain and the solution still be correct. • Soon we will see how we can recover the true pressure from the pseudo-pressure. But for now, recall that

the underdetermined pressure field in the incompressible equations may not be the thermodynamic pressure.

Avoiding the singularity of the Poisson equation

In general, linear equation solvers can not deal with singular matrices. There are different techniques to solve obtain just one of the possible solution vectors. An easy way to do this is, that has the advantage of preserving the symmetry of the matrix is just imposing that one of the diagonal terms is for instance -5 (instead of -4),𝐴(1,1) = −5

Page 18: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.3 The discrete Poisson equation. Computational implications 17

Matrix A is a sparse matrix (with few non-zero elements). For two-dimensional periodic problem, its structure looks like this (non-null elements are marked in blue):

A

A-1

2𝑝 = 𝐴-%𝑏

For a real CFD problem, where N can easily be in the order of millions or more unknowns, it is not practical to store all the N^2 coefficients.Only the no-null are stored, using a diagonal matrix structure for structured meshes in our case or a more general sparse matrix data structure in general.

However, if we invert A, we observe that all its elements are non-null. This is very relevant as the pseudo-pressure can be obtained from

This means that a change in any point of b, resulting for instance from a local perturbation in the velocity, can affect the pseudo-pressure in all the domain, instantaneously.This is consistent with the infinite sound velocity assumed for incompressible flows.It is a serious inconvenient for parallel computers, where each processor is in charge of a part of the domain.In incompressible CFD codes, a large part of the CPU time is typically spend solving the Poisson equation.

Page 19: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.4 Time integration. Recovery of the pressure 18

We can express both discrete equations as:

is the space-discrete velocity vector, with both componentsis the space-discrete pressureis the volume integral of the convective term (both components)is the volume integral of the diffusive term (both components). Note the visosity 𝜈is the volume of each C.V, staggered in x or in y directionV

Consider both momentum equations PDEs, integrated over each control volume V

Note that now they are ODEs

Note that here, to simplify the notation, the symbol gradient 𝛻 is also used in the ODE, but it has to be understood as the discrete gradient as described in section 9.2

5(

𝜕𝑢%𝜕𝑡

𝑑𝑉 + 5(𝛻 ⋅ (𝑢%𝒖) 𝑑𝑉 = − 5

(

1𝜌𝜕𝑝𝜕𝑥%

𝑑𝑉 + 𝜈 5(𝛻 ⋅ (𝛻 𝑢%) 𝑑𝑉

5(

𝜕𝑢#𝜕𝑡

𝑑𝑉 + 5(𝛻 ⋅ (𝑢#𝒖) 𝑑𝑉 = − 5

(

1𝜌𝜕𝑝𝜕𝑥#

𝑑𝑉 + 𝜈 5(𝛻 ⋅ (𝛻 𝑢#) 𝑑𝑉

𝜕u𝜕𝑡𝑉 + 𝐶 u = −

𝑉𝜌𝛻p + 𝐷(u)

Page 20: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.4 Time integration. Recovery of the pressure 19

Now we have to obtain the velocity u as a function of time.Recall that V is just the volume of each control volume, due to our approximation of the non-divergence terms (check part 6.1):

We will ignore that convection and diffusion are a function of the velocity field and just write C and D

Note that the terms that are not obtained from a divergence contain an explicit product by the volume V

is the right-hand-side of the equation, except the pressure gradient term.We will use this notation to describe the time discretization

(9.3)

𝑑u𝑑𝑡𝑉 + 𝐶 u = −

𝑉𝜌𝛻p + 𝐷(u)

5(𝑆 𝑑𝑉 = ̅𝑆𝑉

𝜕u𝜕𝑡+𝐶𝑉= −

1𝜌𝛻p +

𝐷𝑉

𝜕u𝜕𝑡

= 𝑅 −1𝜌𝛻p where 𝑅 =

𝐷𝑉−𝐶𝑉

or

Page 21: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.4 Time integration. Recovery of the pressure 20

We will compute the distributions of discrete velocities at a discrete set of instants, from the known initial conditionsAt each instant, the past distributions from the initial conditions (1 to n) are known, while we want to compute the distribution at discrete time ‘n+1’

Adams-Bashforth (explicit) is used for R (convection and diffusion). Rn and Rn-1 can be evaluated with known velocity fields

Implicit is used for pressure gradient

Now this equation is a (very large) ODE, spatial derivatives have been discretized and u is just a discrete vector, so we use the symbol 𝑑/𝑑𝑡 instead of 𝜕/𝜕𝑡

Different schemes are used for the different terms:

n-1 n n+1

known values unknown values

time

initial conditions

our immediate goal

𝑑u𝑑𝑡

= 𝑅 −1𝜌𝛻p

u&'% − u&

Δ𝑡=32𝑅& −

12𝑅&-% −

1𝜌𝛻p&'%

Page 22: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.4 Time integration. Recovery of the pressure 21

This is the expression for the predictor velocity. Note that as it was introduced in section 9.1, it was considered an arbitrary vector. Now, it will be applied to the contribution of R terms to the velocity at time n+1. Recall that it can be explicitly evaluated from known velocity fields.

From it, we can obtain the next (unknown) velocity distribution

(9.4)

u&'% − u&

Δ𝑡=32𝑅& −

12𝑅&-% −

1𝜌𝛻p&'%

u&'% = u& + Δ𝑡32𝑅& −

12𝑅&-% −

Δ𝑡𝜌𝛻p&'%

u&'% = u$ −Δ𝑡𝜌𝛻p&'%

Page 23: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.4 Time integration. Recovery of the pressure 22

u!"# = u$ − 𝛻 ̃𝑝

If we compare the previous expression (9.4)

With the pseudo-pressure expression (9.1)

We can identify the pseudo-pressure as:

2𝑝 =Δ𝑡𝜌𝑝&'%

And therefore, the pressure can be recovered from the pseudo-pressure as

𝑝&'% =𝜌Δ𝑡

2𝑝

Remember however that the pseudo-pressure is not determined. Depending on how we condition the matrix equation to solve for it, or on the algorithm used, we can obtain values of #𝑝 (and thus 𝑝) that are different.However, at each time step, the difference between two given pressures has to be the same.

(9.5)

u&'% = u$ −Δ𝑡𝜌𝛻p&'%

Page 24: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.4 CFL condition and the time step 23

u

1- Convective time limit (time needed for a particle to move along a control volume):

In explicit methods, the time step has to be below a limit. In our case, there are two limits,the convective time limit and the diffusive time limit (that here we give as a result without a derivation):

Where here |𝑢| is the absolute value of the horizontal velocity. We have to find it for each CV and then choose the minimum of all them. Then, we repeat the operation for the vertical component and again we choose the minimum.

Note that if the mesh is refined, the time step has to be smaller.

Δ𝑡P ≤ 𝑀𝑖𝑛Δ𝑢

Page 25: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.4 CFL condition and the time step 24

In practice, f has to be about 0.2-0.5There are better methods to estimate the time step, that allow f to be close to 1Note that Δ𝑡 has to be evaluated before each time step, as Δ𝑡/depends on the velocity vector.If the maximum time step is exceeded, the algorithm diverges.

To find out time step Δ𝑡, we choose the minimum between the convective and the diffusive, and then apply a safety factor f:

2- Diffusive time limit:

Δ𝑡P ≤ 𝑀𝑖𝑛Δ𝑢

Δ𝑡 = 𝑓 ⋅ 𝑀𝑖𝑛(Δ𝑡*, Δ𝑡+)

Page 26: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.5 How to implement the pressure-velocity coupling 25

d = idiv(u,v) - returns the integral of the divergence of a fieldu,v: vector field (staggered) u(N+2,N+2),v(N+2,N+2)d: scalar field (centred) d(N+2,N+2)with the integral of the divergence of the vector (u,v)

A = ilaplacianMatrix(L,N) - returns a matrix expressing the integral of the Laplacian. For a uniform mesh, only the domain size L and the number of nodes of the main mesh are needed. If a non-uniform mesh is used, the vectors with the mesh description(cx,cy,sx,sy)will be neededMatrix A will be of size A(N^2,N^2)

We suggest you to implement and test the following functions separately before writing the pressure-velocity coupling

Page 27: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.5 How to implement the pressure-velocity coupling 26

b = field2vector(d) - expresses a field as an algebraic vector, removing the halosd: scalar field d(N+2,N+2)b: algebraic vector b(N*N)This function is needed to be able to solve the linear system for the pseudo-pressure using a standard algorithm.

d = vector2field(b) - expresses an algebraic vector as a fieldb: algebraic vector b(N*Nd: scalar field d(N+2,N+2)This function is needed to write the algebraic vector of the pseudo-pressure as a field.

We suggest you to implement and test the following functions separately before writing the pressure-velocity coupling

[gx,gy] = gradient(s)- returns the gradient of a fields: scalar field (centred) gx,gy: vector field (staggered), gx(N+2,N+2), gy(N+2,N+2)

Page 28: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.5 Pressure-velocity coupling algorithm 27

We start with an arbitrary field 𝑢!. It will be the predictor velocity but to test your code we suggest you to begin with field equal to zero everywhere except at some points. Remember to halo-update it before computing the integral of the divergence

d = idiv(u,v);

b = field2vector(d);

A = laplacianMatrix(L,N);

x = A\b;

p = vector2field(x);

p = haloupdate(p);

[gx,gy] = gradient(p);

u = u - gx;v = v - gy;

d2 = idiv(u,v); And the field [u,v] has to be divergence-free at all the nodes. To check it, we compute again the divergence

Here u,v are components of 𝑢!Compute the integral of its divergence, the RHS of the Poisson eq.

𝛻 ⋅ 𝑢&'% = 0

Express it as an algebraic vectorThe sum of b should be zero to satisfy the compatibility condition, check it

Compute the coefficients of the integral of the Laplacian

x now is the solution of Ax=b

Express it as a field

Halo update it to compute correctly the gradient of the pseudopressure

Find the gradient of the pseudopressure

And subtract it from 𝑢!

Now u,v are components of 𝑢(%&𝑢&'% = 𝑢$ − 𝛻 2𝑝

𝛻# 2𝑝 = 𝛻 ⋅ 𝑢$

Page 29: Introduction to the Numerical Solution of the Navier ...

Introduction to the Numerical Solution of the Navier-Stokes equations

9.6 Incompressible Navier-Stokes integration algorithm 28

- Start the integration with t=0 and 𝐮 equal to the initial conditions

While 𝑡 < 𝑡012 (end of integration period)

- Find the time step Δ𝑡 (see 9.4)

- Update the instant being solved, 𝑡 = 𝑡 + Δ𝑡

- Compute 𝐑& = −𝐂&/𝑉 + 𝐃&/𝑉

- Compute the predictor velocity 𝐮$ = 𝐮& + Δ𝑡 3#𝐑& − %

#𝐑&-%

*For the first time step, 𝐑&-% is not available, so assume 𝐑&-% = 𝐑&

- Obtain 𝐮&'% from the predictor velocity (see 9.5)

- Advance to next time step, 𝐑&-% = 𝐑& , 𝐮& = 𝐮&'%