CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   Own Codes (http://www.cfd-online.com/Forums/main/100047-own-codes.html)

balajiviswanath1991 April 19, 2012 04:12

Own Codes
 
Dear all,
I used with CFD packages . But I am interested in writing own codes to which i am completely new. pls tell me in what language should I write the code (C, C++.etc). How should I run the code (In what software) and get the results. How should I build a mesh.????
thanks in Advance.//

balajiviswanath1991@gmail.com

DoHander April 19, 2012 09:45

If you give more details about what you have in mind you will receive pertinent answers.
Try to reformulate your question, for example:

1. What programming languages do you know well ?

2. What is your deadline for implementing your own CFD code ?

3. What CFD code are we talking about here, how complex will be this ?

mazhar April 19, 2012 12:02

I think FORTRAN is the best environment to carry out your own programming. You can visulize your results in any software like TecPlot

leflix April 20, 2012 05:23

I totally agree with Mazhar ! These are the best choices to me, especially with fortran90 or fortran2010 if you are keen on object oriented programming.
Tecplot is also a good software but not free unfortunately.

arjun April 20, 2012 05:35

Quote:

Originally Posted by leflix (Post 355778)
I totally agree with Mazhar ! These are the best choices to me, especially with fortran90 or fortran2010 if you are keen on object oriented programming.
Tecplot is also a good software but not free unfortunately.


On the other hand, I completely disagree with him. I think there is a reason that most of modern CFD solvers are written in C++. Take for example Fluent, Starccm+, openFOAM etc etc. I am sure the guys who work on them are no fools. If they have decided to go with c++ instead of fortran then there must be reasons to do so.

I personally prefer C++ for many reasons.

In the end, choose what you like, if you made wrong choice, you are the only one who is going to pay for it. :-D :-D

leflix April 20, 2012 06:22

First I think that the solver part of Fluent is programmed in fortran like Star-CD for instance.
I do not mean the language used to program the UDF, nor the language used to program the GUI which is surely programmed in C or C++.

The use of C++ was recommended in the past because of the object oriented skill of this language. But now if you really need such stuff for your code, fortran can do it since its 2008 version.

But anyway we won't restart here the very old debate "what is the best programming language for CFD codes ?"
This question already arised in this forum 15 years ago and the debates were very hot between the pros or cons fortran and C++ users. It sounded that some people received death threat !! ;-) So let's stop with it...

I think the best answer is "Do use the language in which you feel the more comfortable and in which your skills are the best !"
Because the main task you will have to overtake once your code is written, will be debugging. And debugging a code is first very cumbersome and a very hard task especially when you do not master well the language ...

In terms of efficiency I believe (it is my personal and humble opinion) that fortran have some powerfull functions particularly well suitable for scientific computation that are not available in other languages. As first example among many the product of two matrices or product of a matrix and vector...

arjun April 20, 2012 08:01

Quote:

Originally Posted by leflix (Post 355791)
First I think that the solver part of Fluent is programmed in fortran like Star-CD for instance.

The modern fluent 6.x and further versions are c and not fortran. This could be verified from their src directory. There is a src directory in fluent installation that i usually look for clues.

But then Fluent 4 was original fluent. (which probably was fortran , may be because of that you have this impression of it). From 5.5 or so fluent is not that fluent. From this time fluent acquired Rampant and Rampant became the precursor to modern Fluent. This code I think was in c and not in fortran.

I am not sure how the latest versions of fluents are. But last I checked their src files are still in c and not in cpp.

StarCCM (not starCD) is definitely in C++.



Quote:

Originally Posted by leflix (Post 355791)
The use of C++ was recommended in the past because of the object oriented skill of this language. But now if you really need such stuff for your code, fortran can do it since its 2008 version.

I agree with you here albeit with C++ things are easier.



Quote:

Originally Posted by leflix (Post 355791)
But anyway we won't restart here the very old debate "what is the best programming language for CFD codes ?"
This question already arised in this forum 15 years ago and the debates were very hot between the pros or cons fortran and C++ users. It sounded that some people received death threat !! ;-) So let's stop with it...

+10 for this.


Quote:

Originally Posted by leflix (Post 355791)
I think the best answer is "Do use the language in which you feel the more comfortable and in which your skills are the best !"

This probably is bottom line. I feel comfortable with C++ so I use. If someone wants Fortran, I occasionally do program in fortran. But not much.

DoHander April 20, 2012 09:11

Quote:

Originally Posted by leflix (Post 355791)
In terms of efficiency I believe (it is my personal and humble opinion) that fortran have some powerfull functions particularly well suitable for scientific computation that are not available in other languages. As first example among many the product of two matrices or product of a matrix and vector...

For small arrays yes, Fortran array functionality is convenient. For large arrays you don't want to use Fortran's built in matmul. In the past I did some tests comparing matmul with a well tunned DGEMM for increasing size arrays. I noticed that matmul performance tends to degrade with the size of the arrays.

leflix April 20, 2012 11:40

Thanx DoHander !! it's good to know such stuff about matmul....

cfdnewbie April 20, 2012 13:34

Quote:

Originally Posted by DoHander (Post 355828)
For small arrays yes, Fortran array functionality is convenient. For large arrays you don't want to use Fortran's built in matmul. In the past I did some tests comparing matmul with a well tunned DGEMM for increasing size arrays. I noticed that matmul performance tends to degrade with the size of the arrays.


I'm wondering if that's a result of your compiler optimisation in combination with your available cache size (in terms of prefetching and such?) .... I find it difficult to generalize statements about the efficiency of routines, since it may or may not strongly dependent of the underlying layers of hard- and software.

Just a little comment about the choice of language to use: In commercial codes, I'd tend to object oriented languages, C++ is fine, or use C for the math and couple it with python. If you want to write real number crunching codes, take Fortran. On the real big machines, about 80 to 85% of all software is (still) written in Fortran.
Pick the language according to your goals. For starters, Matlab is a perfect playground!

DoHander April 20, 2012 18:32

Quote:

Originally Posted by cfdnewbie (Post 355885)
I'm wondering if that's a result of your compiler optimisation in combination with your available cache size (in terms of prefetching and such?) .... I find it difficult to generalize statements about the efficiency of routines, since it may or may not strongly dependent of the underlying layers of hard- and software.

To be more specific, I've noticed this trend with Intel Fortran and gfortran on Linux and Windows machines.

Quote:

Pick the language according to your goals. For starters, Matlab is a perfect playground!
I think Python (+ Numpy, Scipy, Matplotlib ) is a better choice than Matlab. While Matlab can be a good tool for an experienced C, C++ or Fortran programmer, if you start with Matlab you will learn a lot of bad habits ...

arjun April 20, 2012 19:01

Its all about algorithm.

If you do exactly same thing with both languages then fortran might just edge out c or c++ on speed.

But as soon as you chose a language you might end up doing things little bit differently (for achieving the same goal).

So saying that Fortran for speed is not so simple and always true.

Quote:

Originally Posted by DoHander (Post 355917)
To be more specific, I've noticed this trend with Intel Fortran and gfortran on Linux and Windows machines.

Having an inbuilt function does not make it to be better or more efficient. Even for matrix matrix multiplication faster algorithms could be designed.

I remember during development of a CFD code, we were supposed to do some kind of all to all communications between processors. Now MPI has some functions that do exactly what I wanted to do. But when that MPI's function tested on Tsubame (Tokyo university's supercomputer) , it was very slow and killed the performance of whole code.
Finally I wrote an all to all routine that used MPI's simple send recieve functions and that beat the crap out of that inbuilt implementation. The difference in performance was not even funny. It was like inbuilt call took 1 minute and my call took less than 1 second.

DoHander April 20, 2012 20:09

Quote:

Originally Posted by arjun (Post 355919)
Its all about algorithm.

Agree, if you have a better algorithm you can surpass a less efficient one even if you use an interpreted language like Python or Matlab.

cfdnewbie April 21, 2012 03:56

Quote:

Originally Posted by DoHander (Post 355917)
To be more specific, I've noticed this trend with Intel Fortran and gfortran on Linux and Windows machines.

you were probably running into cache problems then, because I think the underlying MATMUTL algorithm scales well.... but that being said, no matter what language you choose, its performance will of course always limited by the hardware you have. If you go down all the way and include assembler code in your C or Fortran routines, you will be as fast as you can get.

I think a rather general statement we can agree on is this: Procedural languages (C, Fortran) are better suited for speed than object oriented ones - the latter are somewhat easier to maintain, though.

Quote:

I think Python (+ Numpy, Scipy, Matplotlib ) is a better choice than Matlab. While Matlab can be a good tool for an experienced C, C++ or Fortran programmer, if you start with Matlab you will learn a lot of bad habits ...
I only do some scripting for paraview in python, no visualization and such. Is it easy to lets say create a line plot in python? a contour plot? I've always found that the lack of easy visualization is what discourages the beginner, that's why I recommended matlab. If python can give you easy plotting, sure, go with it.....teaches you proper indentation, that's a good start :)

cfdnewbie April 21, 2012 03:58

Quote:

Originally Posted by arjun (Post 355919)
I remember during development of a CFD code, we were supposed to do some kind of all to all communications between processors. Now MPI has some functions that do exactly what I wanted to do. But when that MPI's function tested on Tsubame (Tokyo university's supercomputer) , it was very slow and killed the performance of whole code.
Finally I wrote an all to all routine that used MPI's simple send recieve functions and that beat the crap out of that inbuilt implementation. The difference in performance was not even funny. It was like inbuilt call took 1 minute and my call took less than 1 second.


Yes, agreed, we use basic level MPI routines (non block send / receive) and nothing else. We found that everything beyond that doesn't scale as it should, at least on our hardware and our implementation.

DoHander April 21, 2012 10:47

Have a look at some examples of using Python+matplotlib here:

http://matplotlib.sourceforge.net/us...reenshots.html

cfdnewbie April 21, 2012 10:50

Quote:

Originally Posted by DoHander (Post 356010)
Have a look at some examples of using Python+matplotlib here:

http://matplotlib.sourceforge.net/us...reenshots.html


Thanks a lot, cool stuff! will try to install it!

DoHander April 21, 2012 10:57

If you want a complete Python system for scientific work I would recommend to install at least:

Numpy, Scipy, Matplotlib and IPython.

Be careful to match your Python version with the above library versions.


All times are GMT -4. The time now is 11:43.