FEniCS Tutorial: Navier-Stokes Equation for Lid-Driven Cavity

The incompressible Navier-Stokes equations describe the evolution of fluid motion. In this video, we will simulate them using the Finite Element Method and Chorin's Projection using the FEniCS package in Python. Here is the resulting code: github.com/Ceyron/machine-lea...
Computational Fluid Dynamics (=CFD) is concerned with the simulation (=quantitative prediction) of the Partial Differential Equations (=PDEs) that underpin fluid mechanics, the Navier-Stokes Equations. Those set of PDEs are particularly challenging to solve due to multiple reasons, they are non-linear, form a saddle-point structure (and in the case of turbulence: are multi-scale). The Finite Element Method presents a methodology to discretize the spatial derivatives in it. We will combine this with a simple Euler time step, for which we treat the convection fully explicit and the diffusion fully implicit. We will enforce incompressibility as required by the continuity equation by the usage of Chorin's Projection method. This method gives rise to pressure Poisson problem.
-------
📝 : Check out the GitHub Repository of the channel, where I upload all the handwritten notes and source-code files (contributions are very welcome): github.com/Ceyron/machine-lea...
📢 : Follow me on LinkedIn or Twitter for updates on the channel and other cool Machine Learning & Simulation stuff: / felix-koehler and / felix_m_koehler
💸 : If you want to support my work on the channel, you can become a Patreon here: / mlsim
-------
⚙️ My Gear:
(Below are affiliate links to Amazon. If you decide to purchase the product or something else on Amazon through this link, I earn a small commission.)
- 🎙️ Microphone: Blue Yeti: amzn.to/3NU7OAs
- ⌨️ Logitech TKL Mechanical Keyboard: amzn.to/3JhEtwp
- 🎨 Gaomon Drawing Tablet (similar to a WACOM Tablet, but cheaper, works flawlessly under Linux): amzn.to/37katmf
- 🔌 Laptop Charger: amzn.to/3ja0imP
- 💻 My Laptop (generally I like the Dell XPS series): amzn.to/38xrABL
- 📱 My Phone: Fairphone 4 (I love the sustainability and repairability aspect of it): amzn.to/3Jr4ZmV
If I had to purchase these items again, I would probably change the following:
- 🎙️ Rode NT: amzn.to/3NUIGtw
- 💻 Framework Laptop (I do not get a commission here, but I love the vision of Framework. It will definitely be my next Ultrabook): frame.work
As an Amazon Associate I earn from qualifying purchases.
-------
Timestamps:
00:00 Intro
00:30 Navier-Stokes Equations
01:11 About Lid-Driven Cavity & BC
02:27 Solution Strategy with Weak Forms
07:12 Taylor-Hood Elements & Saddle Point Problems
08:29 Choose Time Step size carefully
08:55 Imports
09:25 Simulation Parameters
10:13 Some Boilerplate
10:26 Define Mesh
11:01 Set up Function Spaces (with Taylor-Hood Elements)
12:26 Define Trial & Test Functions
13:32 Boundary Conditions (Stationary & Moving Wall)
18:11 Solution Fields
19:47 Weak Form of Momentum Equation
22:55 Weak Form of Pressure Poisson Problem
24:57 Weak Form of Velocity Projection/Correction
27:09 Time Loop Setup
27:25 (1) Solve for tentative velocity
28:18 (2) Solve for pressure
28:50 (3) Correct velocities for incompressibility
29:12 (4) Advance in time
29:31 Interactive visualization
30:07 First Run + Discussion
31:22 Pre-Computing assembly of system matrices
36:14 Second Run + Small Bug Fix
36:53 Adjusting Linear Solver and Preconditioner
38:06 Third Run + Admiring Speedup
38:35 Outro

Пікірлер: 28

  • @alperozt
    @alperozt2 ай бұрын

    Thank you. This is super helpful as an intro to fenics for fluid.

  • @MachineLearningSimulation

    @MachineLearningSimulation

    Ай бұрын

    Thanks a lot for the kind feedback 😊

  • @carlosandresdelvalle9532
    @carlosandresdelvalle95322 жыл бұрын

    Would be great if you did a variable density fluid, ie. Euler equation + viscosity coupled with advection of density. Everywhere density is constant, viscosity is constant, and fluid incompressible all the time. Doing something out of the mold would be very special.

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    That's a cool suggestion. I will note that down. :) I do not have much experience with compressible flows yet. From my engineering background, I would say that they mostly only relevant for high-speed aerodynamics (like fighter jets etc.). Almost all other engineering CFD is incompressible (or at least in the incompressible limit). Though, I can understand that it can become boring :D. Although, the saddle point structure of the incompressible NS is also very challenging, mathematically speaking.

  • @carlosandresdelvalle9532

    @carlosandresdelvalle9532

    2 жыл бұрын

    @@MachineLearningSimulation yes I know. I'm a physics student an fluids are very difficult. But with the power of the computer, you can do that crazy stuff.

  • @varunkumarr8606
    @varunkumarr86062 жыл бұрын

    Please make more FEniCS videos

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    More to come in the next weeks ;)

  • @icojb25
    @icojb252 жыл бұрын

    Wonderful

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    Thank you! Cheers!

  • @mazdakatri1099
    @mazdakatri10992 жыл бұрын

    Thank you for the nice explanation. I still have problems understanding the solution strategy and derivation of the weak forms. Is it able for you to make a video like the ones for the heat equation and linear elasticity to explain in detail the solution strategy and weak form-derivation? I would also appreciate any suggestions from the literature to clarify the issue.

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    Thanks a lot for the kind words. :) This explanation for the NS equations together with Chorin's projection will be released tomorrow ;)

  • @gregperez6291
    @gregperez629110 ай бұрын

    Hey! Thank you so much for the video. Is there any way to validate that the solver indeed gives the velocities expected?

  • @MachineLearningSimulation

    @MachineLearningSimulation

    9 ай бұрын

    You're very welcome 🤗 I'm glad you enjoyed it. Generally speaking, validating numerical solvers is challenging. A first thing to check is if the two time steps in a trajectory (or the steady-state in a stationary simulation) fulfill the discretized PDE in that you plug the velocities into your discrete equations and computer a norm metric. If it is below a desired tolerance, it is a correct solution to the discrete problem. For the specific algorithm presented here that might not be too easily possible because we do not iterate Back and forth between momentum and continuity equation which would be necessary to ensure both are solved to the desired degree. Another approach would be to use test problems (like the lid-driven cavity) for which reference values are available (for the lid-driven cavity, one often uses the values due to Ghia et al.). I would recommend you to check out chapter 20&21 of book "automated solution of differential equations by the finite element method" by logg et al.

  • @fdzgallen
    @fdzgallen2 жыл бұрын

    Any comment on how to implement periodic boundary conditions on for example at the left and right wall? I'm having problems with PBCs in fenics

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    Unfortunately, I do not have much experience with periodic BCs in FEniCS, maybe you find this pointer to the FEniCS tutorials helpful: fenicsproject.org/olddocs/dolfin/1.4.0/python/demo/documented/periodic/python/documentation.html

  • @chrisli6831
    @chrisli68313 ай бұрын

    Hi, It seems fenics has undergone a large update, and I'm using the latest dolfinx to rewrite the code. However, there is seems a large gap. Do you have any example by using dolfinx? Thanks.

  • @MachineLearningSimulation

    @MachineLearningSimulation

    3 ай бұрын

    Yes, they made a bigger upgrade, also renewing some of the API. I haven't used it yet, unfortunately. The update of the FEniCs tutorial videos is on my to-do list but not of the highest priority atm. This tutorial is the first thing that popped up, maybe you find it helpful: jsdokken.com/dolfinx-tutorial/

  • @habib-ur-rehmaan2532
    @habib-ur-rehmaan25322 жыл бұрын

    is there any way we that get the variational form by using fenics ?

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    Hi, thanks for the comment 😊 Are you referring to the weak form? If so, then to my best knowledge FEniCS does not accept the strong form of the PDE. You always have to present your problem in weak form. Hence, FEniCS does not have a routine to translate the problem for you.

  • @friedrichwilhelmhufnagel3577
    @friedrichwilhelmhufnagel35772 жыл бұрын

    Hallo, was ist denn bitte der Editor? LG

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    Hi, das ist Visual Studio Code mit der Python Extension. Für das Video habe ich mit OBS aber nur einen Teilbereich des Bildschirms aufgenommen.

  • @ronnymonnig139

    @ronnymonnig139

    2 жыл бұрын

    Visual Studio Code

  • @habib-ur-rehmaan2532
    @habib-ur-rehmaan25322 жыл бұрын

    when you post new video , kindly must use fenics word with it

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    Hi, thanks for the comment. 😊 What do you mean by this? There is FEniCS in the title of the video? Or do you mean a post on social media

  • @habib-ur-rehmaan2532

    @habib-ur-rehmaan2532

    2 жыл бұрын

    @@MachineLearningSimulation start with fenics tutorial , just like this video

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    I think it should be since all videos are in one Playlist: kzread.info/head/PLISXH-iEM4Jl0-G1CpvG-mhrV0233tG_D But I will set a flag in the KZread settings such that those videos are best watched in order 😊

  • @habib-ur-rehmaan2532

    @habib-ur-rehmaan2532

    2 жыл бұрын

    @@MachineLearningSimulation Thank you

  • @MachineLearningSimulation

    @MachineLearningSimulation

    2 жыл бұрын

    You're welcome 😊