Beginners guide to own CFD code? 2D Euler Equation

5.8k Views Asked by At

Do you know a good and especially easy guide to code one's own Computational Fluid Dynamics solver, for the 2D Euler equations? I just would like to understand what commercial software like Fluent is doing. And when it's easy enough I would like to show some friends how to do and code that.

Unfortunately I couldn't find how to translate this http://en.wikipedia.org/wiki/Euler_equations_%28fluid_dynamics%29 into a numeric application.

Has anyone done this before? Any help is appreciated,

Andreas

4

There are 4 best solutions below

7
On

Yes, lots of people have done it before.

The trick is to write conservation laws for mass, momentum, and energy as integral equations and turn them into matrix equations so you can solve them numerically. The transformation process usually involves discretizing a control volume using simple shapes like triangles and quadrilaterals for 2D and tetrahedra and bricks for 3D and assuming distributions of pertinent variables within the shape.

You'll need to know a fair amount about linear algebra, and numerical integration if the problem is transient.

There are several techniques for doing it: finite differences, finite elements, and boundary elements (if a suitable Green's function exists).

It's not trivial. You'll want to read something like this:

http://www.amazon.com/Numerical-Transfer-Hemisphere-Computational-Mechanics/dp/0891165223

1
On

The answer to your question depends on the approach you want to use to solve the 2D Euler equation . Personally , I recommend the finite Volume approach and to understand it, I think you should take a look on this book: Computational Fluid Dynamics: Principles and Applications by Jiri Blazek.

It's a good book that takes from the beginning to stand the finite volume method to writing your own code and it also comes with a companion code to guide along the way . It's very good book, it did me wonders when I was writing my Master's thesis.

0
On

This book:

http://www.amazon.com/Computational-Fluid-Dynamics-John-Anderson/dp/0070016852

is a pretty straightforward, simple description of what it takes to write a CFD code. It's suitable for an undergraduate level intro with more practical examples than theory.

0
On

Your 6 year old question is still fairly common among all Computational Fluid Dynamics (CFD) newbies ("How hard can this be?"). However, one must at this stage be careful to not trivialize the math behind solving a given system of equations.

To those new to (or interested) in CFD -

Before you start thinking about coding, it is important to understand the nature of the equations you are trying to solve. An elliptic problem (like a Poisson solver for potential flow) is very different from a hyperbolic system (like the Euler equations) in which information "propagates" through the numerical domain in the form of different wave modes. Which is my first point,

1. Know the properties of the system and study the equations - For this step, you will need to go through math textbooks on partial differential equations, and know how to classify different equations. (See Partial Differential Equations for Scientists and Engineers by Farlow, or revisit your undergraduate math courses.)

2. Study linear algebra - The best CFD experts I know, have strong fundamentals in linear algebra.

Moving to a specific case for hyperbolic problems, e.g. the Euler equations

3. Read on spatial and temporal discretization - This is the point that is less well understood by people new to CFD. Since information propagates in a definite direction and speed in hyperbolic problems, you cannot discretize your equations arbitrarily. For this, you need to understand the concept of Riemann problems, i.e. given a discontinuous interface between two states at a given time, how does the system evolve? Modern finite-volume methods, use spatial discretizations that replicate how information is propagated through your simulation in space and time. This is called upwinding. Read Toro's book on Riemann solvers for a good introduction to upwinding.

4. Understand the concept of stability - Not all discretizations and time-integration methods will lead to a stable solution. Understand the concept of a limiting time-step (CFL-condition). If you don't follow the laws of upwinding, it will be difficult to get a stable solution.

At this point of time, you will have a clearer idea of what goes into a CFD code and you can start worrying about which language to use to code. Most widely used CFD codes are written in C or Fortran for computational speed and parallelization. However, if you intend to code only to learn, you can use Matlab or Python, which will be less frustrating to work with. I should also mention that coding a 2D Euler solver is a typical homework problem for new graduate students in Aerospace engineering, so try and be humble and open to learning if you succeed.

For anyone who is looking into CFD, know that it is a challenging and amazing field, with many advancements. If you wish to succeed, read up on papers (especially the fundamentals) and don't give up if you can't understand a topic. Keep working hard, and you will find yourself pushing the boundaries of what CFD can do.