CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   fluent udf problem: write specific data for every iteration in a file. (

nnvoro May 23, 2013 14:20

fluent udf problem: write specific data for every iteration in a file.
Hi guys,

I have a problem with my calculations in Fluent. Could somebody please help me with it?

I calculate blood flow in a straight pipe with taper. I use parallel calculations with 4 processors. I need to store pressure data for specific plane for each iteration. As I know there are at least 2 way to do that:

The first one is to write macro and to run command after each iteration. But it doesn't work for me because fluent overwrites file after each iteration. I could add the number of iteration in the name of file so that files don't overwrite. But I would have too much files stored if I save separate file for each iteration.

Second way is to write udf which writes pressure measurement in a file for each iteration. I tried to write it but it doesn't work and I can't find the reason why it doesn't work. Fluent interprets it but when I execute udf Fluent crashes. There is the code for my last udf:

#include "udf.h"

FILE *fp;
Domain *domain;
Thread *t;
real p4 ,p5;
real p_monitor;
real Lh = 236;

t=Lookup_Thread(domain, 4); /**/
p4 = C_P(1,t); /*pressure in plane-4*/
t=Lookup_Thread(domain, 5);
p5 = C_P(1,t); /*pressure in plane-5*/

fp = fopen("output_file.txt","w");
fprintf(fp, "%f", p_monitor);

I simply take the pressure in the cell #1 for two planes, which are defined by ids: 4 and 5. For my case pressure should be the same everywhere in the plane-4 and it is the same everywhere in the plane-5 and it doesn't matter which cell I take, thus I could take cell#1.

Could the reason why my udf doesn't work be that I run Fluent in parallel?

nnvoro May 27, 2013 15:26

It turned out that reading and writing files require parallelization of serial source code: Need to rewrite completely my udf.
For the people who might be interested in the same problem, I found useful example (Example: Writing Data to a Common File on the Host Process's File System):

All times are GMT -4. The time now is 04:52.