CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   fluent udf problem: write specific data for every iteration in a file. (http://www.cfd-online.com/Forums/fluent-udf/118262-fluent-udf-problem-write-specific-data-every-iteration-file.html)

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"

DEFINE_EXECUTE_AT_END(execute_at_end)
{
FILE *fp;
Domain *domain;
Thread *t;
real p4 ,p5;
real p_monitor;
real Lh = 236;

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

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

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: http://jullio.pe.kr/fluent6.1/help/html/udf/node187.htm. 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): http://cdlab2.fluid.tuwien.ac.at/LEH...df/node219.htm


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