Hi. I am trying to call a Fort
Hi. I am trying to call a Fortran program from OpenFoam code, where some standard Fortran libraries are needed. I compile the Fortran program individually and add the .o file in the list of objectFile. Is that correct? What else should I do? And I have no idea how to include the information of the Fortran libraries. Please give me some advice. Thanks!
Bei |
Hi Bei,
I donīt know, if this
Hi Bei,
I donīt know, if this is the most comfortable way to include Fortran into C/C++, but I got it going under a linux system some time ago: You may have a function or routine in Fortran in a file called test.f: SUBROUTINE TEST(par1, par2, par3) . . . To call this routine in C/C++ create a header file, maybe definitions.h: #define test test__ (double underscore) Include this header file, where you want to call the fortran routine, maybe: #include "definitions.h" main(...) { . . test(par1, par2, par3); . . } Thatīs it. Have fun. By the way: -Distinuish small and capital letters above. -Put the definitions of all routines/functions, you want to use, in definitions.h Rolando |
I think there are no OpenFOAM
I think there are no OpenFOAM specific problems. The major problem is that Fortran passes variables "by Referenence" while C (as a general rule) passes "by value".
Googling for "fortran c mixing" gives a number of useful pages amongst them: http://owen.sj.ca.us/rkowen/howto/FandC/FandC.call.html I know this is not the place to start a language dispute, but as a wise man once said: "The true programmer can program FORTRAN in any language" If your routines are not to large I would port them to C because then you won't have to fuss with portability issues if you switch systems/compilers. If you must stay with the Fortran-code, just one tip: if you are unsure how many additional _ you Fortran-compiler produces or what the routine-names look like use "objdumd -t" on the .o-files. The names that are listed there (small/large, underscore etc) can be used in the C-programs. |
Thanks for the answers! I will
Thanks for the answers! I will follow your tips and see how it works. http://www.cfd-online.com/OpenFOAM_D...part/happy.gif
Best regards, Bei |
I would say, this is a really good example:
testC.cpp : Code:
#include <iostream> Code:
subroutine fortfunc(ii,ff) * f77 -c testF.f * g++ -c testC.cpp * g++ -o test testF.o testC.o Run : ./test Output : ii= 5 ff= 5.500 That's it! Regards, Andreas P.S.1: Found here: http://www.yolinux.com/TUTORIALS/LinuxTutorialMixingFortranAndC.html It's all out there. P.S.2: @Bei: Please post your solutions, once you find them. You also profit from others' suggestions. P.S.3: @Roland: Double underscore doesn't work and a Fortran (dosen't matter if F77/90/95/2003) function in C++ has to be defined within Code:
extern "C" |
Hi Bernhard,
If I add the line to call a fortran code in, e.g. rhoPimpleFoam.C, and I pass the velocity field to the fortran code. is this velocity field for the whole computational domain or only for one core? From the fortran code side, another quantity will be passed to the openfoam, should this quantity be for the whole domain or only for the particular rank? I not know how the parallelization is implemented in openfoam. How can we extract the rank No. and logical variable ROOT from openfoam. Thank you very much! Quote:
|
Quote:
Quote:
|
All times are GMT -4. The time now is 01:43. |