CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   UDF to read and write data (

Mcgregor June 6, 2003 07:05

UDF to read and write data

Does anyone know how i should go about including a section in a UDF that reads an entire data file once certain conditions are reached.

I monitor the temperature at a point throughout a simulation and once that temperature reaches a certain value, i want to read in another data file without having to be at my computer to reinitialise.

Any ideas? All help will be gratefully received


Alex Munoz June 6, 2003 14:14

Re: UDF to write data

Follow this pice of code that I wrote for this purposes. Keep in mind that fluent does not allow you to write the filename on your screen therefore you must to change the filename on this C-code, also you have to store that information on a UDM or UDS

Do not forget to request in fluent one or more than one UDM memory. (I don't know how may data do you have). In addition I paste the basic comand that you need to made this task. Hoever, you can made your code much more complex. (I left this part to you..)

/************************************************** ********************/ /* UDF to read a scalar from an external file and stored in UDM Memory*/ /************************************************** ********************/

#include "udf.h" #include "sg.h" #include "dpm.h"

#define UDM_RH 0 #define N_REQ_UDM 1

DEFINE_ON_DEMAND(add_data) { extern Domain* domain; cell_t cell; Thread *thread; real x[ND_ND]; real a[4]; int i; char filename[]="myfilename.txt"; FILE *sfp; /*destination file pointer*/

Message("\n FILENAME:%s\n",filename);

sfp = fopen(filename, "r"); if(sfp == NULL) { Message("\n Warning: unable to open %s for reading\n", filename);






fscanf(sfp, "%g", &a[0]);

C_UDMI(cell,thread,UDM_RH) = a[0];



} fclose(sfp); }

Alex Munoz June 6, 2003 14:18

Re: UDF to read and write data

Sorry I misunderstood your question you can use several functions such us define macro under comands or read and write under define UDF functions

Best regards

Alex Munoz

Mcgregor June 9, 2003 07:52

Re: UDF to read and write data
Hi Alex,

How do i use read or write under define UDF functions?

What line do i include in my UDF?

Is it a simple as:

read-file ("path/filename")



Alex Munoz June 9, 2003 13:21

Re: UDF to read and write data

I gave a code then compiled it, then under UDF load the library.

Then under execute on demand browse the name of the code (i.e., add_data) and excecuted.

However, what you want to do is totally diferent, Fluent allow you to import an external file that could contained a scalar field, boundary condition etc.

If I understood you problem you want to read a data file after a certain number of iteration. Therefoer, you must to search how to create a macro. I have never made this type of work so you have to find the information by yourself.


Alex Munoz

All times are GMT -4. The time now is 03:32.