CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   Not able to interpret UDF (http://www.cfd-online.com/Forums/fluent/45729-not-able-interpret-udf.html)

Prasad August 15, 2007 05:13

Not able to interpret UDF
 
I am not able to Interpret the following UDF in Fluent6.2.16 on Unix. Error seems to be in FILE *fp. And it gives a message that line 14: syntax error (ie FILE *fp) and line 15: undeclared fp (ie fp = fopen...). Can some one let me know how I should modify this. Thanks in advance. (This UDF is intended to print out the data for the boundary at the end of run for steady state. In future I want to modify it to do the same for every time step for transient case)

#include "udf.h"

DEFINE_EXECUTE_AT_END(acoustic)

{

face_t f;

cell_t c0;

Thread *t0;

Domain *d;

real u, v, w, psta, ke, epsi;

real x[3];

Thread *t_boundary;

d = Get_Domain(1);

t_boundary = Lookup_Thread(d, 1);

/* Change this number to the ZONE-ID of the BC for which data is needed*/

FILE *fp;

fp = fopen("acoustic.out", "w");

fprintf(fp, "x y z u v w psta Turb-KE Epsilon \n");

begin_f_loop(f, t_boundary)

{

F_CENTROID(x, f, t_boundary);

c0 = F_C0(f, t_boundary);

t0 = THREAD_T0(t_boundary);

u = C_U(c0, t0);

v = C_V(c0, t0);

w = C_W(c0, t0);

psta = C_P(c0, t0);

ke = C_K(c0, t0);

epsi = C_D(c0, t0);

fprintf(fp, "%8.3d %8.3d %8.3d %8.3d %8.3d %8.3d %8.3d %8.3d %8.3d\n", x[1], x[2], x[3], u, v, w, psta, ke, epsi);

} end_f_loop(f, t_boundary) fclose(fp); }


Prasad August 15, 2007 09:44

Re: Not able to interpret UDF
 
I could figure out what was the problem. Please find below the correct UDF.. in some one is interested, can use it.. It writes out the data for boundary after each iteration in steady state (run it with UDF just for 1 iteration if you need data). It also writes the data for transient for every time step. but the file is over written every time.. To avoid it you can append to the same file or write a small C program to change the file with each timestep...

#include "udf.h"

DEFINE_EXECUTE_AT_END(acoustic)

{

face_t f;

cell_t c0;

Thread *t0;

Domain *d;

real u, v, w, psta, ke, epsi;

real x[ND_ND];

Thread *t_boundary;

int curr_ts, n;

FILE *fp;

n = 0;

d = Get_Domain(1);

t_boundary = Lookup_Thread(d, 15);

/* Change this number to the ZONE-ID of the BC for which data is needed*/

curr_ts = N_TIME; fp = fopen("acoustic.out", "w");

fprintf(fp, "Time Step = %d \n", curr_ts);

fprintf(fp, " S.No. x y z u v w psta Turb-KE Epsilon \n");

begin_f_loop(f, t_boundary)

{

n++;

F_CENTROID(x, f, t_boundary);

c0 = F_C0(f, t_boundary);

t0 = THREAD_T0(t_boundary);

u = C_U(c0, t0);

v = C_V(c0, t0);

w = C_W(c0, t0);

psta = C_P(c0, t0);

ke = C_K(c0, t0);

epsi = C_D(c0, t0);

fprintf(fp, "%7d %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f\n", n, x[0], x[1], x[2], u, v, w, psta, ke, epsi);

}

end_f_loop(f, t_boundary)

fclose(fp);

}



All times are GMT -4. The time now is 18:43.