CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   C++ fortran confusion (https://www.cfd-online.com/Forums/main/14843-c-fortran-confusion.html)

prapanj February 25, 2008 13:51

C++ fortran confusion
 
Hi

I currently use fortran 90 for all my codes. But these days I see that opens source CFD libraries like open FOAM are written in c++. I dont find any open source stuff like that for a fortran user. Do you think a CFD-ian these days should be good in both fortran and C++/C ? Please guide me.

thank you

Prapanj

Quarkz February 25, 2008 21:41

Re: C++ fortran confusion
 
Hi,

I'm also using fortran 90. I've learnt C in sch too but I prefer fortran 90. I feel more comfortable with it. I wonder if there's a real advantage to using C++...

Anyway, I found that most new linear eqn solvers seem to be written in C, although a fortran interface is still present. These include PETSc, hypre, just to name a few.

It seems that most sch don't teach fortran nowadays, which is quite a pity. Moreover, most ppl I talk to feel that fortran's an outdated ancient language. Of cos, they're not in the CFD field.

Anyway, to answer your qn, I think knowing C should help. Not sure abt C++

rt February 25, 2008 23:03

Re: C++ fortran confusion
 
c++ is recently prefarable mainly due to OOP capability, when u develop ur code in ur short period research, Fortran could be quit sufficient (+ wrapping third party tools), but when u should think to reusability, future extension, having multiple developers, having a clean modular code, ease of use (data & functionality encapsulation), ... using OOP programming is unavoidable.

for OOP c++ could be the best choice. Note that C is not OOP language but it is possible to use its for this purpose (there are some text on OOC), e.g. GLib is wrriten in this way.

some peoples have used mixed programming to relax from performance drop of c++ (e.g. Chombo code), but experts use additional power of c++ to do this job e.g. expression templete programming (e.g. BLITZ++)

hadian February 26, 2008 00:24

Re: C++ fortran confusion
 
Fortran is much easier for CFD and numerical purposes and there are some notes on the internet for OOP by fortran. the main week point is that there is not any powerful graphical library for fortran while you can find plenty of those libraries for C and C++ (and many of theme are free). It seems Mixed Language programming can overcome these problems but it is not easy and maybe your code will not be portable. Hadian

rt February 26, 2008 09:30

Re: C++ fortran confusion
 
>... there is not any powerful graphical library for fortran while you can find plenty of those libraries for C and C++

This is not important, we rarely like to visualize results on-the-fly and usually CFD post-processors (Paraveiw, Ensight, Tecplot, ...) works on exported data (also for moderate size problems generation of results are very slow)

> but it is not easy and maybe your code will not be portable

recently the portability issue of mixed language programming is just due to posrability of Fortran code or C++ code itself, and so it is not issue too (several opensources use this with autoconfig which is fairly portable).

Regarding to OOP programming i should add this that, OOP programming needs knowledge in this regard and its design is very very important, usually design of OOP code (design of classes, their import/export, hierarch, ..) take more time than programming (e.g. for early stage of VTK lib. development, this phase takes 6 fold more time than programming).


jinwon park February 26, 2008 09:48

Re: C++ fortran confusion
 
It is very questionable whether C++ can replace scientific fortran codes since one has different preferences in terms of OOP, efficiency and reusuability. I have learnt c++, fortran, java and matlab for my researches so far. Before starting ph.d, I had preferred c++ since it provides efficient framework for OOP. However, in doing Ph.D work, these were not major portions. Anyway, for better research, I do not want to study programming more since most CFD peoples are not computer engineer.

Good luck!

cfd_newbie February 26, 2008 10:05

Re: C++ fortran confusion
 
My advice is to use FORTRAN 95/2003 for number crunching programs and, if you need a decent GUI, you could always use Python for that.

By the way Python could glue Fortran and C/C++ application very easy. In that way you could use an open source library written in C++ and your one Fortran code.

A very good book for mixing Python, Fortran and C++ is:

Python Scripting for Computational Science.

hadian February 26, 2008 23:12

Re: C++ fortran confusion
 
As i experienced during my pdh, having a graphical library for limited visualization in a CFD code can save time during the development. For example, graphical monitoring of the residuals in an implicit solver, make the debugging much easier than monitoring the numbers.

about Python, it seems that python is going to be very popular. But it is an interpreter. IS it as fast as fortran or c++ which are compilers? does anybody have experience working with python in CFD? Hadian

Rami February 27, 2008 05:05

Re: C++ fortran confusion
 
There are some F90 open source codes, e.g., Elmer (http://www.csc.fi/elmer/) and Dolfyn (sorry, I don't have a link, but it is a dutch software).

cfd_newbie February 27, 2008 09:45

Re: C++ fortran confusion
 
About Python ...

Python is an interpreted language and in Python you could not achieve the speed of a Fortran or C++ code, but:

1. A professional CFD code is made of many parts and except the solver everything could be developed in Python.

2. You could have only the IDE written in Python, your solver could be a Fortran or a C++ code. This will ensure the portability of your code between Linux and Windows for example.

3. You could have the pre-processing and post-processing part in Python.

....


J February 29, 2008 03:10

Re: C++ fortran confusion
 
Hi,

What are the graphical engines you know of for Fortran? (free preferably!)



All times are GMT -4. The time now is 09:05.