Lorena A. Barba group

CFD Python: 12 steps to Navier-Stokes

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

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

  • 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.

    • http://lorenabarba.com/ Lorena A. Barba

      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 !

  • Jungyeoul Brad Maeng

    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.

    • http://lorenabarba.com/ Lorena A. Barba

      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

    • http://lorenabarba.com/ Lorena A. Barba

      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

  • http://ondrejcertik.com/ Ondřej Čertík

    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.

    • http://lorenabarba.com/ Lorena A. Barba

      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

    • http://lorenabarba.com/ Lorena A. Barba

      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.

    I am looking for your help, please.

    Thank you so much

    • http://lorenabarba.com/ Lorena A. Barba

      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
      When I add a blog post about that, I'd be glad to get a comment about how (if) you used them.

  • 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

    • http://lorenabarba.com/ Lorena A. Barba

      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!

  • Miloud Hadj

    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

    • http://lorenabarba.com/ Lorena A. Barba

      Thank you so much for the excellent work!

      • cacheme

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

  • Pingback: SC13 Birds-of-a-Feather Session Python for High Performance Computing

  • 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)

    • http://lorenabarba.com/ Lorena A. Barba

      Thanks for your comment and I'm glad that the videos on iTunes U and YouTube have been helpful to you.

      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.

  • http://lorenabarba.com/ Lorena A. Barba

    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.

  • http://fr.linkedin.com/in/abdaddi/ Abdallah

    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!!

    • http://lorenabarba.com/ Lorena A. Barba

      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!

    • http://lorenabarba.com/ Lorena A. Barba

      Thanks for taking the time to leave a comment, Luke!
      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?

    • http://lorenabarba.com/ Lorena A. Barba

      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!

  • 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.