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

  • MATLAB
  • Thread starter Saladsamurai
  • Start date
In summary, the conversation discusses the topic of creating a simple CFD code in MATLAB and the necessary components for it. The participants mention the difficulties of boundary conditions and recommend starting with a 1D solver before moving on to more complex 2D and 3D solvers. They also discuss recommended books and publications for learning CFD.
  • #1
Saladsamurai
3,020
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
  • #2
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.
 
  • #3
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
 
  • #4
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
 
  • #5
Sounds great.

Thanks
Matt
 
  • #6
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.
 
  • #7
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:
  • #8
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?
 
  • #9
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
 

1. What is CFD/MATLAB WizardsHelp Wanted?

CFD/MATLAB WizardsHelp Wanted is a software tool that combines the capabilities of computational fluid dynamics (CFD) and MATLAB to help users solve complex fluid flow problems.

2. How does CFD/MATLAB WizardsHelp Wanted work?

CFD/MATLAB WizardsHelp Wanted uses a combination of numerical methods, algorithms, and user-defined inputs to simulate fluid flow and provide visualizations of the results.

3. What are the benefits of using CFD/MATLAB WizardsHelp Wanted?

Some benefits of using CFD/MATLAB WizardsHelp Wanted include faster and more accurate simulations, the ability to handle complex geometries and boundary conditions, and the convenience of having all tools in one software package.

4. Is CFD/MATLAB WizardsHelp Wanted suitable for beginners?

While some knowledge of CFD and MATLAB is helpful, CFD/MATLAB WizardsHelp Wanted offers a user-friendly interface and tutorials to help beginners get started with the software.

5. Can CFD/MATLAB WizardsHelp Wanted be used for any type of fluid flow problem?

CFD/MATLAB WizardsHelp Wanted is designed to handle a wide range of fluid flow problems, including laminar and turbulent flows, compressible and incompressible flows, and single and multi-phase flows.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
745
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • Mechanical Engineering
Replies
8
Views
3K
Back
Top