|
[Sponsors] |
June 30, 2011, 23:15 |
How to call FORTRAN files as UDF?
|
#1 |
New Member
Ehsan
Join Date: Jun 2011
Posts: 9
Rep Power: 15 |
I have some FORTRAN files and I like to use them as UDF files in FLUENT, but UDF files programming language is C with macros.
These FORTRAN files basically calculate source terms for some equations in FLUENT and the calculations need to be updated in every iteration. I like to know, how hard is that to use FORTRAN files with a UDF interface? Does it smart enough to understand the FORTRAN tricks? If you have any special documents please share with me. Thank you Ehsan |
|
July 1, 2011, 05:38 |
|
#2 | |
Senior Member
|
Quote:
refer to: UDF user manual: (6.3.26) 5.4 Link Precompiled Object Files From Non-FLUENT Sources I didn't try it before; share your experiences if you have any progress ! Amir |
||
July 1, 2011, 16:10 |
|
#3 |
New Member
Ehsan
Join Date: Jun 2011
Posts: 9
Rep Power: 15 |
Hi Amir,
Thanks for your reply, I am actually fighting with that using instruction in 5.4 of the manual. I like to know if anyone has done that before and had success on that. Also if it is easier to translate whole FORTRAN file (in my case it is fairly complicated) to C or it is easier to write an interface? Ehsan |
|
June 4, 2012, 06:32 |
|
#4 | |
New Member
Dinesh
Join Date: Nov 2009
Location: India
Posts: 25
Rep Power: 17 |
Quote:
Did u find success in conversion of FORTRAN program in UDF? If yes kindly help me also. I am also fighting with conversion of the same kind of stuff. Thanks in advance. |
||
July 9, 2012, 22:38 |
|
#5 |
New Member
Join Date: Jul 2010
Posts: 8
Rep Power: 16 |
It can be done and I've done it with varying success, but it is tedious.
Here's a quick overview of the procedure: -In your Fluent case that you want to link with Fortran, go to Define->User-Defined->Functions->Compiled... -Under "Library Name" type in the name you want to use for your library of udf's and Fortran files (for example i'll use: libudf) then click the Build button. This will build the directory structure within your Fluent working directory. -Your Fluent working directory will now have a folder in it with the library name you chose (in this case: libudf) and within that folder another for the computer architecture (in my case, win64). Within that folder is yet another, for the solver you are using (in my case, "2ddp" for 2-Dimensional double-precision). -Your libudf directory may also (I can't recall) have another folder in it named "src". If it doesn't have this folder, create it. This is the folder where you will place the UDF c-file that must be compiled and which will interface with Fluent and the Fortran code. For example, we will name this file: udfsource.c -Open that bottom folder (2ddp) and open the text file named user_nt.udf and edit it to look as follows: Code:
SOURCES = $(SRC)udfsource.c VERSION = 2ddp PARALLEL_NODE = none USER_OBJECTS =C:\*FLUENT CASE WORKING DIRECTORY*\FORTRAN_CODE.lib -There are also a whole laundry list of Fortran libraries you may need to include in the USER_OBJECTS term, depending on your Fortran compiler. I am using Absoft to compile my Fortran code, so here is the full list of what mine looks like: Code:
C:\Absoft11.0\lib64\afiodll.lib C:\Absoft11.0\lib64\GdiPlus.lib C:\Absoft11.0\lib64\Uuid.lib C:\Absoft11.0\lib64\Uxtheme.lib C:\Absoft11.0\lib64\absoftmain.lib C:\Absoft11.0\lib64\af77math.lib C:\Absoft11.0\lib64\af77mathdll.lib C:\Absoft11.0\lib64\af90math.lib C:\Absoft11.0\lib64\af90mathdll.lib C:\Absoft11.0\lib64\af90mblas.lib C:\Absoft11.0\lib64\afio.lib C:\Absoft11.0\lib64\afiodll.lib C:\Absoft11.0\lib64\amisc.lib C:\Absoft11.0\lib64\blacs.lib C:\Absoft11.0\lib64\blacsC.lib C:\Absoft11.0\lib64\blacsF77.lib C:\Absoft11.0\lib64\bufferoverflowu.lib C:\Absoft11.0\lib64\comsupp.lib C:\Absoft11.0\lib64\comsuppd.lib C:\Absoft11.0\lib64\comsuppw.lib C:\Absoft11.0\lib64\comsuppwd.lib C:\Absoft11.0\lib64\cryptui.lib C:\Absoft11.0\lib64\dciman32.lib C:\Absoft11.0\lib64\delayimp.lib C:\Absoft11.0\lib64\f90gl.lib C:\Absoft11.0\lib64\f90glu.lib C:\Absoft11.0\lib64\f90glut.lib C:\Absoft11.0\lib64\glut32.lib C:\Absoft11.0\lib64\gtrts32w.lib C:\Absoft11.0\lib64\gtrtst32.lib C:\Absoft11.0\lib64\httpapi.lib C:\Absoft11.0\lib64\inetcomm.lib C:\Absoft11.0\lib64\ksuser.lib C:\Absoft11.0\lib64\libaomp.lib C:\Absoft11.0\lib64\libcmt.lib C:\Absoft11.0\lib64\libcmtd.lib C:\Absoft11.0\lib64\libcpmt.lib C:\Absoft11.0\lib64\libcpmtd.lib C:\Absoft11.0\lib64\libgomp.lib C:\Absoft11.0\lib64\libinstr.lib C:\Absoft11.0\lib64\libmv.lib C:\Absoft11.0\lib64\libpthread.lib C:\Absoft11.0\lib64\mrwe.lib C:\Absoft11.0\lib64\msdasc.lib C:\Absoft11.0\lib64\msvcmrt.lib C:\Absoft11.0\lib64\msvcmrtd.lib C:\Absoft11.0\lib64\msvcprt.lib C:\Absoft11.0\lib64\msvcprtd.lib C:\Absoft11.0\lib64\msvcrt.lib C:\Absoft11.0\lib64\msvcrtd.lib C:\Absoft11.0\lib64\msvcurt.lib C:\Absoft11.0\lib64\msvcurtd.lib C:\Absoft11.0\lib64\mtxdm.lib C:\Absoft11.0\lib64\nmapi.lib C:\Absoft11.0\lib64\normaliz.lib C:\Absoft11.0\lib64\npptools.lib C:\Absoft11.0\lib64\odbc32.lib C:\Absoft11.0\lib64\odbcbcp.lib C:\Absoft11.0\lib64\odbccp32.lib C:\Absoft11.0\lib64\oldnames.lib C:\Absoft11.0\lib64\oledb.lib C:\Absoft11.0\lib64\osptk.lib C:\Absoft11.0\lib64\parser.lib C:\Absoft11.0\lib64\plplot.lib C:\Absoft11.0\lib64\plplot_d.lib C:\Absoft11.0\lib64\powrprof.lib C:\Absoft11.0\lib64\refblas.lib C:\Absoft11.0\lib64\reflapack.lib C:\Absoft11.0\lib64\runtmchk.lib C:\Absoft11.0\lib64\scalapack.lib C:\Absoft11.0\lib64\sisbkup.lib C:\Absoft11.0\lib64\strsafe.lib C:\Absoft11.0\lib64\unix.lib C:\Absoft11.0\lib64\vms.lib C:\Absoft11.0\lib64\wmiutils.lib -So, once your user_nt.udf file is properly set up, you can now compile the whole thing together. (Note that the fortran code should already be compiled into a single library file as I mentioned previously.) To do this, open your c-compiler (in my case, Microsoft Visual Studio 2008 command prompt) and navigate to the libudf\win64\2ddp directory. In windows, the compile command is nmake, so I just type that once I'm in that directory. In other operating systems, this process would be different and I don't know how to do it. NOTE: When you do this on Windows (it's different in Linux) the udf library can NOT already be loaded in Fluent. So you must either close the fluent case (save it first) or go to Define->User-Defined->Functions->Manage... and select your fluent library (in this case: libudf) and click Unload. -Now there should be several new files in that libudf\win64\2ddp directory, including libudf.lib, which is the library Fluent will ultimately use. Go back to your Fluent case, go to Define->User-Defined->Functions->Compiled... and under Source Files click Add..., then navigate to the libudf\src directory and select your c-file (in this case: udfsourc.c) and click OK. The file should now show up on this list under Source Files. Click the Load button on the Compiled UDFs window to load your library. If you have a subroutine in your UDF called DEFINE_EXECUTE_ON_LOADING, this subroutine will execute when you click the load button. -Now you can link cell source terms to the udf. If you've read the Fluent UDF Manual (and you should) your c-file will have a subroutine called DEFINE_SOURCE, whose first argument is a name of your choosing. You can go to Cell Zone Conditions->(whatever fluid zone)->Edit and check the Source Terms box. Then click the Source Terms tab in that window, and you can see all the particular equations you want to add sourc terms to (mass/momentum/energy/etc.) Click Edit next to the equation you want, increment the "number of sources" to 1, and your source udf will show up on the drop-down list here. That is how to get everything all pointed in the right direction, but there are still some things to be aware of when writing your c and fortran codes: -At the top of your c-file, just after the #include lines, you need to declare all the fortran functions you want to call from within the c. They need to be declared using this format: Code:
void fsource_(double *, double *); -Similarly, when you call a fortran function from the c-code, it must be done using this format: Code:
fsource_(&all_source[0][0], &wall_source[0]); -Additionally, every time you wish to make a change to your c-file, you must unload the udf library from fluent, recompile the c-code, and re-load the library into Fluent. When you wish to make changes to the Fortran code, you must unload the udf library from Fluent, recompile the Fortran code, then recompile the c-code as well (since the c-compile will include the Fortran library) then re-load the library into Fluent. There may be additional complications with getting your c-compiler to work. I had trouble with it and someone in the IT department here sorted it all out for me. That part of the process will depend on what kind of system you are using. Good luck, and consider rewriting or translating the Fortran code into C instead, to avoid this whole headache. I really think it's probably easier, unless you are an experienced programmer or have one around with the time to help you get going. |
|
July 11, 2012, 09:47 |
|
#6 |
New Member
Dinesh
Join Date: Nov 2009
Location: India
Posts: 25
Rep Power: 17 |
Dear friend bawfuls,
Thaks for ur reply. It looks very tedious process. Hats of to u if u hav done yourself. I hav a fortran program with me and i want to convert it to C. If you come across any simple solution of conversion of fortran files to C kindly let me know.I will be very thankful to you. Thanks in advance. |
|
September 11, 2012, 12:03 |
|
#7 |
New Member
Join Date: Jun 2009
Posts: 15
Rep Power: 17 |
How to call a precompiled .obj file in a udf (c language)
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
CFX11 + Fortran compiler ? | Mohan | CFX | 20 | March 30, 2011 19:56 |
how to call diffusivity from Fluent to UDF | Kim | FLUENT | 0 | June 18, 2008 13:52 |
call fortran routines from UDF | lily | FLUENT | 0 | March 29, 2005 19:26 |
UDF CALL FOR PRESSURE | D Harvey | FLUENT | 2 | June 3, 2004 22:46 |
Open files in a UDF | Riccardo | FLUENT | 2 | June 26, 2002 11:45 |