CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Writing txt file in an UDF (https://www.cfd-online.com/Forums/fluent-udf/129303-writing-txt-file-udf.html)

sayan_bose February 2, 2014 12:11

Writing txt file in an UDF
 
I want to write the particle accelerations in a separate txt file, in a DPM_BODY_FORCE UDF, by performing a file operation, to do that I added this few line in the DPM body force UDF, which logically should have worked.

But after loading the udf, when I am executing calculation fluent is getting closed when the particle update is about to happen, and the txt files created doe not have any thing in them, they are just blank.

This is the code, which just show the file operation part along with the conventional DPM body force codes, please tell me where I have gone wrong and what should I do to correct it.

DEFINE_DPM_BODY_FORCE(particle_body_force,p,i)
{
FILE *x_comp;
FILE *y_comp;
FILE *z_comp;

real bforce,bforcex,bforcey,bforcez;

x_comp=fopen("x-comp.txt","w");
y_comp=fopen("y-comp.txt","w");
z_comp=fopen("z-comp.txt","w");

x=P_POS(p)[0]-xmag;
y=P_POS(p)[1]-ymag;
z=P_POS(p)[2]-zmag;
modr=............................................. ........
................................Denomx;


if(i==0.)

{
bforcex=bforce*unitsx;
Ax = bforcex/P_MASS(p);
fprintf(x_comp,"%g\t\n",Ax);

}
else if(i==1.)
{
bforcey=bforce*unitsy;
Ay = bforcey/P_MASS(p);
fprintf(y_comp,"%g\t\n",Ay);

}
else if(i==2.)
{
bforcez=bforce*unitsz;
Az = bforcez/P_MASS(p);
fprintf(z_comp,"%g\t\n",Az);

}

return((bforce)/P_MASS(p));

fclose(x_comp);
fclose(y_comp);
fclose(z_comp);


}

pakk February 3, 2014 07:52

It can be that you still have the files opened in some editor (notepad or whatever). I think I did that once and then Fluent also shut down without warning.


All times are GMT -4. The time now is 19:24.