1

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

Andrew Walker
  • 40,984
  • 8
  • 62
  • 84
Andreas Hornig
  • 2,439
  • 5
  • 28
  • 36

4 Answers4

3

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.

3

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

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • Hi, the library finally got it back and I have it now. The SIMPLE algo is great, because I understand how it works. BUT I'm not sure where I get the a_n (a_e, a_...) factors from. Can you give mea hint, how this is done? It's explained where to get tha a_E (capial indices) from, but they use the a_e (small indices) and I don't see, where those are taken from. – Andreas Hornig Nov 10 '11 at 22:27
  • 1
    I don't have access to a copy of the book anymore, but usually those are based on some kind of finite difference approximation. – duffymo Nov 11 '11 at 15:51
  • yeah, it is based on it, but you need to calculate all the grid values for pressure, velocity and co from this and at one point, I don't know where they take a value from :(. Too bad you don't have a copy anymore. – Andreas Hornig Nov 11 '11 at 17:07
  • It's usually done by expressing all the equations at once in a matrix and solving it. You should only have known values at a few points, called boundary conditions, and your linear algebra solution solves for all the rest. Are you asking how to solve the matrix or how to write it in the first place? – duffymo Nov 12 '11 at 15:21
  • I'm not asking about the matrix, I'm asking about the SIMPLE algorithm and the way how it solves the a_smallindex and a_capitalindex. The latter one's are described, but they have a variable, where you need the others first and then it's not described, where to get those, or if you have to guess them in the first place like the pressure field. – Andreas Hornig Nov 17 '11 at 17:06
  • I'm sorry, you'll have to get the book. I don't have the details in front of me or off the top of my head. Sorry – duffymo Nov 17 '11 at 19:20
  • Hi, I only have this only version, that's nearly the samle like the book, but it's in German http://www.cfd.tu-berlin.de/Vorlesungen/fvm_skript/node81.html But on that site you can see the equation I mean. On the left hand side there is u* times a_e and this a_e I mean. – Andreas Hornig Nov 19 '11 at 12:57
3

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.

tpg2114
  • 14,112
  • 6
  • 42
  • 57
1

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.

Nikana Reklawyks
  • 3,233
  • 3
  • 33
  • 49
Mohammed
  • 87
  • 1
  • 1
  • 7