There seem to be many books and papers that explain various CFD methods in great detail, but unfortunately I have not been able to find many good resources of such methods implemented in codes such as MATLAB or Python (besides the most basic of problems such as the linear advection equation). As such, I was wondering if there are any books out there that I could purchase that come with many coded examples, or if there are any free online resources that show one how to solve various CFD problems. I realise that CFD can be a very difficult field, especially when dealing with complex geometries. However, if I could find a resource that, for example, gives step-by-step instructions on how to solve the 2D Euler equations (with very simple geometry), which seems to be the logical step up when moving from scalar to vector equations, this would be a great starting point on how to learn more advanced topics. Unfortunately, I learn by example, and can get bogged down by too much theory. As such, having code examples to work through and understand alongside the theory would be a big help. Thank you very much.

  • 4
    $\begingroup$ Have you studied the 12 Steps to Navier Stokes by Lorena Barba? $\endgroup$ – nicoguaro Mar 10 '17 at 19:39
  • $\begingroup$ I had a look at it a little while before I posted this and it seems like a very nice resource. I did notice though that it seems to jump from relatively simple PDEs to the Navier-Stokes equations, without giving any treatment to the Euler equations, which is a little unfortunate (although I could be wrong about this). $\endgroup$ – InquisitiveInquirer Mar 10 '17 at 19:52
  • 1
    $\begingroup$ I suggest that you first follow the "lectures", and if after that you think that the approach is not adequate keep your opinion. Right now, you are pressuming that will be the case. $\endgroup$ – nicoguaro Mar 10 '17 at 21:40
  • $\begingroup$ They seem to state that they do not cover the Euler equations on this page: lorenabarba.com/blog/cfd-python-12-steps-to-navier-stokes. Having not much CFD experience, I assumed it would be best to try the Euler equations before jumping into the complex Navier-Stokes equations, but you're right, I'll delve deeper into this course and it should make sense. $\endgroup$ – InquisitiveInquirer Mar 11 '17 at 2:56

Depends on what you mean by CFD. I would differentiate between academic and applied approaches.

For academic purposes -- say, for acquisition of skills in numerical analysis and scientific computing or a playground for your newly developed preconditioners -- I can recommend the book by Griebel, Dornseifer, and Neunhoeffer Numerical Simulations in Fluid Dynamics. It covers the whole range:

  1. Statement of the physics and the PDEs, boundary conditions, and the expected difficulties
  2. Discretization technique (here, finite differences)
  3. pseudocode
  4. ready to use C-code

If you want to become a CFD-engineer for a company, you should get yourself some theoretical background about modelling and approximation of flows and turbulence. (Maybe find a lecture note on turbulent flows) And then just go and do the tutorials with your favorite commercial CFD tool. (Ansys, Fluent, Star...)



I am assuming you are an undergrad, in engineering, because if you are a grad, you should have taken the CFD course in the respective department first. If you are in math, I don't know how to relate to your knowledge of things in classical fluid dynamics.Moving on...


I understand the position you are in quite well, I was myself stuck in the same bog for quite some time and things never really came to me theoretically, and as far as I have experienced, reading a book like J.D. Anderson or Versteeg doesn't really help much. And, I feel it is rather insensitive to ask someone to read J.D Anderson cover to cover, even the first few chapters, and only then allow him to start real CFD coding. During my time as an eager undergrad trying to learn CFD I spent several dorm nights scanning the internet to find decent tutorials on CFD, scouring CFD online and reddit. Some even wanted me to read the entire JDA and Versteeg before starting coding(which is ridiculous), and I couldn't make jack of it, and got really frustrated. I still couldn't easily make jack of half the things in those books, and I am in my 2nd advanced CFD course in grad school. I hope my answer here outlines a better way for the next generation to start coding in CFD.


First things first, if you are an undergrad student and not something of a genius, it will be very hard to battle CFD and the regular coursework together. I suggest you forget 2D and stick to 1D codes for now. CFD is pretty hard and you definitely need a grad-level course to start understanding the nuances of finite volume method and finite element method in 2D. I suggest firmly, firmly sticking to 1D, and learning the different numerical methods in Finite Differencing, like Lax schemes(normal, Friedrich, Wendroff, etc.), central, upwind differencing schemes and time discretizing schemes. If you need examples, just google something like "Lax Friedrich 1D Advection C++ code simple" and try and match the theory in those books with the code, understand how they work, and why they work the way they do. Do error analysis(Von Neumann, and multi-mode too). There is a world of things to be learnt in 1D, you will never run out of things. Most importantly, to an undergrad, they are easy, logical and indispensable while building concepts.

I suggest trying the inviscid, incompressible, linear transient advection equation, and then the transient Heat equation, playing around with different boundary conditions(dirichlet, neumann, periodic, Robin) and ghost cells. If that is done, you can try to move on to compressible 1D Euler, but the above two should be done perfectly and rigorously, including the theory. This will help you build up a base perfectly for a grad school course, where you can then relax and focus on getting your 2D concepts right.

If you are not sure about anything, just Google.


To give you an idea, I did two 2D Navier-Stokes projects which basically included like 8 codes last semester. I then thought I was sorted for CFD, and then half-way into the advanced CFD course this sem I am still doing 1D codes. This is how important and emphasized getting a firm hand on 1D is. Don't be disappointed by the lack of lovely colors and shapes, they will come. :D

SCREW 2D #2!!!!!!!

Assuming you did all of this to your satisfaction, you can try constructing the 2D Poisson solver. You can usually find sample codes and a simple sample grid on the internet. If not, you can always make your own square grid uniform and solve on it. It is THE starting point for coding any NS equations. You can learn the different iterative schemes like ILU, Point Jacobi and stuff. You can find easy samples of everything on the internet.

Forget about 2D Euler for now, as it's main flavor comes when you attempt compressible flows, which have some tricky physics in them. Learning numerical schemes now will make it much easier for you to understand 2D Euler in the future. You can do 2D with Finite differences, but that would be pretty simplistic, useless and cumbersome for the most part if you are not a master at 1D. Most modern 2D codes use Finite Volume or Discontinuous Galerkin methods today, which are very advanced in terms of formulation.


I would like to conclude by giving a few more pointers which might help you realistically start CFD

1.) Try learning commercial codes first and doing internships in places which use them. They will give you an idea of what to expect, and form an excellent educational tool for understanding the elements and workflow that go into a CFD problem.

2.) Switch to C++ or Fortran ASAP if you are even dreaming about 2D codes. My professor last sem told the class about a student senior to me who wrote his code in Python, and it took a week for him to converge the final project which took just a handful of minutes for us in C++ and Fortran. He couldn't turn his whole project in and got a bad grade. Matlab is equally bad at scicomp. Learn to output your data in a .dat file and use Tecplot or Origin to plot graphs and contours. Between C++ and Fortran, doesn't really matter much at your stage.

3.) Again, I cannot stress this enough, DO NOT GO FOR 2D. It is cumbersome and irrelevant to your growth in CFD at this stage.

4.) If you do not plan on doing grad studies, forget about CFD coding. It will take you years to master a CFD sub-area, and doing it on a commercial code will take you a day or two tops. The codes are designed to be idiot-proof, and the results are pretty good too. It will be much more useful in non-fundamental-scicomp-research engineering teams if you understand the basics of FM and HT properly.

5.) CFD is going to kick your ass, and you will love it. I haven't slept more than a total of 4 hours in 3 consecutive days, and this is in the middle of my spring break(no shit). Be prepared for it's learning curve, but it is guaranteed to be worth it when you generate your own colorful pile of garbage.


You can try doing the 12 steps thing as a hobby, but in hindsight it was a useless, self-congratulatory, overrated endeavor in terms of trying to gain insight into real CFD, since most of it is just too well-structured and simplistic. It's a great course, I admit, but it is almost too good to the point of being ultimately useless, if you know what I mean. The professor is very cogent and smart, but goes too easy on the topics. I know a lot of people here swear by her course and might get pretty offended with me, but I think quite a few who have taken a grad course in CFD might agree with me too.


An Ode to CFD

By Steve Bova and Alfred Lorber University of Texas CFD Laboratory

Old codes never die

They get handed down to you and I

If yours does not have much robosity

You need only add more viscosity

Many a knob and several a switch

Are required to run it without a hitch

If higher flop rates you must realize

Simply generate a larger grid size

If a trivial modification your manager seeks

My estimation is at least ten weeks.

  • $\begingroup$ +1 for this rant, as sometimes some personal opinions help a newcomer to understand what's going on. However, I totally disagree with your "screw 2D" arguments. There is no Navier-Stokes or Euler equation in 1D... $\endgroup$ – Jan Mar 13 '17 at 9:44
  • $\begingroup$ @Jan Well, I didn't mean anything very much resembling CFD but I know that there do exist 1D codes for NS and Euler for eg. in combustion modelling and shock tubes. You simplify NS and thread them with more complex physics in 1D. I simply wanted to emphasize that 1D is where someone starting cfd would gain more depth and insight. If he/she goes into 2D now, I fear the deeper concepts will be sidelined. Anyway, thanks for upvoting! Just discovered and getting started here at stackexchange(I love it!) and had started to think the rant had gotten too far. :D $\endgroup$ – Ayush Agrawal Mar 13 '17 at 11:14
  • $\begingroup$ I've already been through a few techniques in my course using 1D equations, and that's why I wanted to find more advanced 2D examples to attempt. $\endgroup$ – InquisitiveInquirer Mar 13 '17 at 14:56
  • 1
    $\begingroup$ I agree on your point to first fully understand 1D, since the higher-dimensional cases overwhelm students with technicalities which are irrelevant for learning about the very basics of CFD. But 2D/3D is where coding and the right choice of algorithms get interesting and where relevant physical problems can be tackled. I would not start here without a solid knowledge about the underlying physics and mathematics though. Many practitioners guides tend to teach sophisticated techniques which at first seem to appear out of nowhere, but many tricks are rather "obvious" from a mathematical viewpoint. $\endgroup$ – Christian Waluga Mar 13 '17 at 22:41
  • 1
    $\begingroup$ If you are interested in incompressible flows, there is simply no 1D, period. You have to do 2D or 3D. $\endgroup$ – Vladimir F Mar 15 '17 at 10:09

The CFD book by Blazek helped me more than any other. He explains finite volume methods very well. Using this book, I wrote a 2D Euler solver and a 2D compressible Navier--Stokes solver.

I would also suggest that you watch Qiqi Wang's lecture videos. Not the aerodynamics of viscous fluids course -- scroll further down and you should see videos with Lecture 20 ... Lecture 1. These videos are from a numerical methods course at MIT. This is where I really learned how to write finite volume codes. He explains the theory/how the methods work and then develops examples in MATLAB so you can follow along. He teaches very well and is easy to follow.


This question is extremely broad. As Jan stated above, CFD could be industry related or based on a research topic. Furthermore there are big difference between compressible and incompressible flow problems. If you are focusing on compressible flow, then familiarizing yourself with hyperbolic conservation laws is a good start. And as James above has said, implementing a finite volume solver in a simple 2D Cartesian grid is another good step.

I recommend books such as:

  • Finite Volume Methods for Hyperbolic Problems by Randall J. LeVeque
  • Nodal Discontinuous Galerkin Methods by Jan S. Hesthaven and Tim Warburton

Hesthaven and Warburton have both matlab and C++ codes for implementing DG schemes for Euler equations in 1D and 2D. Finite volume methods are DG with piecewise constant approximations.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.