CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Own Codes

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By arjun
  • 1 Post By DoHander

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 19, 2012, 04:12
Default Own Codes
  #1
New Member
 
Balaji Viswanath
Join Date: Apr 2012
Posts: 1
Rep Power: 0
balajiviswanath1991 is on a distinguished road
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
balajiviswanath1991 is offline   Reply With Quote

Old   April 19, 2012, 09:45
Default
  #2
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
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 ?
DoHander is offline   Reply With Quote

Old   April 19, 2012, 12:02
Default
  #3
New Member
 
Mazhar Iqbal
Join Date: Mar 2009
Posts: 10
Rep Power: 17
mazhar is on a distinguished road
I think FORTRAN is the best environment to carry out your own programming. You can visulize your results in any software like TecPlot
mazhar is offline   Reply With Quote

Old   April 20, 2012, 05:23
Default
  #4
Senior Member
 
Join Date: Aug 2011
Posts: 272
Rep Power: 15
leflix is on a distinguished road
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.
leflix is offline   Reply With Quote

Old   April 20, 2012, 05:35
Default
  #5
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,272
Rep Power: 34
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by leflix View Post
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
arjun is offline   Reply With Quote

Old   April 20, 2012, 06:22
Default
  #6
Senior Member
 
Join Date: Aug 2011
Posts: 272
Rep Power: 15
leflix is on a distinguished road
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...
leflix is offline   Reply With Quote

Old   April 20, 2012, 08:01
Default
  #7
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,272
Rep Power: 34
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by leflix View Post
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 View Post
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 View Post
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 View Post
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.
arjun is offline   Reply With Quote

Old   April 20, 2012, 09:11
Default
  #8
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
Quote:
Originally Posted by leflix View Post
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.
DoHander is offline   Reply With Quote

Old   April 20, 2012, 11:40
Default
  #9
Senior Member
 
Join Date: Aug 2011
Posts: 272
Rep Power: 15
leflix is on a distinguished road
Thanx DoHander !! it's good to know such stuff about matmul....
leflix is offline   Reply With Quote

Old   April 20, 2012, 13:34
Default
  #10
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
Quote:
Originally Posted by DoHander View Post
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!
cfdnewbie is offline   Reply With Quote

Old   April 20, 2012, 18:32
Default
  #11
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
Quote:
Originally Posted by cfdnewbie View Post
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 ...
DoHander is offline   Reply With Quote

Old   April 20, 2012, 19:01
Default
  #12
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,272
Rep Power: 34
arjun will become famous soon enougharjun will become famous soon enough
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 View Post
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 likes this.
arjun is offline   Reply With Quote

Old   April 20, 2012, 20:09
Default
  #13
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
Quote:
Originally Posted by arjun View Post
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.
DoHander is offline   Reply With Quote

Old   April 21, 2012, 03:56
Default
  #14
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
Quote:
Originally Posted by DoHander View Post
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 is offline   Reply With Quote

Old   April 21, 2012, 03:58
Default
  #15
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
Quote:
Originally Posted by arjun View Post
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.
cfdnewbie is offline   Reply With Quote

Old   April 21, 2012, 10:47
Default
  #16
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
Have a look at some examples of using Python+matplotlib here:

http://matplotlib.sourceforge.net/us...reenshots.html
cfdnewbie likes this.
DoHander is offline   Reply With Quote

Old   April 21, 2012, 10:50
Default
  #17
Senior Member
 
cfdnewbie
Join Date: Mar 2010
Posts: 557
Rep Power: 20
cfdnewbie is on a distinguished road
Quote:
Originally Posted by DoHander View Post
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!
cfdnewbie is offline   Reply With Quote

Old   April 21, 2012, 10:57
Default
  #18
Senior Member
 
Join Date: Nov 2009
Posts: 411
Rep Power: 19
DoHander is on a distinguished road
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.

Last edited by DoHander; April 21, 2012 at 11:25.
DoHander is offline   Reply With Quote

Reply

Tags
own coding


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison of CFD Codes Kerem Main CFD Forum 9 May 9, 2003 04:29
help Navier vs Panel codes!!! bobby Main CFD Forum 3 April 2, 2002 08:55
Self-made codes vs. commercial John Van Workum Main CFD Forum 27 April 1, 2001 21:23
New List of Free CFD Codes Bert Laney Main CFD Forum 5 September 15, 1999 15:24
Anyone used Ansys/Flotran - cf. with other codes? S. Langsford Main CFD Forum 3 October 19, 1998 20:51


All times are GMT -4. The time now is 18:10.