# CFD Python: 12 steps to Navier-Stokes

Cavity flow solution at Reynolds number of 200 with a 41x41 mesh.

We announce the public release of online educational materials for self-learners of CFD using IPython Notebooks: the CFD Python Class!

Update! (Jan.2014) CFD Python has a new home on GitHub

### Some background

This post describes the first practical module of Prof. Barba's Computational Fluid Dynamics class, as taught between 2010 and 2013 at Boston University. The module is called "12 steps to Navier-Stokes equations" (yes, it's a tongue-in-check allusion of the recovery programs for behavioral problems). It was inspired by the ideas of Dr. Rio Yokota, who was a post-doc in Barba's lab, and has been refined by Prof. Barba and her students over several semesters teaching the course.

The course is for beginners. It assumes only basic programming skills —the concepts of iterations, function calls and so on— and builds immediate hands-on experience via this module and several others that come after. In the future, we hope to publish materials for the other modules also (e.g., convection schemes with Burgers equation, Euler equations and shock-tube problem, and others).

We use Python for this class, and those engineering students that are dependent on Matlab just have to bite the bullet and learn Python. (The reasons for this are many and would be subject for another blog post!)

Prof. Barba has a long track record of sharing educational materials freely online. Recordings of her lectures for the CFD course were made available first on iTunesU in 2010. Then, in 2012, she decided to use the flipped classroom model and re-posted the videos on YouTube, after editing for length and with some additions.

The new CFD Python class notebooks are her latest free online materials!

### Instructions

The simplest way to enjoy these materials is to view each lesson online (follow the links below), as rendered by the IPython Notebook Viewer. In that case, you could follow along and write your own version of the programs to run with your local Python installation.

But you can also download the whole collection of Notebooks from the CFD Python GitHub repository. If you have a full distribution of the Python "ecosystem," then navigate to the directory where you've downloaded the collection, and launch the IPython Notebook with the following command on the terminal:
`ipython notebook`

### Description of the practical module

This module has been proved in the classroom for four consecutive years. It has brought several dozen students to develop their own 2D Navier-Stokes finite-difference solver from scratch in just over a month (with two class meetings per week). The module consists of the following steps (links are to the individual IPython Notebooks):

Steps 1–4 are in one dimension:

(i) linear convection with a step-function initial condition (IC) and appropriate boundary conditions (BC);

with the same IC/BCs:

(ii) nonlinear convection, and

(iii) diffusion only;

with a saw-tooth IC and periodic BCs

(iv) Burgers' equation.

Steps 5–10 are in two dimensions:

(v) linear convection with square function IC and appropriate BCs;

(vi)  nonlinear convection, with the same IC/BCs

(vii) diffusion only, with the same IC/BCs;

(viii) Burgers' equation;

(ix)  Laplace equation, with zero IC and both Neumann and Dirichlet BCs;

(x) Poisson equation in 2D.

Steps 11–12 solve the Navier-Stokes equation in 2D:

(xi) cavity flow;

(xii) channel flow.

Students are instructed to follow these steps one by one, without skipping any! The most important step is #1, in fact. Everything builds from there.

We know that self-learners around the world have already started following this "12-step program" using the videos on iTunesU and YouTube since 2010. In fact, at least two students have blogged about their experience: DaFeda in Norway (June 2011) and  Sidafa Conde at UMass-Dartmouth (January 2012).

And clearly the contributions of Suraj Shankar to the Matlab Central file exchange were also result of his following the class online.

Prof. Barba often receives emails of appreciation from students in far-away places who are learning with her free online materials. And in 2012, she opened her CFD Piazza class to off-campus students, resulting in about 180 students "auditing" and participating in the online class discussions —this effort resulted in Prof. Barba being featured in the Piazza Blog as "Innovator of the Week" in April 2012.

We hope that the CFD Python series will help a new cohort of students and self-learners gain basic CFD skills. Let us know what you think!

### Acknowledgements

• Prof. Lorena Barba's educational program is supported by NSF via CAREER award #1149784

• CFD Python has been translated to Spanish by F.J. Navarro-Brull for CAChemE.org // GitHub repo
• CFD Python is now published! Please cite as: Barba, Lorena A., and Forsyth, Gilbert F. (2018). CFD Python: the 12 steps to Navier-Stokes equations. Journal of Open Source Education, 1(9), 21, https://doi.org/10.21105/jose.00021

• William Lane

Looks great, Gil and Prof. Barba! I might have to give iPython notebooks a try. One thing I noticed, is that the animations didn't work for me. It could just be a browser/operating system bug (Chrome/Ubuntu)... Additionally, it might be helpful to people to point out the odd-even decoupling that occurs in Step 11 with the pressure field. I know that was a great learning point for me.

• Thanks for leaving a comment, Will. I was debating whether to include a discussion of the issue of collocated versus staggered grid. Maybe it could be subject of a separate notebook (rather than adding it to Step 11). We'll think about it !

Great effort. From a previous student who took this course, it is a great way to get introduced to the joy of CFD. I am now doing fundamental research in CFD due to this eye opening course.

• I'm so glad to hear from you, Brad. I knew you had gone to graduate school but I did not know you were working in CFD! This is of course gratifying to hear. Best of luck in your research and thanks for leaving a comment!

• Francisco Botero

Great material. I'd like to implement it in my class. However, I'd like to have a Spanish version. Are you interested? How can I contact you?

My best regards,

Francisco

• Hi Francisco -- you've just contacted me
If you want to translate these, go ahead! You can send me email if you want to discuss further. I'm glad you find this material useful.

• Kevin Kennedy

These are fantastic! I've been trying to learn python but it's tough to find interesting projects to learn it with. Have you given any thought to having a lesson or two on 3D CFD? Every class I've ever taken does one and two, but never three. I'd love some help making that jump.

• omkar raut

This is great....i am learning CFD....this material will really help me...thanx..and i want basics of CFD so how should i contact you??

• Pingback: This Week in CFD | Another Fine Mesh()

• Lorena, this is fantastic! Thanks a lot for sharing. If you have any problems with SymPy, please don't hesitate to ask us (for example on the sympy mailinglist). I'll be very happy to help make it do what you need.

• I'll keep that in mind, and thanks! We are developing more educational notebooks but haven't yet used more SymPy. I have a project in mind where SymPy will feature more prominently, though … I just need the time!

• Jonathan Nickerson

Professor Barba,

I am a graduate student currently trying to teach myself CFD. I have spent this week working through your CFD Python course. I must say, this course has been a blessing. It has made learning CFD fun and straightforward. Thank you very much for being awesome!

Are you interested in active feedback regarding the course? I ran into a few snags and, provided you are interested, I would like to bring them to your attention. If this is the case, then can I perhaps contact you via email?

Thanks again

• Hi Jonathan,
Thanks for leaving a comment and I'm glad this has been helpful to you! Please do send any feedback you have, and I'll be happy to introduce modifications to the lessons to improve them with your feedback.

• Binhjamin

professor Baraba!

This is terrific! thank you for making learning fun!

• Hassan Imani

These are very good for me and I think for every body. I had many book and pdf lecture about CFD, but i couldn't understand them very well. At the moment, i have CFD course in my university and i am very good in that because I saw your course.
At the end i have a question, could you please help me about Boundary Element Method, because I want to use to this method in my thesis.

Thank you so much

• Hello Hassani — Thanks for your comment!

I don't have materials on BEM, even though we actually use BEM in our research activities. However, as a basic foundation, you might find value in the AeroPython series, which builds up the skills to write a panel method:
https://github.com/barbagroup/AeroPython

• Abhay

Dear prof, can you please separate course on finite volume method only. That would help us lot.

thank you,
Abhay

• Abhay

Dear Prof, Can you please take a course on CFD finite volume method separately. This will help us a lot.
thank you,
Abhay

• It's certainly among my aspirations to provide more CFD materials online, and FVM is one of the important topics. But given my many teaching and research obligations, it will have to wait until I teach another on-campus CFD course.

But there are some new materials coming soon in the form of IPython Notebooks, so keep checking back!

• Guest

These are fantastic!

Thank you so much

These are fantastic!

• cacheme

Hi Francisco, in case you are still interested we have already translated the module. Of course, you can use it in your class and let us know how was it!

https://bitbucket.org/franktoffel/cfd-python-class-es

• Thank you so much for the excellent work!

• cacheme

It was a pleasure! We would like to speak more languages 😉

• Eshan

Thank you prof Barba for this wonderful work... much much helpful it has been. I have been following all the videos uploaded on youtube: starting from Lecture Zero to Lecture 28, which stups abruptly and I can not find any further lectures, which i guess would be on FEM and FVM. I tried mailing you about the same but couldnt get u. Please help me on how to find furtherlectures after Lecture No.28(CFD ME702)

Although I did cover some basics of FVM in that course, I never got to making the videos for that topic. Until I teach CFD again (on campus), I might not find a reason to develop more videos. But when I do, I'll remember to include FVM, for sure.

• I hope you are making progress with learning Python and CFD. And thanks for leaving a comment!

CFD in 3D gets very computationally intensive and almost inevitably requires parallel computing. By the time you are ready to work in 3D, you are an expert. There are many steps to get there, and I have a long list of IPython-Notebook-powered lessons planned to help in that growth!

• Arid Piloti

Thanks for this learning material.

• Thank you so much Prof. Barba for these powerful lessons. We gradually learn how to code and solve numerically some of the classical equations in physics. It was a good initiation for us in CFD using the programming language Python. Formerly I find it too scary to write programs in computers but now I feel more confident to go ahead and discover the beauty of the computational world. I would like to ask you if you have other lessons using different schemes such as the spectral method. Thank you again for making these lessons for us!!

• Thanks, Abdallah.

There will be more lessons using convection schemes for Burgers and Euler equations, but I've no plans to write some on spectral methods. Perhaps when I teach a numerical methods class (if I do!) … in the meantime, you might enjoy AeroPython:
https://github.com/barbagroup/AeroPython

I'll write a blog post soon about how I am using the AeroPython notebooks in an Aerodynamics class at GW.

• Luke Mondy

Hi Lorena, I'm a PhD student in Australia, doing long-term geodynamic modelling, and these tutorials are fantastic. Very clear and enjoyable.
Thanks very much!

I'm very glad the materials are helpful to you. There are more notebooks coming, but it's been hard to find the time to finally finish and release them. I'll announce on Twitter when I do.

• Rajib Anwar

Great tutorials.. It was very helpful. I was wondering if it is possible to provide some tutorials on immersed boundary method?

• Hi Rajib,
Thanks for your comment. I'm glad you find these helpful. Next time I teach this class, I will add new materials. For the time being, you might be interested to look at our research code called "cuIBM" and the technical report on figshare documenting its verification & validation. Search our Publications.

• Oscar Aguilar Gutiérrez

Hello Prof. Barba! I find your website really fascinating and helpful especially for following the iTunes U course. I am just starting too learn CFD and I have a question about the codes of the early steps (1 - 3) I can't find where are the boundary conditions that according to the videos should be u(0,t) = 0 and u(2,t) = 0 in the code, so I would like to know in which part of the code are the BCs? Thanks in advance!

• Ah, to be honest, we are just ignoring the BCs in the code for steps 1 to 3. This means that the code is only valid while the wave does not hit the right boundary, but we just went for a simple code here. It would probably be a good idea to add at least an explanation about this.
Thanks for the comment!

• Luis Felipe Gutierrez M

Congratulations, it's a very good material for learning and teaching cfd, and python is a wonderful selection to introduce concepts without getting lost in details related to programming.

• Bran Liang

This is one of the most awesome lessons in the world!!Exactly what i want!!!And you published it online for free!!!Really appreciate... And i will try to let more people around me to know your work^_^

• Well, you really sound happy to find *study materials* online

• Dan Sandiford

Hi Lorena,

In Step 6 the 2D non-linear convection equation becomes a pair of coupled equations. The linear version, on the other hand, is written with only one independent variable. I don't quite follow the maths here, could you explain how you get there, is there a derivation somewhere I could look at?

Wonderful tutorial, thanks very much.

• Hello, Dan.

I'm glad you find these useful.

Did you see the YouTube lesson that goes over the derivation? This might help ...

http://youtu.be/tUg_dE3NXoY

• Robson Nazareth

Hi Prof. Lorena, I am really enjoying your lessons and this is being very helpful to me. I have a question about the discretized pressure-Poisson eqn: Why the discretized pressure-Poisson eqn in the step 11 is differente than that found at the end of the youtube video lesson 11? In the step 11 it looks like a descretized version of the the continuous pressure-Poisson eqn plus the term rho*d/dt(du/dx + dv/dy), which should be equal to zero to satisfy continuity in the continuous case.

• Hi Robson,

Ah, you touch on a subtle issue that—among others—makes the Poisson equation the source of lots of arguments.

First, we have to be careful when we are dealing with the *continuum* and *discretized* equations.

In the video lesson 11, we write out the 2D momentum equation component-wise, apply the divergence operator, write out all the terms, and cancel out the terms with Del(u) because they are zero by continuity. For the *continuum equations*, the momentum and continuity equations imply the following pressure-Poisson equation (see screenshot attached)…

This derivation is the easiest to understand and follow, and that's why we do it in the lesson. But we have to realize that in the *discrete equations* we cannot be sure that the divergence of the velocity is zero, because of possible numerical errors. So we keep the divergence terms —at least some of them— and we don't' eliminate the time derivative term.

We work with a semi-discretized form of the momentum equation (in vector form) towards the end of video lesson 11, and we kept all the terms with divergence, viewing the pressure-Poisson equation as a correction. But there are many versions of this!

• Hi Robson,

Ah, you touch on a subtle issue that—among others—makes the Poisson equation the source of lots of arguments.

First, we have to be careful when we are dealing with the *continuum* and *discretized* equations.

In the video lesson 11, we write out the 2D momentum equation component-wise, apply the divergence operator, write out all the terms, and cancel out the terms with Del(u) because they are zero by continuity. For the *continuum equations*, the momentum and continuity equations imply the following pressure-Poisson equation (see screenshot attached)…

This derivation is the easiest to understand and follow, and that's why we do it in the lesson. But we have to realize that in the *discrete equations* we cannot be sure that the divergence of the velocity is zero, because of possible numerical errors. So we keep the divergence terms —at least some of them— and we don't' eliminate the time derivative term.

We work with a semi-discretized form of the momentum equation (in vector form) towards the end of video lesson 11, and we kept all the terms with divergence, viewing the pressure-Poisson equation as a correction. But there are many versions of this!

(trying the comment again, to attach the image)

• The image now, second try ...

• Robson Nazareth

Hi Prof. Lorena,

I saw that from the semi-discretized form of the momentum equation (1) to the semi-discretized form of the pressure-Poisson equation (2), it is disconsidered the high order derivatives terms (3) (attached). If this is correct, which is the assumption to disconsider this terms?

• Guest user

I'm also curious why the terms mentioned by the guest author are dropped. I understand how I could rearrange the equation to get all of the dropped terms as products of divergence, but since we're attempting to ensure that divergence is zero, this elimination does not make sense to me.

You mention in your videos that the viscosity term is small, and can often be ignored, which eliminates some of the terms, but not all of them. Even with the elimination of the viscosity terms, I still see the terms in the attached image.

Thanks for taking the time to post these lessons, I've found them very helpful.

Edit: Apparently, no image. Here's a link: http://i.imgur.com/bCkTPgZ.png

Here is my take on it ...

You have the continuous Poisson eq for pressure, and the plan is to use it for two purposes, 1 - to compute p, and 2 - to enforce the continuity eq. So, by writing the update eqs for un+1 and vn+1 and then deriving the Poisson eq from them you get the additional term, the divergence of un and vn, and by setting the divergence of un+1 and vn+1 to 0, that gives a variation of the Poisson eq which forces the divergence of the calculated values un+1,vn+1 to be 0. So, it's an ad hoc approach to enforcing the continuity equation with p. Thus the continuity eq is driving the calculation of p.

• Jared

Hi prof. Lorena,
thank you so much for your work. I really enjoyed myself studying this application of numerical analysis, and I had the occasion to brush up long forgotten skills.
Could I ask you which are the implications behind using an implicit scheme for the time derivation? I'd really like to implement a backward Euler, a Crank-Nicolson, or even a Runge-Kutta! Could you recommend me some articles that deals with this problem, any book or online resource?

Thank you.

• Hi Jared,
Coming soon, we'll have several other lessons on numerical methods, as I'll be teaching that class in the Fall'14 semester. Everything will be open on the web, and you'll be able to follow our course. Keep an eye out for announcements!

• Jared

Thank you! I can't wait!

• You can make comments on our new home on Github, using either an Issue or a pull request. Enjoy!

• Rocko Brown

I am having trouble getting plots to show inline. Could someone tell me where I could find help with this?

• Rocko Brown

Got it - love these lessons! Thank you!

• Glad you solved it, and glad you're liking the lessons. There'll be more coming this Fall semester, when I teach an numerical methods course, so stay tuned!

• Alberto Lozoya Rodríguez

Your course is amazing and I'm learning a lot. But I have some doubts.
In the lesson 11, when you obtain the graphic, I have noticed that you delete
even rows. Could you explain why? I think it must be the decoupling between
velocity and pressure. Is really like this?These rows are deleted later, but
what is the implication of keeping on the integration domain?

• Gil Forsyth

Hi Alberto,

Are you referring to this line?

plt.quiver(X[::2,::2],Y[::2,::2],u[::2,::2],v[::2,::2])

The quiver function is drawing the arrows that show the velocity throughout the cavity. Every other arrow is skipped because otherwise there are so many arrows on the plot that it's hard to see what's happening with the pressure contours below.

Hi Prof. Barba,

I made it to the 12th step, i.e. completed step 11 in MATLAB, and am reporting in as directed. Truly a wonderul series of lessons. Innovative in important ways - a course in CFD with actual computations ! Making MATLAB/Python integral to the course is the only way to go IMO. The 'flipped classroom' has got to be a huge improvement over past practices.

A comment: I was quite sure this thing was not going to work as I when I modified some of the early projects, like setting c=-1 in step 1, the thing blew up, so since the fluid goes every which I way in step 11 I figured something would blow up. But, it worked like a charm. What happened?

Also, my goal is step 13, the backward facing step. That was my CFD goal from the start, and I'm feeling pretty close. The sim for step 11 seems very robust. I'm thinking I can modify the geometry on step 11, give it a dp/dx = 0 and u some appropriate profile at the inlet (do I have to specify dp/dy?), and dp/dx = du/dx = 0 (again I'd like to let dp/dy float) at outlet, and it should work. Suggestions? The backward facing step would be a very impressive demonstration. I don't see step 12 as contributing so I'm thinking I'll skip that step.

Thanks for your great and innovative course.

• Anush Krishnan

Hi Joe,

You're right that in Step 11, the flow
moves in all directions. The backward-difference scheme is used
throughout the domain, and one would expect it to be unstable in regions
where the flow velocity is negative. But in the full Navier-Stokes
equations, we not only have the convection terms, but also the diffusion
terms due to the viscosity. The dissipation caused by the viscous terms
can ameliorate the instabilities due to a forward-difference stencil
for the convection term, and overall the numerical scheme is stable.

You can try this out yourself by performing a stability
analysis of the 1-D linear convection-diffusion equation: du/dt +
c(du/dx) = nu(d^2u/dx^2). Discretize the convection term using a
forward-difference stencil, and the diffusion term using a central
difference stencil, and use an explicit time-stepping scheme. You will
find that this scheme is conditionally stable. [An interesting special
case is when you perform this discretization on a uniform grid and choose
nu = c*dx. Compare this expression for u_i^{n+1} with the expression
obtained when a backward-difference stencil is used]

However, it is possible that the numerical scheme can end
up unstable in certain parts of the domain. One common way to ensure
that it is conditionally stable everywhere in the domain is using a
technique called "upwinding". The discretization scheme used at each
grid point is dynamically chosen depending on the sign of the velocity
at that point. If c>0, a backward-difference scheme is used, and if
c<0, a forward difference scheme is used. This can change for each
grid point and at each time step. The time step size dt will still need to
satisfy the CFL condition and other stability criteria, but upwinding
will ensure that the scheme is never unconditionally unstable at any
point.

Thanks

• Pingback: Résolution Python | Pearltrees()

Dr Barba,

Good Afternoon. I appreciate your philanthropic idea. I was curious to run one of your code (linear convection) in the compiler prescribed by this website, but the it doesn't display the graph you made.
Thanks a lot.

Sandip

• Jai Prakash Gautam

Either select the part of the code and run the lines selectively

OR add plt.show() at the end... Probably you will get it...

• Deewakar Sharma

Hello all,

I just came across this course and have just begun the same. I have completed step 1 and 2 . I have certain concern before I proceed further.
In step 1 when I created no, of grids points to be large, I got some weird curve. My question is how do I know whether the solution is correct or not??

• sandy

hi professor Lorena
here is the problem on lid driven cavity
unit square with u = 0 and v = 0 on all sides but the top side where u =1 and v = 0
and kinematic viscosity as 0.01
using CDS2 for convection term and explicit euler scheme for time

i have seen your lessons but im not good at python would you help me with matlab

• Arta Lotfi

Hi, I need analytical solving of fluid flow in a cylindrical channel, it must be simplest model of flow, and it isn't important to choose what BC or other quantities. I just want to know the solving process of flow in a channel. Can you help me?

• Ryan Farber

I really appreciate that you posted these; however, I was going back through step 4 and did the derivative by hand (double-checked with wolfram alpha) and I found that u(0) = -u(2*pi) [including after double checking with wolfram alpha] whereas it is posted in step 4 that u(0) = u(2*pi) for the given expression of phi. Can anyone explain i) how u(0) does equal u(2*pi) for the expression of u and phi [given in step 4], ii) they are off by a sign but it is somehow okay, or iii) what typo may exist in the expressions of u and phi given in step 4?

• Ryan Farber

Also, I'm fairly certain that the later plot of step 8 displays the state somewhere around cycle 480 whereas nt=120; it's hard to say for certain my code is equivalent since the time-stepping piece is rather involved but this is what I had found when I was copy pasting the notebook commands and cleaning them up as well.

• Cayetano Martínez

First of all, thank you for all these posts. But there is a problem with the link of the Burgers' equation (step 4) as it does not work. It would be great if you upload it again.

Thank you.

• Haider

Hello Professor, I just joined this group, fortunately found on "Google Search". Can you please explain Lattice Boltzmann Method just like that " 12 steps to Navier-Stokes"?
However, this will be very useful to learn CFD specially using Python as a programming language.

• Haider

Will you please guide me how to compute Aerodynamic forces of an obstacle (square or circular cylinder) in a fluid through a self generated code?

• mehrez agnaou

Hi dear Barba,

Thank you for this work.

I have a small remark. Please correct me if I'm wrong.
In your scripts, when you comment presPoissPeriodic an presPeriodic functions, I think you inverted variable x and y.
This doesn't affect the code.

Best regards,

Mehrez

• Gonzalo Sáez

Dear Lorena,

Thank you for sharing your work, it's awesome. But I'm having a hard time understanding your 2D implementation. In every of the notebooks I can see that the u is initialised as:

u = np.ones((ny,nx))

This means that the rows of the u array are related to the y direction and the columns are related to the x direction.

Furthermore when (for example) the 2D linear burger equation is solved you are using the following expression:

c*dt/dx*(un[i,j] - un[i-1,j])

To evaluate the derivative in the x-direction. As far as I'm concerned the rows of un, do have the information of the y axis,
and thus you should be using dy instead of dx. This problem is not raised up because you are using the same dimensions and subdivisions for
the x and y axis, but whenever this is changed there will be some errors.

Problem could be solved changing the u initialisation to:

u = np.ones((nx,ny))

Although the plots should be using the transposed of u in order to get the right axis.

Hope I'm wrong with my comments, but I've been thinking about this for a long time and I just cannot see if I'm making a mistake.

Thank you very much

• Scott Morken

i was just wondering how you can attach units to this... the pressure graph in the final step seems to be centered around 0... So really is what you are representing here the deviation from the ambient pressure?

Hi again, I just belatedly did step12 the channel flow, and it seems a little cooler if instead of imposing that constant F forcing function and going through all the trouble of the periodic boundary conditions, instead specify a Neumann bc for pressure at the left and right boudaries, say dp/dx = -F, and also Neumann bcs for u at the left and right boundaries, du/dx = 0, and you're good to go, plus you get the pressure levels appearing if you do a contour plot.

• Sahar Nasrallah

Thank you very much for your great idea, you help me so much, could you please send me your modified code ? I appreciate that very much
sahar_nasrallah@yahoo.com

• Sahar Nasrallah

did you get a fully develped flow rate ?

• kamal2

I get a lot of great information from this blog. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
Python Training Institutes in Chennai

• Thiago

I've lost count on how many times I've visited this module. And everytime it's like the first time
Thank you not just for making my academic life richer, but also for contributing to the good of knowledge. That's the true purpose of a real teacher.

• Ritesh Sojitra

Thanks for sharing. It is a great initiative. God bless you.

• Jinge Chen

Many thanks for your lessons, Prof.
I notice that the 2D geometry boundary here is rectangular. And I am wondering whether it is difficult to deal with the complicated boundary such as a laval nozzle? Is there much difference between FDM and FVM discretization?

I have same doubt. As you posted 4 years back. I would like to know if you have found out how solve / code same type of problem with complex boundary condition using FVM method.
Note: What i know is for structured grid / discretisation , FDM is used. Is my concept correct ?

• Jorge Andrés Solar

Thank you Prof. Lorena for this information by the way I was listening to you talking about flight snakes at Universidad Técnica Federico Santa María last Monday.

Jorge Solar Olivares.
Master Sc degree Candidate. UTFSM.

• Thanks for your lessons, mam. It had been a gateway for my coding in cfd. It provides me missing link between the my subject knowledge and programming skill.

Mam, In the 11th step of cfd-python "Cavity flow, with Navier Stokes", the pressure equation (3rd equation) is missing a term,
- delta t term (the time difference of velocities)

(I'm noting it because, your material is awesome and I feel, it shouldn't have any flaws.

secondly, in your lecture video: you mentioned that term as d/dt(du/dx+dv/dy), but in executing we take it as 1/dt(du/dx+dv/dy).

• Ganesh Visavale

Dear Professor Lorena Barba, this is amazing lecture series to learn CFD from the very basics all for free !. I have been going through lectures and seem to be adding new things to my learning. Thanks for this !. I wish I could have also understood Python coding with the pseudocodes you discuss in lectures. I could not install it on my windows system and need help manual if there is any.

Hola Lore! Infinitas gracias por compartir todo este conocimiento! Para los que estamos empezando es super útil y estimulante (y hay poca gente en la web que comparta código, y menos con explicación) Un beso grande desde Argentina. Ramiro

Great utility! thanks for sharing! in step 1 ln3, with the code as it is in the notebook dx is being defined as an integer where it should be a float right? (1.0 instead of 1)

• Eloy Marquez

I get the same error when trying to run it using Anaconda and Jupyter. I used float and I get the following warning:
/step1.py:17: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
u[.5/dx: 1/dx+1]=2 #setting u = 2 between 0.5 and 1 as per our I.C.s

Also, to be able to show the graphs I added the following code after pyplot.plot: pyplot.show(block=True)

Everything else works fine so far!

I will be using this blog to teach my students some CFD and Python. Great tool!

I just realised that this is probably a version thing. I haven't tried it because I don't currently have python 3 kernel set up to run with jupyter on my laptop but I'm fairly certain that in python 3 (Which I believe they are using here) that the code should work fine as is

• We have an update coming to fix this.

• Mohamed Oumza

Please can some one help me to implement the R13 moments equations in matlab. Thank you so much in advance.

• Vinay kumar Minajagi

For burger equation, I am getting results as follows. Orange is computational one after 20 time steps and blue is our saw tooth profile. That is how our burger equation has to represent the saw tooth profile but in the website, your scales are different. it starts with something like 2.8 or 2.9 insted of 4. Correct me please.I have coded in C.

• Earl Wallace

Thank you Prof. Barba.
Your videos allow me to pursue my passion, while I toil to pay bills.

I'm not sure if this will get a reply ... BUT, the pressure poisson equation in Step 11 has a few terms which seem to magically appear in the discretized form ... can someone explain to me where the "... 1/dt*[(u_i+1,j - u_i-1,j)/2/dx + (v_i,j+1 - v_i,j-1)/2/dy ..." comes from? I do not see analogous terms in the PDE.

• Mohammed A. Boraey

I think the description of the initial conditions for step (5) needs to be corrected. It's given in the x-direction only while the plot shows a square bound between x=0.5:1.0 and y=0.6:1.0.

• qomar bulan

hi prof. LOrena, i have a question for you. i've trying to learn the stress analysis problem in plane stress. but i have many problems to solve it. the basic problem is to find the displacement boundary condition of this problem. i want you to give me your opinion about it prof. lorena. thanks alot

• Chris Baylis

I love this course, it has taught me so much about Python and CFD, do you have any textbook recommendations for the overall science behind this particular course? I already have a degree in Physics, FYI. Thanks!

• Mike

Hello, fantastic tutorials! I have one question: You choose nu=0.1 for the kinematic vicosity. Which unit does this value have ? In real there are gases with viscosity about 1.5e-5 m²/s and if I set this parameter to like this the whole velocity field is about Zero everywhere (u=0 and v=0, instead of u[-1:0]). Actually with lower viscosity the velocity feild must be with more vortices, isn't it ?

• Dipanjan Barman

Dear Lorena,
I want to thank you for such great help. I was trying to find streamlines and vorticity in the cavity problem (step 11). There is 'streamplot' function in pyplot but I don't want to use it. I couldn't find out how to integrate discrete 2D values of u and v. I will be glad if you please guide me.
While trying to find vorticity, I didn't know which discretization will be proper choice and how to find vorticity on the boundaries.
Thanking you.
Dipanjan

• Manas Shukla

Hi Professor:
First of all, thank you so much. I really wanted to improve my Python skills and your lectures and codes have been very very helpful. I just wanted to point out that the way 'dy' is defined in [4] of step 9 doesn't seem correct. Shouldn't it be: 1/(ny-1) instead of 2 (as y varies from 0 to 1?)

• Domagoj Vulin

Hi, I tried the code of the first example (1D Heat Diffusion in ideal rod) and by changing the array of "u" values I've got strange results.
For example, if I define u[0]=1 and all other values u=10, the result (at least visually on graph) has some sense. But if I define u[39]=1 and all other values u = 10, nothing changes in the system!
The results seem reasonable while such "disturbance" of initial values inside the mesh is not on the right side of the model. For ex., when u[33] is set to 1., (or some cell right to the u[33]), result doesn't have physical explanation. In real world, we could say that if we cool some cell all the time, temperature distribution near the cell should be in some way symetrical. However, I put one new line after:
for n in range(nt):
u[20]=1.

... and the result made sense only for cells where x>20...

• Chanchi Pollo

these script don't work in python3.6

• Salvatore Rappoccio

This is really cool! I love these modules! I am planning to use one of these notebooks as a stellar example of notebooks in my computational physics class, I hope you don't mind (of course, it comes with the proper reference to you).

One trivial bug I found (at least in python 2) is that it will interpret this badly:

dx = 2 / (nx - 1)
dy = 2 / (ny - 1)

Since "2" is interpreted as an integer, nx and ny are integers, this evaluates to (int) 2 / (int) 40, which is zero as an integer. Adding a decimal after the 2 is better:

dx = 2. / (nx - 1)
dy = 2. / (ny - 1)

fantastically organized and awsomely moduled lectures......thank you professor for your efforts..

• Paulo Roberto Vieira de Castro

I thank you for these marvelous classes. I can now go deep in others methods like Second order upwind and high order schemes to advection. Do you have plans to teach FVM in Python or C++ and Euler implicit method?
Regards from Brazil

• Lucas Cavalcante

Awesome!

• Cole Shepherd

Dr. Barba,

Thank you so much for creating and publishing this module! By following along I was able to build my first fluid simulation, and finally get a grasp on the Navier-Stokes equations.

I have published my C++ source code to the 12 steps of the module on GitHub at https://github.com/ColeDeanShepherd/12-Steps-To-Navier-Stokes if it is helpful to anyone.

Thanks again!

Cole

• Anton Wahl
• Judas503

Prof. Barba,

• Rafael Cruz Alvarez

Hi professor Lorena Barba. Thank you for your open course, 12 steps to Navier Stokes, it helped me a lot in my first steps to CFD. Most online courses asume previous knowledge and for novice self learners can be really hard to find a way through. Your work is great, clear, complete and accessible.

By the way, I am specifically interested in putting an obstacle in a flow, like a circle, but I am not sure how to declare the boundary conditions of it, mainly because the ones of the course deal only with straight walls. Is there an easy way to implement this or should I use an square instead?

• ker2x

• TY for reporting—I've now updated the nbviewer links to point to jupyter.org rather than the deprecated ipython.org.

• choi

Dr Barba,
In 12 steps to Navier–Stokes -Step 11: Cavity Flow with Navier–Stokes,
The solution can be obtained without the variable c. Why do we know where the variable c is set to 1?

• Harsha Sathi

I know it is late, it is 2019. I am willing to to learn the course, however, step 11 and step 12 are not available anymore. Kindly re-post the links. Thanks in advance.

• Harsha Sathi

Got the mentioned steps from github repository. Thank you.

• Pranav Bapat

Hello Prof. Barba,
Thank you very much for the helpful tutorials. If possible can you please update the link to step 11 and 12 tutorials, apparently it seems they have been removed and now after we click on the link it gives a '404' page not found error.