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

C++, Fortran and Matlab

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 6, 2000, 19:53
Default C++, Fortran and Matlab
  #1
Wole F.
Guest
 
Posts: n/a
My current CFD codes are in Fortran 77 but I would like to write codes in C++ and Matlab. Does anyone know associated advantages or disadvantages.?. Thanks for your help.
  Reply With Quote

Old   September 7, 2000, 02:19
Default Re: C++, Fortran and Matlab
  #2
eddy
Guest
 
Posts: n/a
I tryied to write poisson solvers in Matlab, but finally give up because it was too slow to run. For 2d ADI solver, you may need one hour to get results. In FORATRAN, you only need few seconds. I never tried to compile Matlab code, perhaps, that will speed up code.

Advantages: 1) easy to draw nice figure of all the variables you are interested in. 2) Many functions you can use, no need to re-write.

Disavantages: 1) Too much CPU time. 2) Memory limitations.
  Reply With Quote

Old   September 7, 2000, 16:00
Default Re: C++, Fortran and Matlab
  #3
Aaron
Guest
 
Posts: n/a
there is another matlab-like software called omatrix that is pretty quick and relatively easy to use, its graphing capabilities are limited, so you might to plot in tecplot or sigmaplot or something, you can find info at harmonicsoftware.com
  Reply With Quote

Old   September 8, 2000, 04:53
Default Re: C++, Fortran and Matlab
  #4
Steve Amphlett
Guest
 
Posts: n/a
I like MATLAB! MATLAB is a brilliant environment for prototyping (and sometimes even implementing) numerical solvers and data processing schemes.

Unfortunately it is all to easy for newcomers to write really inefficient loop-based code rather than take advantage of the in-built vectorization in MATLAB. If you lurk around on the comp.soft-sys.matlab news group, you'll find a fair number of "how do you vectorize this code" questions, along with numerous answers. Basically, anything can be vectorized if you know what you're doing.

I tend to prototype a numerical scheme directly in MATLAB, then implement it standalone in FORTRAN/C/C++, then put a MATLAB MEX wrapper around it. That way I can pre- and post-process my data in MATLAB and hand it off directly to my own code. Best of both worlds. The MATLAB compiler is basically for people who aren't confident (skilled?) enough to go whole-hog and write MEX files.

Just my 2 cents' worth.

- Steve
  Reply With Quote

Old   September 8, 2000, 08:15
Default Re: C++, Fortran and Matlab
  #5
Sebastien Perron
Guest
 
Posts: n/a
I used to program in F77, but for the last 5 years all my new code was developped in C++: 1) Advantages: a) portable b) reusability c) flexibility d) It is easier to make use of dynamic memory allocation than F90 (you can't in f77) e) When you build good classes, the main code becomes easier to write and manipulate. f) If you take advantages of pointers when doing loops, the code can become faster than F77.

I don't see any disavantages. Just a few weeks ago, I had to work on a project for an industry. The code they use is written in F77. Even though I only had to make small changes, thi wasn't easy. We might have to do major changes in the future, if we do so, th whole code will ported using f2c.

  Reply With Quote

Old   September 9, 2000, 02:55
Default Re: C++, Fortran and Matlab
  #6
Istadi
Guest
 
Posts: n/a
Hi all,

I like MATLAB for visualizing directly of graphic solutions. However, it's take a many memory to run, if we can't organizing a simple or economic code. I think, we may develope CFD code in F77 or F90, so we visualize graphic solution in Matlab code directly or tecplot. In my opinion, it is a simple.
  Reply With Quote

Old   September 11, 2000, 07:06
Default Re: C++, Fortran and Matlab
  #7
Vidyadhar Y. Mudkavi
Guest
 
Posts: n/a
i completely endorse the views of Sebastien Perron as far as coding in c++ goes.

fortran codes tend to be very stiff. even small changes need good amount of code touching. on the other hand, c++ allows for clean and neat incremental development.

the only difficulty you will face is to learn c++. this can be quite a task as the language is pretty complex. but once you are in it, you won't feel like getting out of it ;-)

one way to go at your fortran codes quickly is to translate them to c (using f2c, say) and encapsulate them in c++ code. you can return at your leisure and code them incrementally in c++.
  Reply With Quote

Old   September 11, 2000, 19:34
Default Re: C++, Fortran and Matlab
  #8
clifford bradford
Guest
 
Posts: n/a
where do I get this f2c. i have an old f77 CFD code and it'd be nice to have it in C, since I know C and not f77
  Reply With Quote

Old   September 11, 2000, 19:48
Default Re: C++, Fortran and Matlab
  #9
clifford bradford
Guest
 
Posts: n/a
Matlab is a great environment for code development because: 1)almost every function you could want is already there including doing stuff like taking derivatives etc. 2)F90 style array masking and other vectorised operations not only is your code compact but it's faster 3)for code prototyping there is automatic dynamic allocation. you don't have to allocate arrays you can just add to them as needed. this is poor programming in general but is usefull when writing small blocks of code to check things out 4)Matlab code is totally and completely portable. 5)quick and easy postprocessing even for unstructured meshes as I only just recently discovered. 6)you can compile matlab code to make it run fast. 7)as Steve said you can incorporate MEX files to take advantage of existing fortran and C code. this is a good way to do multilanguage programming although I'vve never done this myself. i've had to develop code that had C++ and fortran subroutines and let me tell you it's not easy. 8)you can be come a very competent Matlab programmer in a short time particularly if you remember to avoid loops and ifs

also I'd say that the combination of Matlab and C++ will do you pretty good. the inability to use dynamic allocation in F77 often leads to codes that use too much memory or that need frequent compiling when parameters have to be changed. as a result this encourages code with too many separate subroutines to avoid long compiles with modification while I prefer to goup my subroutines into larger code files.
  Reply With Quote

Old   September 11, 2000, 20:15
Default Re: C++, Fortran and Matlab
  #10
Sebastien Perron
Guest
 
Posts: n/a
This is the address for the main web site: www.netlib.org

(I don't know why this site seems to be down tonight, first time it happens)

You can also try for linux ftp://ftp.freesoftware.com/pub/linux.../lang/fortran/

For other OS try to look in ftp://ftp.freesoftware.com/pub


  Reply With Quote

Old   September 25, 2000, 22:26
Default Re: C++, Fortran and Matlab
  #11
Greg Perkins
Guest
 
Posts: n/a
I notice a number of people suggest C++ is very good. I agree, however, I often wonder whether the extra levels of abstraction in going to Object Orientated style, vs structured methods in plain C results in slower code. Does anybody know??

I suspect C++ will be slower but is this really the case? If so and if speed is important, perhaps using straight C is a good compromise between speed and flexibility.

Greg
  Reply With Quote

Old   September 26, 2000, 11:01
Default Re: C++, Fortran and Matlab
  #12
John C. Chien
Guest
 
Posts: n/a
(1). There are books available on the efficiency of C++ programming. (2). For example, the use of the class and object requires the construction and the destruction (initialization and clean-up) of the objects, it takes time to perform such operations each time you need to create an object(s). (3). The speed in cfd is really not an issue, if you know how to obtain the converged solution accurately. (4). If you are just looking for cfd solutions, then most of the time, you are getting the wrong answers. So, most people like to have faster codes to obtain the wrong solution as soon as possible. In other words, most of the time, we are doing the parameter study and looking for the possible optimum solution. (5). I would say that the best place to check the trend of the language is in the computer games programming. The trend has been from assembly language, to c, to C++. Even the computer graphics programming is being taught in C++. So, the speed alone is relative. In Internet, a lot of people are still using VB, Java, which are rather slow when compared with Fortran, c or C++.
  Reply With Quote

Reply


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
caling matlab in Fortran HaKu Main CFD Forum 0 July 16, 2009 16:35
matlab in fortran HaKu Main CFD Forum 2 June 18, 2009 12:46
Fortran vs Matlab Help idee Main CFD Forum 3 July 2, 2008 16:05
MATLAB FORTRAN Ally Main CFD Forum 4 July 12, 2007 04:51
matlab to fortran ztdep Main CFD Forum 4 November 15, 2006 09:15


All times are GMT -4. The time now is 16:55.