How to call FORTRAN files as UDF?
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.
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 !
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?
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.
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:
-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:
-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:
-Similarly, when you call a fortran function from the c-code, it must be done using this format:
-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.
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.
How to call a precompiled .obj file in a udf (c language)
|All times are GMT -4. The time now is 13:51.|