Let's implement a fluid simulation that shows the transient development of the parabolic pipe flow profile when a fluid enters through an inlet and exits through an outlet. The problem has to be discretized on a staggered grid to avoid checkerboard oscillations. Here is the code: https://github.com/Ceyron/machine-learning-and-simulation/blob/main/english/simulation_scripts/pipe_flow_with_inlet_and_outlet_python.py The pipe flow (sometimes also called channel flow) is one of the simplest scenarios for interior flows. Due to the viscous effects of the Navier-Stokes equations, boundary layers create in the proximity to the walls at the top and bottom edge. The strength of these layers increases over the longitudinal axis of the pipe as well as over time until we reach a steady state. Everything that enters the pipe section on the left also has to leave on the right. This is the hard constraint of incompressibility, a special case of mass conservation. In this video, we will use a P2 pressure correction scheme, which is due to the taxonomy of Gresho (https://ui.adsabs.harvard.edu/abs/1990IJNMF..11..587G/abstract ). It differs from the P1 operator splitting (also known as Chorin's projection) in that it does not neglect the pressure gradient while solving the momentum equations. In our scenario here, that is crucial since the pipe flow is strongly pressure driven. ------- 📝 : Check out the GitHub Repository of the channel, where I upload all the handwritten notes and source-code files (contributions are very welcome): https://github.com/Ceyron/machine-learning-and-simulation 📢 : Follow me on LinkedIn or Twitter for updates on the channel and other cool Machine Learning & Simulation stuff: https://www.linkedin.com/in/felix-koehler and https://twitter.com/felix_m_koehler 💸 : If you want to support my work on the channel, you can become a Patreon here: https://www.patreon.com/MLsim ------- Timestamps: 00:00 Introduction 01:27 Scenario, Geometry & Boundary 00:03:13 Expected Outcome 00:04:18 Co-Located Grid and its problems 00:06:58 Staggered Grid 00:10:35 Ghost Cells Layer in the Staggered Grid 00:13:28 Solution Algorithm (P2 pressure correction scheme) 00:17:20 Imports 00:17:58 Defining Simulation Constants 00:19:37 Main Function Boilerplate 00:19:56 Creating the mesh 00:21:54 Initial Condition 00:27:03 Preallocate Arrays 00:27:52 Time Loop Setup 00:28:08 Momentum Update Overview 00:28:22 Diffusion on u grid 00:30:41 Convection on u grid 00:35:15 Pressure Gradient on u grid 00:36:49 Solve u momentum equation 00:37:53 Boundary Conditions on u grid 00:40:50 Diffusion on v grid 00:42:11 Convection on v grid 00:46:19 Pressure Gradient on v grid 00:47:17 Solve v momentum equation 00:47:50 Boundary Conditions on v grid 00:51:27 Compute divergence of tentative velocity 00:53:55 Compute Pressure Poisson right-hand side 00:54:24 Solve Pressure Poisson Correction Problem 00:58:07 Pressure Boundary Conditions 01:00:59 Update the pressure 01:01:36 Correct Velocities for Incompressibility 01:04:24 Boundary Conditions for Velocity again 01:05:29 Advance in time 01:06:07 Visualization setup 01:09:02 First Run 01:09:29 Tweak Simulation 01:10:03 Dark Mode 01:10:48 Colorbar and Vector Plot 01:12:43 More Tweaks 01:13:04 Highlighting the cross-sectional velocity profile 01:15:53 Discussion 01:16:20 Ensure Global Mass Conservation 01:20:56 Stability Considerations 01:22:30 Outro