CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   Open files in a UDF (

Riccardo June 25, 2002 04:09

Open files in a UDF
Hi everyone! could you tell me in which way I can access data stored in a file and use it in UDF to define a profile? I'm not so expert in C language, and the UDF i've made is this one:

#include "udf.h" DEFINE_PROFILE(wall_temp,thread,position) { face_t f; real cond; FILE *fp; fp=fopen("space/ICADdisk/provafile.ext,"r"); begin_f_loop (f,thread) {


F_PROFILE(f,thread,position) = cond; } end_f_loop (f,thread) }

Fluent can compile the UDF, but when I try to initialize the solution to start the iterations, i get a"SEGMENTATION VIOLATION" error. What can I do? Thank you! Riccardo

Greg Perkins June 25, 2002 20:04

Re: Open files in a UDF
Its probably best not to do file manipulation inside a DEFINE_PROFILE rotuine - since this can be executed frequently during the solution process.

I've been using file read/writes for a long time, without problems. In the past I found it best to use format of "%f" for single precision and "%lf" for double precision in the read statements. Never tried the "%g" format.

Here's some other tips:

1. open and then close files - don't leave open as in the above code 2. probably do the file stuff in a routine called from either a DEFINE_INITIALIZE or DEFINE_ON_DEMAND. 3. if you use parallel fluent - you will need to pay special attention when writing files. reading should be ok, but writing is best performed by only the host or a specified node - this will require #ifdef switches in your code.

Good Luck


Lanre June 26, 2002 10:45

Re: Open files in a UDF

Missing a quote here------------------^

All times are GMT -4. The time now is 09:57.