Solving the Navier-Stokes equations in Python | CFD in Python | Lid-Driven Cavity

preview_player
Показать описание

We will discretize the incompressible Navier Stokes equations, consisting of a momentum equation and an incompressibility constraint, by Finite Differences. Partial Derivatives are resolved using a central difference scheme, the Laplace operator via the five-point stencil, and we use an explicit Euler in time. We account for incompressibility by using Chorin's Projection, which consists of the three steps:
1. Solve for a tentative velocity by forward stepping the momentum equations without the pressure gradient
2. Solve the Pressure-Poisson equation for a corrective pressure
3. Correct the Velocity to enforce incompressibility.

The second step is done approximately by 50 Jacobi iterations to reduce complexity.

Step (1) and (3) involve Dirichlet Boundary Conditions for the Velocity, which are homogeneous everywhere except for the horizontal velocity at the top that is prescribed. The Pressure Boundary Conditions are homogeneous Neumann (zero gradient over the boundary) everywhere except for the top, where it is a homogeneous Dirichlet BC. That is of course because we do not have an outflow over our solid walls.

If this simulation runs for at least 0.1 seconds, swirly motion takes place that can be beautifully seen by the streamlines we plot in the end.

Finally, we implement a stability constraint that is based on the von Neumann stability analysis of the Forward in time Central in Space (FTCS) scheme of the heat equation (also known as the CFL condition).

-------

-------

Timestamps:
00:00 Introduction
00:25 Problem Description
00:54 Boundary Conditions
01:30 Chorin's Projection (a splitting method)
02:00 Expected Outcome: Swirls
02:12 Strategy in Index Notation
02:37 Imports
02:56 Defining Constants (Parameters of the Simulation)
04:05 Main Switch (Boilerplate)
04:27 Define Mesh: Spatial Discretizations
05:11 Prescribe Initial Condition
05:48 Central Differences in x
07:13 Central Differences in y
08:11 Five-Point Stencil for Laplace Operator
09:33 Time stepping Boilerplate
09:49 Solving Momentum for Tentative Velocity
12:48 Enforce Velocity Boundary Conditions
14:30 Solving Pressure Poisson for Pressure Correction
20:29 Velocity Correction
21:54 Again Enforce Velocity Boundary Conditions
22:14 Advance in Time
22:37 Plot Solution (+ Bug Fix)
23:42 Discussing the Solution
24:32 Streamline Plot
25:13 Check for Numerical Stability
28:33 Outro
Рекомендации по теме
Комментарии
Автор

I highly appreciate your efforts on these excellent videos! Please keep it up!

jethromauricius
Автор

Mister, these are incredible videos. Keep up the good work. Best Regards from Germany.

mertyigit
Автор


This is because the FTCS scheme only works for advection-diffusion problems (like the Navier-Stokes equations are) if diffusive transport is dominant.

MachineLearningSimulation
Автор

Thank you for these videos! I am trying to improve at python (particularly for CFD) after mostly using openfoam, and these have been perfect.

tiddlywinks
Автор

Thank you for this wonderful video.
Please can you also do another one for a vertical flow for two phase liquid and gas

ntowebenezer
Автор

Brilliant tutorial, man. Such a clear explanation

torcher
Автор

Great work, I like it, especially when you use tqdm

hasnaouiacademy
Автор

Could you make a video on this example but in 3d and with no slip boundary conditions on only five of the walls, (the wall with slip condition is the one where the 'stream' is that causes the swirls.) I really love this video and the pressure displays.

heavennoes
Автор

Very interesting and very well explained! That's the kind of video that helps students like me.
Simple question: does the fluid inside the cavity can "flow out"? What if the "lid" is another fluid, is it possible to modify your code to compute the mixing that will occur?

pedrohenriquecerqueira
Автор

Nice Explanation! Which text editor are you using btw?

smitpatel
Автор

Thank you .
Can u make a tutorial for FVM, projection method ? That would be so helpful..

muhammadsaadkhan
Автор

I didn't understood shouldn't u_tent [0, :] be top boundary? Row indexing starting from upper row? 13:21

sm
Автор

Hi, thx a lot for this tutorial, very helpful ^^.
I am new to CFD and I came across the existence of different type of discretization schemes (upwind, linear upwind, and central). I guess u are making use of the central one in this video. Also, why did u choose this one specifically?
I guess in such a simple case it would not make any difference, but I suppose there are scenarios in which one gives better results than the others. Are there some rules depending on the domain structure? Thx again!

matteoricci
Автор

Thank you very much for the video. I am wondering if you may teach me how to adjust the boundary conditions such that the flow goes around a cylinder. Thank you.

ayliose
Автор

Is there any source that I can receive detailed explanation regarding the central difference scheme that is provided in 8.00 (row 157)? Actually I could not umderstand that part clearly.

mertekmen
Автор

How come I get this when running the code?

RuntimeWarning: invalid value encountered in add
u_prev * d_u_prev__d_x + v_prev * d_u_prev__d_y
RuntimeWarning: overflow encountered in multiply

antares
Автор

Where does the external flow come from? Is the lid being moved and therefore causing flow? Or are you programming some arbitrary flow to force vorticity?

Tommybotham
Автор

which editor are you using? i am using spyder and i absolutely hate how slow it performs on my computer
also i have 3d ascii cfd data generated from a fortran code. is there a way to plot it on python? (x, y, z, pressure)

astafzciba
Автор

Hello, after updating the velocities (applying the pressure correction), don't we need to check if du/dx + dv/dy = 0, and if it is not, keep repeating the process for that time step till it is?

atharvnaik
Автор

Could you please help on how to use projection method to solve Navier-Stokes equation in cylindrical coordinates?

sindhujaj