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.
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:
- Statement of the physics and the PDEs, boundary conditions, and the expected difficulties
- Discretization technique (here, finite differences)
- 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...)
SUPER LONG POST HERE, I WISH I COULD TL;DR IT, BUT IT WOULD BE PRETTY USELESS
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...
BACKGROUND FOR ME
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.
BACKGROUND FOR ME #2
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.
POINTS TO CONSIDER
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.
ON THE 12 STEPS COURSE
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.
LEARN THIS BY HEART!
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.
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.