MATLAB How to Write a Simple CFD Code in MATLAB: A Beginner's Guide

  • Thread starter Thread starter Saladsamurai
  • Start date Start date
Click For Summary
The discussion centers on writing a simple Computational Fluid Dynamics (CFD) code in MATLAB, focusing on a basic model with a single grid cell. Participants emphasize starting small, suggesting a quasi-2D solver that requires solving three equations and implementing boundary conditions, which are noted as particularly challenging. Recommendations for learning resources include "Computational Fluid Dynamics" by John D. Anderson, which is praised for its approachable mathematics and foundational concepts. Additionally, a paper by Thomas Pulliam is mentioned as a useful, quicker resource for beginners. Overall, the conversation encourages collaboration and emphasizes the learning potential in tackling CFD challenges.
Saladsamurai
Messages
3,009
Reaction score
7
Okay then :smile: Here is another one of my ridiculous posts. Yay!

Let's say I want to write my own CFD code in MATLAB. Is does not need to be robust. I want it to be as simple as possible.

It should be able to solve a model that consists of only one, single grid cell.

I know that I will be solving seven equations simultaneously.

I know I need to give boundary conditions. But how many do I need? I have a six-sided grid cell. I am fairly sure that I need more than 1 BC, but less than 6.

I know that I have left out a fair amount of necessary info. I also know that this might be a lot more difficult than I am making it out to be. But I think I could learn a lot even by failing at it.

So what else do I need here? What exactly are the equations?

I know we have x,y,x momentum, Navier-Stokes (I think), some form of turbulence equation (probably k-Epsilon), continuity and Energy. Correct?

What's next?

Anyone who might be interested in joining me in this project, feel free! no experience required--I don't have much!


Casey
 
Physics news on Phys.org
1 cell? You really can't have a single cell CFD program. You can start small though. Try writing a quasi-2D solver. Basically, you'll just have a "line" of grid points, each with an associated area. Since its 1D, you'll only need to solve 3 equations.

You'll need:
  • A differencing routine (one that can take derivatives both in the main domain, and near the boundaries). I would recommend a central-differencing routine
  • If you use a central-differencing routine, then you'll need a routine to add artificial dissipation. Again, both central domain, and near the boundaries
  • A time marching routine. I would recommend a Runge-Kutta-style routine for stability.
  • Boundary condition routines. These will be the most difficult. Boundary conditions are the biggest pain in the *** for CFD solvers. Start with Thompson-style boundary conditions and specify total pressure and temp at the inflow, and static pressure at the outflow
  • Since you're only 1D, you won't be calculating turbulence, so you won't need to worry about it.

Definately start small with a 1D solver. You'd be surprised how much complexity even going to 2D adds. 3D is a whole-nother animal.
 
I have written finite difference solutions for simple CFD problems before. I would like to help if the offer is still open.

But I think I could learn a lot even by failing at it.

With that attitude, you will go far.

Thanks
Matt
 
That would be awesome! I will post back tomorrow or later tonight with more details on what I actually know about Fluid mechanics and CFD. It is very little. But I am willing to do a lot of reading on the subject.

Thanks again,
Casey
 
Sounds great.

Thanks
Matt
 
CFDFEAGURU said:
..."Computational Fluid Dynamics" by John D. Anderson...

Would you say that this book would be good if I am interested in a 'crash course' in CFD?

I am currently trying to read a book my boss lent me "An Intro To CFD" by Versteeg and Malalasekera and I want to gorge my eyes out.

I realize that no CFD text will be 'easy,' but I believe there has got to be one out there that dives into the concepts a little better as opposed to just being a long list of equations.
 
I wouldn't say Andersons's book is a crash course. This book will provide a great understand of how and what CFD is. It also provides a down to Earth approach to the mathematics. If you really want to understand CFD start with the Anderson book.

Also, once you get through Anderson you can better understand some of the higher level CFD books.

Thanks
Matt
 
Last edited:
CFDFEAGURU said:
I wouldn't say Andersons's book is a crash course. This book will provide a great understand of how and what CFD is. It also provides a down to Earth approach to the mathematics. If you really want to understand CFD start with the Anderson book.

Also, once you get through Anderson you can better understand some of the higher level CFD books.

Thanks
Matt

OK great. So it would be a good '1st Book' in CFD for someone with my background?
 
Yes, it is the first book that I used.

Thanks
Matt
 
  • #10
For people just getting started, a slightly quicker (than textbook) is the ARC2D paper put out by Thomas Pulliam. He has the paper on his website (U of Miss. IIRC). Basically, it was one of the first full solvers created, so the paper covers many topics of interest in CFD, particularly useful in describing implicit solver using LDI approaches.
 
  • #11
Cool, never heard of that one. Is it a free publication?

Thanks
Matt
 
  • #12
CFDFEAGURU said:
Cool, never heard of that one. Is it a free publication?

Thanks
Matt

If either of you guys find it, could you link it here? I am having trouble locating it. If it is the same Thomas Pulliam that is at NASA, a lot of the links are dead.

Minger: Is that U of "Missouri" ? Or "Mississippi" ?
 
  • #13
Saladsamurai said:
If either of you guys find it, could you link it here? I am having trouble locating it. If it is the same Thomas Pulliam that is at NASA, a lot of the links are dead.

Minger: Is that U of "Missouri" ? Or "Mississippi" ?

Yeah. Every one of his links are dead. Maybe it's a coverup ?
 
  • #14
Yeah, I looked all over, and couldn't get anything other then dead links.

Maybe that's why I never heard of him or his paper. LOL

Thanks
Matt
 
  • #15
yea that's the guy...who is at Miss...

Sorry I was thinking of Thompson, who has a terrific book on grid generation located:
http://www.erc.msstate.edu/publications/gridbook/

but I digress. I think I have a copy of it though. Gimme a second. Linky
http://www.eng.utoledo.edu/~mheminge/ARC2D.pdf

Also some personal notes (some 100+ pages of nicely LaTeX'ed notes)
http://www.eng.utoledo.edu/~mheminge/CFD_Notes.pdf

Enjoy!

Maybe that's why I never heard of him or his paper. LOL
He's a real important person in the field. Him and Anthony Jameson (http://aero-comlab.stanford.edu/jameson/ look through his website and you'll see [he was solving the 3D Eulers in 1981, multiblock a couple years later!]) come to mind as some of the leading pioneers in CFD.
 
Last edited by a moderator:
  • #16
Minger, thanks. I have only written some very crude grid generators. Can't wait to get into the Thompson book.

Thanks
Matt
 
  • #17
minger said:
yea that's the guy...who is at Miss...

Sorry I was thinking of Thompson, who has a terrific book on grid generation located:
http://www.erc.msstate.edu/publications/gridbook/

but I digress. I think I have a copy of it though. Gimme a second. Linky
http://www.eng.utoledo.edu/~mheminge/ARC2D.pdf

Also some personal notes (some 100+ pages of nicely LaTeX'ed notes)
http://www.eng.utoledo.edu/~mheminge/CFD_Notes.pdf

Enjoy!


Minger! That's stupendous of you! When I was searching for Pulliam, Google returned an old PF thread you replied to in which you offered up these notes.

I was going to PM you to see if you still had them but now I don't have too!

Thanks! :smile:
 
Last edited by a moderator:
  • #18
Good luck; the first like 4 chapters just set up the mathematics behind it all. I read and took notes over a bit of it. How much I understood though...
 
  • #19
Update:


CFDFEAGURU said:
"Computational Fluid Dynamics" by John D. Anderson

Just ordered text. Got the "international Edition" 'cause I am cheap and fickle.
 
  • #20
Great,

You will enjoy the book.

Thanks
Matt
 

Similar threads

Replies
6
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
Replies
3
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K