CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   UDF programming (

fullmonty October 19, 2006 23:09

UDF programming
I need to write a udf to connect my fairly complex Fortran program into my Fluent model.

As a C programming novice, I have been reading the UDF manual and primarily using the example in the UDF manual 8.4.1 as a guide, I have come to the following understanding:

1. Write a C file to take the parameters from the fortran file and pass them to the udf

2. Write an on-demand UDF to display parameters from this C file

3. Compile and Hook the UDF to Fluent

Now my problems...

Firstly, I don't know what the C file in point 1. is supposed to do and how it will pass the fortran parameters to the UDF file.

Secondly, my UDF layout so far is outlined below. The C file I don't quite know what to do with will most likely be called ashdep and is referred to inside the DEFINE_ON_DEMAND parantheses... am I on the right track?

#include "udf.h"



Domain *domain;

domain = Get_Domain(1);

Message("Depth of Ash Deposited: %g\n", ash_depth);


Any help or suggestions would be very much appreciated.

max October 20, 2006 08:13

Re: UDF programming
Hi Fullmonty. I think the easiest way to do is to translate your Frotran program into a C program. May be will it take you less time to write a new program than translate the frotran to C and load th parameters through another program. Tell us what you think about that. Good Luck

jasond October 20, 2006 12:28

Re: UDF programming
I'd say that your understanding is generally correct as you stated it. The one thing I would modify is that the connection between your Fortran code and Fluent need not be through DEFINE_ON_DEMAND. Now, to your two questions:

"Firstly, I don't know what the C file in point 1. is supposed to do..."

The C code you need to write will be the glue between your Fortran code and Fluent. I'll just make something up: suppose I have a Fortran code that computes a velocity magnitude from an analytical solution:


and I want to use that as a velocity boundary condition. The UDF glue that I'll need will look something like:

real x[ND_ND];
face_t f;
F_PROFILE(f,t,i) = velprof_mangled(&x[0],&x[1],&x[2]);

I haven't compiled this, so the details might not be quite right. And we'd need to figure out the whole name mangling issue. At any rate, that's the general idea. The second part of your question (about how parameters are passed back and forth) is harder to answer, but I would expect that you might need to write some code to move data back and forth between your Fortran code and Fluent.

"Secondly, my UDF layout so far is outlined below..."

I don't know exactly what you need to pass back and forth, so I can't say for sure if that is the right track or not. If your Fortran calculation is simple, that might be enough. More detail on what your Fortran calculation needs would help me point you in the right direction.


fullmonty October 20, 2006 23:14

Re: UDF programming

Translating the program into C would be more straight forward, but after this initial trial, I have several other fortran programs which we want to run, and this one alone is extremely long and complicated, so I keep that as my back up plan... along that line however, I know f2c has shown mixed results with this type of translation, do you know a better way?

fullmonty October 20, 2006 23:31

Re: UDF programming

Thanks for the advice on DEFINE statements, my reason for using on_demand was simply because that's how it was illustrated in the example and so I'll continue to investigate other DEFINE statements in the manual to choose one that suits better.

The FORTRAN is an ash deposition program which takes user inputs on boundary layers, viscosities, temperatures etc, and finally returns a deposition volume. It will need to take temperature and particle properties from the FLUENT model and return the Message to the fluent window stating the deposition thickness for a particular area selected.

Your suggestion for the glue program sounds good and I'll have a go at customising it. The program is fairly complex so may need me to ask your advice as I go!


Ehsan-F June 30, 2011 02:40

Hi fullmonty,
Since the post was for 2006, I am assuming that you already solved the problem! I am doing the same task and my FORTRAN code is not simple to translate to C. I like to know how you solved the problem and which option was the best?

All times are GMT -4. The time now is 20:14.